Repository: AuthorizeNet/sample-code-php Branch: master Commit: 6f14b0f30e30 Files: 75 Total size: 236.8 KB Directory structure: gitextract_p37jv6o6/ ├── .gitignore ├── .travis.yml ├── AcceptSuite/ │ ├── create-an-accept-payment-transaction.php │ ├── get-accept-customer-profile-page.php │ └── get-an-accept-payment-page.php ├── CustomerProfiles/ │ ├── create-customer-payment-profile.php │ ├── create-customer-profile-from-transaction.php │ ├── create-customer-profile-with-accept-nonce.php │ ├── create-customer-profile.php │ ├── create-customer-shipping-address.php │ ├── delete-customer-payment-profile.php │ ├── delete-customer-profile.php │ ├── delete-customer-shipping-address.php │ ├── get-customer-payment-profile-list.php │ ├── get-customer-payment-profile.php │ ├── get-customer-profile-ids.php │ ├── get-customer-profile.php │ ├── get-customer-shipping-address.php │ ├── update-customer-payment-profile.php │ ├── update-customer-profile.php │ ├── update-customer-shipping-address.php │ └── validate-customer-payment-profile.php ├── FraudManagement/ │ ├── approve-or-decline-held-transaction.php │ └── get-held-transaction-list.php ├── LICENSE ├── MobileInAppTransactions/ │ ├── create-an-accept-transaction.php │ ├── create-an-android-pay-transaction.php │ ├── create-an-apple-pay-transaction.php │ └── create-google-pay-transaction.php ├── PayPalExpressCheckout/ │ ├── authorization-and-capture-continued.php │ ├── authorization-and-capture.php │ ├── authorization-only-continued.php │ ├── authorization-only.php │ ├── credit.php │ ├── get-details.php │ ├── prior-authorization-capture.php │ └── void.php ├── PaymentTransactions/ │ ├── authorize-credit-card.php │ ├── capture-funds-authorized-through-another-channel.php │ ├── capture-previously-authorized-amount.php │ ├── charge-credit-card.php │ ├── charge-customer-profile.php │ ├── charge-tokenized-credit-card.php │ ├── create-chase-pay-transaction.php │ ├── credit-bank-account.php │ ├── debit-bank-account.php │ ├── refund-transaction.php │ ├── update-split-tender-group.php │ └── void-transaction.php ├── README.md ├── RecurringBilling/ │ ├── cancel-subscription.php │ ├── create-subscription-from-customer-profile.php │ ├── create-subscription.php │ ├── get-list-of-subscriptions.php │ ├── get-subscription-status.php │ ├── get-subscription.php │ └── update-subscription.php ├── SampleCodeList.txt ├── Sha512/ │ └── compute_trans_hashSHA2.php ├── TestRunner.php ├── TransactionReporting/ │ ├── get-account-updater-job-details.php │ ├── get-account-updater-job-summary.php │ ├── get-batch-statistics.php │ ├── get-customer-profile-transaction-list.php │ ├── get-merchant-details.php │ ├── get-settled-batch-list.php │ ├── get-transaction-details.php │ ├── get-transaction-list.php │ └── get-unsettled-transaction-list.php ├── VisaCheckout/ │ ├── create-visa-src-transaction.php │ └── decrypt-visa-src-data.php ├── composer.json ├── composer.json.sdk-dev ├── constants/ │ └── SampleCodeConstants.php └── phpunit.xml.dist ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # Cache and logs (Symfony2) /app/cache/* /app/logs/* !app/cache/.gitkeep !app/logs/.gitkeep # Cache and logs (Symfony3) /var/cache/* /var/logs/* !var/cache/.gitkeep !var/logs/.gitkeep # Parameters /app/config/parameters.yml /app/config/parameters.ini # Managed by Composer /app/bootstrap.php.cache /var/bootstrap.php.cache /bin/* !bin/console !bin/symfony_requirements /vendor/ # Assets and user uploads /web/bundles/ /web/uploads/ # PHPUnit /app/phpunit.xml /phpunit.xml # Build data /build/ # Composer PHAR /composer.phar /composer.lock # log files /phplog # PHP Storm /.idea/* # Operating system files .DS_Store /lib /*.cache /testslog ================================================ FILE: .travis.yml ================================================ language: php matrix: include: - php: 5.6 env: PHPUNIT_VERSION=5.6.* dist: trusty - php: 7.0 env: PHPUNIT_VERSION=5.6.* dist: trusty - php: 7.1 env: PHPUNIT_VERSION=5.7.* dist: trusty - php: 7.2 env: PHPUNIT_VERSION=8.5.* dist: bionic - php: 7.3 env: PHPUNIT_VERSION=9.5.* dist: bionic - php: 7.4 env: PHPUNIT_VERSION=9.5.* dist: bionic - php: 8.0 env: PHPUNIT_VERSION=9.5.* dist: bionic sudo: false before_script: - composer require "phpunit/phpunit:${PHPUNIT_VERSION}" --no-update - composer update --prefer-dist script: - phpunit TestRunner.php . ================================================ FILE: AcceptSuite/create-an-accept-payment-transaction.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Create the payment object for a payment nonce $opaqueData = new AnetAPI\OpaqueDataType(); $opaqueData->setDataDescriptor("COMMON.ACCEPT.INAPP.PAYMENT"); $opaqueData->setDataValue("119eyJjb2RlIjoiNTBfMl8wNjAwMDUyN0JEODE4RjQxOUEyRjhGQkIxMkY0MzdGQjAxQUIwRTY2NjhFNEFCN0VENzE4NTUwMjlGRUU0M0JFMENERUIwQzM2M0ExOUEwMDAzNzlGRDNFMjBCODJEMDFCQjkyNEJDIiwidG9rZW4iOiI5NDkwMjMyMTAyOTQwOTk5NDA0NjAzIiwidiI6IjEuMSJ9"); // Add the payment data to a paymentType object $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setOpaqueData($opaqueData); // Create order information $order = new AnetAPI\OrderType(); $order->setInvoiceNumber("10101"); $order->setDescription("Golf Shirts"); // Set the customer's Bill To address $customerAddress = new AnetAPI\CustomerAddressType(); $customerAddress->setFirstName("Ellen"); $customerAddress->setLastName("Johnson"); $customerAddress->setCompany("Souveniropolis"); $customerAddress->setAddress("14 Main Street"); $customerAddress->setCity("Pecan Springs"); $customerAddress->setState("TX"); $customerAddress->setZip("44628"); $customerAddress->setCountry("USA"); // Set the customer's identifying information $customerData = new AnetAPI\CustomerDataType(); $customerData->setType("individual"); $customerData->setId("99999456654"); $customerData->setEmail("EllenJohnson@example.com"); // Add values for transaction settings $duplicateWindowSetting = new AnetAPI\SettingType(); $duplicateWindowSetting->setSettingName("duplicateWindow"); $duplicateWindowSetting->setSettingValue("60"); // Add some merchant defined fields. These fields won't be stored with the transaction, // but will be echoed back in the response. $merchantDefinedField1 = new AnetAPI\UserFieldType(); $merchantDefinedField1->setName("customerLoyaltyNum"); $merchantDefinedField1->setValue("1128836273"); $merchantDefinedField2 = new AnetAPI\UserFieldType(); $merchantDefinedField2->setName("favoriteColor"); $merchantDefinedField2->setValue("blue"); // Create a TransactionRequestType object and add the previous objects to it $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType("authCaptureTransaction"); $transactionRequestType->setAmount($amount); $transactionRequestType->setOrder($order); $transactionRequestType->setPayment($paymentOne); $transactionRequestType->setBillTo($customerAddress); $transactionRequestType->setCustomer($customerData); $transactionRequestType->addToTransactionSettings($duplicateWindowSetting); $transactionRequestType->addToUserFields($merchantDefinedField1); $transactionRequestType->addToUserFields($merchantDefinedField2); // Assemble the complete transaction request $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setTransactionRequest($transactionRequestType); // Create the controller and get the response $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { // Check to see if the API request was successfully received and acted upon if ($response->getMessages()->getResultCode() == "Ok") { // Since the API request was successful, look for a transaction response // and parse it to display the results of authorizing the card $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Successfully created transaction with Transaction ID: " . $tresponse->getTransId() . "\n"; echo " Transaction Response Code: " . $tresponse->getResponseCode() . "\n"; echo " Message Code: " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Auth Code: " . $tresponse->getAuthCode() . "\n"; echo " Description: " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if ($tresponse->getErrors() != null) { echo " Error Code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } // Or, print errors if the API request wasn't successful } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getErrors() != null) { echo " Error Code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error Code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error Message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if (!defined('DONT_RUN_SAMPLES')) { createAnAcceptPaymentTransaction("2.23"); } ?> ================================================ FILE: AcceptSuite/get-accept-customer-profile-page.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Use an existing payment profile ID for this Merchant name and Transaction key $setting = new AnetAPI\SettingType(); $setting->setSettingName("hostedProfileReturnUrl"); $setting->setSettingValue("https://returnurl.com/return/"); //$alist = new AnetAPI\ArrayOfSettingType(); //$alist->addToSetting($setting); $request = new AnetAPI\GetHostedProfilePageRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setCustomerProfileId($customerprofileid); $request->addToHostedProfileSettings($setting); $controller = new AnetController\GetHostedProfilePageController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { echo $response->getToken()."\n"; } else { echo "ERROR : Failed to get hosted profile page\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) getAcceptCustomerProfilePage(); ?> ================================================ FILE: AcceptSuite/get-an-accept-payment-page.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); //create a transaction $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType("authCaptureTransaction"); $transactionRequestType->setAmount("12.23"); // Set Hosted Form options $setting1 = new AnetAPI\SettingType(); $setting1->setSettingName("hostedPaymentButtonOptions"); $setting1->setSettingValue("{\"text\": \"Pay\"}"); $setting2 = new AnetAPI\SettingType(); $setting2->setSettingName("hostedPaymentOrderOptions"); $setting2->setSettingValue("{\"show\": false}"); $setting3 = new AnetAPI\SettingType(); $setting3->setSettingName("hostedPaymentReturnOptions"); $setting3->setSettingValue( "{\"url\": \"https://mysite.com/receipt\", \"cancelUrl\": \"https://mysite.com/cancel\", \"showReceipt\": true}" ); // Build transaction request $request = new AnetAPI\GetHostedPaymentPageRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setTransactionRequest($transactionRequestType); $request->addToHostedPaymentSettings($setting1); $request->addToHostedPaymentSettings($setting2); $request->addToHostedPaymentSettings($setting3); //execute request $controller = new AnetController\GetHostedPaymentPageController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { echo $response->getToken()."\n"; } else { echo "ERROR : Failed to get hosted payment page token\n"; $errorMessages = $response->getMessages()->getMessage(); echo "RESPONSE : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if (!defined('DONT_RUN_SAMPLES')) { getAnAcceptPaymentPage(); } ================================================ FILE: CustomerProfiles/create-customer-payment-profile.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Create a Customer Profile Request // 1. (Optionally) create a Payment Profile // 2. (Optionally) create a Shipping Profile // 3. Create a Customer Profile (or specify an existing profile) // 4. Submit a CreateCustomerProfile Request // 5. Validate Profile ID returned // Set credit card information for payment profile $creditCard = new AnetAPI\CreditCardType(); $creditCard->setCardNumber("4242424242424242"); $creditCard->setExpirationDate("2038-12"); $creditCard->setCardCode("142"); $paymentCreditCard = new AnetAPI\PaymentType(); $paymentCreditCard->setCreditCard($creditCard); // Create the Bill To info for new payment type $billto = new AnetAPI\CustomerAddressType(); $billto->setFirstName("Ellen".$phoneNumber); $billto->setLastName("Johnson"); $billto->setCompany("Souveniropolis"); $billto->setAddress("14 Main Street"); $billto->setCity("Pecan Springs"); $billto->setState("TX"); $billto->setZip("44628"); $billto->setCountry("USA"); $billto->setPhoneNumber($phoneNumber); $billto->setfaxNumber("999-999-9999"); // Create a new Customer Payment Profile object $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); $paymentprofile->setCustomerType('individual'); $paymentprofile->setBillTo($billto); $paymentprofile->setPayment($paymentCreditCard); $paymentprofile->setDefaultPaymentProfile(true); $paymentprofiles[] = $paymentprofile; // Assemble the complete transaction request $paymentprofilerequest = new AnetAPI\CreateCustomerPaymentProfileRequest(); $paymentprofilerequest->setMerchantAuthentication($merchantAuthentication); // Add an existing profile id to the request $paymentprofilerequest->setCustomerProfileId($existingcustomerprofileid); $paymentprofilerequest->setPaymentProfile($paymentprofile); $paymentprofilerequest->setValidationMode("liveMode"); // Create the controller and get the response $controller = new AnetController\CreateCustomerPaymentProfileController($paymentprofilerequest); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { echo "Create Customer Payment Profile SUCCESS: " . $response->getCustomerPaymentProfileId() . "\n"; } else { echo "Create Customer Payment Profile: ERROR Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if (!defined('DONT_RUN_SAMPLES')) { createCustomerPaymentProfile("1929905607", "000-000-0009"); } ?> ================================================ FILE: CustomerProfiles/create-customer-profile-from-transaction.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); $customerProfile = new AnetAPI\CustomerProfileBaseType(); $customerProfile->setMerchantCustomerId("123212"); $customerProfile->setEmail(rand(0, 10000) . "@test" .".com"); $customerProfile->setDescription(rand(0, 10000) ."sample description"); $request = new AnetAPI\CreateCustomerProfileFromTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setTransId($transId); // You can either specify the customer information in form of customerProfileBaseType object $request->setCustomer($customerProfile); // OR // You can just provide the customer Profile ID //$request->setCustomerProfileId("123343"); $controller = new AnetController\CreateCustomerProfileFromTransactionController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { echo "SUCCESS: PROFILE ID : " . $response->getCustomerProfileId() . "\n"; } else { echo "ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } // Provide a transaction that has customer information if (!defined('DONT_RUN_SAMPLES')) { createCustomerProfileFromTransaction("2249066517"); } ?> ================================================ FILE: CustomerProfiles/create-customer-profile-with-accept-nonce.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Create a Customer Profile Request // 1. (Optionally) create a Payment Profile // 2. (Optionally) create a Shipping Profile // 3. Create a Customer Profile (or specify an existing profile) // 4. Submit a CreateCustomerProfile Request // 5. Validate Profile ID returned // Set the payment data for the payment profile to a token obtained from Accept.js $op = new AnetAPI\OpaqueDataType(); $op->setDataDescriptor("COMMON.ACCEPT.INAPP.PAYMENT"); $op->setDataValue("119eyJjb2RlIjoiNTBfMl8wNjAwMDUyN0JEODE4RjQxOUEyRjhGQkIxMkY0MzdGQjAxQUIwRTY2NjhFNEFCN0VENzE4NTUwMjlGRUU0M0JFMENERUIwQzM2M0ExOUEwMDAzNzlGRDNFMjBCODJEMDFCQjkyNEJDIiwidG9rZW4iOiI5NDkwMjMyMTAyOTQwOTk5NDA0NjAzIiwidiI6IjEuMSJ9"); $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setOpaqueData($op); // Create the Bill To info for new payment type $billto = new AnetAPI\CustomerAddressType(); $billto->setFirstName("Ellen"); $billto->setLastName("Johnson"); $billto->setCompany("Souveniropolis"); $billto->setAddress("14 Main Street"); $billto->setCity("Pecan Springs"); $billto->setState("TX"); $billto->setZip("44628"); $billto->setCountry("USA"); $billto->setPhoneNumber(123-123-1234); $billto->setfaxNumber("999-999-9999"); // Create a new Customer Payment Profile object $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); $paymentprofile->setCustomerType('individual'); $paymentprofile->setBillTo($billto); $paymentprofile->setPayment($paymentOne); $paymentprofile->setDefaultPaymentProfile(true); $paymentprofiles[] = $paymentprofile; // Create a new CustomerProfileType and add the payment profile object $customerprofile = new AnetAPI\CustomerProfileType(); $customerprofile->setDescription("Customer Test PHP Accept Test"); $customerprofile->setMerchantCustomerId("M_".$email); $customerprofile->setEmail($email); $customerprofile->setPaymentProfiles($paymentprofiles); // Assemble the complete transaction request $request = new AnetAPI\CreateCustomerProfileRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setProfile($customerprofile); // Create the controller and get the response $controller = new AnetController\CreateCustomerProfileController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { echo "Succesfully created customer profile : " . $response->getCustomerProfileId() . "\n"; $paymentProfiles = $response->getCustomerPaymentProfileIdList(); echo "SUCCESS: PAYMENT PROFILE ID : " . $paymentProfiles[0] . "\n"; } else { echo "ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if (!defined('DONT_RUN_SAMPLES')) { createCustomerProfileWithAcceptNonce("test123@test.com"); } ?> ================================================ FILE: CustomerProfiles/create-customer-profile.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Create a Customer Profile Request // 1. (Optionally) create a Payment Profile // 2. (Optionally) create a Shipping Profile // 3. Create a Customer Profile (or specify an existing profile) // 4. Submit a CreateCustomerProfile Request // 5. Validate Profile ID returned // Set credit card information for payment profile $creditCard = new AnetAPI\CreditCardType(); $creditCard->setCardNumber("4242424242424242"); $creditCard->setExpirationDate("2038-12"); $creditCard->setCardCode("142"); $paymentCreditCard = new AnetAPI\PaymentType(); $paymentCreditCard->setCreditCard($creditCard); // Create the Bill To info for new payment type $billTo = new AnetAPI\CustomerAddressType(); $billTo->setFirstName("Ellen"); $billTo->setLastName("Johnson"); $billTo->setCompany("Souveniropolis"); $billTo->setAddress("14 Main Street"); $billTo->setCity("Pecan Springs"); $billTo->setState("TX"); $billTo->setZip("44628"); $billTo->setCountry("USA"); $billTo->setPhoneNumber("888-888-8888"); $billTo->setfaxNumber("999-999-9999"); // Create a customer shipping address $customerShippingAddress = new AnetAPI\CustomerAddressType(); $customerShippingAddress->setFirstName("James"); $customerShippingAddress->setLastName("White"); $customerShippingAddress->setCompany("Addresses R Us"); $customerShippingAddress->setAddress(rand() . " North Spring Street"); $customerShippingAddress->setCity("Toms River"); $customerShippingAddress->setState("NJ"); $customerShippingAddress->setZip("08753"); $customerShippingAddress->setCountry("USA"); $customerShippingAddress->setPhoneNumber("888-888-8888"); $customerShippingAddress->setFaxNumber("999-999-9999"); // Create an array of any shipping addresses $shippingProfiles[] = $customerShippingAddress; // Create a new CustomerPaymentProfile object $paymentProfile = new AnetAPI\CustomerPaymentProfileType(); $paymentProfile->setCustomerType('individual'); $paymentProfile->setBillTo($billTo); $paymentProfile->setPayment($paymentCreditCard); $paymentProfiles[] = $paymentProfile; // Create a new CustomerProfileType and add the payment profile object $customerProfile = new AnetAPI\CustomerProfileType(); $customerProfile->setDescription("Customer 2 Test PHP"); $customerProfile->setMerchantCustomerId("M_" . time()); $customerProfile->setEmail($email); $customerProfile->setpaymentProfiles($paymentProfiles); $customerProfile->setShipToList($shippingProfiles); // Assemble the complete transaction request $request = new AnetAPI\CreateCustomerProfileRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setProfile($customerProfile); // Create the controller and get the response $controller = new AnetController\CreateCustomerProfileController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { echo "Succesfully created customer profile : " . $response->getCustomerProfileId() . "\n"; $paymentProfiles = $response->getCustomerPaymentProfileIdList(); echo "SUCCESS: PAYMENT PROFILE ID : " . $paymentProfiles[0] . "\n"; } else { echo "ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if (!defined('DONT_RUN_SAMPLES')) { createCustomerProfile("test123@test.com"); } ================================================ FILE: CustomerProfiles/create-customer-shipping-address.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Use An existing customer profile id for this merchant name and transaction key // Create the customer shipping address $customershippingaddress = new AnetAPI\CustomerAddressType(); $customershippingaddress->setFirstName("James"); $customershippingaddress->setLastName("White"); $customershippingaddress->setCompany("Addresses R Us"); $customershippingaddress->setAddress(rand() . " North Spring Street"); $customershippingaddress->setCity("Toms River"); $customershippingaddress->setState("NJ"); $customershippingaddress->setZip("08753"); $customershippingaddress->setCountry("USA"); $customershippingaddress->setPhoneNumber($phoneNumber); $customershippingaddress->setFaxNumber("999-999-9999"); // Create a new customer shipping address for an existing customer profile $request = new AnetAPI\CreateCustomerShippingAddressRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setCustomerProfileId($existingcustomerprofileid); $request->setAddress($customershippingaddress); $controller = new AnetController\CreateCustomerShippingAddressController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { echo "Create Customer Shipping Address SUCCESS: ADDRESS ID : " . $response-> getCustomerAddressId() . "\n"; } else { echo "Create Customer Shipping Address ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if (!defined('DONT_RUN_SAMPLES')) { createCustomerShippingAddress(); } ?> ================================================ FILE: CustomerProfiles/delete-customer-payment-profile.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Use an existing payment profile ID for this Merchant name and Transaction key $request = new AnetAPI\DeleteCustomerPaymentProfileRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setCustomerProfileId($customerProfileId); $request->setCustomerPaymentProfileId($customerpaymentprofileid); $controller = new AnetController\DeleteCustomerPaymentProfileController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { echo "SUCCESS: Delete Customer Payment Profile SUCCESS :" . "\n"; } else { echo "ERROR : Delete Customer Payment Profile: Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) deleteCustomerPaymentProfile(); ?> ================================================ FILE: CustomerProfiles/delete-customer-profile.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Delete an existing customer profile $request = new AnetAPI\DeleteCustomerProfileRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setCustomerProfileId( $customerProfileId ); $controller = new AnetController\DeleteCustomerProfileController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { echo "DeleteCustomerProfile SUCCESS : " . "\n"; } else { echo "ERROR : DeleteCustomerProfile: Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) deleteCustomerProfile("1929905651"); ?> ================================================ FILE: CustomerProfiles/delete-customer-shipping-address.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Use an existing customer profile and address id for this merchant name and transaction key // Delete an existing customer shipping address for an existing customer profile $request = new AnetAPI\DeleteCustomerShippingAddressRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setCustomerProfileId($customerprofileid); $request->setCustomerAddressId($customeraddressid); $controller = new AnetController\DeleteCustomerShippingAddressController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { echo "Delete Customer Shipping Address SUCCESS" . "\n"; } else { echo "Delete Customer Shipping Address ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) deleteCustomerShippingAddress(); ?> ================================================ FILE: CustomerProfiles/get-customer-payment-profile-list.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); //Setting the paging $paging = new AnetAPI\PagingType(); $paging->setLimit("1000"); $paging->setOffset("1"); //Setting the sorting $sorting = new AnetAPI\CustomerPaymentProfileSortingType(); $sorting->setOrderBy("id"); $sorting->setOrderDescending(false); //Creating the request with the required parameters $request = new AnetAPI\GetCustomerPaymentProfileListRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setPaging($paging); $request->setSorting($sorting); $request->setSearchType("cardsExpiringInMonth"); $request->setMonth("2020-12"); // Controller $controller = new AnetController\GetCustomerPaymentProfileListController($request); // Getting the response $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null)) { if ($response->getMessages()->getResultCode() == "Ok") { // Success echo "GetCustomerPaymentProfileList SUCCESS: " . "\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; echo "Total number of Results in the result set" . $response->getTotalNumInResultSet() . "\n"; // Displaying the customer payment profile list foreach ($response->getPaymentProfiles() as $paymentProfile) { echo "\nCustomer Profile ID: " . $paymentProfile->getCustomerProfileId() . "\n"; echo "Payment profile ID: " . $paymentProfile->getCustomerPaymentProfileId() . "\n"; echo "Credit Card Number: " . $paymentProfile->getPayment()->getCreditCard()->getCardNumber() . "\n"; if ($paymentProfile->getBillTo() != null) { echo "First Name in Billing Address: " . $paymentProfile->getBillTo()->getFirstName() . "\n"; } } } else { // Error echo "GetCustomerPaymentProfileList ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } } else { // Failed to get the response echo "NULL Response Error"; } return $response; } if (!defined('DONT_RUN_SAMPLES')) { getCustomerPaymentProfileList(); } ================================================ FILE: CustomerProfiles/get-customer-payment-profile.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); //request requires customerProfileId and customerPaymentProfileId $request = new AnetAPI\GetCustomerPaymentProfileRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId( $refId); $request->setCustomerProfileId($customerProfileId); $request->setCustomerPaymentProfileId($customerPaymentProfileId); $controller = new AnetController\GetCustomerPaymentProfileController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if(($response != null)){ if ($response->getMessages()->getResultCode() == "Ok") { echo "GetCustomerPaymentProfile SUCCESS: " . "\n"; echo "Customer Payment Profile Id: " . $response->getPaymentProfile()->getCustomerPaymentProfileId() . "\n"; echo "Customer Payment Profile Billing Address: " . $response->getPaymentProfile()->getbillTo()->getAddress(). "\n"; echo "Customer Payment Profile Card Last 4 " . $response->getPaymentProfile()->getPayment()->getCreditCard()->getCardNumber(). "\n"; if($response->getPaymentProfile()->getSubscriptionIds() != null) { if($response->getPaymentProfile()->getSubscriptionIds() != null) { echo "List of subscriptions:"; foreach($response->getPaymentProfile()->getSubscriptionIds() as $subscriptionid) echo $subscriptionid . "\n"; } } } else { echo "GetCustomerPaymentProfile ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } } else{ echo "NULL Response Error"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) getCustomerPaymentProfile(); ?> ================================================ FILE: CustomerProfiles/get-customer-profile-ids.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Get all existing customer profile ID's $request = new AnetAPI\GetCustomerProfileIdsRequest(); $request->setMerchantAuthentication($merchantAuthentication); $controller = new AnetController\GetCustomerProfileIdsController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { echo "GetCustomerProfileId's SUCCESS: " . "\n"; $profileIds[] = $response->getIds(); echo "There are " . count($profileIds[0]) . " Customer Profile ID's for this Merchant Name and Transaction Key" . "\n"; } else { echo "GetCustomerProfileId's ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) getCustomerProfileIds(); ?> ================================================ FILE: CustomerProfiles/get-customer-profile.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Create the payment data for a credit card $creditCard = new AnetAPI\CreditCardType(); $creditCard->setCardNumber( "4111111111111111" ); $creditCard->setExpirationDate("2038-12"); $paymentCreditCard = new AnetAPI\PaymentType(); $paymentCreditCard->setCreditCard($creditCard); // Create the Bill To info $billto = new AnetAPI\CustomerAddressType(); $billto->setFirstName("Ellen"); $billto->setLastName("Johnson"); $billto->setCompany("Souveniropolis"); $billto->setAddress("14 Main Street"); $billto->setCity("Pecan Springs"); $billto->setState("TX"); $billto->setZip("44628"); $billto->setCountry("USA"); // Create a Customer Profile Request // 1. create a Payment Profile // 2. create a Customer Profile // 3. Submit a CreateCustomerProfile Request // 4. Validate Profiiel ID returned $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); $paymentprofile->setCustomerType('individual'); $paymentprofile->setBillTo($billto); $paymentprofile->setPayment($paymentCreditCard); $paymentprofiles[] = $paymentprofile; $customerprofile = new AnetAPI\CustomerProfileType(); $customerprofile->setDescription("Customer 2 Test PHP"); $merchantCustomerId = time().rand(1,150); $customerprofile->setMerchantCustomerId($merchantCustomerId); $customerprofile->setEmail("test2@domain.com"); $customerprofile->setPaymentProfiles($paymentprofiles); $request = new AnetAPI\CreateCustomerProfileRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId( $refId); $request->setProfile($customerprofile); $controller = new AnetController\CreateCustomerProfileController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { echo "SUCCESS: CreateCustomerProfile PROFILE ID : " . $response->getCustomerProfileId() . "\n"; $profileIdRequested = $response->getCustomerProfileId(); } else { echo "ERROR : CreateCustomerProfile: Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } // Retrieve an existing customer profile along with all the associated payment profiles and shipping addresses $request = new AnetAPI\GetCustomerProfileRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setCustomerProfileId($profileIdRequested); $controller = new AnetController\GetCustomerProfileController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { echo "GetCustomerProfile SUCCESS : " . "\n"; $profileSelected = $response->getProfile(); $paymentProfilesSelected = $profileSelected->getPaymentProfiles(); echo "Profile Has " . count($paymentProfilesSelected). " Payment Profiles" . "\n"; if($response->getSubscriptionIds() != null) { if($response->getSubscriptionIds() != null) { echo "List of subscriptions:"; foreach($response->getSubscriptionIds() as $subscriptionid) echo $subscriptionid . "\n"; } } } else { echo "ERROR : GetCustomerProfile: Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) { getCustomerProfile(); } ?> ================================================ FILE: CustomerProfiles/get-customer-shipping-address.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // An existing customer profile id and shipping address id for this merchant name and transaction key $customerProfileId = $customerprofileid; $customerAddressId = $customeraddressid; $request = new AnetAPI\GetCustomerShippingAddressRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setCustomerProfileId($customerProfileId); $request->setCustomerAddressId($customerAddressId); $controller = new AnetController\GetCustomerShippingAddressController($request); //Retrieving existing customer shipping address $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { echo "Get Customer Shipping Address SUCCESS" . "\n"; echo " FirstName : " . $response->getAddress()->getFirstName() . "\n"; echo " LastName : " . $response->getAddress()->getLastName() . "\n"; echo " Company : " . $response->getAddress()->getCompany() . "\n"; echo " Address : " . $response->getAddress()->getAddress() . "\n"; echo " City : " . $response->getAddress()->getCity() . "\n"; echo " State : " . $response->getAddress()->getState() . "\n"; echo " Zip : " . $response->getAddress()->getZip() . "\n"; echo " Country : " . $response->getAddress()->getCountry() . "\n"; echo " Phone Number : " . $response->getAddress()->getPhoneNumber() . "\n"; echo " FAX Number : " . $response->getAddress()->getFaxNumber() . "\n"; echo "Customer AddressId : " . $response->getAddress()->getCustomerAddressId() . "\n"; if($response->getSubscriptionIds() != null) { if($response->getSubscriptionIds() != null) { echo "List of subscriptions:"; foreach($response->getSubscriptionIds() as $subscriptionid) echo $subscriptionid . "\n"; } } } else { echo "Get Customer Shipping Address ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) getCustomerShippingAddress("36152127","36976566"); ?> ================================================ FILE: CustomerProfiles/update-customer-payment-profile.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); $request = new AnetAPI\GetCustomerPaymentProfileRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId( $refId); $request->setCustomerProfileId($customerProfileId); $request->setCustomerPaymentProfileId($customerPaymentProfileId); $controller = new AnetController\GetCustomerPaymentProfileController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { $billto = new AnetAPI\CustomerAddressType(); $billto = $response->getPaymentProfile()->getbillTo(); $creditCard = new AnetAPI\CreditCardType(); $creditCard->setCardNumber( "4111111111111111" ); $creditCard->setExpirationDate("2038-12"); $paymentCreditCard = new AnetAPI\PaymentType(); $paymentCreditCard->setCreditCard($creditCard); $paymentprofile = new AnetAPI\CustomerPaymentProfileExType(); $paymentprofile->setBillTo($billto); $paymentprofile->setCustomerPaymentProfileId($customerPaymentProfileId); $paymentprofile->setPayment($paymentCreditCard); // We're updating the billing address but everything has to be passed in an update // For card information you can pass exactly what comes back from an GetCustomerPaymentProfile // if you don't need to update that info // Update the Bill To info for new payment type $billto->setFirstName("Mrs Mary"); $billto->setLastName("Doe"); $billto->setAddress("9 New St."); $billto->setCity("Brand New City"); $billto->setState("WA"); $billto->setZip("98004"); $billto->setPhoneNumber("000-000-0000"); $billto->setfaxNumber("999-999-9999"); $billto->setCountry("USA"); // Update the Customer Payment Profile object $paymentprofile->setBillTo($billto); // Submit a UpdatePaymentProfileRequest $request = new AnetAPI\UpdateCustomerPaymentProfileRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setCustomerProfileId($customerProfileId); $request->setPaymentProfile( $paymentprofile ); $controller = new AnetController\UpdateCustomerPaymentProfileController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { $Message = $response->getMessages()->getMessage(); print_r($response); echo "Update Customer Payment Profile SUCCESS: " . $Message[0]->getCode() . " " .$Message[0]->getText() . "\n"; } else if ($response != null) { $errorMessages = $response->getMessages()->getMessage(); echo "Failed to Update Customer Payment Profile : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } else { echo "Failed to Get Customer Payment Profile : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) updateCustomerPaymentProfile(); ?> ================================================ FILE: CustomerProfiles/update-customer-profile.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Create the payment data for a credit card $creditCard = new AnetAPI\CreditCardType(); $creditCard->setCardNumber( "4111111111111111" ); $creditCard->setExpirationDate("2038-12"); $paymentCreditCard = new AnetAPI\PaymentType(); $paymentCreditCard->setCreditCard($creditCard); // Create the Bill To info $billto = new AnetAPI\CustomerAddressType(); $billto->setFirstName("Ellen"); $billto->setLastName("Johnson"); $billto->setCompany("Souveniropolis"); $billto->setAddress("14 Main Street"); $billto->setCity("Pecan Springs"); $billto->setState("TX"); $billto->setZip("44628"); $billto->setCountry("USA"); // Create a Customer Profile Request // 1. create a Payment Profile // 2. create a Customer Profile // 3. Submit a CreateCustomerProfile Request // 4. Validate Profiiel ID returned $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); $paymentprofile->setCustomerType('individual'); $paymentprofile->setBillTo($billto); $paymentprofile->setPayment($paymentCreditCard); $paymentprofiles[] = $paymentprofile; $customerprofile = new AnetAPI\CustomerProfileType(); $customerprofile->setDescription("Update Customer Profile Request Test for PHP"); $merchantCustomerId = time().rand(1,150); $customerprofile->setMerchantCustomerId($merchantCustomerId); $customerprofile->setEmail(rand(0,10000) . "@test.com"); $customerprofile->setPaymentProfiles($paymentprofiles); $request = new AnetAPI\CreateCustomerProfileRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId( $refId); $request->setProfile($customerprofile); $controller = new AnetController\CreateCustomerProfileController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { echo "SUCCESS: CreateCustomerProfile PROFILE ID : " . $response->getCustomerProfileId() . "\n"; $profileidcreated = $response->getCustomerProfileId(); } else { echo "ERROR : CreateCustomerProfile: Invalid response\n"; } // Update an existing customer profile $updatecustomerprofile = new AnetAPI\CustomerProfileExType(); $updatecustomerprofile->setCustomerProfileId($profileidcreated); $updatecustomerprofile->setDescription("Updated existing Profile Request"); $updatecustomerprofile->setEmail("updated".rand(0,10000)."@test.com"); $request = new AnetAPI\UpdateCustomerProfileRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setProfile($updatecustomerprofile); $controller = new AnetController\UpdateCustomerProfileController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { echo "UpdateCustomerProfile SUCCESS : " . "\n"; // Validate the description and e-mail that was updated $request = new AnetAPI\GetCustomerProfileRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setCustomerProfileId($profileidcreated ); $controller = new AnetController\GetCustomerProfileController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { echo "Get updated CustomerProfile SUCCESS : " . "\n"; $profileselected = $response->getProfile(); echo "Updated Customer Profile Customer description : " . $profileselected->getDescription() . "\n"; echo "Updated Customer Profile EMail description : " . $profileselected->getEmail() . "\n"; } else { echo "ERROR : GetCustomerProfile: Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } } else { echo "ERROR : UpdateCustomerProfile: Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) updateCustomerProfile(); ?> ================================================ FILE: CustomerProfiles/update-customer-shipping-address.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // An existing customer profile id for this merchant name and transaction key $existingcustomerprofileid = $customerprofileid; // Create the customer shipping address $customershippingaddress = new AnetAPI\CustomerAddressExType(); $customershippingaddress->setFirstName("Jane"); $customershippingaddress->setLastName("White"); $customershippingaddress->setCompany("Addresses R Us"); $customershippingaddress->setAddress("14 North Spring Street Suite 240"); $customershippingaddress->setCity("Toms River"); $customershippingaddress->setState("NJ"); $customershippingaddress->setZip("08753"); $customershippingaddress->setCountry("USA"); $customershippingaddress->setPhoneNumber("201-000-0000"); $customershippingaddress->setFaxNumber("973-999-9999"); $customershippingaddress->setCustomerAddressId($customeraddressid); // Update an existing customer shipping address for an existing customer profile $request = new AnetAPI\UpdateCustomerShippingAddressRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setCustomerProfileId($existingcustomerprofileid); $request->setAddress($customershippingaddress); $controller = new AnetController\UpdateCustomerShippingAddressController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { echo "Update Customer Shipping Address SUCCESS.\n"; } else { echo "Update Customer Shipping Address ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) updateCustomerShippingAddress( "1929905607","901116911"); ?> ================================================ FILE: CustomerProfiles/validate-customer-payment-profile.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Use an existing payment profile ID for this Merchant name and Transaction key //validationmode tests , does not send an email receipt $validationmode = "testMode"; $request = new AnetAPI\ValidateCustomerPaymentProfileRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setCustomerProfileId($customerProfileId); $request->setCustomerPaymentProfileId($customerPaymentProfileId); $request->setValidationMode($validationmode); $controller = new AnetController\ValidateCustomerPaymentProfileController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { $validationMessages = $response->getMessages()->getMessage(); echo "Response : " . $validationMessages[0]->getCode() . " " .$validationMessages[0]->getText() . "\n"; } else { echo "ERROR : Validate Customer Payment Profile: Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) validateCustomerPaymentProfile(); ?> ================================================ FILE: FraudManagement/approve-or-decline-held-transaction.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); //create a transaction $transactionRequestType = new AnetAPI\HeldTransactionRequestType(); $transactionRequestType->setAction("approve"); //other possible value: decline $transactionRequestType->setRefTransId("60012148205"); $request = new AnetAPI\UpdateHeldTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setHeldTransactionRequest( $transactionRequestType); $controller = new AnetController\UpdateHeldTransactionController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n"; echo "Charge Credit Card TRANS ID : " . $tresponse->getTransId() . "\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) approveOrDeclineHeldTransaction(); ?> ================================================ FILE: FraudManagement/get-held-transaction-list.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); $request = new AnetAPI\GetUnsettledTransactionListRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setStatus("pendingApproval"); $controller = new AnetController\GetUnsettledTransactionListController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { if(null != $response->getTransactions()) { foreach($response->getTransactions() as $tx) { echo "SUCCESS: TransactionID: " . $tx->getTransId() . "\n"; } } else{ echo "No suspicious transactions for the merchant." . "\n"; } } else { echo "ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) getHeldTransactionList(); ?> ================================================ FILE: LICENSE ================================================ The MIT License (MIT) Copyright (c) 2015 Authorize.Net Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: MobileInAppTransactions/create-an-accept-transaction.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Create the payment object for a payment nonce $opaqueData = new AnetAPI\OpaqueDataType(); $opaqueData->setDataDescriptor("COMMON.ACCEPT.INAPP.PAYMENT"); $opaqueData->setDataValue("119eyJjb2RlIjoiNTBfMl8wNjAwMDUyN0JEODE4RjQxOUEyRjhGQkIxMkY0MzdGQjAxQUIwRTY2NjhFNEFCN0VENzE4NTUwMjlGRUU0M0JFMENERUIwQzM2M0ExOUEwMDAzNzlGRDNFMjBCODJEMDFCQjkyNEJDIiwidG9rZW4iOiI5NDkwMjMyMTAyOTQwOTk5NDA0NjAzIiwidiI6IjEuMSJ9"); // Add the payment data to a paymentType object $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setOpaqueData($opaqueData); // Create order information $order = new AnetAPI\OrderType(); $order->invoiceNumber("10101"); $order->setDescription("Golf Shirts"); // Set the customer's Bill To address $customerAddress = new AnetAPI\CustomerAddressType(); $customerAddress->setFirstName("Ellen"); $customerAddress->setLastName("Johnson"); $customerAddress->setCompany("Souveniropolis"); $customerAddress->setAddress("14 Main Street"); $customerAddress->setCity("Pecan Springs"); $customerAddress->setState("TX"); $customerAddress->setZip("44628"); $customerAddress->setCountry("USA"); // Set the customer's identifying information $customerData = new AnetAPI\CustomerDataType(); $customerData->setType("individual"); $customerData->setId("99999456654"); $customerData->setEmail("EllenJohnson@example.com"); //Add values for transaction settings $duplicateWindowSetting = new AnetAPI\SettingType(); $duplicateWindowSetting->setSettingName("duplicateWindow"); $duplicateWindowSetting->setSettingValue("600"); // Create a transactionRequestType object and add the previous objects to it $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType( "authCaptureTransaction"); $transactionRequestType->setAmount($amount); $transactionRequestType->setOrder($order); $transactionRequestType->setPayment($paymentOne); $transactionRequestType->setBillTo($customerAddress); $transactionRequestType->setCustomer($customerData); $transactionRequestType->addToTransactionSettings($duplicateWindowSetting); // Assemble the complete transaction request $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setTransactionRequest($transactionRequestType); // Create the controller and get the response $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { // Check to see if the API request was successfully received and acted upon if ($response->getMessages()->getResultCode() == "Ok") { // Since the API request was successful, look for a transaction response // and parse it to display the results of authorizing the card $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Successfully created transaction with Transaction ID: " . $tresponse->getTransId() . "\n"; echo " Transaction Response Code: " . $tresponse->getResponseCode() . "\n"; echo " Message Code: " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Auth Code: " . $tresponse->getAuthCode() . "\n"; echo " Description: " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if ($tresponse->getErrors() != null) { echo " Error Code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } // Or, print errors if the API request wasn't successful } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getErrors() != null) { echo " Error Code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error Code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error Message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if (!defined('DONT_RUN_SAMPLES')) { CreateAnAcceptTransaction("2.23"); } ?> ================================================ FILE: MobileInAppTransactions/create-an-android-pay-transaction.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); $op = new AnetAPI\OpaqueDataType(); $op->setDataDescriptor("COMMON.ANDROID.INAPP.PAYMENT"); $op->setDataValue("eyJkYXRhIjoiQkRQTldTdE1tR2V3UVVXR2c0bzdFXC9qKzFjcTFUNzhxeVU4NGI2N2l0amNZSTh3UFlBT2hzaGpoWlBycWRVcjRYd1BNYmo0emNHTWR5KysxSDJWa1BPWStCT01GMjV1YjE5Y1g0bkN2a1hVVU9UakRsbEIxVGdTcjhKSFp4Z3A5ckNnc1NVZ2JCZ0tmNjBYS3V0WGY2YWpcL284WkliS25yS1E4U2gwb3VMQUtsb1VNbit2UHU0K0E3V0tycXJhdXo5SnZPUXA2dmhJcStIS2pVY1VOQ0lUUHlGaG1PRXRxK0grdzB2UmExQ0U2V2hGQk5uQ0hxenpXS2NrQlwvMG5xTFpSVFliRjBwK3Z5QmlWYVdIZWdoRVJmSHhSdGJ6cGVjelJQUHVGc2ZwSFZzNDhvUExDXC9rXC8xTU5kNDdrelwvcEhEY1JcL0R5NmFVTStsTmZvaWx5XC9RSk4rdFMzbTBIZk90SVNBUHFPbVhlbXZyNnhKQ2pDWmxDdXcwQzltWHpcL29iSHBvZnVJRVM4cjljcUdHc1VBUERwdzdnNjQybTRQendLRitIQnVZVW5lV0RCTlNEMnU2amJBRzMiLCJ2ZXJzaW9uIjoiRUNfdjEiLCJoZWFkZXIiOnsiYXBwbGljYXRpb25EYXRhIjoiOTRlZTA1OTMzNWU1ODdlNTAxY2M0YmY5MDYxM2UwODE0ZjAwYTdiMDhiYzdjNjQ4ZmQ4NjVhMmFmNmEyMmNjMiIsInRyYW5zYWN0aW9uSWQiOiJjMWNhZjVhZTcyZjAwMzlhODJiYWQ5MmI4MjgzNjM3MzRmODViZjJmOWNhZGYxOTNkMWJhZDlkZGNiNjBhNzk1IiwiZXBoZW1lcmFsUHVibGljS2V5IjoiTUlJQlN6Q0NBUU1HQnlxR1NNNDlBZ0V3Z2ZjQ0FRRXdMQVlIS29aSXpqMEJBUUloQVBcL1wvXC9cLzhBQUFBQkFBQUFBQUFBQUFBQUFBQUFcL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL01Gc0VJUFwvXC9cL1wvOEFBQUFCQUFBQUFBQUFBQUFBQUFBQVwvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cLzhCQ0JheGpYWXFqcVQ1N1BydlZWMm1JYThaUjBHc014VHNQWTd6ancrSjlKZ1N3TVZBTVNkTmdpRzV3U1RhbVo0NFJPZEpyZUJuMzZRQkVFRWF4ZlI4dUVzUWtmNHZPYmxZNlJBOG5jRGZZRXQ2ek9nOUtFNVJkaVl3cFpQNDBMaVwvaHBcL200N242MHA4RDU0V0s4NHpWMnN4WHM3THRrQm9ONzlSOVFJaEFQXC9cL1wvXC84QUFBQUFcL1wvXC9cL1wvXC9cL1wvXC9cLys4NXZxdHB4ZWVoUE81eXNMOFl5VlJBZ0VCQTBJQUJHbStnc2wwUFpGVFwva0RkVVNreHd5Zm84SnB3VFFRekJtOWxKSm5tVGw0REdVdkFENEdzZUdqXC9wc2hCWjBLM1RldXFEdFwvdERMYkUrOFwvbTB5Q21veHc9IiwicHVibGljS2V5SGFzaCI6IlwvYmI5Q05DMzZ1QmhlSEZQYm1vaEI3T28xT3NYMkora0pxdjQ4ek9WVmlRPSJ9LCJzaWduYXR1cmUiOiJNSUlEUWdZSktvWklodmNOQVFjQ29JSURNekNDQXk4Q0FRRXhDekFKQmdVckRnTUNHZ1VBTUFzR0NTcUdTSWIzRFFFSEFhQ0NBaXN3Z2dJbk1JSUJsS0FEQWdFQ0FoQmNsK1BmMytVNHBrMTNuVkQ5bndRUU1Ba0dCU3NPQXdJZEJRQXdKekVsTUNNR0ExVUVBeDRjQUdNQWFBQnRBR0VBYVFCQUFIWUFhUUJ6QUdFQUxnQmpBRzhBYlRBZUZ3MHhOREF4TURFd05qQXdNREJhRncweU5EQXhNREV3TmpBd01EQmFNQ2N4SlRBakJnTlZCQU1lSEFCakFHZ0FiUUJoQUdrQVFBQjJBR2tBY3dCaEFDNEFZd0J2QUcwd2daOHdEUVlKS29aSWh2Y05BUUVCQlFBRGdZMEFNSUdKQW9HQkFOQzgra2d0Z212V0YxT3pqZ0ROcmpURUJSdW9cLzVNS3ZsTTE0NnBBZjdHeDQxYmxFOXc0ZklYSkFEN0ZmTzdRS2pJWFlOdDM5ckx5eTd4RHdiXC81SWtaTTYwVFoyaUkxcGo1NVVjOGZkNGZ6T3BrM2Z0WmFRR1hOTFlwdEcxZDlWN0lTODJPdXA5TU1vMUJQVnJYVFBITmNzTTk5RVBVblBxZGJlR2M4N20wckFnTUJBQUdqWERCYU1GZ0dBMVVkQVFSUk1FK0FFSFpXUHJXdEpkN1laNDMxaENnN1lGU2hLVEFuTVNVd0l3WURWUVFESGh3QVl3Qm9BRzBBWVFCcEFFQUFkZ0JwQUhNQVlRQXVBR01BYndCdGdoQmNsK1BmMytVNHBrMTNuVkQ5bndRUU1Ba0dCU3NPQXdJZEJRQURnWUVBYlVLWUNrdUlLUzlRUTJtRmNNWVJFSW0ybCtYZzhcL0pYditHQlZRSmtPS29zY1k0aU5ERkFcL2JRbG9nZjlMTFU4NFRId05SbnN2VjNQcnY3UlRZODFncTBkdEM4elljQWFBa0NISUkzeXFNbko0QU91NkVPVzlrSmsyMzJnU0U3V2xDdEhiZkxTS2Z1U2dRWDhLWFFZdVpMazJScjYzTjhBcFhzWHdCTDNjSjB4Z2VBd2dkMENBUUV3T3pBbk1TVXdJd1lEVlFRREhod0FZd0JvQUcwQVlRQnBBRUFBZGdCcEFITUFZUUF1QUdNQWJ3QnRBaEJjbCtQZjMrVTRwazEzblZEOW53UVFNQWtHQlNzT0F3SWFCUUF3RFFZSktvWklodmNOQVFFQkJRQUVnWUJhSzNFbE9zdGJIOFdvb3NlREFCZitKZ1wvMTI5SmNJYXdtN2M2VnhuN1phc05iQXEzdEF0OFB0eSt1UUNnc3NYcVprTEE3a3oyR3pNb2xOdHY5d1ltdTlVandhcjFQSFlTK0JcL29Hbm96NTkxd2phZ1hXUnowbk1vNXkzTzFLelgwZDhDUkhBVmE4OFNyVjFhNUpJaVJldjNvU3RJcXd2NXh1WmxkYWc2VHI4dz09In0="); $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setOpaqueData($op); //create a transaction $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType( "authCaptureTransaction"); $transactionRequestType->setAmount(151); $transactionRequestType->setPayment($paymentOne); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId( $refId); $request->setTransactionRequest( $transactionRequestType); $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo " AUTH CODE : " . $tresponse->getAuthCode() . "\n"; echo " TRANS ID : " . $tresponse->getTransId() . "\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) createAnAndroidPayTransaction(); ?> ================================================ FILE: MobileInAppTransactions/create-an-apple-pay-transaction.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); $op = new AnetAPI\OpaqueDataType(); $op->setDataDescriptor("COMMON.APPLE.INAPP.PAYMENT"); $op->setDataValue("eyJkYXRhIjoiQkRQTldTdE1tR2V3UVVXR2c0bzdFXC9qKzFjcTFUNzhxeVU4NGI2N2l0amNZSTh3UFlBT2hzaGpoWlBycWRVcjRYd1BNYmo0emNHTWR5KysxSDJWa1BPWStCT01GMjV1YjE5Y1g0bkN2a1hVVU9UakRsbEIxVGdTcjhKSFp4Z3A5ckNnc1NVZ2JCZ0tmNjBYS3V0WGY2YWpcL284WkliS25yS1E4U2gwb3VMQUtsb1VNbit2UHU0K0E3V0tycXJhdXo5SnZPUXA2dmhJcStIS2pVY1VOQ0lUUHlGaG1PRXRxK0grdzB2UmExQ0U2V2hGQk5uQ0hxenpXS2NrQlwvMG5xTFpSVFliRjBwK3Z5QmlWYVdIZWdoRVJmSHhSdGJ6cGVjelJQUHVGc2ZwSFZzNDhvUExDXC9rXC8xTU5kNDdrelwvcEhEY1JcL0R5NmFVTStsTmZvaWx5XC9RSk4rdFMzbTBIZk90SVNBUHFPbVhlbXZyNnhKQ2pDWmxDdXcwQzltWHpcL29iSHBvZnVJRVM4cjljcUdHc1VBUERwdzdnNjQybTRQendLRitIQnVZVW5lV0RCTlNEMnU2amJBRzMiLCJ2ZXJzaW9uIjoiRUNfdjEiLCJoZWFkZXIiOnsiYXBwbGljYXRpb25EYXRhIjoiOTRlZTA1OTMzNWU1ODdlNTAxY2M0YmY5MDYxM2UwODE0ZjAwYTdiMDhiYzdjNjQ4ZmQ4NjVhMmFmNmEyMmNjMiIsInRyYW5zYWN0aW9uSWQiOiJjMWNhZjVhZTcyZjAwMzlhODJiYWQ5MmI4MjgzNjM3MzRmODViZjJmOWNhZGYxOTNkMWJhZDlkZGNiNjBhNzk1IiwiZXBoZW1lcmFsUHVibGljS2V5IjoiTUlJQlN6Q0NBUU1HQnlxR1NNNDlBZ0V3Z2ZjQ0FRRXdMQVlIS29aSXpqMEJBUUloQVBcL1wvXC9cLzhBQUFBQkFBQUFBQUFBQUFBQUFBQUFcL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL01Gc0VJUFwvXC9cL1wvOEFBQUFCQUFBQUFBQUFBQUFBQUFBQVwvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cLzhCQ0JheGpYWXFqcVQ1N1BydlZWMm1JYThaUjBHc014VHNQWTd6ancrSjlKZ1N3TVZBTVNkTmdpRzV3U1RhbVo0NFJPZEpyZUJuMzZRQkVFRWF4ZlI4dUVzUWtmNHZPYmxZNlJBOG5jRGZZRXQ2ek9nOUtFNVJkaVl3cFpQNDBMaVwvaHBcL200N242MHA4RDU0V0s4NHpWMnN4WHM3THRrQm9ONzlSOVFJaEFQXC9cL1wvXC84QUFBQUFcL1wvXC9cL1wvXC9cL1wvXC9cLys4NXZxdHB4ZWVoUE81eXNMOFl5VlJBZ0VCQTBJQUJHbStnc2wwUFpGVFwva0RkVVNreHd5Zm84SnB3VFFRekJtOWxKSm5tVGw0REdVdkFENEdzZUdqXC9wc2hCWjBLM1RldXFEdFwvdERMYkUrOFwvbTB5Q21veHc9IiwicHVibGljS2V5SGFzaCI6IlwvYmI5Q05DMzZ1QmhlSEZQYm1vaEI3T28xT3NYMkora0pxdjQ4ek9WVmlRPSJ9LCJzaWduYXR1cmUiOiJNSUlEUWdZSktvWklodmNOQVFjQ29JSURNekNDQXk4Q0FRRXhDekFKQmdVckRnTUNHZ1VBTUFzR0NTcUdTSWIzRFFFSEFhQ0NBaXN3Z2dJbk1JSUJsS0FEQWdFQ0FoQmNsK1BmMytVNHBrMTNuVkQ5bndRUU1Ba0dCU3NPQXdJZEJRQXdKekVsTUNNR0ExVUVBeDRjQUdNQWFBQnRBR0VBYVFCQUFIWUFhUUJ6QUdFQUxnQmpBRzhBYlRBZUZ3MHhOREF4TURFd05qQXdNREJhRncweU5EQXhNREV3TmpBd01EQmFNQ2N4SlRBakJnTlZCQU1lSEFCakFHZ0FiUUJoQUdrQVFBQjJBR2tBY3dCaEFDNEFZd0J2QUcwd2daOHdEUVlKS29aSWh2Y05BUUVCQlFBRGdZMEFNSUdKQW9HQkFOQzgra2d0Z212V0YxT3pqZ0ROcmpURUJSdW9cLzVNS3ZsTTE0NnBBZjdHeDQxYmxFOXc0ZklYSkFEN0ZmTzdRS2pJWFlOdDM5ckx5eTd4RHdiXC81SWtaTTYwVFoyaUkxcGo1NVVjOGZkNGZ6T3BrM2Z0WmFRR1hOTFlwdEcxZDlWN0lTODJPdXA5TU1vMUJQVnJYVFBITmNzTTk5RVBVblBxZGJlR2M4N20wckFnTUJBQUdqWERCYU1GZ0dBMVVkQVFSUk1FK0FFSFpXUHJXdEpkN1laNDMxaENnN1lGU2hLVEFuTVNVd0l3WURWUVFESGh3QVl3Qm9BRzBBWVFCcEFFQUFkZ0JwQUhNQVlRQXVBR01BYndCdGdoQmNsK1BmMytVNHBrMTNuVkQ5bndRUU1Ba0dCU3NPQXdJZEJRQURnWUVBYlVLWUNrdUlLUzlRUTJtRmNNWVJFSW0ybCtYZzhcL0pYditHQlZRSmtPS29zY1k0aU5ERkFcL2JRbG9nZjlMTFU4NFRId05SbnN2VjNQcnY3UlRZODFncTBkdEM4elljQWFBa0NISUkzeXFNbko0QU91NkVPVzlrSmsyMzJnU0U3V2xDdEhiZkxTS2Z1U2dRWDhLWFFZdVpMazJScjYzTjhBcFhzWHdCTDNjSjB4Z2VBd2dkMENBUUV3T3pBbk1TVXdJd1lEVlFRREhod0FZd0JvQUcwQVlRQnBBRUFBZGdCcEFITUFZUUF1QUdNQWJ3QnRBaEJjbCtQZjMrVTRwazEzblZEOW53UVFNQWtHQlNzT0F3SWFCUUF3RFFZSktvWklodmNOQVFFQkJRQUVnWUJhSzNFbE9zdGJIOFdvb3NlREFCZitKZ1wvMTI5SmNJYXdtN2M2VnhuN1phc05iQXEzdEF0OFB0eSt1UUNnc3NYcVprTEE3a3oyR3pNb2xOdHY5d1ltdTlVandhcjFQSFlTK0JcL29Hbm96NTkxd2phZ1hXUnowbk1vNXkzTzFLelgwZDhDUkhBVmE4OFNyVjFhNUpJaVJldjNvU3RJcXd2NXh1WmxkYWc2VHI4dz09In0="); $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setOpaqueData($op); //create a transaction $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType( "authCaptureTransaction"); $transactionRequestType->setAmount(151); $transactionRequestType->setPayment($paymentOne); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId( $refId); $request->setTransactionRequest( $transactionRequestType); $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo " AUTH CODE : " . $tresponse->getAuthCode() . "\n"; echo " TRANS ID : " . $tresponse->getTransId() . "\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) createAnApplePayTransaction(); ?> ================================================ FILE: MobileInAppTransactions/create-google-pay-transaction.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); $refId = 'ref' . time(); $opaqueData = new AnetAPI\OpaqueDataType(); $opaqueData->setDataDescriptor("COMMON.GOOGLE.INAPP.PAYMENT"); $opaqueData->setDataValue("1234567890ABCDEF1111AAAA2222BBBB3333CCCC4444DDDD5555EEEE6666FFFF7777888899990000"); $paymentType = new AnetAPI\PaymentType(); $paymentType->setOpaqueData($opaqueData); $lineItem = new AnetAPI\LineItemType(); $lineItem->setItemId("1"); $lineItem->setName("vase"); $lineItem->setDescription("Cannes logo"); $lineItem->setQuantity(18); $lineItem->setUnitPrice(45.00); $lineItemsArray = array(); $lineItemsArray[0] = $lineItem; $tax = new AnetAPI\ExtendedAmountType(); $tax->setAmount(5.00); $tax->setName("level2 tax name"); $tax->setDescription("level2 tax"); $userField = new AnetAPI\UserFieldType(); $userFields = array(); $userField->setName("UserDefinedFieldName1"); $userField->setValue("UserDefinedFieldValue1"); $userFields[0] = $userField; $userField->setName("UserDefinedFieldName2"); $userField->setValue("UserDefinedFieldValue2"); $userFields[1] = $userField; $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType("authCaptureTransaction"); $transactionRequestType->setAmount(151); $transactionRequestType->setPayment($paymentType); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setTransactionRequest( $transactionRequestType); $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo " AUTH CODE : " . $tresponse->getAuthCode() . "\n"; echo " TRANS ID : " . $tresponse->getTransId() . "\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) createGooglePayTransaction(); ?> ================================================ FILE: PayPalExpressCheckout/authorization-and-capture-continued.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Set PayPal compatible merchant credentials $payPalType=new AnetAPI\PayPalType(); $payPalType->setPayerID($payerID); $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setPayPal($payPalType); // Create an authorize and capture continued transaction $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType("authCaptureContinueTransaction"); $transactionRequestType->setPayment($paymentOne); $transactionRequestType->setRefTransId($refTransId); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setTransactionRequest($transactionRequestType); $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if ($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo "Transaction Response...\n"; echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; //Valid response codes: 1=Approved, 2=Declined, 3=Error, 5=Need Payer Consent echo "Secure acceptance URL: ".$tresponse->getSecureAcceptance()->getSecureAcceptanceUrl()."\n"; echo "Transaction ID: ".$tresponse->getTransId()."\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if ($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if (!defined('DONT_RUN_SAMPLES')) { payPalAuthorizeCaptureContinued("2241708986", "6ZSCSYG33VP8Q"); } ================================================ FILE: PayPalExpressCheckout/authorization-and-capture.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); $payPalType=new AnetAPI\PayPalType(); $payPalType->setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); $payPalType->setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setPayPal($payPalType); // Create an authorize and capture transaction $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType( "authCaptureTransaction"); $transactionRequestType->setPayment($paymentOne); $transactionRequestType->setAmount($amount); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setTransactionRequest( $transactionRequestType); $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; //Valid response codes: 1=Approved, 2=Declined, 3=Error, 5=Need Payer Consent echo "Secure acceptance URL: ".$tresponse->getSecureAcceptance()->getSecureAcceptanceUrl()."\n"; echo "Transaction ID: ".$tresponse->getTransId()."\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) payPalAuthorizeCapture(12.322); ?> ================================================ FILE: PayPalExpressCheckout/authorization-only-continued.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Set PayPal compatible merchant credentials $payPalType=new AnetAPI\PayPalType(); $payPalType->setPayerID($payerID); $paypal_type->setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); $paypal_type->setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); $payment_type = new AnetAPI\PaymentType(); $payment_type->setPayPal($paypal_type); //create a transaction $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType("authOnlyContinueTransaction"); $transactionRequestType->setRefTransId($transactionId); $transactionRequestType->setAmount(125.34); $transactionRequestType->setPayment($payment_type); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setTransactionRequest($transactionRequestType); $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if ($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo "TRANS ID : " . $tresponse->getTransId() . "\n"; echo "Payer ID : " . $tresponse->getSecureAcceptance()->getPayerID(); echo "Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if ($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if (!defined('DONT_RUN_SAMPLES')) { payPalAuthorizeOnlyContinued("2241711631", "JJLRRB29QC7RU"); } ================================================ FILE: PayPalExpressCheckout/authorization-only.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Create the payment data for a paypal account $payPalType = new AnetAPI\PayPalType(); $payPalType->setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); $payPalType->setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setPayPal($payPalType); //create a auth-only transaction $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType( "authOnlyTransaction"); $transactionRequestType->setAmount($amount); $transactionRequestType->setPayment($paymentOne); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId( $refId); $request->setTransactionRequest( $transactionRequestType); $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo "Received response code: ".$tresponse->getResponseCode()."\n"; //Valid response codes: 1=Approved, 2=Declined, 3=Error, 5=Need Payer Consent\n"; echo "Secure acceptance URL: ".$tresponse->getSecureAcceptance()->getSecureAcceptanceUrl()."\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) payPalAuthorizeOnly(23.34); ?> ================================================ FILE: PayPalExpressCheckout/credit.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); //use transaction of already settled paypal checkout transaction $refTransId = $transactionId; // Create the payment data for a paypal account $payPalType = new AnetAPI\PayPalType(); $payPalType->setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); $payPalType->setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setPayPal($payPalType); //create a refund transaction $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType( "refundTransaction"); $transactionRequestType->setAmount(181); $transactionRequestType->setPayment($paymentOne); ///refTransId of successfully settled transaction $transactionRequestType->setRefTransId($refTransId); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId( $refId); $request->setTransactionRequest( $transactionRequestType); $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo "Credit SUCCESS AUTH CODE : " . $tresponse->getAuthCode() . "\n"; echo "Credit TRANS ID : " . $tresponse->getTransId() . "\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')){ //use transaction id of already settled transaction payPalCredit("2241762126"); } ?> ================================================ FILE: PayPalExpressCheckout/get-details.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); //create a transaction of type get details $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType( "getDetailsTransaction"); //replace following transaction ID with your transaction ID for which the details are required $transactionRequestType->setRefTransId($transactionId); // Create the payment data for a paypal account $payPalType = new AnetAPI\PayPalType(); $payPalType->setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); $payPalType->setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setPayPal($payPalType); $transactionRequestType->setPayment($paymentOne); //create a transaction request $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId( $refId); $request->setTransactionRequest( $transactionRequestType); $controller = new AnetController\CreateTransactionController($request); //execute the api call to get transaction details $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo "Transaction Response...\n"; echo "Received response code: ".$tresponse->getResponseCode()."\n"; echo "Transaction ID: ".$tresponse->getTransId()."\n"; //Valid response codes: 1=Approved, 2=Declined, 3=Error, 5=Need Payer Consent if(null != $tresponse->getSecureAcceptance()) { echo "Payer ID : " . $tresponse->getSecureAcceptance()->getPayerID() . "\n"; } //parse the shipping information from response $shipping_response = $tresponse->getShipTo(); if(null != $shipping_response) { echo "Shipping address : " . $shipping_response->getAddress() . ", " . $shipping_response->getCity() . ", " . $shipping_response->getState() . ", " . $shipping_response->getCountry() . "\n"; } echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) payPalGetDetails("60007107304"); ?> ================================================ FILE: PayPalExpressCheckout/prior-authorization-capture.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); $payPalType = new AnetAPI\PayPalType(); $payPalType->setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); $payPalType->setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); $paymentType = new AnetAPI\PaymentType(); $paymentType->setPayPal($payPalType); $transactionRequest = new AnetAPI\TransactionRequestType(); $transactionRequest->setTransactionType("priorAuthCaptureTransaction"); $transactionRequest->setPayment($paymentType); $transactionRequest->setAmount(floatval(19.45)); $transactionRequest->setRefTransId($transactionId); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId( $refId); $request->setTransactionRequest($transactionRequest); $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo "Prior Authorization capture AUTH CODE : " . $tresponse->getAuthCode() . "\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) { payPalPriorAuthorizationCapture("2249863278"); } ?> ================================================ FILE: PayPalExpressCheckout/void.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); $payPalType = new AnetAPI\PayPalType(); $payPalType->setSuccessUrl(""); $payPalType->setCancelUrl(""); $paymentType = new AnetAPI\PaymentType(); $paymentType->setPayPal($payPalType); $transactionRequest = new AnetAPI\TransactionRequestType(); $transactionRequest->setTransactionType("voidTransaction"); $transactionRequest->setPayment($paymentType); $transactionRequest->setRefTransId($transactionId); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId( $refId); $request->setTransactionRequest($transactionRequest); $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo "Void transaction SUCCESS TRANS ID : " . $tresponse->getTransId() . "\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) payPalVoid("2241706281"); ?> ================================================ FILE: PaymentTransactions/authorize-credit-card.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Create the payment data for a credit card $creditCard = new AnetAPI\CreditCardType(); $creditCard->setCardNumber("4111111111111111"); $creditCard->setExpirationDate("2038-12"); $creditCard->setCardCode("123"); // Add the payment data to a paymentType object $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setCreditCard($creditCard); // Create order information $order = new AnetAPI\OrderType(); $order->setInvoiceNumber("10101"); $order->setDescription("Golf Shirts"); // Set the customer's Bill To address $customerAddress = new AnetAPI\CustomerAddressType(); $customerAddress->setFirstName("Ellen"); $customerAddress->setLastName("Johnson"); $customerAddress->setCompany("Souveniropolis"); $customerAddress->setAddress("14 Main Street"); $customerAddress->setCity("Pecan Springs"); $customerAddress->setState("TX"); $customerAddress->setZip("44628"); $customerAddress->setCountry("USA"); // Set the customer's identifying information $customerData = new AnetAPI\CustomerDataType(); $customerData->setType("individual"); $customerData->setId("99999456654"); $customerData->setEmail("EllenJohnson@example.com"); // Add values for transaction settings $duplicateWindowSetting = new AnetAPI\SettingType(); $duplicateWindowSetting->setSettingName("duplicateWindow"); $duplicateWindowSetting->setSettingValue("60"); // Add some merchant defined fields. These fields won't be stored with the transaction, // but will be echoed back in the response. $merchantDefinedField1 = new AnetAPI\UserFieldType(); $merchantDefinedField1->setName("customerLoyaltyNum"); $merchantDefinedField1->setValue("1128836273"); $merchantDefinedField2 = new AnetAPI\UserFieldType(); $merchantDefinedField2->setName("favoriteColor"); $merchantDefinedField2->setValue("blue"); // Create a TransactionRequestType object and add the previous objects to it $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType("authOnlyTransaction"); $transactionRequestType->setAmount($amount); $transactionRequestType->setOrder($order); $transactionRequestType->setPayment($paymentOne); $transactionRequestType->setBillTo($customerAddress); $transactionRequestType->setCustomer($customerData); $transactionRequestType->addToTransactionSettings($duplicateWindowSetting); $transactionRequestType->addToUserFields($merchantDefinedField1); $transactionRequestType->addToUserFields($merchantDefinedField2); // Assemble the complete transaction request $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setTransactionRequest($transactionRequestType); // Create the controller and get the response $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { // Check to see if the API request was successfully received and acted upon if ($response->getMessages()->getResultCode() == "Ok") { // Since the API request was successful, look for a transaction response // and parse it to display the results of authorizing the card $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Successfully created transaction with Transaction ID: " . $tresponse->getTransId() . "\n"; echo " Transaction Response Code: " . $tresponse->getResponseCode() . "\n"; echo " Message Code: " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Auth Code: " . $tresponse->getAuthCode() . "\n"; echo " Description: " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if ($tresponse->getErrors() != null) { echo " Error Code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } // Or, print errors if the API request wasn't successful } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getErrors() != null) { echo " Error Code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error Code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error Message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if (!defined('DONT_RUN_SAMPLES')) { authorizeCreditCard("2.23"); } ?> ================================================ FILE: PaymentTransactions/capture-funds-authorized-through-another-channel.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); $creditCard = new AnetAPI\CreditCardType(); $creditCard->setCardNumber("4111111111111111"); $creditCard->setExpirationDate("2038-12"); $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setCreditCard($creditCard); $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType("captureOnlyTransaction"); $transactionRequestType->setAmount($amount); $transactionRequestType->setPayment($paymentOne); //Auth code of the previously authorized amount $transactionRequestType->setAuthCode("ROHNFQ"); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setTransactionRequest( $transactionRequestType); $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo "Successful." . "\n"; echo "Capture funds authorized through another channel TRANS ID : " . $tresponse->getTransId() . " Amount : $amount \n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) captureFundsAuthorizedThroughAnotherChannel((rand(1, 999)/12*12)); ?> ================================================ FILE: PaymentTransactions/capture-previously-authorized-amount.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Now capture the previously authorized amount echo "Capturing the Authorization with transaction ID : " . $transactionid . "\n"; $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType("priorAuthCaptureTransaction"); $transactionRequestType->setRefTransId($transactionid); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setTransactionRequest( $transactionRequestType); $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo "Successful." . "\n"; echo "Capture Previously Authorized Amount, Trans ID : " . $tresponse->getRefTransId() . "\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) capturePreviouslyAuthorizedAmount(60007076002); ?> ================================================ FILE: PaymentTransactions/charge-credit-card.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Create the payment data for a credit card $creditCard = new AnetAPI\CreditCardType(); $creditCard->setCardNumber("4111111111111111"); $creditCard->setExpirationDate("2038-12"); $creditCard->setCardCode("123"); // Add the payment data to a paymentType object $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setCreditCard($creditCard); // Create order information $order = new AnetAPI\OrderType(); $order->setInvoiceNumber("10101"); $order->setDescription("Golf Shirts"); // Set the customer's Bill To address $customerAddress = new AnetAPI\CustomerAddressType(); $customerAddress->setFirstName("Ellen"); $customerAddress->setLastName("Johnson"); $customerAddress->setCompany("Souveniropolis"); $customerAddress->setAddress("14 Main Street"); $customerAddress->setCity("Pecan Springs"); $customerAddress->setState("TX"); $customerAddress->setZip("44628"); $customerAddress->setCountry("USA"); // Set the customer's identifying information $customerData = new AnetAPI\CustomerDataType(); $customerData->setType("individual"); $customerData->setId("99999456654"); $customerData->setEmail("EllenJohnson@example.com"); // Add values for transaction settings $duplicateWindowSetting = new AnetAPI\SettingType(); $duplicateWindowSetting->setSettingName("duplicateWindow"); $duplicateWindowSetting->setSettingValue("60"); // Add some merchant defined fields. These fields won't be stored with the transaction, // but will be echoed back in the response. $merchantDefinedField1 = new AnetAPI\UserFieldType(); $merchantDefinedField1->setName("customerLoyaltyNum"); $merchantDefinedField1->setValue("1128836273"); $merchantDefinedField2 = new AnetAPI\UserFieldType(); $merchantDefinedField2->setName("favoriteColor"); $merchantDefinedField2->setValue("blue"); // Create a TransactionRequestType object and add the previous objects to it $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType("authCaptureTransaction"); $transactionRequestType->setAmount($amount); $transactionRequestType->setOrder($order); $transactionRequestType->setPayment($paymentOne); $transactionRequestType->setBillTo($customerAddress); $transactionRequestType->setCustomer($customerData); $transactionRequestType->addToTransactionSettings($duplicateWindowSetting); $transactionRequestType->addToUserFields($merchantDefinedField1); $transactionRequestType->addToUserFields($merchantDefinedField2); // Assemble the complete transaction request $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setTransactionRequest($transactionRequestType); // Create the controller and get the response $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { // Check to see if the API request was successfully received and acted upon if ($response->getMessages()->getResultCode() == "Ok") { // Since the API request was successful, look for a transaction response // and parse it to display the results of authorizing the card $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Successfully created transaction with Transaction ID: " . $tresponse->getTransId() . "\n"; echo " Transaction Response Code: " . $tresponse->getResponseCode() . "\n"; echo " Message Code: " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Auth Code: " . $tresponse->getAuthCode() . "\n"; echo " Description: " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if ($tresponse->getErrors() != null) { echo " Error Code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } // Or, print errors if the API request wasn't successful } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getErrors() != null) { echo " Error Code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error Code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error Message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if (!defined('DONT_RUN_SAMPLES')) { chargeCreditCard("2.23"); } ================================================ FILE: PaymentTransactions/charge-customer-profile.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); $profileToCharge = new AnetAPI\CustomerProfilePaymentType(); $profileToCharge->setCustomerProfileId($profileid); $paymentProfile = new AnetAPI\PaymentProfileType(); $paymentProfile->setPaymentProfileId($paymentprofileid); $profileToCharge->setPaymentProfile($paymentProfile); $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType( "authCaptureTransaction"); $transactionRequestType->setAmount($amount); $transactionRequestType->setProfile($profileToCharge); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId( $refId); $request->setTransactionRequest( $transactionRequestType); $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo "Charge Customer Profile APPROVED :" . "\n"; echo " Charge Customer Profile AUTH CODE : " . $tresponse->getAuthCode() . "\n"; echo " Charge Customer Profile TRANS ID : " . $tresponse->getTransId() . "\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) chargeCustomerProfile("36731856","32689274",12.23); ?> ================================================ FILE: PaymentTransactions/charge-tokenized-credit-card.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Create the payment data for a credit card $creditCard = new AnetAPI\CreditCardType(); $creditCard->setCardNumber("4111111111111111"); $creditCard->setExpirationDate("2038-12"); // Set the token specific info $creditCard->setIsPaymentToken(true); $creditCard->setCryptogram("EjRWeJASNFZ4kBI0VniQEjRWeJA="); $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setCreditCard($creditCard); //create a transaction $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType("authCaptureTransaction"); $transactionRequestType->setAmount($amount); $transactionRequestType->setPayment($paymentOne); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId( $refId); $request->setTransactionRequest( $transactionRequestType); $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo "Charge Tokenized Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n"; echo "Charge Tokenized Credit Card TRANS ID : " . $tresponse->getTransId() . "\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) chargeTokenizedCreditCard(12.23); ?> ================================================ FILE: PaymentTransactions/create-chase-pay-transaction.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Create the payment data for a credit card $creditCard = new AnetAPI\CreditCardType(); $creditCard->setCardNumber("4111111111111111"); $creditCard->setExpirationDate("2038-12"); $creditCard->setCardCode("999"); // Set the token specific info $creditCard->setIsPaymentToken(true); $creditCard->setCryptogram("EjRWeJASNFZ4kBI0VniQEjRWeJA="); $creditCard->setTokenRequestorName("CHASE_PAY"); $creditCard->setTokenRequestorId("12345678901"); $creditCard->setTokenRequestorEci("07"); $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setCreditCard($creditCard); //create a transaction $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType("authCaptureTransaction"); $transactionRequestType->setAmount($amount); $transactionRequestType->setPayment($paymentOne); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId( $refId); $request->setTransactionRequest( $transactionRequestType); $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo "Charge Tokenized Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n"; echo "Charge Tokenized Credit Card TRANS ID : " . $tresponse->getTransId() . "\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) createChasePayTransaction(12.23); ?> ================================================ FILE: PaymentTransactions/credit-bank-account.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); //Generate random bank account number $randomAccountNumber= rand(100000000,9999999999); // Create the payment data for a Bank Account $bankAccount = new AnetAPI\BankAccountType(); $bankAccount->setAccountType('checking'); // see eCheck documentation for proper echeck type to use for each situation //$bankAccount->setEcheckType('WEB'); $bankAccount->setRoutingNumber('122000661'); //('122235821'); //('125008547'); $bankAccount->setAccountNumber($randomAccountNumber); $bankAccount->setNameOnAccount('John Doe'); $bankAccount->setBankName('Wells Fargo Bank NA'); $paymentBank= new AnetAPI\PaymentType(); $paymentBank->setBankAccount($bankAccount); // Order info $order = new AnetAPI\OrderType(); $order->setInvoiceNumber("101"); $order->setDescription("Golf Shirts"); //create a bank credit transaction $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType("refundTransaction"); $transactionRequestType->setAmount($amount); $transactionRequestType->setPayment($paymentBank); $transactionRequestType->setOrder($order); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setTransactionRequest($transactionRequestType); $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if ($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo "Credit Bank Account APPROVED :" . "\n"; echo "Credit Bank Account AUTH CODE : " . $tresponse->getAuthCode() . "\n"; echo "Credit Bank Account TRANS ID : " . $tresponse->getTransId() . "\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if ($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if (!defined('DONT_RUN_SAMPLES')) { creditBankAccount(5.29); } ================================================ FILE: PaymentTransactions/debit-bank-account.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); //Generate random bank account number $randomAccountNumber= rand(100000000,9999999999); // Create the payment data for a Bank Account $bankAccount = new AnetAPI\BankAccountType(); $bankAccount->setAccountType('checking'); // see eCheck documentation for proper echeck type to use for each situation $bankAccount->setEcheckType('WEB'); $bankAccount->setRoutingNumber('122000661'); $bankAccount->setAccountNumber(rand(10000,999999999999)); $bankAccount->setNameOnAccount('John Doe'); $bankAccount->setBankName('Wells Fargo Bank NA'); $paymentBank= new AnetAPI\PaymentType(); $paymentBank->setBankAccount($bankAccount); // Order info $order = new AnetAPI\OrderType(); $order->setInvoiceNumber("101"); $order->setDescription("Golf Shirts"); //create a bank debit transaction $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType("authCaptureTransaction"); $transactionRequestType->setAmount($amount); $transactionRequestType->setPayment($paymentBank); $transactionRequestType->setOrder($order); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setTransactionRequest($transactionRequestType); $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if ($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo " Debit Bank Account APPROVED :" . "\n"; echo " Debit Bank Account AUTH CODE : " . $tresponse->getAuthCode() . "\n"; echo " Debit Bank Account TRANS ID : " . $tresponse->getTransId() . "\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if ($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if (!defined('DONT_RUN_SAMPLES')) { debitBankAccount(5.29); } ================================================ FILE: PaymentTransactions/refund-transaction.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Create the payment data for a credit card $creditCard = new AnetAPI\CreditCardType(); $creditCard->setCardNumber("0015"); $creditCard->setExpirationDate("XXXX"); $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setCreditCard($creditCard); //create a transaction $transactionRequest = new AnetAPI\TransactionRequestType(); $transactionRequest->setTransactionType( "refundTransaction"); $transactionRequest->setAmount($amount); $transactionRequest->setPayment($paymentOne); $transactionRequest->setRefTransId($refTransId); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setTransactionRequest( $transactionRequest); $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo "Refund SUCCESS: " . $tresponse->getTransId() . "\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) refundTransaction( "2.23"); ?> ================================================ FILE: PaymentTransactions/update-split-tender-group.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); $request = new AnetAPI\UpdateSplitTenderGroupRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setSplitTenderId("115901"); $request->setSplitTenderStatus("voided"); $controller = new AnetController\UpdateSplitTenderGroupController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { $errorMessages = $response->getMessages()->getMessage(); echo "SUCCESS Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } else { echo "ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) updateSplitTenderGroup(); ?> ================================================ FILE: PaymentTransactions/void-transaction.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); //create a transaction $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType( "voidTransaction"); $transactionRequestType->setRefTransId($transactionid); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setTransactionRequest( $transactionRequestType); $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo " Void transaction SUCCESS AUTH CODE: " . $tresponse->getAuthCode() . "\n"; echo " Void transaction SUCCESS TRANS ID : " . $tresponse->getTransId() . "\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) voidTransaction("60009605785"); ?> ================================================ FILE: README.md ================================================ # PHP Sample Code for the Authorize.Net SDK [![Travis CI Status](https://travis-ci.org/AuthorizeNet/sample-code-php.svg?branch=master)](https://travis-ci.org/AuthorizeNet/sample-code-php) This repository contains working code samples which demonstrate PHP integration with the [Authorize.Net PHP SDK](https://github.com/AuthorizeNet/sdk-php). The samples are organized into categories and common usage examples, just like our [API Reference Guide](http://developer.authorize.net/api/reference). Our API Reference Guide is an interactive reference for the Authorize.Net API. It explains the request and response parameters for each API method and has embedded code windows to allow you to send actual requests right within the API Reference Guide. ## Using the Sample Code The samples are all completely independent and self-contained. You can analyze them to get an understanding of how a particular method works, or you can use the snippets as a starting point for your own project. You can also run each sample directly from the command line. ## Running the Samples From the Command Line * Clone this repository: ``` $ git clone https://github.com/AuthorizeNet/sample-code-php.git ``` * Run composer with the "update" option in the root directory of the repository. ``` $ composer update ``` * Run the individual samples by name. For example: ``` $ php PaymentTransactions/[CodeSampleName] ``` e.g. ``` $ php PaymentTransactions/authorize-credit-card.php ``` ### Installation Notes Note: If during "composer update", you get the error "composer failed to open stream invalid argument", go to your php.ini file (present where you have installed PHP), and uncomment the following lines: ``` extension=php_openssl.dll extension=php_curl.dll ``` On Windows systems, you also have to uncomment: ``` extension_dir = "ext" ``` Then run `composer update` again. You might have to restart your machine before the changes take effect. ### What if I'm not using Composer? We provide a custom `SPL` autoloader. Just [download the SDK](https://github.com/AuthorizeNet/sdk-php/releases) and point to its `autoload.php` file: ```php require 'path/to/anet_php_sdk/autoload.php'; ``` ================================================ FILE: RecurringBilling/cancel-subscription.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); $request = new AnetAPI\ARBCancelSubscriptionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setSubscriptionId($subscriptionId); $controller = new AnetController\ARBCancelSubscriptionController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { $successMessages = $response->getMessages()->getMessage(); echo "SUCCESS : " . $successMessages[0]->getCode() . " " .$successMessages[0]->getText() . "\n"; } else { echo "ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) cancelSubscription("7087965"); ?> ================================================ FILE: RecurringBilling/create-subscription-from-customer-profile.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Subscription Type Info $subscription = new AnetAPI\ARBSubscriptionType(); $subscription->setName("Sample Subscription"); $interval = new AnetAPI\PaymentScheduleType\IntervalAType(); $interval->setLength($intervalLength); $interval->setUnit("days"); $paymentSchedule = new AnetAPI\PaymentScheduleType(); $paymentSchedule->setInterval($interval); $paymentSchedule->setStartDate(new DateTime('2035-08-30')); $paymentSchedule->setTotalOccurrences("12"); $paymentSchedule->setTrialOccurrences("1"); $subscription->setPaymentSchedule($paymentSchedule); $subscription->setAmount(rand(1,99999)/12.0*12); $subscription->setTrialAmount("0.00"); $profile = new AnetAPI\CustomerProfileIdType(); $profile->setCustomerProfileId($customerProfileId); $profile->setCustomerPaymentProfileId($customerPaymentProfileId); $profile->setCustomerAddressId($customerAddressId); $subscription->setProfile($profile); $request = new AnetAPI\ARBCreateSubscriptionRequest(); $request->setmerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setSubscription($subscription); $controller = new AnetController\ARBCreateSubscriptionController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { echo "SUCCESS: Subscription ID : " . $response->getSubscriptionId() . "\n"; } else { echo "ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) createSubscriptionFromCustomerProfile( \SampleCode\Constants::SUBSCRIPTION_INTERVAL_DAYS, "247150", "215472", "189691"); ?> ================================================ FILE: RecurringBilling/create-subscription.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Subscription Type Info $subscription = new AnetAPI\ARBSubscriptionType(); $subscription->setName("Sample Subscription"); $interval = new AnetAPI\PaymentScheduleType\IntervalAType(); $interval->setLength($intervalLength); $interval->setUnit("days"); $paymentSchedule = new AnetAPI\PaymentScheduleType(); $paymentSchedule->setInterval($interval); $paymentSchedule->setStartDate(new DateTime('2035-12-30')); $paymentSchedule->setTotalOccurrences("12"); $paymentSchedule->setTrialOccurrences("1"); $subscription->setPaymentSchedule($paymentSchedule); $subscription->setAmount(rand(1,99999)/12.0*12); $subscription->setTrialAmount("0.00"); $creditCard = new AnetAPI\CreditCardType(); $creditCard->setCardNumber("4111111111111111"); $creditCard->setExpirationDate("2038-12"); $payment = new AnetAPI\PaymentType(); $payment->setCreditCard($creditCard); $subscription->setPayment($payment); $order = new AnetAPI\OrderType(); $order->setInvoiceNumber("1234354"); $order->setDescription("Description of the subscription"); $subscription->setOrder($order); $billTo = new AnetAPI\NameAndAddressType(); $billTo->setFirstName("John"); $billTo->setLastName("Smith"); $subscription->setBillTo($billTo); $request = new AnetAPI\ARBCreateSubscriptionRequest(); $request->setmerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setSubscription($subscription); $controller = new AnetController\ARBCreateSubscriptionController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { echo "SUCCESS: Subscription ID : " . $response->getSubscriptionId() . "\n"; } else { echo "ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) createSubscription(23); ?> ================================================ FILE: RecurringBilling/get-list-of-subscriptions.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); $sorting = new AnetAPI\ARBGetSubscriptionListSortingType(); $sorting->setOrderBy("id"); $sorting->setOrderDescending(false); $paging = new AnetAPI\PagingType(); $paging->setLimit("10"); $paging->setOffset("1"); $request = new AnetAPI\ARBGetSubscriptionListRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setSearchType("subscriptionInactive"); $request->setSorting($sorting); $request->setPaging($paging); $controller = new AnetController\ARBGetSubscriptionListController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { echo "SUCCESS: Subscription Details:" . "\n"; echo "Total Number In Results:" . $response->getTotalNumInResultSet() . "\n"; if ($response->getTotalNumInResultSet() > 0) { foreach ($response->getSubscriptionDetails() as $subscriptionDetails) { echo "Subscription ID: " . $subscriptionDetails->getId() . "\n"; } } } else { echo "ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if (!defined('DONT_RUN_SAMPLES')) { getListOfSubscriptions(); } ================================================ FILE: RecurringBilling/get-subscription-status.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); $request = new AnetAPI\ARBGetSubscriptionStatusRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setSubscriptionId($subscriptionId); $controller = new AnetController\ARBGetSubscriptionStatusController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { echo "SUCCESS: Subscription Status : " . $response->getStatus() . "\n"; } else { echo "ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) getSubscriptionStatus("3056948"); ?> ================================================ FILE: RecurringBilling/get-subscription.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Creating the API Request with required parameters $request = new AnetAPI\ARBGetSubscriptionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setSubscriptionId($subscriptionId); $request->setIncludeTransactions(true); // Controller $controller = new AnetController\ARBGetSubscriptionController($request); // Getting the response $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if($response->getMessages()->getResultCode() == "Ok") { // Success echo "SUCCESS: GetSubscription:" . "\n"; // Displaying the details echo "Subscription Name: " . $response->getSubscription()->getName(). "\n"; echo "Subscription amount: " . $response->getSubscription()->getAmount(). "\n"; echo "Subscription status: " . $response->getSubscription()->getStatus(). "\n"; echo "Subscription Description: " . $response->getSubscription()->getProfile()->getDescription(). "\n"; echo "Customer Profile ID: " . $response->getSubscription()->getProfile()->getCustomerProfileId() . "\n"; echo "Customer payment Profile ID: ". $response->getSubscription()->getProfile()->getPaymentProfile()->getCustomerPaymentProfileId() . "\n"; $transactions = $response->getSubscription()->getArbTransactions(); if($transactions != null){ foreach ($transactions as $transaction) { echo "Transaction ID : ".$transaction->getTransId()." -- ".$transaction->getResponse()." -- Pay Number : ".$transaction->getPayNum()."\n"; } } } else { // Error echo "ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } } else { // Failed to get response echo "Null Response Error"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) getSubscription("2942461"); ?> ================================================ FILE: RecurringBilling/update-subscription.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); $subscription = new AnetAPI\ARBSubscriptionType(); $creditCard = new AnetAPI\CreditCardType(); $creditCard->setCardNumber("4111111111111111"); $creditCard->setExpirationDate("2038-12"); $payment = new AnetAPI\PaymentType(); $payment->setCreditCard($creditCard); //set profile information $profile = new AnetAPI\CustomerProfileIdType(); $profile->setCustomerProfileId("121212"); $profile->setCustomerPaymentProfileId("131313"); $profile->setCustomerAddressId("141414"); $subscription->setPayment($payment); //set customer profile information //$subscription->setProfile($profile); $request = new AnetAPI\ARBUpdateSubscriptionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setSubscriptionId($subscriptionId); $request->setSubscription($subscription); $controller = new AnetController\ARBUpdateSubscriptionController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { $errorMessages = $response->getMessages()->getMessage(); echo "SUCCESS Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } else { echo "ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) updateSubscription("3056948"); ?> ================================================ FILE: SampleCodeList.txt ================================================ SampleCodeName,IsDependent,ShouldRun ChargeCreditCard,1,1 CreateSubscription,1,1 CreateSubscriptionFromCustomerProfile,1,1 GetCustomerPaymentProfileList,0,1 GetTransactionList,0,1 CreateAnApplePayTransaction,0,0 CreateAnAcceptTransaction,0,0 CreateAnAndroidPayTransaction,0,0 decryptVisaSrcData,0,0 createVisaSrcTransaction,0,0 CaptureFundsAuthorizedThroughAnotherChannel,1,1 AuthorizeCreditCard,1,1 DebitBankAccount,1,1 ChargeTokenizedCreditCard,0,0 PayPalAuthorizeOnly,1,1 GetListOfSubscriptions,0,1 GetUnsettledTransactionList,0,1 GetBatchStatistics,1,1 GetSettledBatchList,1,1 UpdateSplitTenderGroup,0,1 UpdateCustomerShippingAddress,1,1 UpdateCustomerProfile,0,1 UpdateCustomerPaymentProfile,1,1 GetCustomerShippingAddress,1,1 GetCustomerProfileIds,0,0 GetCustomerProfile,1,1 GetAcceptCustomerProfilePage,1,1 GetCustomerPaymentProfile,1,1 DeleteCustomerShippingAddress,1,1 DeleteCustomerProfile,1,1 DeleteCustomerPaymentProfile,1,1 CreateCustomerShippingAddress,1,1 CreateCustomerProfileFromTransaction,0,0 GetTransactionDetails,1,1 CapturePreviouslyAuthorizedgetAmount,1,0 RefundTransaction,1,0 VoidTransaction,1,1 CreditBankAccount,1,0 ChargeCustomerProfile,1,1 PayPalVoid,1,0 PayPalAuthorizeCapture,1,1 PayPalAuthorizeCaptureContinued,1,1 PayPalAuthorizeOnlyContinued,1,0 PayPalCredit,1,0 PayPalGetDetails,1,1 PayPalPriorAuthorizationCapture,1,0 CancelSubscription,1,1 GetSubscriptionStatus,1,1 GetSubscription,1,1 UpdateSubscription,1,1 CreateCustomerProfile,1,1 CreateCustomerPaymentProfile,1,1 ValidateCustomerPaymentProfile,1,0 GetMerchantDetails,0,1 UpdateHeldTransaction,1,0 GetAnAcceptPaymentPage,0,1 CreateAnAcceptPaymentTransaction,0,0 ================================================ FILE: Sha512/compute_trans_hashSHA2.php ================================================ ================================================ FILE: TestRunner.php ================================================ '); } $dirPath = $_SERVER['argv'][2]; echo $dirPath; if (substr($dirPath, -1) != "/") { $dirPath = $dirPath."/"; } $directories = array( 'CustomerProfiles/', 'RecurringBilling/', 'PayPalExpressCheckout/', 'PaymentTransactions/', 'TransactionReporting/', 'MobileInappTransactions/', 'VisaCheckout/', 'AcceptSuite/' ); $errorlevel=error_reporting(); error_reporting($errorlevel & ~E_NOTICE); //turn off constant re-defined and other notices foreach ($directories as $directory) { foreach (glob($dirPath.$directory . "*.php") as $sample) { require_once $sample; //echo $sample; } } error_reporting($errorlevel); class TestRunner extends PHPUnit\Framework\TestCase { public static $apiLoginId = "5KP3u95bQpv"; public static $transactionKey = "346HZ32z3fP4hTG2"; public static $transactionID = "2245440957"; public static $payerID = "LM6NCLZ5RAKBY"; //random amount for transactions/subscriptions public static function getAmount() { return 12 + (rand(1, 9000)/10); } //random email for a new customer profile public static function getEmail() { return rand(0, 10000) . "@test" .rand(0, 10000) .".com"; } //random phonenumber for customer payment profile public static function getPhoneNumber() { return self::toPhoneNumber(rand(0, 9999999999)); } public static function getDay() { return rand(7, 365); } public function testAllSampleCodes() { $runTests = 0; $file = $GLOBALS["dirPath"]."SampleCodeList.txt"; $data = file($file) or die('\nCould not read SampleCodeList.'); foreach ($data as $line) { $line=trim($line); if (trim($line)) { list($apiName, $isDependent, $shouldRun)=explode(",", $line); $apiName = trim($apiName); echo "\nApi name: " . $apiName."\n"; fwrite(STDOUT, print_r("\nStarting Test: " . $apiName."\n", TRUE)); } if ($apiName && (false === strpos($apiName, SAMPLE_CODE_NAME_HEADING))) { echo "should run:".$shouldRun."\n"; if ("0" === $shouldRun) { echo ":Skipping " . $apiName . "\n"; } else { //Try the request twice for ($i=0; $i<=1; $i++) { if ("0" === $isDependent) { echo "not dependent\n"; $sampleMethodName = $apiName; $sampleMethodName[0] = strtolower($sampleMethodName[0]); } else { $sampleMethodName = "TestRunner::run" . $apiName; echo " is dependent\n"; } //request the api echo "Running sample: " . $sampleMethodName . "\n"; fwrite(STDOUT, print_r($apiName . "Start Time: " . date("H:i:s."). gettimeofday()['usec'] . "\n", TRUE)); $response = call_user_func($sampleMethodName); fwrite(STDOUT, print_r($apiName . "Finish Time: " . date("H:i:s."). gettimeofday()['usec'] . "\n", TRUE)); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { break; } } //response must be successful $this->assertNotNull($response); $this->assertEquals($response->getMessages()->getResultCode(), "Ok"); echo $sampleMethodName . " - OK \n"; $runTests++; } } } echo "Number of sample codes run: ". $runTests; } private static function toPhoneNumber($num) { $zeroPadded = sprintf("%10d", $num); return substr($zeroPadded, 0, 3)."-".substr($zeroPadded, 3, 3)."-".substr(6, 4); } public static function runAuthorizeCreditCard() { return authorizeCreditCard(self::getAmount()); } public static function runCaptureFundsAuthorizedThroughAnotherChannel() { return captureFundsAuthorizedThroughAnotherChannel(self::getAmount()); } public static function runDebitBankAccount() { return debitBankAccount(self::getAmount()%98+1); //cannot debit more than 100 } public static function runChargeTokenizedCreditCard() { return chargeTokenizedCreditCard(self::getAmount()); } public static function runCreateAnAcceptPaymentTransaction() { return createAnAcceptPaymentTransaction(self::getAmount()); } public static function runChargeCreditCard() { return chargeCreditCard(self::getAmount()); } public static function runCapturePreviouslyAuthorizedAmount() { $response = authorizeCreditCard(self::getAmount()); return capturePreviouslyAuthorizedAmount($response->getTransactionResponse()->getTransId()); } public static function runRefundTransaction() { $response = authorizeCreditCard.run(self::getAmount()); $response = capturePreviouslyAuthorizedAmount($response->getTransactionResponse()->getTransId()); return refundTransaction(self::getAmount()); } public static function runVoidTransaction() { $response = authorizeCreditCard(self::getAmount()); return voidTransaction($response->getTransactionResponse()->getTransId()); } public static function runCreditBankAccount() { return creditBankAccount(self::getAmount()); } public static function runChargeCustomerProfile() { $response = createCustomerProfile(self::getEmail()); $paymentProfileResponse = createCustomerPaymentProfile( $response->getCustomerProfileId(), self::getPhoneNumber() ); $chargeResponse = chargeCustomerProfile( $response->getCustomerProfileId(), $paymentProfileResponse->getCustomerPaymentProfileId(), self::getAmount() ); deleteCustomerProfile($response->getCustomerProfileId()); return $chargeResponse; } private static function runPayPalVoid() { $response = payPalAuthorizeCapture(self::getAmount()); return payPalVoid($response->getTransactionResponse()->getTransId()); } private static function runPayPalAuthorizeCapture() { return payPalAuthorizeCapture(self::getAmount()); } private static function runPayPalAuthorizeCaptureContinued() { $response = payPalAuthorizeCapture(self::getAmount()); return payPalAuthorizeCaptureContinued($response->getTransactionResponse()->getTransId(), self::$payerID); } public static function runPayPalAuthorizeOnlyContinued() { return payPalAuthorizeOnlyContinued(self::$transactionID, self::$payerID); } public static function runPayPalCredit() { return payPalCredit(self::$transactionID); } public static function runPayPalAuthorizeOnly() { return payPalAuthorizeOnly(self::getAmount()); } public static function runPayPalGetDetails() { $response = payPalAuthorizeCapture(self::getAmount()); return payPalGetDetails($response->getTransactionResponse()->getTransId()); } public static function runPayPalPriorAuthorizationCapture() { $response = payPalAuthorizeCapture(self::getAmount()); return payPalPriorAuthorizationCapture($response->getTransactionResponse()->getTransId()); } // ****ARB Subscription methods****** public static function runCreateSubscription() { $response = createSubscription(self::getDay()); cancelSubscription($response->getSubscriptionId()); return $response; } public static function runCreateSubscriptionFromCustomerProfile() { $responseCustomerProfile = createCustomerProfile(self::getEmail()); $responseCustomerPaymentProfile = createCustomerPaymentProfile( $responseCustomerProfile->getCustomerProfileId(), self::getPhoneNumber() ); $responseCustomerShippingAddress = createCustomerShippingAddress( $responseCustomerProfile->getCustomerProfileId(), self::getPhoneNumber() ); $response = createSubscription( self::getDay(), $responseCustomerProfile->getCustomerProfileId(), $responseCustomerPaymentProfile->getCustomerPaymentProfileId(), $responseCustomerShippingAddress->getCustomerAddressId() ); cancelSubscription($response->getSubscriptionId()); deleteCustomerProfile($responseCustomerProfile->getCustomerProfileId()); return $response; } public static function runCancelSubscription() { $response = createSubscription(self::getDay()); return cancelSubscription($response->getSubscriptionId()); } public static function runGetSubscriptionStatus() { $response = createSubscription(self::getDay()); $status_response = getSubscriptionStatus($response->getSubscriptionId()); cancelSubscription($response->getSubscriptionId()); return $status_response; } public static function runGetSubscription() { $response = createSubscription(self::getDay()); $status_response = getSubscription($response->getSubscriptionId()); cancelSubscription($response->getSubscriptionId()); return $status_response; } public static function runUpdateSubscription() { $response = createSubscription(self::getDay()); $update_response = updateSubscription($response->getSubscriptionId()); cancelSubscription($response->getSubscriptionId()); return $update_response; } //*****Customer Profiles methods******** public static function runCreateCustomerProfile() { $response = createCustomerProfile(self::getEmail()); deleteCustomerProfile($response->getCustomerProfileId()); return $response; } public static function runDeleteCustomerProfile() { $responseCustomerProfile = createCustomerProfile(self::getEmail()); return deleteCustomerProfile($responseCustomerProfile->getCustomerProfileId()); } public static function runGetCustomerProfile() { $responseCustomerProfile = createCustomerProfile(self::getEmail()); $response = getCustomerProfile($responseCustomerProfile->getCustomerProfileId()); deleteCustomerProfile($responseCustomerProfile->getCustomerProfileId()); return $response; } // *******Customer Profiles - Payment Profiles methods****** public static function runCreateCustomerPaymentProfile() { $responseCustomerProfile = createCustomerProfile(self::getEmail()); $response=createCustomerPaymentProfile( $responseCustomerProfile->getCustomerProfileId(), self::getPhoneNumber() ); deleteCustomerProfile($responseCustomerProfile->getCustomerProfileId()); return $response; } public static function runGetCustomerPaymentProfile() { $customerProfileId = createCustomerProfile(self::getEmail())->getCustomerProfileId(); $customerPaymentProfileId = createCustomerPaymentProfile( $customerProfileId, self::getPhoneNumber() )->getCustomerPaymentProfileId(); $response= getCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId); deleteCustomerProfile($customerProfileId); return $response; } public static function runValidateCustomerPaymentProfile() { $customerProfileId = createCustomerProfile(self::getEmail())->getCustomerProfileId(); $customerPaymentProfileId = createCustomerPaymentProfile( $customerProfileId, self::getPhoneNumber() )->getCustomerPaymentProfileId(); $response = validateCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId); deleteCustomerProfile($customerProfileId); return $response; } public static function runUpdateCustomerPaymentProfile() { $customerProfileId = createCustomerProfile(self::getEmail())->getCustomerProfileId(); $customerPaymentProfileId = createCustomerPaymentProfile( $customerProfileId, self::getPhoneNumber() )->getCustomerPaymentProfileId(); $response = updateCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId); deleteCustomerProfile($customerProfileId); return $response; } public static function runDeleteCustomerPaymentProfile() { $customerProfileId = createCustomerProfile(self::getEmail())->getCustomerProfileId(); $customerPaymentProfileId = createCustomerPaymentProfile( $customerProfileId, self::getPhoneNumber() )->getCustomerPaymentProfileId(); $response = deleteCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId); deleteCustomerProfile($customerProfileId); return $response; } // ****Customer Profiles - Shipping Address***** public static function runCreateCustomerShippingAddress() { $customerProfileId = createCustomerProfile(self::getEmail())->getCustomerProfileId(); $response = createCustomerShippingAddress($customerProfileId, self::getPhoneNumber()); deleteCustomerProfile($customerProfileId); return $response; } public static function runDeleteCustomerShippingAddress() { $customerProfileId = createCustomerProfile(self::getEmail())->getCustomerProfileId(); $responseCreateShipping = createCustomerShippingAddress($customerProfileId, self::getPhoneNumber()); $response = deleteCustomerShippingAddress($customerProfileId, $responseCreateShipping->getCustomerAddressId()); deleteCustomerProfile($customerProfileId); return $response; } public static function runUpdateCustomerShippingAddress() { $response = createCustomerProfile(self::getEmail()); $shippingResponse = createCustomerShippingAddress($response->getCustomerProfileId()); $updateResponse = updateCustomerShippingAddress( $response->getCustomerProfileId(), $shippingResponse->getCustomerAddressId() ); deleteCustomerProfile($response->getCustomerProfileId()); return $updateResponse; } public static function runGetCustomerShippingAddress() { $response = createCustomerProfile(self::getEmail()); $shippingResponse = createCustomerShippingAddress($response->getCustomerProfileId()); $getResponse = getCustomerShippingAddress( $response->getCustomerProfileId(), $shippingResponse->getCustomerAddressId() ); deleteCustomerProfile($response->getCustomerProfileId()); return $getResponse; } //*****Accept - Accept Customer Profile Page******** public static function runGetAcceptCustomerProfilePage() { $response = createCustomerProfile(self::getEmail()); $profileResponse = GetAcceptCustomerProfilePage($response->getCustomerProfileId()); deleteCustomerProfile($response->getCustomerProfileId()); return $profileResponse; } // *****Transaction Reporting methods******** public static function runGetTransactionDetails() { $response = authorizeCreditCard(self::getAmount()); return getTransactionDetails($response->getTransactionResponse()->getTransId()); } public static function runGetSettledBatchList() { $lastSettlementDate=new DateTime(); // current time $lastSettlementDate->format("Y-m-d\TH:i:s\Z"); $lastSettlementDate->setTimezone(new DateTimeZone('UTC')); $firstSettlementDate=new DateTime(); $firstSettlementDate->format("Y-m-d\TH:i:s\Z"); $firstSettlementDate->setTimezone(new DateTimeZone('UTC')); $firstSettlementDate->sub(new DateInterval('P28D')); return getSettledBatchList($firstSettlementDate, $lastSettlementDate); } public static function runGetBatchStatistics() { $response = getBatchStatistics(self::runGetSettledBatchList()->getBatchList()[0]->getBatchId()); return $response; } } ================================================ FILE: TransactionReporting/get-account-updater-job-details.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the request's refId $refId = 'ref' . time(); // Set a valid month (and other parameters) for the request $month = "2017-07"; $modifedTypeFilter = "all"; $paging = new AnetAPI\PagingType; $paging->setLimit("1000"); $paging->setOffset("1"); // Build tbe request object $request = new AnetAPI\GetAUJobDetailsRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setMonth($month); $request->setModifiedTypeFilter($modifedTypeFilter); $request->setPaging($paging); $controller = new AnetController\GetAUJobDetailsController($request); // Retrieving details for the given month and parameters $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { echo "SUCCESS: Get Account Updater Details for Month : " . $month . "\n\n"; if ($response->getAuDetails() == null) { echo "No Account Updater Details for this month.\n"; return ; } else { $details = new AnetAPI\ListOfAUDetailsType; $details = $response->getAuDetails(); if (($details->getAuUpdate() == null) && ($details->getAuDelete() == null)) { echo "No Account Updater Details for this month.\n"; return ; } } // Displaying the details of each response in the list echo "Total Num in Result Set : " . $response->getTotalNumInResultSet() . "\n\n"; $details = new AnetAPI\ListOfAUDetailsType; $details = $response->getAuDetails(); echo "Updates:\n"; foreach ($details->getAuUpdate() as $update) { echo " Profile ID / Payment Profile ID : " . $update->getCustomerProfileID() . " / " . $update->getCustomerPaymentProfileID() . "\n"; echo " Update Time (UTC) : " . $update->getUpdateTimeUTC() . "\n"; echo " Reason Code : " . $update->getAuReasonCode() . "\n"; echo " Reason Description : " . $update->getReasonDescription() . "\n"; echo "\n"; } echo "\nDeletes:\n"; foreach ($details->getAuDelete() as $delete) { echo " Profile ID / Payment Profile ID : " . $delete->getCustomerProfileID() . " / " . $delete->getCustomerPaymentProfileID() . "\n"; echo " Update Time (UTC) : " . $delete->getUpdateTimeUTC() . "\n"; echo " Reason Code : " . $delete->getAuReasonCode() . "\n"; echo " Reason Description : " . $delete->getReasonDescription() . "\n"; echo "\n"; } } else { echo "ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if (!defined('DONT_RUN_SAMPLES')) { getAccountUpdaterJobDetails(); } ================================================ FILE: TransactionReporting/get-account-updater-job-summary.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the request's refId $refId = 'ref' . time(); // Set a valid month for the request $month = "2017-07"; // Build tbe request object $request = new AnetAPI\GetAUJobSummaryRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setMonth($month); $controller = new AnetController\GetAUJobSummaryController($request); // Get the response from the service (errors contained if any) $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { echo "SUCCESS: Get Account Updater Summary for Month : " . $month . "\n\n"; if ($response->getAuSummary() == null) { echo "No Account Updater summary for this month.\n"; return ; } // Displaying the summary of each response in the list foreach ($response->getAuSummary() as $result) { echo " Reason Code : " . $result->getAuReasonCode() . "\n"; echo " Reason Description : " . $result->getReasonDescription() . "\n"; echo " # of Profiles updated for this reason : " . $result->getProfileCount() . "\n"; } } else { echo "ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if (!defined('DONT_RUN_SAMPLES')) { getAccountUpdaterJobSummary(); } ================================================ FILE: TransactionReporting/get-batch-statistics.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Creating a request $request = new AnetAPI\GetBatchStatisticsRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setBatchId($batchId); //Creating the controller $controller = new AnetController\GetBatchStatisticsController($request); //Retrieving response $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { echo "SUCCESS: Successfully got the list of subscriptions : \n\n"; echo "Batch ID : " . $response->getBatch()->getBatchId() . "\n"; echo "Settlement Time : " . date_format($response->getBatch()->getSettlementTimeUTC(),"Y/m/d H:i:s") . "\n"; echo "Settlement state : " . $response->getBatch()->getSettlementState() . "\n"; echo "Payment Method : " . $response->getBatch()->getPaymentMethod() . "\n"; echo "Statistic Details:"; //Displaying the details of each transaction in the list foreach ($response->getBatch()->getStatistics() as $statistics) { echo " Account Type : " . $statistics->getAccountType() . "\n"; echo " Charge Amount : " . $statistics->getChargeAmount() . "\n"; echo " Charge Count : " . $statistics->getChargeCount() . "\n"; echo " Refund Amount : " . $statistics->getRefundAmount() . "\n"; echo " Refund Count : " . $statistics->getRefundCount() . "\n"; echo " Void Count : " . $statistics->getRefundCount() . "\n"; echo " Decline Count : " . $statistics->getRefundCount() . "\n"; echo " Error Count : " . $statistics->getRefundCount() . "\n"; } } else { echo "ERROR : Failed to get the batch statistics\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) getBatchStatistics(); ?> ================================================ FILE: TransactionReporting/get-customer-profile-transaction-list.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); $request = new AnetAPI\GetTransactionListForCustomerRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setCustomerProfileId($customerProfileId); $controller = new AnetController\GetTransactionListForCustomerController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { if(null != $response->getTransactions()) { foreach($response->getTransactions() as $tx) { echo "SUCCESS: TransactionID: " . $tx->getTransId() . "\n"; } } else{ echo "No transactions associated with given customer profile" . "\n"; } } else { echo "ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) getTransactionListForCustomerRequest("36152127"); ?> ================================================ FILE: TransactionReporting/get-merchant-details.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); $request = new AnetAPI\GetMerchantDetailsRequest(); $request->setMerchantAuthentication($merchantAuthentication); $controller = new AnetController\GetMerchantDetailsController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { echo "SUCCESS: Merchant Name:" . $response->getMerchantName() . "\n"; echo " Gateway Id:" . $response->getGatewayId(). "\n"; foreach ($response->getProcessors() as $processor) { echo " ->Name : " . $processor->getName() . "\n"; } foreach ($response->getCurrencies() as $currency) { echo " ->Currency : " . $currency . "\n"; } } else { echo "ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) getMerchantDetails(); ?> ================================================ FILE: TransactionReporting/get-settled-batch-list.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); $request = new AnetAPI\GetSettledBatchListRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setIncludeStatistics(true); // Both the first and last dates must be in the same time zone // The time between first and last dates, inclusively, cannot exceed 31 days. $request->setFirstSettlementDate($firstSettlementDate); $request->setLastSettlementDate($lastSettlementDate); $controller = new AnetController\GetSettledBatchListController ($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { foreach($response->getBatchList() as $batch) { echo "\n\n"; echo "Batch ID: " . $batch->getBatchId() . "\n"; echo "Batch settled on (UTC): " . $batch->getSettlementTimeUTC()->format('r') . "\n"; echo "Batch settled on (Local): " . $batch->getSettlementTimeLocal()->format('D, d M Y H:i:s') . "\n"; echo "Batch settlement state: " . $batch->getSettlementState() . "\n"; echo "Batch market type: " . $batch->getMarketType() . "\n"; echo "Batch product: " . $batch->getProduct() . "\n"; foreach($batch->getStatistics() as $statistics) { echo "Account type: ".$statistics->getAccountType()."\n"; echo "Total charge amount: ".$statistics->getChargeAmount()."\n"; echo "Charge count: ".$statistics->getChargeCount()."\n"; echo "Refund amount: ".$statistics->getRefundAmount()."\n"; echo "Refund count: ".$statistics->getRefundCount()."\n"; echo "Void count: ".$statistics->getVoidCount()."\n"; echo "Decline count: ".$statistics->getDeclineCount()."\n"; echo "Error amount: ".$statistics->getErrorCount()."\n"; } } } else { echo "ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } // both the first and last dates must be in the same time zone // a date constructed from an ISO8601 format date string $firstSettlementDate=new DateTime("2018-01-23T06:00:00Z"); // a date constructed manually $lastSettlementDate=new DateTime(); $lastSettlementDate->setDate(2018,2,19); $lastSettlementDate->setTime(13,33,59); $lastSettlementDate->setTimezone(new DateTimeZone('UTC')); if(!defined('DONT_RUN_SAMPLES')) getSettledBatchList($firstSettlementDate, $lastSettlementDate); ?> ================================================ FILE: TransactionReporting/get-transaction-details.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId // The refId is a Merchant-assigned reference ID for the request. // If included in the request, this value is included in the response. // This feature might be especially useful for multi-threaded applications. $refId = 'ref' . time(); $request = new AnetAPI\GetTransactionDetailsRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setTransId($transactionId); $controller = new AnetController\GetTransactionDetailsController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { echo "SUCCESS: Transaction Status:" . $response->getTransaction()->getTransactionStatus() . "\n"; echo " Auth Amount:" . $response->getTransaction()->getAuthAmount() . "\n"; echo " Trans ID:" . $response->getTransaction()->getTransId() . "\n"; } else { echo "ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) getTransactionDetails("2238968786"); ?> ================================================ FILE: TransactionReporting/get-transaction-list.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the request's refId $refId = 'ref' . time(); //Setting a valid batch Id for the Merchant $batchId = "4606008"; $request = new AnetAPI\GetTransactionListRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setBatchId($batchId); $controller = new AnetController\GetTransactionListController($request); //Retrieving transaction list for the given Batch Id $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { echo "SUCCESS: Get Transaction List for BatchID : " . $batchId . "\n\n"; if ($response->getTransactions() == null) { echo "No Transaction to display in this Batch."; return $response; } //Displaying the details of each transaction in the list foreach ($response->getTransactions() as $transaction) { echo " ->Transaction Id : " . $transaction->getTransId() . "\n"; echo " Submitted on (Local) : " . date_format($transaction->getSubmitTimeLocal(), 'Y-m-d H:i:s') . "\n"; echo " Status : " . $transaction->getTransactionStatus() . "\n"; echo " Settle amount : " . number_format($transaction->getSettleAmount(), 2, '.', '') . "\n"; } } else { echo "ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) getTransactionList(); ?> ================================================ FILE: TransactionReporting/get-unsettled-transaction-list.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); $request = new AnetAPI\GetUnsettledTransactionListRequest(); $request->setMerchantAuthentication($merchantAuthentication); $controller = new AnetController\GetUnsettledTransactionListController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { if(null != $response->getTransactions()) { foreach($response->getTransactions() as $tx) { echo "SUCCESS: TransactionID: " . $tx->getTransId() . "\n"; } } else{ echo "No unsettled transactions for the merchant." . "\n"; } } else { echo "ERROR : Invalid response\n"; $errorMessages = $response->getMessages()->getMessage(); echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) getUnsettledTransactionList(); ?> ================================================ FILE: VisaCheckout/create-visa-src-transaction.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Create the payment data from a Visa Checkout blob $op = new AnetAPI\OpaqueDataType(); $op->setDataDescriptor("COMMON.VCO.ONLINE.PAYMENT"); $op->setDataValue("4Ng5pzJ6DXfAvLSzVauN9KTufx5lTHhFlnuIr248N3fjtyHrHqMuhOkB1BLiSjKWeTM9+BNj3+9nY56d7CsUfIuvVSTaJRhQQSex1dS2Y2Y+/cA5U+3D1pg5YtTmDVUGlsu1simAd3huwPnwD+CG6O8Ml0AmXvYHntmL3vFaJomadMQBy27k8Dbh5eplPBwyawKUVJ7GqTyKLe8aOYkBUHT5ANWkq2hlGps44BOoDHZ26JWjHdorBZtVIqMK1SIyW4Dih5c/Y//w2toA8WBTPILIvt4h6HPPvWZMZCHCqom9D2k4WGH5+BCEY2jHI7gfYV6xRx54i5vitsYTKm3CyA0C5+l0FNDkfUFHDvVUG9FVzRWVd0TXYhDwfa2pcfI68eYvkEfeT+ZNJ24ZXKPrJo6KZ3x6eZAhzgAMFiC+tPsiygb2zQy5PVoYoBIGj/NGNRqmhZTOEajcO3ZjWxfAnLZAmvMi+pEwJCMmuIY4qRU3RfcaXhAoaUPpDxqrSxR1m+CUKYVdt3nnnQeVaVqf+RaeV9cyFJvILeBPXTBVC50AckVLS37UuBWgWaWcchjRPk9mriDu2KlHQwdR4zu0jnLh4i3tbxV416QBcYLO6AF2Ixlm3GzqGE6QcVssgFCUAhklBWGNLP62O1jtyV4NgTD36QhvHEHby7o4XBB+mjlY6xSEXR+IW9u64AzfDCsTxWiAOE65le6cSk4NDV8DrtYeIozILivWu6wFSpy1gMfiDot4Ndv3C9xCFvH0Bzlky7NoZrvSolKTVNTs8W8UqMFV19qGl6SRaNUEhCqgso/FkdO0eGXFMdQPuP11wQzK/9F3yB9gS2rpXi9sy8DrCqnJ9EXMmliSstKuQl5+yfGc8K3Urot3t+BmNoOvzM9Aha/PzmbLnuKBN6/DUbIw5mhNMCvIA1ByispKpjeV682jl4uslkRsitGLcIOBREFXvGaLxRb37HJkXCHk+jorpDz7LUQhVkClN+hW0vXtgdHQFCIOL7uREdbvk6BZbQlFsuVEKGZxPbKPEJfqMbH54B4a4P5XNQHm4Yt4haH4T0JuYgzoSo76uuXD3g5IuUvy7x8Ykuja1rwW/k//SZAiGaZraRIIAEnzHiUP8dcufb/RonHGnJcYXIEWeIF1lX980bDA+H4vlO8/nN/Mj+EL6tT95MfRDiQHUW69qkqotQd7FJ5uWT+NtetzqDsN5s3sIhwkLKIn9EDLIav5v4SXKxkG+ycMJmGFcfhs7Td9O6hl+Om/JD3he3rgfClaFi/ZR7AVY6fWbAAm9QftKijQ6rskPDYL9Y3gVSA9rdduSg97fUHC+FdfyQXGH552cDLs2ZgzYw6KluXHEuwhACgNotxToPYTTdZxxNr1vPoqYCqHDL2dL8dkuO59/sbZE1m4ektKvUC2wz0UdTDVbHN8HSrLPn2hf/xQp5bKeDDjYkWvNKuwy+aug9H+Uu/m1LuPK/YdogVv9l25y/c2Qbj3dAJ9xTuKjmiJLKlRh4SUI9+05HjDF+i84AoUZ8LuC7LGtrN8ReYIktLhaXq9+XDh5fv4NYhnuYgWkUioKtx1dmfOMHjpLm4aE8Ra1gpJQcZAgwnqYubQvnYy0nY4VaykNix7m3vZwItpKOLqxDYxa3q0qUw25X9zafAM61kPW6EP+4idPzHNww6r1FD4Ihq644dCnCXwoSQ531DW6oAPot8iLZ/xXwoWwrW05k9t2RHjjLbw1L5r1CKgShJQfX7nkJxfGyuw1RmqoQDuNt/tj9M/dHOnoPnOYZZN0JX+Al8PI5zs+LLajw1imu9YcSpwMz3ZlfQqTfI0fjSCc8Is6qVYDMvKD0TweY4hiIxkzs+RyQmPgIeIWqf7Su5+RcnXitb3OuFibBGCjdDeG0ESG8qeiBQKZ3wEyZG09eDAfhuUR5kfZCG4Q01u2YDoRzObxLd8Ruf7HNvtefucFLubciWvOSzbDUisoz0wwOSgJGHucC3IR+1mb/4gz/dI2wvWFInhKcQz4ivkuHaFj8XwvZMcpkwPKtg3pRGTleX/gfjbHcx2VcWRcMPdlDMgTgst9ouN763TZUHHLxjECyB9pkLrR1nhG0cS/aig8Bq1+AH7tvl1wLVxm1Z77DVX4aUIxBH2YUcOgpe6mrWFi6LK3im4/grZECsL/XC4tsTEHjO/U3SazUuhP+6LiCYqp50+3zZf3RpWlxZoYjm5SJ9VIWabocO/Ef26G38lKottW1XsSQUan7myYFFyeyon2hnufzMuxpyXTJ7TLekXCi2gLYbGjldgiRmGShPXzSar+hC2"); $op->setDataKey("JxAB39A9yUsf6wMD0jwGKCuY7mmzWaeEj85MH02AfKGUxOkJ00JK+o8vGG55cUF9voYU4QQ1Jec4p6nKmsxXmTREEaJwmQErotD4fpcFOyoqWTLMZfslrkHgiqbwru/V"); $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setOpaqueData($op); //create a transaction $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType( "authCaptureTransaction"); $transactionRequestType->setAmount(76); $transactionRequestType->setCallId("9004180129978687101"); $transactionRequestType->setPayment($paymentOne); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId( $refId); $request->setTransactionRequest( $transactionRequestType); $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; echo " AUTH CODE : " . $tresponse->getAuthCode() . "\n"; echo " TRANS ID : " . $tresponse->getTransId() . "\n"; echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { echo "Transaction Failed \n"; if($tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } } } else { echo "Transaction Failed \n"; $tresponse = $response->getTransactionResponse(); if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; } } } else { echo "No response returned \n"; } return $response; } if(!defined('DONT_RUN_SAMPLES')) createVisaSrcTransaction(); ?> ================================================ FILE: VisaCheckout/decrypt-visa-src-data.php ================================================ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); // Set the transaction's refId $refId = 'ref' . time(); // Create the payment data from a Visa Checkout blob $op = new AnetAPI\OpaqueDataType(); $op->setDataDescriptor("COMMON.VCO.ONLINE.PAYMENT"); $op->setDataValue("4Ng5pzJ6DXfAvLSzVauN9KTufx5lTHhFlnuIr248N3fjtyHrHqMuhOkB1BLiSjKWeTM9+BNj3+9nY56d7CsUfIuvVSTaJRhQQSex1dS2Y2Y+/cA5U+3D1pg5YtTmDVUGlsu1simAd3huwPnwD+CG6O8Ml0AmXvYHntmL3vFaJomadMQBy27k8Dbh5eplPBwyawKUVJ7GqTyKLe8aOYkBUHT5ANWkq2hlGps44BOoDHZ26JWjHdorBZtVIqMK1SIyW4Dih5c/Y//w2toA8WBTPILIvt4h6HPPvWZMZCHCqom9D2k4WGH5+BCEY2jHI7gfYV6xRx54i5vitsYTKm3CyA0C5+l0FNDkfUFHDvVUG9FVzRWVd0TXYhDwfa2pcfI68eYvkEfeT+ZNJ24ZXKPrJo6KZ3x6eZAhzgAMFiC+tPsiygb2zQy5PVoYoBIGj/NGNRqmhZTOEajcO3ZjWxfAnLZAmvMi+pEwJCMmuIY4qRU3RfcaXhAoaUPpDxqrSxR1m+CUKYVdt3nnnQeVaVqf+RaeV9cyFJvILeBPXTBVC50AckVLS37UuBWgWaWcchjRPk9mriDu2KlHQwdR4zu0jnLh4i3tbxV416QBcYLO6AF2Ixlm3GzqGE6QcVssgFCUAhklBWGNLP62O1jtyV4NgTD36QhvHEHby7o4XBB+mjlY6xSEXR+IW9u64AzfDCsTxWiAOE65le6cSk4NDV8DrtYeIozILivWu6wFSpy1gMfiDot4Ndv3C9xCFvH0Bzlky7NoZrvSolKTVNTs8W8UqMFV19qGl6SRaNUEhCqgso/FkdO0eGXFMdQPuP11wQzK/9F3yB9gS2rpXi9sy8DrCqnJ9EXMmliSstKuQl5+yfGc8K3Urot3t+BmNoOvzM9Aha/PzmbLnuKBN6/DUbIw5mhNMCvIA1ByispKpjeV682jl4uslkRsitGLcIOBREFXvGaLxRb37HJkXCHk+jorpDz7LUQhVkClN+hW0vXtgdHQFCIOL7uREdbvk6BZbQlFsuVEKGZxPbKPEJfqMbH54B4a4P5XNQHm4Yt4haH4T0JuYgzoSo76uuXD3g5IuUvy7x8Ykuja1rwW/k//SZAiGaZraRIIAEnzHiUP8dcufb/RonHGnJcYXIEWeIF1lX980bDA+H4vlO8/nN/Mj+EL6tT95MfRDiQHUW69qkqotQd7FJ5uWT+NtetzqDsN5s3sIhwkLKIn9EDLIav5v4SXKxkG+ycMJmGFcfhs7Td9O6hl+Om/JD3he3rgfClaFi/ZR7AVY6fWbAAm9QftKijQ6rskPDYL9Y3gVSA9rdduSg97fUHC+FdfyQXGH552cDLs2ZgzYw6KluXHEuwhACgNotxToPYTTdZxxNr1vPoqYCqHDL2dL8dkuO59/sbZE1m4ektKvUC2wz0UdTDVbHN8HSrLPn2hf/xQp5bKeDDjYkWvNKuwy+aug9H+Uu/m1LuPK/YdogVv9l25y/c2Qbj3dAJ9xTuKjmiJLKlRh4SUI9+05HjDF+i84AoUZ8LuC7LGtrN8ReYIktLhaXq9+XDh5fv4NYhnuYgWkUioKtx1dmfOMHjpLm4aE8Ra1gpJQcZAgwnqYubQvnYy0nY4VaykNix7m3vZwItpKOLqxDYxa3q0qUw25X9zafAM61kPW6EP+4idPzHNww6r1FD4Ihq644dCnCXwoSQ531DW6oAPot8iLZ/xXwoWwrW05k9t2RHjjLbw1L5r1CKgShJQfX7nkJxfGyuw1RmqoQDuNt/tj9M/dHOnoPnOYZZN0JX+Al8PI5zs+LLajw1imu9YcSpwMz3ZlfQqTfI0fjSCc8Is6qVYDMvKD0TweY4hiIxkzs+RyQmPgIeIWqf7Su5+RcnXitb3OuFibBGCjdDeG0ESG8qeiBQKZ3wEyZG09eDAfhuUR5kfZCG4Q01u2YDoRzObxLd8Ruf7HNvtefucFLubciWvOSzbDUisoz0wwOSgJGHucC3IR+1mb/4gz/dI2wvWFInhKcQz4ivkuHaFj8XwvZMcpkwPKtg3pRGTleX/gfjbHcx2VcWRcMPdlDMgTgst9ouN763TZUHHLxjECyB9pkLrR1nhG0cS/aig8Bq1+AH7tvl1wLVxm1Z77DVX4aUIxBH2YUcOgpe6mrWFi6LK3im4/grZECsL/XC4tsTEHjO/U3SazUuhP+6LiCYqp50+3zZf3RpWlxZoYjm5SJ9VIWabocO/Ef26G38lKottW1XsSQUan7myYFFyeyon2hnufzMuxpyXTJ7TLekXCi2gLYbGjldgiRmGShPXzSar+hC2"); $op->setDataKey("JxAB39A9yUsf6wMD0jwGKCuY7mmzWaeEj85MH02AfKGUxOkJ00JK+o8vGG55cUF9voYU4QQ1Jec4p6nKmsxXmTREEaJwmQErotD4fpcFOyoqWTLMZfslrkHgiqbwru/V"); //create a decrypt request $decryptRequest = new AnetAPI\DecryptPaymentDataRequest(); $decryptRequest->setRefId( $refId); $decryptRequest->setMerchantAuthentication($merchantAuthentication); $decryptRequest->setOpaqueData($op); $decryptRequest->setCallId("9004180129978687101"); $controller = new AnetController\DecryptPaymentDataController($decryptRequest); $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { if ($response->getMessages()->getResultCode() == "Ok") { echo "Card Number : " . $response->getCardInfo()->getCardNumber() . "\n"; echo "Amount : " . $response->getPaymentDetails()->getAmount() . "\n"; } } return $response; } if(!defined('DONT_RUN_SAMPLES')) decryptVisaSrcData(); ?> ================================================ FILE: composer.json ================================================ { "require": { "php": ">=5.6", "ext-curl": "*", "authorizenet/authorizenet": ">=2.0 || <2.1" } } ================================================ FILE: composer.json.sdk-dev ================================================ { "require": { "php": ">=5.6", "ext-curl": "*", "phpunit/phpunit": "~9.0||~9.5", "authorizenet/authorizenet": ">=2.0 || <2.1" }, "autoload": { "classmap": ["constants", "lib"] } } ================================================ FILE: constants/SampleCodeConstants.php ================================================ ================================================ FILE: phpunit.xml.dist ================================================ . ./lib ./vendor ./tests ./build