PHP SDK Sample: Custom Thank You From Order Token

This example will show you have to use the [OrderToken] on your custom thank you URL and then take that token and retrieve the order using an SDK sample. First lets cover how to configure the token. Pay close attention to using the ? mark if this is your first parameter or & if it’s an additional parameter as your separator.

Now on to the SDK example. This example will read the encrypted token off the URL, use the Order REST API to retrieve the order and also demonstrate using our formatters.

 

<?php require_once __DIR__ . '/vendor/autoload.php'; // TODO: Replace YOUR KEY HERE with an Application API Key that has read permission to the order resource. // Configure API key authorization: ultraCartSimpleApiKey ultracart\v2\Configuration::getDefaultConfiguration()->setApiKey('x-ultracart-simple-key', 'YOUR API KEY HERE'); // Disable SSL verification if we're having issues with this PHP install not having the proper CA installed. Fix your CA for a production environment! // Set debug to true if you need more information on request/response $client = new GuzzleHttp\Client(['verify' => false, 'debug' => false]); $api_instance = new ultracart\v2\api\OrderApi( $client, ultracart\v2\Configuration::getDefaultConfiguration(), new ultracart\v2\HeaderSelector("2016-10-01") ); // Extract the token from the parameters passed to our URL $orderToken = $_GET["orderToken"]; // Setup the query object $orderByTokenQuery = new ultracart\v2\models\OrderByTokenQuery(); $orderByTokenQuery->setOrderToken($orderToken); /* Determine how much data that you need to expand. Valid values are: affiliate affiliate.ledger auto_order billing buysafe channel_partner checkout coupon customer_profile digital_order edi fraud_score gift gift_certificate internal item linked_shipment marketing payment payment.transaction quote salesforce shipping summary taxes */ $_expand = "billing,coupon,digital_order,item,payment,shipping,summary,taxes"; // Grab the order $result = $api_instance->getOrderByToken($orderByTokenQuery, $_expand); if ($result->getSuccess()) { $order = $result->getOrder(); // Dump the result for debug // var_dump($order); // TODO: If you want to get rally fancy you can take the $order object and output your entirely custom HTML DOM instead of using our formatter method // Generate a text formatted version of the order for display. $formatOptions = new \ultracart\v2\models\OrderFormat(); $formatOptions->setFormat("text"); // Valid options are: text, div, table $formattedOrder = $api_instance->format($order->getOrderId(), $formatOptions); echo $formattedOrder->getFormattedResult(); } ?>