On the previous posts we went over the different options of online payment processing and then dived a bit deeper into a discussion about how user-experience effects the conversion and how can we improve both by using an API.
The last two examples showed how to use an API in order to create a shopper entity on Bluesnap servers and then use it with a token (which was generate by the API as well) in order to “log the shopper into” a buy page, meaning, redirect the shopper to a buy-page where all his information (except the billing information) is pre-filled. The reason we couldn’t pre-fill the billing info is due to regulations forced on us by the credit-card companies: a merchant which is not PCI compliant, should not hold billing information records of his/her customers. It sounds like this restriction sucks, but it’s actually very good since it forces us to protect our clients data!
That said, we still want to provide the best customer experience to our shoppers, and by using an API we can do just that. The last post gave us the “taste” of what can be achieved and now we’ll see the “real thing”: after a shopper already placed an order and bought one of our products, we may offer the customer a promo-code for future purchase or an upgrade for a reduced price etc. Even though we don’t have the shopper’s billing information the processor (Bluesnap) does – and we’ll take advantage of it to create a single-click order experience.
Since we created the shopper entity we have a “shopper-id” (unique identifier for a shopper – supplied by the processor) which we can use to place future orders:
<?php /* * Written By: Ben Hultin & Nir Alfasi (alfasin) * Nov. 2012 * * This code is used to call an API (RESTful) service of Bluesnap that places an order on Bluesnaps' backend. * We chose using CURL to place the API request in this demo, but we urge anyone who implements an API client * to work with a RESTful API client framework in order to have a full support of all the properties of REST, such as: * set HTTP method, get return-code, read/write headers, full XML support etc. * * The API manual is available under "Developer Toolbox" section: * http://www.bluesnap.com/helpcenter/Static/default.htm?bluesnap_web_services.htm * */ //here we define $credentials = $username . ":" . $password; include_once('../credentials.php'); /** * Retrieve data from input fields */ $shopperId = $_REQUEST['shopper-id']; $cardLastFour = $_REQUEST['card-last-four-digits']; $cardType = $_REQUEST['card-type']; $skuId = $_REQUEST['sku-id']; $amount = $_REQUEST['amount']; $currency = $_REQUEST['currency']; /** * Assemble the XML string with variables instantiated above */ $xmlToSend = '<order xmlns="http://ws.plimus.com"> <soft-descriptor></soft-descriptor> <ordering-shopper> <credit-card> <card-last-four-digits>'.$cardLastFour.'</card-last-four-digits> <card-type>'.$cardType.'</card-type> </credit-card> <shopper-id>'.$shopperId.'</shopper-id> <web-info> <ip>'.$ipAddress.'</ip> <remote-host>bzq-219-121-253.static.bezeqint.net.reinventhosting.com</remote-host> <user-agent>Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.3; .NET CLR 2.0.50727)</user-agent> <accept-language>en-us</accept-language> </web-info> </ordering-shopper> <cart> <cart-item> <sku> <sku-id>'.$skuId.'</sku-id> </sku> <quantity>1</quantity> </cart-item> </cart> <expected-total-price> <amount>'.$amount.'</amount> <currency>'.$currency.'</currency> </expected-total-price> </order>'; /** * Initialize handle and set options */ $url = 'https://sandbox.plimus.com/services/2/orders/'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/xml")); curl_setopt($ch, CURLOPT_USERPWD, "$credentials"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlToSend); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); /** * Execute Curl call and display XML response */ $response = curl_exec($ch); curl_close($ch); echo show_xml($response); ?>
By clicking on the following link you’ll place a (single-click) order in Bluesnap’s sandbox using the API code displayed above.