<?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) {
// make sure you place the purchasedat_sdk.php file is present on your server require_once 'purchasedat_sdk.php'; $apiKey = 'REPLACE_WITH_API_KEY'; // be sure to specify the customer's e-mail address (mandatory!) $options = new \PurchasedAt\PurchaseOptions('*****@*****.**'); // test mode $options->setTestEnabled(true); // $options->setTestCountry('CH'); // $options->setTestLanguage('de'); // redirect url // $options->setRedirectUrl('REPLACE_WITH_REDIRECT_URL'); // callback url (specify your api endpoint to receive transaction status change notifications) // $options->setNotificationUrl('REPLACE_WITH_CALLBACK_URL'); // allow only a specific item to be purchased // $options->setSelectItem('REPLACE_WITH_ITEM_ID'); $apiClient = new PurchasedAt\APIClient($apiKey); $result = $apiClient->sessionEntryUrl($options); if (!$result->success) { die('request failed: ' . $result->errorCode); } $entryUrl = $result->result->getEntryUrl(); ?> <html> <body> <a href="<?php echo $entryUrl; ?> " target="_blank">Open purchased.at</a>
<?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); $result = $apiClient->parseTransactionNotificationForRequest(); if (!$result->success) { error_log(sprintf('failed to process notification: %s'), $result->errorCode); die('failed to handle request'); } $notification = $result->result; error_log(sprintf('transaction: %s, external transaction: %s, new state: %s, revision number: %d, timestamp: %s, test: %s', $notification->getTransactionId(), $notification->getExternalTransactionId(), $notification->getNewState(), $notification->getRevisionNumber(), date('c', $notification->getTimestamp()), $notification->isTest() ? 'true' : 'false'), 0); // react to transaction status accordingly // (e.g. provision service, write to database) // in order to access more transaction details simply fetch the transaction $result = $apiClient->fetchTransaction($notification->getTransactionId()); if (!$result->success) { error_log(sprintf('failed to fetch transaction: %s'), $result->errorCode); die('failed to handle request'); } $transaction = $result->result; // acknowledge the transaction notification (writes a corresponding response) $apiClient->acknowledgeTransactionNotification();