PHP SDK Sample: Download specific order and extract fields

This example downloads a specific order and extracts a set of payment related fields.

 

<?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") ); // TODO: Replace this with the order id you want to query $sourceOrderId = "DEMO-1242889"; $_expand = "payment"; // Expansion controls how much data about an object comes back. In this example we only need payment detail. // Query the order $result = $api_instance->getOrder($sourceOrderId, $_expand); // Was the API call successful? if ($result->getSuccess()) { // Grab the order object $order = $result->getOrder(); // Dump the result for debug // var_dump($order); $currentStage = $order->getCurrentStage(); $paymentStatus = $order->getPayment()->getPaymentStatus(); $paymentDate = $order->getPayment()->getPaymentDts(); $paymentMethod = $order->getPayment()->getPaymentMethod(); echo "\$currentStage : " . $currentStage . PHP_EOL; echo "\$paymentStatus : " . $paymentStatus . PHP_EOL; echo "\$paymentDate : " . $paymentDate . PHP_EOL; echo "\$paymentMethod : " . $paymentMethod . PHP_EOL; if ($paymentMethod == "Credit Card") { $cardType = $order->getPayment()->getCreditCard()->getCardType(); $cardNumber = $order->getPayment()->getCreditCard()->getCardNumber(); // Masked number $cardExpMonth = $order->getPayment()->getCreditCard()->getCardExpirationMonth(); $cardExpYear = $order->getPayment()->getCreditCard()->getCardExpirationYear(); $cardAuthTicket = $order->getPayment()->getCreditCard()->getCardAuthTicket(); echo "\$cardType : " . $cardType . PHP_EOL; echo "\$cardNumber : " . $cardNumber . PHP_EOL; echo "\$cardExpMonth : " . $cardExpMonth . PHP_EOL; echo "\$cardExpYear : " . $cardExpYear . PHP_EOL; echo "\$cardAuthTicket: " . $cardAuthTicket . PHP_EOL; } } ?>