Order API Calling the Order API
Given the PHP data structure created in the examples section, the following code will make a complete checkout.
-Note that all numbers have to be integers, i.e. 21.35€ should be sent as 2135. Note also that the API expects the sum of all the order rows to equal order_total_with_tax and will reject requests if this does not hold. This protects your implementation against forgetting things like shipment costs, discounts, etc.
Also note that the client library (from the PrestaShop references implementation) adds the root element ("order"
) to the request, so if you implement your own client, you will need to do
the same.
$client = new SequraClient('the_username', 'the_password', 'https://sandbox.sequrapi.com/orders');
// 1. This is the POST step that creates the order solicitation on the server side.
$client->startSolicitation($order);
if ($client->succeeded()) {
$sequra_order_url = $client->getOrderUri();
setcookie('sequra_order_url', $sequra_order_url);
} else {
// handle error
}
// 2. This GETs the form that you need to include in the page.
// If you use REST "by the book" this action should take place in a
// separate server action and then you need to find the URL in the
// cookie:
$sequra_order_url = $_COOKIE['sequra_order_url'];
$html = $client->getIdentificationForm($sequra_order_url);
// Display a page where you include the $html and wait for the callback
// to $order["merchant"]["approved_url"]
// 3. This is the callback step. At this point the shopper might have changed
// the content of the order cart in another browser tab, so you need to confirm
// with SeQura that any changes are OK. For instance, it is OK if the shopper
// removes an item but not if they add one.
$sequra_order_url = $_COOKIE['sequra_order_url'];
$sequra_order = buildOrderStructureFromCart(); // implement this!
$client->updateOrder($sequra_order_url, $sequra_order);
if (! $client->succeeded()) {
if ($client->cartHasChanged()) {
// Tell shopper that they need to start over since their cart has
// changed.
} else {
// Handle unexpected error
}
exit();
}
// 4. Tell SeQura what your order number is so that shoppers and your own support
// staff can refer to this when they communicate with SeQura. This usually
// follows directly on step 3.
$order_ref = saveCurrentCartAsOrder(); // implement this!
$extra = array('merchant_reference' => array('order_ref_1' => $order_ref));
$order_2 = array_merge($order, $extra);
$client->updateOrder($this->sequra_order_url, $order_2);
if (! $client->succeeded()) {
// Handle exception
}
Note about title
There is an optional title
field in the customer
block, and its preferred values are
mr
for “Mr.”, “Mister”, “Sr.”, “Señor”, etcmrs
for “Mrs.”, “Sra.”, “Señora”, etcmiss
for “Miss”, “Srta.”, “Señorita”, etcms
for “Ms.” or any other title that indicates a woman but does not indicate marital statusmx
for “Mx.” or any other title that indicates that the bearer chose not to identify with a specific gender
Titles which do not fall into these categories, e.g. “Prof.”, “Dr.”, etc, may be used as-is.