home > support > API > Marketplace API > Create new Spreedly Payment
Charge a credit card vaulted with Spreedly, storing details of the transaction on the booking and on success automatically committing the booking (if not already committed)
For those using Spreedly as a gateway this replaces the generic Payment Create API method and possibly also the Booking Commit method. Allows charging of a card using a payment token obtained via one of Spreedly's card collection methods (environment keys available via the Show Channel API).
For environments where AVS is likely to be enabled (i.e. most online transactions) do ensure you are providing Spreedly with the clients billing address at the poinft of adding the payment method. In the case of the JSONP/CORS methods you can check this has been stored successfully by viewing the response from Spreedly.
Learn more about TourCMS Spreedly integration
Endpoint | /c/booking/payment/spreedly/new |
Formats | XML |
Example | URL: /c/booking/payment/spreedly/new.xml POST data:
|
Verb | POST |
PHP examples use the PHP Client Library with SimpleXML
object spreedly_create_payment ( SimpleXMLElement $payment_data, int $channel )
// Set your Channel ID, as per the TourCMS API settings page
$channel = 3;
// Create a new SimpleXMLElement to hold the payment details
$payment = new SimpleXMLElement('<payment />');
// Set the Spreedly payment method token to use
$payment->addChild('spreedly_payment_method', 'AAABBBCCCDDDDEEE');
// Must set the Booking ID on the XML, so TourCMS knows which to update
$payment->addChild('booking_id', '194');
// Must set the value of the payment
$payment->addChild('payment_value', '20');
// Must set the currency
$payment->addChild('payment_currency', 'GBP');
// (optional - only using Trust My Travel) Send cardholder details
// instead of using lead customer details
$customer = $payment->addChild('cardholder_customer');
$customer->addChild('firstname', 'Cardholder name');
$customer->addChild('surname', 'Cardholder surname');
$customer->addChild('email', 'email@example.com');
$customer->addChild('address', 'Cardholder address');
$customer->addChild('city', 'Cardholder city');
$customer->addChild('county', 'Cardholder county');
$customer->addChild('country', 'Cardholder country');
$customer->addChild('postcode', 'Cardholder postcode');
$customer->addChild('tel_home', 'Cardholder tel_home');
// Call TourCMS API, charging the card
$result = $tourcms->spreedly_create_payment($payment, $channel);
if($result->error == "OK") {
// Spreedly has successfully charged the card
// TourCMS has committed the booking (if not already committed)
// And stored details of the payment on the booking
print "Thanks, payment added";
} else {
// Spreedly was unable to charge the card
// In the case of a 3D Secure transaction,
// further processing may be required
print "Transaction not complete";
}
Thanks, payment added
C# examples use the .Net Client Library
XmlDocument SpreedlyCreatePayment ( XmlDocument paymentData, int channelId )
// Set the ID for the channel the booking is made with
int channelID = 3;
// Create an XMLDocument to hold the payment details
XmlDocument paymentData = new XmlDocument();
// Create the XML Declaration, append it to XML document
XmlDeclaration dec = paymentData.CreateXmlDeclaration("1.0", null, null);
paymentData.AppendChild(dec);
// Create the root element, append it to the XML document
XmlElement root = paymentData.CreateElement("payment");
paymentData.AppendChild(root);
// Now add the various elements to the payment
// Must set the Booking ID so TourCMS knows which booking to add payment onto
XmlElement bookingId = paymentData.CreateElement("booking_id");
bookingId.InnerText = "12345";
root.AppendChild(bookingId);
// _MUST_ set the value of the payment (negative if it's a refund)
XmlElement paymentValue = paymentData.CreateElement("payment_value");
paymentValue.InnerText = "100";
root.AppendChild(paymentValue);
// Must set the currency
XmlElement paymentCurrency = paymentData.CreateElement("payment_value");
paymentCurrency.InnerText = "GBP";
root.AppendChild(paymentCurrency);
// Set the Spreedly payment token (credit card) to use
XmlElement paymentToken = paymentData.CreateElement("payment_token");
paymentToken.InnerText = "AAABBBCCCDDD";
root.AppendChild(paymentToken);
// Send the data to the TourCMS API, recording the payment/refund
XmlDocument doc = myTourCMS.SpreedlyCreatePayment(paymentData, channelId);
// Check the status
// Will be "OK" if the payment was stored successfully
string status = doc.SelectSingleNode("//error").InnerText;
Console.WriteLine(status);
OK
VB examples use the .Net Client Library
XmlDocument SpreedlyCreatePayment ( XmlDocument paymentData, Integer channelId )
' Set the ID for the channel the booking is made with
Dim channelID As Integer = 3
' Create an XMLDocument to hold the payment details
Dim paymentData As XmlDocument = new XmlDocument()
' Create the XML Declaration, append it to XML document
Dim dec As XmlDeclaration = paymentData.CreateXmlDeclaration("1.0", null, null)
paymentData.AppendChild(dec)
' Create the root element, append it to the XML document
Dim root As XmlElement = paymentData.CreateElement("payment")
paymentData.AppendChild(root)
' Now add the various elements to the payment
' Must set the Booking ID so TourCMS knows which booking to add payment onto
Dim bookingId As XmlElement = paymentData.CreateElement("booking_id")
bookingId.InnerText = "12345"
root.AppendChild(bookingId)
' _MUST_ set the value of the payment (negative if it's a refund)
Dim paymentValue As XmlElement = paymentData.CreateElement("payment_value")
paymentValue.InnerText = "100"
root.AppendChild(paymentValue)
' Must set the currency
Dim paymentCurrency As XmlElement = paymentData.CreateElement("payment_value")
paymentCurrency.InnerText = "GBP"
root.AppendChild(paymentCurrency)
' Set the Spreedly payment token (credit card) to use
Dim paymentToken As XmlElement = paymentData.CreateElement("spreedly_payment_method")
paymentToken = "AAAABBBBCCCCDDD"
root.AppendChild(paymentToken)
' Send the data to the TourCMS API, recording the payment/refund
Dim doc As XmlDocument = myTourCMS.SpreedlyCreatePayment(paymentData, channelId)
' Check the status
' Will be "OK" if the payment was stored successfully
Dim status As String = doc.SelectSingleNode("//error").InnerText
Console.WriteLine(status)
OK
NodeJS examples use the NodeJS Wrapper
// Tell spreedly to charge 10GBP to the card represented by SPREEDLY_PAYMENT_METHOD_TOKEN
TourCMS.createSpreedlyPayment({
channelId: 3930,
payment: {
spreedly_payment_method: "SPREEDLY_PAYMENT_METHOD_TOKEN",
booking_id: "8400",
payment_value: "10",
currency: "GBP"
},
callback: function(response, status) {
console.log(response.error);
}
});
OK
Looking for sample code in a different language? TourCMS and community provided API libraries
Enter your TourCMS API credentials below to call the Send booking email endpoint.
Take care, submitting this form will modify live data!
There are no querystring parameters supported by this method.
The following fields can be posted as XML when calling the API.
XML Node | Notes | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
payment |
The root XML element, can contain any of the following child nodes.
|
XML Node | Notes | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
request | Confirmation of the request that you sent | ||||||||||||||||||||||||||||
error | An error response of "OK" indicates a transaction has succeeded, otherwise an error will be displayed indicating the issue In the case of 3D Secure transactions, instead check the //transaction/state and //transaction/required_action before deciding how to continue. |
||||||||||||||||||||||||||||
booking |
If the booking is found the booking node will contain the following child nodes.
|
Caution: This is an advanced and potentially complex topic.
Payment via installments is a feature popular and often supported by gateways in countries such as Brazil, Mexico, Turkey and Japan whereby the customers card is billed in regular incremements, e.g. speading a payment over 6 payments, one every 30 days.
Installment support (including the allowed number of installments) can vary by gateway, merchant country, customer country etc. It is the responsibility of the API consumer to understand when and how many installments to offer.
The following is an example of a payment request with installments, based on this TourCMS will instruct Spreedly to pass the appropriate gateway-specific field(s).
<?xml version="1.0"?>
<payment>
<spreedly_payment_method>AAABBBCCC</spreedly_payment_method>
<booking_id>12345</booking_id>
<payment_value>120</payment_value>
<payment_currency>EUR</payment_currency>
<installments>
<count>6</count>
</installments>
</payment>
If your payment facilities have been provided by Trust My Travel and you are looking to implement their Multi Currency Pricing functionality - allowing your customers to pay in their own currency, yet have the correct amount be deducted from the TourCMS - you should use the following logic:
Use payment_value and payment_currency as normal
Send the amount to bill the customer (i.e. their chosen payment currency) as payment_value and payment_currency, then send the amount to store on the sales ledger (i.e. the amount in your sale currency) as salesledger_payment_value and salesledger_payment_currency.
Trust My Travel will calculate the exchange rate you have used and verify that it is in a range that they will accept, if so they will attempt to charge the customer to the value of payment_value and if the payment is successful TourCMS will update the customers booking with a payment to the value salesledger_payment_value, keeping a note of the amount that the customer paid.