<?php // make sure you place the purchasedat_sdk.php file is present on your server require_once 'purchasedat_sdk.php'; $apiKey = 'REPLACE_WITH_API_KEY'; $apiClient = new PurchasedAt\APIClient($apiKey); // this will work when called from a purchased.at redirect, // if you want to fetch the information of any transaction use // $apiClient->fetchTransaction('REPLACE_WITH_TRANSACTION_ID') $result = $apiClient->fetchTransactionForRedirect(); // if the request failed for any reason success will be false and processing SHOULD BE aborted if (!$result->success) { die('request failed: ' . $result->errorCode); } // the response field of an API result will always contain the data that was requested $transaction = $result->result; printf('Transaction: %s (created=%s, state=%s, paymentmethod=%s, test=%s)<br>', $transaction->getId(), date('c', $transaction->getCreated()), $transaction->getState(), $transaction->getPaymentMethod(), $transaction->isTest() ? 'true' : 'false'); $customer = $transaction->getCustomer(); printf('Customer: %s (country=%s, language=%s)<br>', $customer->getEmail(), $customer->getCountry(), $customer->getLanguage()); $item = $transaction->getItem(); printf('Item: %s (sku=%s)<br>', $item->getId(), $item->getSku()); // transaction can be of type simple checkout if this feature has been enabled on the project, otherwise they are items created in the vendor portal switch ($transaction->getType()) { case 'item': $item = $transaction->getItem(); printf("Item: %s (sku=%s)<br>", $item->getId(), $item->getSku()); break; case 'checkout': $checkout = $transaction->getCheckout(); printf("Checkout: %s %s", $checkout->getTotal()->getGross(), $checkout->getTotal()->getCurrency()); foreach ($checkout->getItems() as $item) {