diff --git a/.gitignore b/.gitignore index 301b14c..5e1ed6a 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,8 @@ # PHP Storm /.idea/* +# Operating system files +.DS_Store +/lib +/*.cache +/testslog diff --git a/.travis.yml b/.travis.yml index f47fce1..45de70f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,35 @@ language: php -php: - - 5.5 - - 5.6 - - 7.0 - +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 install --prefer-dist --ignore-platform-reqs + - composer require "phpunit/phpunit:${PHPUNIT_VERSION}" --no-update + - composer update --prefer-dist script: - - phpunit test-runner.php . + - phpunit TestRunner.php . diff --git a/AcceptSuite/create-an-accept-payment-transaction.php b/AcceptSuite/create-an-accept-payment-transaction.php new file mode 100644 index 0000000..562d514 --- /dev/null +++ b/AcceptSuite/create-an-accept-payment-transaction.php @@ -0,0 +1,133 @@ +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"); +} +?> \ No newline at end of file diff --git a/CustomerProfiles/get-accept-customer-profile-page.php b/AcceptSuite/get-accept-customer-profile-page.php similarity index 72% rename from CustomerProfiles/get-accept-customer-profile-page.php rename to AcceptSuite/get-accept-customer-profile-page.php index a1450af..e784f06 100644 --- a/CustomerProfiles/get-accept-customer-profile-page.php +++ b/AcceptSuite/get-accept-customer-profile-page.php @@ -1,16 +1,21 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); +function getAcceptCustomerProfilePage($customerprofileid = "123212") +{ + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->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 diff --git a/AcceptSuite/get-an-accept-payment-page.php b/AcceptSuite/get-an-accept-payment-page.php new file mode 100644 index 0000000..30fe57e --- /dev/null +++ b/AcceptSuite/get-an-accept-payment-page.php @@ -0,0 +1,65 @@ +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(); +} diff --git a/CustomerProfiles/create-customer-payment-profile.php b/CustomerProfiles/create-customer-payment-profile.php index b61c8d4..3c3812f 100644 --- a/CustomerProfiles/create-customer-payment-profile.php +++ b/CustomerProfiles/create-customer-payment-profile.php @@ -1,68 +1,84 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - $refId = 'ref' . time(); +function createCustomerPaymentProfile($existingcustomerprofileid, $phoneNumber) +{ + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->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( "4242424242424242"); - $creditCard->setExpirationDate( "2038-12"); - $creditCard->setCardCode( "142"); - $paymentCreditCard = new AnetAPI\PaymentType(); - $paymentCreditCard->setCreditCard($creditCard); + // 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 - // Create the Bill To info for new payment type - $billto = new AnetAPI\CustomerAddressType(); - $billto->setFirstName("Mrs Mary".$phoneNumber); - $billto->setLastName("Doe"); - $billto->setCompany("My company"); - $billto->setAddress("123 Main St."); - $billto->setCity("Bellevue"); - $billto->setState("WA"); - $billto->setZip("98004"); - $billto->setPhoneNumber($phoneNumber); - $billto->setfaxNumber("999-999-9999"); - $billto->setCountry("USA"); + // 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 a new Customer Payment Profile - $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); - $paymentprofile->setCustomerType('individual'); - $paymentprofile->setBillTo($billto); - $paymentprofile->setPayment($paymentCreditCard); - $paymentprofile->setDefaultPaymentProfile(true); + // 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"); - $paymentprofiles[] = $paymentprofile; + // Create a new Customer Payment Profile object + $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); + $paymentprofile->setCustomerType('individual'); + $paymentprofile->setBillTo($billto); + $paymentprofile->setPayment($paymentCreditCard); + $paymentprofile->setDefaultPaymentProfile(true); - // Submit a CreateCustomerPaymentProfileRequest to create a new Customer Payment Profile - $paymentprofilerequest = new AnetAPI\CreateCustomerPaymentProfileRequest(); - $paymentprofilerequest->setMerchantAuthentication($merchantAuthentication); - //Use an existing profile id - $paymentprofilerequest->setCustomerProfileId( $existingcustomerprofileid ); - $paymentprofilerequest->setPaymentProfile( $paymentprofile ); - $paymentprofilerequest->setValidationMode("liveMode"); - $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("1807545561","000-000-0009"); + $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"); +} ?> diff --git a/CustomerProfiles/create-customer-profile-from-transaction.php b/CustomerProfiles/create-customer-profile-from-transaction.php index 86683e6..fa9c002 100644 --- a/CustomerProfiles/create-customer-profile-from-transaction.php +++ b/CustomerProfiles/create-customer-profile-from-transaction.php @@ -1,48 +1,54 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); +function createCustomerProfileFromTransaction($transId= "2249066517") +{ + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->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"); + $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"); + $request = new AnetAPI\CreateCustomerProfileFromTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setTransId($transId); - $controller = new AnetController\CreateCustomerProfileFromTransactionController($request); + // 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"); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + $controller = new AnetController\CreateCustomerProfileFromTransactionController($request); - 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')) + $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"); +} + ?> diff --git a/CustomerProfiles/create-customer-profile-with-accept-nonce.php b/CustomerProfiles/create-customer-profile-with-accept-nonce.php index 41ab983..abce577 100644 --- a/CustomerProfiles/create-customer-profile-with-accept-nonce.php +++ b/CustomerProfiles/create-customer-profile-with-accept-nonce.php @@ -1,75 +1,90 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - $refId = 'ref' . time(); +function createCustomerProfileWithAcceptNonce($email) +{ + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); - // Create the payment data for an accept token - $op = new AnetAPI\OpaqueDataType(); - $op->setDataDescriptor("COMMON.ACCEPT.INAPP.PAYMENT"); - $op->setDataValue("9475089993864215505001"); - $paymentOne = new AnetAPI\PaymentType(); - $paymentOne->setOpaqueData($op); + // 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 - // 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 + // 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); - $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); - $paymentprofile->setCustomerType('individual'); - $paymentprofile->setBillTo($billto); - $paymentprofile->setPayment($paymentOne); - $paymentprofiles[] = $paymentprofile; - $customerprofile = new AnetAPI\CustomerProfileType(); - $customerprofile->setDescription("Customer Test PHP Accept Test"); + // 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"); - $customerprofile->setMerchantCustomerId("M_".$email); - $customerprofile->setEmail($email); - $customerprofile->setPaymentProfiles($paymentprofiles); + // Create a new Customer Payment Profile object + $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); + $paymentprofile->setCustomerType('individual'); + $paymentprofile->setBillTo($billto); + $paymentprofile->setPayment($paymentOne); + $paymentprofile->setDefaultPaymentProfile(true); - $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 "Succesfully create 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"); + $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"); +} ?> diff --git a/CustomerProfiles/create-customer-profile.php b/CustomerProfiles/create-customer-profile.php index ffaf655..49fb43f 100644 --- a/CustomerProfiles/create-customer-profile.php +++ b/CustomerProfiles/create-customer-profile.php @@ -1,75 +1,106 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - $refId = 'ref' . time(); +function createCustomerProfile($email) +{ + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->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 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 - // 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 + // 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); - $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); + // 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"); - $paymentprofile->setCustomerType('individual'); - $paymentprofile->setBillTo($billto); - $paymentprofile->setPayment($paymentCreditCard); - $paymentprofiles[] = $paymentprofile; - $customerprofile = new AnetAPI\CustomerProfileType(); - $customerprofile->setDescription("Customer 2 Test PHP"); + // 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"); - $customerprofile->setMerchantCustomerId("M_".$email); - $customerprofile->setEmail($email); - $customerprofile->setPaymentProfiles($paymentprofiles); + // Create an array of any shipping addresses + $shippingProfiles[] = $customerShippingAddress; - $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 "Succesfully create 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"); -?> + + // 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"); +} diff --git a/CustomerProfiles/create-customer-shipping-address.php b/CustomerProfiles/create-customer-shipping-address.php index 7ee5536..3044353 100644 --- a/CustomerProfiles/create-customer-shipping-address.php +++ b/CustomerProfiles/create-customer-shipping-address.php @@ -1,53 +1,56 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); +function createCustomerShippingAddress($existingcustomerprofileid = "1929905607", + $phoneNumber="000-000-0000" +) { + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); - // Use An existing customer profile id for this merchant name and 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 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 + // 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')) + $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(); +} ?> diff --git a/CustomerProfiles/delete-customer-payment-profile.php b/CustomerProfiles/delete-customer-payment-profile.php index 8f9d309..ce3e6ca 100644 --- a/CustomerProfiles/delete-customer-payment-profile.php +++ b/CustomerProfiles/delete-customer-payment-profile.php @@ -1,17 +1,22 @@ -]setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); +function deleteCustomerPaymentProfile($customerProfileId= "1929905607", + $customerpaymentprofileid = "1842074814" +) { + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->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 diff --git a/CustomerProfiles/delete-customer-profile.php b/CustomerProfiles/delete-customer-profile.php index ea33cc7..ee918cc 100644 --- a/CustomerProfiles/delete-customer-profile.php +++ b/CustomerProfiles/delete-customer-profile.php @@ -1,17 +1,21 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - $refId = 'ref' . time(); +function deleteCustomerProfile($customerProfileId) +{ + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->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(); @@ -35,5 +39,5 @@ function deleteCustomerProfile($customerProfileId) } if(!defined('DONT_RUN_SAMPLES')) - deleteCustomerProfile("38958129"); + deleteCustomerProfile("1929905651"); ?> diff --git a/CustomerProfiles/delete-customer-shipping-address.php b/CustomerProfiles/delete-customer-shipping-address.php index fedfac3..d3f2ccc 100644 --- a/CustomerProfiles/delete-customer-shipping-address.php +++ b/CustomerProfiles/delete-customer-shipping-address.php @@ -1,16 +1,21 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); +function deleteCustomerShippingAddress($customerprofileid = "1929905607", $customeraddressid = "901116911") +{ + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->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 diff --git a/CustomerProfiles/get-customer-payment-profile-list.php b/CustomerProfiles/get-customer-payment-profile-list.php index 1e337e9..51da3b3 100644 --- a/CustomerProfiles/get-customer-payment-profile-list.php +++ b/CustomerProfiles/get-customer-payment-profile-list.php @@ -1,77 +1,76 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - $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(); -?> +function getCustomerPaymentProfileList() +{ + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->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(); +} diff --git a/CustomerProfiles/get-customer-payment-profile.php b/CustomerProfiles/get-customer-payment-profile.php index 9279a1b..6e056a5 100644 --- a/CustomerProfiles/get-customer-payment-profile.php +++ b/CustomerProfiles/get-customer-payment-profile.php @@ -1,20 +1,23 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - $refId = 'ref' . time(); +function getCustomerPaymentProfile($customerProfileId="1929905607", + $customerPaymentProfileId= "1842074814" +) { + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->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(); diff --git a/CustomerProfiles/get-customer-profile-ids.php b/CustomerProfiles/get-customer-profile-ids.php index d1ac23d..20b68a0 100644 --- a/CustomerProfiles/get-customer-profile-ids.php +++ b/CustomerProfiles/get-customer-profile-ids.php @@ -1,16 +1,20 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->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 diff --git a/CustomerProfiles/get-customer-profile.php b/CustomerProfiles/get-customer-profile.php index 6af433a..c69efc6 100644 --- a/CustomerProfiles/get-customer-profile.php +++ b/CustomerProfiles/get-customer-profile.php @@ -1,22 +1,26 @@ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); - $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); - $merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - $refId = 'ref' . time(); + // 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->setExpirationDate("2038-12"); $paymentCreditCard = new AnetAPI\PaymentType(); $paymentCreditCard->setCreditCard($creditCard); diff --git a/CustomerProfiles/get-customer-shipping-address.php b/CustomerProfiles/get-customer-shipping-address.php index 53b9b66..1e1b541 100644 --- a/CustomerProfiles/get-customer-shipping-address.php +++ b/CustomerProfiles/get-customer-shipping-address.php @@ -1,16 +1,21 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); +function getCustomerShippingAddress($customerprofileid, $customeraddressid) +{ + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->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; diff --git a/CustomerProfiles/update-customer-payment-profile.php b/CustomerProfiles/update-customer-payment-profile.php index ecf034f..484d5e5 100644 --- a/CustomerProfiles/update-customer-payment-profile.php +++ b/CustomerProfiles/update-customer-payment-profile.php @@ -1,100 +1,95 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - $refId = 'ref' . time(); +function updateCustomerPaymentProfile($customerProfileId = "1916322670", + $customerPaymentProfileId = "1829639667") +{ + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); - //Set profile ids of profile to be updated - $request = new AnetAPI\UpdateCustomerPaymentProfileRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setCustomerProfileId($customerProfileId); - $controller = new AnetController\GetCustomerProfileController($request); - - - // 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 - $creditCard = new AnetAPI\CreditCardType(); - $creditCard->setCardNumber( "4111111111111111" ); - $creditCard->setExpirationDate( "0718"); - $paymentCreditCard = new AnetAPI\PaymentType(); - $paymentCreditCard->setCreditCard($creditCard); - - // Create the Bill To info for new payment type - $billto = new AnetAPI\CustomerAddressType(); - $billto->setFirstName("Mrs Mary"); - $billto->setLastName("Doe"); - $billto->setAddress("1 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"); + $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); - // Create the Customer Payment Profile object - $paymentprofile = new AnetAPI\CustomerPaymentProfileExType(); - $paymentprofile->setCustomerPaymentProfileId($customerPaymentProfileId); - $paymentprofile->setBillTo($billto); - $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->setPaymentProfile( $paymentprofile ); + // 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") ) - { - echo "Update Customer Payment Profile SUCCESS: " . "\n"; - - // Update only returns success or fail, if success - // confirm the update by doing a GetCustomerPaymentProfile - $getRequest = new AnetAPI\GetCustomerPaymentProfileRequest(); - $getRequest->setMerchantAuthentication($merchantAuthentication); - $getRequest->setRefId( $refId); - $getRequest->setCustomerProfileId($customerProfileId); - $getRequest->setCustomerPaymentProfileId($customerPaymentProfileId); + $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"; + } - $controller = new AnetController\GetCustomerPaymentProfileController($getRequest); - $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"; - } - 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; +} - } - else - { - echo "Update 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')) - updateCustomerPaymentProfile(); +if(!defined('DONT_RUN_SAMPLES')) + updateCustomerPaymentProfile(); ?> diff --git a/CustomerProfiles/update-customer-profile.php b/CustomerProfiles/update-customer-profile.php index 87e61ac..4a2c708 100644 --- a/CustomerProfiles/update-customer-profile.php +++ b/CustomerProfiles/update-customer-profile.php @@ -1,21 +1,26 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->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->setExpirationDate("2038-12"); $paymentCreditCard = new AnetAPI\PaymentType(); $paymentCreditCard->setCreditCard($creditCard); diff --git a/CustomerProfiles/update-customer-shipping-address.php b/CustomerProfiles/update-customer-shipping-address.php index ea4b496..36ad6ad 100644 --- a/CustomerProfiles/update-customer-shipping-address.php +++ b/CustomerProfiles/update-customer-shipping-address.php @@ -1,16 +1,21 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); +function updateCustomerShippingAddress($customerprofileid, $customeraddressid) +{ + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->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; @@ -49,5 +54,5 @@ function updateCustomerShippingAddress($customerprofileid, $customeraddressid) return $response; } if(!defined('DONT_RUN_SAMPLES')) - updateCustomerShippingAddress( "36152127","36976566"); + updateCustomerShippingAddress( "1929905607","901116911"); ?> diff --git a/CustomerProfiles/validate-customer-payment-profile.php b/CustomerProfiles/validate-customer-payment-profile.php index 565d03a..ca57209 100644 --- a/CustomerProfiles/validate-customer-payment-profile.php +++ b/CustomerProfiles/validate-customer-payment-profile.php @@ -1,17 +1,22 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); +function validateCustomerPaymentProfile($customerProfileId= "1929905607", + $customerPaymentProfileId= "1842074814" +) { + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->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 diff --git a/FraudManagement/approve-or-decline-held-transaction.php b/FraudManagement/approve-or-decline-held-transaction.php index e538b58..c3e6df5 100644 --- a/FraudManagement/approve-or-decline-held-transaction.php +++ b/FraudManagement/approve-or-decline-held-transaction.php @@ -1,16 +1,21 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - $refId = 'ref' . time(); +function approveOrDeclineHeldTransaction() +{ + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->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(); @@ -27,7 +32,7 @@ function approveOrDeclineHeldTransaction(){ if ($response != null) { - if($response->getMessages()->getResultCode() == 'Ok') + if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); @@ -73,5 +78,5 @@ function approveOrDeclineHeldTransaction(){ return $response; } if(!defined('DONT_RUN_SAMPLES')) - updateHeldTransaction(); + approveOrDeclineHeldTransaction(); ?> diff --git a/FraudManagement/get-held-transaction-list.php b/FraudManagement/get-held-transaction-list.php index b6be049..9405614 100644 --- a/FraudManagement/get-held-transaction-list.php +++ b/FraudManagement/get-held-transaction-list.php @@ -1,16 +1,20 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - + $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId $refId = 'ref' . time(); @@ -47,6 +51,6 @@ function getHeldTransactionList() { } if(!defined('DONT_RUN_SAMPLES')) - getHeldTransactions(); + getHeldTransactionList(); ?> diff --git a/MobileInAppTransactions/create-an-accept-transaction.php b/MobileInAppTransactions/create-an-accept-transaction.php new file mode 100644 index 0000000..ea7650e --- /dev/null +++ b/MobileInAppTransactions/create-an-accept-transaction.php @@ -0,0 +1,120 @@ +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"); +} +?> diff --git a/MobileInappTransactions/create-an-android-pay-transaction.php b/MobileInAppTransactions/create-an-android-pay-transaction.php similarity index 92% rename from MobileInappTransactions/create-an-android-pay-transaction.php rename to MobileInAppTransactions/create-an-android-pay-transaction.php index ebd0176..175a0a4 100644 --- a/MobileInappTransactions/create-an-android-pay-transaction.php +++ b/MobileInAppTransactions/create-an-android-pay-transaction.php @@ -1,15 +1,20 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId $refId = 'ref' . time(); $op = new AnetAPI\OpaqueDataType(); @@ -34,7 +39,7 @@ function createAnAndroidPayTransaction(){ if ($response != null) { - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) + if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); diff --git a/MobileInappTransactions/create-an-apple-pay-transaction.php b/MobileInAppTransactions/create-an-apple-pay-transaction.php similarity index 91% rename from MobileInappTransactions/create-an-apple-pay-transaction.php rename to MobileInAppTransactions/create-an-apple-pay-transaction.php index 387d33f..4a8006a 100644 --- a/MobileInappTransactions/create-an-apple-pay-transaction.php +++ b/MobileInAppTransactions/create-an-apple-pay-transaction.php @@ -1,15 +1,20 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId $refId = 'ref' . time(); $op = new AnetAPI\OpaqueDataType(); @@ -35,7 +40,7 @@ function createAnApplePayTransaction(){ if ($response != null) { - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) + if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); diff --git a/MobileInappTransactions/create-an-accept-transaction.php b/MobileInAppTransactions/create-google-pay-transaction.php similarity index 55% rename from MobileInappTransactions/create-an-accept-transaction.php rename to MobileInAppTransactions/create-google-pay-transaction.php index 670dbe5..75ecc36 100644 --- a/MobileInappTransactions/create-an-accept-transaction.php +++ b/MobileInAppTransactions/create-google-pay-transaction.php @@ -1,40 +1,68 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + $refId = 'ref' . time(); - $op = new AnetAPI\OpaqueDataType(); - $op->setDataDescriptor("COMMON.ACCEPT.INAPP.PAYMENT"); - $op->setDataValue("9471471570959063005001"); - $paymentOne = new AnetAPI\PaymentType(); - $paymentOne->setOpaqueData($op); + $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; - //create a transaction $transactionRequestType = new AnetAPI\TransactionRequestType(); - $transactionRequestType->setTransactionType( "authCaptureTransaction"); + $transactionRequestType->setTransactionType("authCaptureTransaction"); $transactionRequestType->setAmount(151); - $transactionRequestType->setPayment($paymentOne); + $transactionRequestType->setPayment($paymentType); $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); - $request->setRefId( $refId); + $request->setRefId($refId); $request->setTransactionRequest( $transactionRequestType); $controller = new AnetController\CreateTransactionController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); + if ($response != null) { - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) + if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); @@ -44,7 +72,7 @@ function createAnAcceptTransaction(){ 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"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { @@ -81,5 +109,5 @@ function createAnAcceptTransaction(){ } if(!defined('DONT_RUN_SAMPLES')) - createAnAcceptTransaction(); + createGooglePayTransaction(); ?> diff --git a/PayPalExpressCheckout/authorization-and-capture-continued.php b/PayPalExpressCheckout/authorization-and-capture-continued.php new file mode 100644 index 0000000..6ef77cd --- /dev/null +++ b/PayPalExpressCheckout/authorization-and-capture-continued.php @@ -0,0 +1,78 @@ +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"); +} diff --git a/PaypalExpressCheckout/authorization-and-capture.php b/PayPalExpressCheckout/authorization-and-capture.php similarity index 72% rename from PaypalExpressCheckout/authorization-and-capture.php rename to PayPalExpressCheckout/authorization-and-capture.php index 562bfeb..5252c27 100644 --- a/PaypalExpressCheckout/authorization-and-capture.php +++ b/PayPalExpressCheckout/authorization-and-capture.php @@ -1,23 +1,28 @@ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); - // Common setup for API credentials (with PayPal compatible merchant credentials) - $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); - $merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $payPalType=new AnetAPI\PayPalType(); + $payPalType->setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); + $payPalType->setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); - $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); + $paymentOne = new AnetAPI\PaymentType(); + $paymentOne->setPayPal($payPalType); // Create an authorize and capture transaction $transactionRequestType = new AnetAPI\TransactionRequestType(); @@ -33,7 +38,7 @@ function payPalAuthorizeCapture($amount) { if ($response != null) { - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) + if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); diff --git a/PayPalExpressCheckout/authorization-only-continued.php b/PayPalExpressCheckout/authorization-only-continued.php new file mode 100644 index 0000000..20422d7 --- /dev/null +++ b/PayPalExpressCheckout/authorization-only-continued.php @@ -0,0 +1,85 @@ +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"); +} diff --git a/PaypalExpressCheckout/authorization-only.php b/PayPalExpressCheckout/authorization-only.php similarity index 86% rename from PaypalExpressCheckout/authorization-only.php rename to PayPalExpressCheckout/authorization-only.php index f95f47f..32fd18e 100644 --- a/PaypalExpressCheckout/authorization-only.php +++ b/PayPalExpressCheckout/authorization-only.php @@ -1,16 +1,20 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->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 @@ -36,7 +40,7 @@ function payPalAuthorizeOnly($amount) { if ($response != null) { - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) + if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); diff --git a/PaypalExpressCheckout/credit.php b/PayPalExpressCheckout/credit.php similarity index 85% rename from PaypalExpressCheckout/credit.php rename to PayPalExpressCheckout/credit.php index 0a19fa8..498eba8 100644 --- a/PaypalExpressCheckout/credit.php +++ b/PayPalExpressCheckout/credit.php @@ -1,20 +1,23 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - + $merchantAuthentication->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 + + //use transaction of already settled paypal checkout transaction $refTransId = $transactionId; // Create the payment data for a paypal account @@ -42,7 +45,7 @@ function payPalCredit($transactionId) { if ($response != null) { - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) + if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); diff --git a/PaypalExpressCheckout/get-details.php b/PayPalExpressCheckout/get-details.php similarity index 89% rename from PaypalExpressCheckout/get-details.php rename to PayPalExpressCheckout/get-details.php index 683f774..4a81b70 100644 --- a/PaypalExpressCheckout/get-details.php +++ b/PayPalExpressCheckout/get-details.php @@ -1,20 +1,23 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->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 @@ -46,7 +49,7 @@ function payPalGetDetails($transactionId) { if ($response != null) { - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) + if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); diff --git a/PaypalExpressCheckout/prior-authorization-capture.php b/PayPalExpressCheckout/prior-authorization-capture.php similarity index 85% rename from PaypalExpressCheckout/prior-authorization-capture.php rename to PayPalExpressCheckout/prior-authorization-capture.php index 679af87..432d0fe 100644 --- a/PaypalExpressCheckout/prior-authorization-capture.php +++ b/PayPalExpressCheckout/prior-authorization-capture.php @@ -1,16 +1,20 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId $refId = 'ref' . time(); $payPalType = new AnetAPI\PayPalType(); @@ -37,7 +41,7 @@ function payPalPriorAuthorizationCapture($transactionId) { if ($response != null) { - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) + if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); diff --git a/PaypalExpressCheckout/void.php b/PayPalExpressCheckout/void.php similarity index 85% rename from PaypalExpressCheckout/void.php rename to PayPalExpressCheckout/void.php index bd3c67c..bb6e242 100644 --- a/PaypalExpressCheckout/void.php +++ b/PayPalExpressCheckout/void.php @@ -1,16 +1,20 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId $refId = 'ref' . time(); $payPalType = new AnetAPI\PayPalType(); @@ -36,7 +40,7 @@ function payPalVoid($transactionId) { if ($response != null) { - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) + if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); diff --git a/PaymentTransactions/authorize-credit-card.php b/PaymentTransactions/authorize-credit-card.php index ea75b01..10c8198 100644 --- a/PaymentTransactions/authorize-credit-card.php +++ b/PaymentTransactions/authorize-credit-card.php @@ -1,88 +1,133 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->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("1226"); + $creditCard->setExpirationDate("2038-12"); $creditCard->setCardCode("123"); + + // Add the payment data to a paymentType object $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setCreditCard($creditCard); - //create a transaction + // 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->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); + $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); + $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); - if ($response != null) - { - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) - { - $tresponse = $response->getTransactionResponse(); + + 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 " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; - echo " Successfully created a transaction with 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->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"; + 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( 23.32); +} + +if (!defined('DONT_RUN_SAMPLES')) { + authorizeCreditCard("2.23"); +} ?> \ No newline at end of file diff --git a/PaymentTransactions/capture-funds-authorized-through-another-channel.php b/PaymentTransactions/capture-funds-authorized-through-another-channel.php index 791cc60..8879a05 100644 --- a/PaymentTransactions/capture-funds-authorized-through-another-channel.php +++ b/PaymentTransactions/capture-funds-authorized-through-another-channel.php @@ -1,15 +1,20 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId $refId = 'ref' . time(); $creditCard = new AnetAPI\CreditCardType(); @@ -36,7 +41,7 @@ function captureFundsAuthorizedThroughAnotherChannel($amount){ if ($response != null) { - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) + if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); diff --git a/PaymentTransactions/capture-previously-authorized-amount.php b/PaymentTransactions/capture-previously-authorized-amount.php index 0221eb6..de19ffd 100644 --- a/PaymentTransactions/capture-previously-authorized-amount.php +++ b/PaymentTransactions/capture-previously-authorized-amount.php @@ -1,15 +1,20 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->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 @@ -28,7 +33,7 @@ function capturePreviouslyAuthorizedAmount($transactionid){ if ($response != null) { - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) + if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); diff --git a/PaymentTransactions/charge-credit-card.php b/PaymentTransactions/charge-credit-card.php index f80ee1d..c05df53 100644 --- a/PaymentTransactions/charge-credit-card.php +++ b/PaymentTransactions/charge-credit-card.php @@ -1,91 +1,132 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - $refId = 'ref' . time(); - - // Create the payment data for a credit card - $creditCard = new AnetAPI\CreditCardType(); - $creditCard->setCardNumber("4111111111111111"); - $creditCard->setExpirationDate("1226"); - $creditCard->setCardCode("123"); - $paymentOne = new AnetAPI\PaymentType(); - $paymentOne->setCreditCard($creditCard); - - $order = new AnetAPI\OrderType(); - $order->setDescription("New Item"); - - //create a transaction - $transactionRequestType = new AnetAPI\TransactionRequestType(); - $transactionRequestType->setTransactionType( "authCaptureTransaction"); - $transactionRequestType->setAmount($amount); - $transactionRequestType->setOrder($order); - $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() == \SampleCode\Constants::RESPONSE_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 - { +function chargeCreditCard($amount) +{ + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->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"; - if($tresponse->getErrors() != null) - { - echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; - echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\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 "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 - { + } else { echo "No response returned \n"; - } + } + + return $response; +} - return $response; - } - if(!defined('DONT_RUN_SAMPLES')) - chargeCreditCard(\SampleCode\Constants::SAMPLE_AMOUNT); -?> +if (!defined('DONT_RUN_SAMPLES')) { + chargeCreditCard("2.23"); +} diff --git a/PaymentTransactions/charge-customer-profile.php b/PaymentTransactions/charge-customer-profile.php index e90e41f..7482001 100644 --- a/PaymentTransactions/charge-customer-profile.php +++ b/PaymentTransactions/charge-customer-profile.php @@ -1,15 +1,20 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId $refId = 'ref' . time(); $profileToCharge = new AnetAPI\CustomerProfilePaymentType(); @@ -32,7 +37,7 @@ function chargeCustomerProfile($profileid, $paymentprofileid, $amount){ if ($response != null) { - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) + if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); diff --git a/PaymentTransactions/charge-tokenized-credit-card.php b/PaymentTransactions/charge-tokenized-credit-card.php index 72c4088..7b11b1d 100644 --- a/PaymentTransactions/charge-tokenized-credit-card.php +++ b/PaymentTransactions/charge-tokenized-credit-card.php @@ -1,22 +1,28 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->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->setCardNumber("4111111111111111"); $creditCard->setExpirationDate("2038-12"); - //Set the cryptogram + // Set the token specific info + $creditCard->setIsPaymentToken(true); $creditCard->setCryptogram("EjRWeJASNFZ4kBI0VniQEjRWeJA="); $paymentOne = new AnetAPI\PaymentType(); @@ -38,17 +44,17 @@ function chargeTokenizedCreditCard($amount){ if ($response != null) { - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) + if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); - if ($tresponse != null && $tresponse->getMessages() != null) + 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"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; } else { @@ -67,7 +73,7 @@ function chargeTokenizedCreditCard($amount){ if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; - echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { diff --git a/PaypalExpressCheckout/authorization-only-continued.php b/PaymentTransactions/create-chase-pay-transaction.php similarity index 52% rename from PaypalExpressCheckout/authorization-only-continued.php rename to PaymentTransactions/create-chase-pay-transaction.php index 0664290..ccf1b02 100644 --- a/PaypalExpressCheckout/authorization-only-continued.php +++ b/PaymentTransactions/create-chase-pay-transaction.php @@ -1,56 +1,64 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId $refId = 'ref' . time(); - $paypal_type = new AnetAPI\PayPalType(); - $paypal_type->setPayerID($payerId); - $paypal_type->setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); - $paypal_type->setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); + // 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); - $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); + $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() == \SampleCode\Constants::RESPONSE_OK) + if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); - if ($tresponse != null && $tresponse->getMessages() != null) + 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"; + 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 { @@ -69,7 +77,7 @@ function payPalAuthorizeOnlyContinue($transactionId, $payerId) { if($tresponse != null && $tresponse->getErrors() != null) { echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; - echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; } else { @@ -80,13 +88,11 @@ function payPalAuthorizeOnlyContinue($transactionId, $payerId) { } else { - echo "No response returned \n"; + echo "No response returned \n"; } return $response; } - if(!defined('DONT_RUN_SAMPLES')) - payPalAuthorizeOnlyContinue("2241711631", "JJLRRB29QC7RU"); - + createChasePayTransaction(12.23); ?> diff --git a/PaymentTransactions/credit-bank-account.php b/PaymentTransactions/credit-bank-account.php index 0ba4d07..b68f771 100644 --- a/PaymentTransactions/credit-bank-account.php +++ b/PaymentTransactions/credit-bank-account.php @@ -1,93 +1,94 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->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->setRoutingNumber('125000024'); - $bankAccount->setAccountNumber('12345678'); - $bankAccount->setNameOnAccount('Jane Doe'); + $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 info $order = new AnetAPI\OrderType(); $order->setInvoiceNumber("101"); $order->setDescription("Golf Shirts"); - //create a debit card Bank transaction + //create a bank credit transaction $transactionRequestType = new AnetAPI\TransactionRequestType(); - $transactionRequestType->setTransactionType( "refundTransaction"); + $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); + $request->setRefId($refId); + $request->setTransactionRequest($transactionRequestType); $controller = new AnetController\CreateTransactionController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); - - if ($response != null) - { - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) - { - $tresponse = $response->getTransactionResponse(); + 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"; - } + 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 "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"; + } else { + echo "No response returned \n"; } return $response; - } - if(!defined('DONT_RUN_SAMPLES')) - creditBankAccount(12.23); -?> +} + +if (!defined('DONT_RUN_SAMPLES')) { + creditBankAccount(5.29); +} + diff --git a/PaymentTransactions/debit-bank-account.php b/PaymentTransactions/debit-bank-account.php index e2d0fc6..6d50388 100644 --- a/PaymentTransactions/debit-bank-account.php +++ b/PaymentTransactions/debit-bank-account.php @@ -1,92 +1,95 @@ -setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->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'); + $bankAccount->setAccountType('checking'); + // see eCheck documentation for proper echeck type to use for each situation $bankAccount->setEcheckType('WEB'); - $bankAccount->setRoutingNumber('121042882'); - $bankAccount->setAccountNumber('123456789123'); - $bankAccount->setNameOnAccount('Jane Doe'); - $bankAccount->setBankName('Bank of the Earth'); + $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 debit card Bank transaction + //create a bank debit transaction $transactionRequestType = new AnetAPI\TransactionRequestType(); - $transactionRequestType->setTransactionType( "authCaptureTransaction"); + $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); + $request->setRefId($refId); + $request->setTransactionRequest($transactionRequestType); $controller = new AnetController\CreateTransactionController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); - if ($response != null) - { - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) - { - $tresponse = $response->getTransactionResponse(); + 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 Banlk Account TRANS ID : " . $tresponse->getTransId() . "\n"; - echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; - echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + 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 "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"; + } else { + echo "No response returned \n"; } return $response; - } - if(!defined('DONT_RUN_SAMPLES')) - debitBankAccount(12.23); -?> +} + +if (!defined('DONT_RUN_SAMPLES')) { + debitBankAccount(5.29); +} diff --git a/PaymentTransactions/get-an-accept-payment-page.php b/PaymentTransactions/get-an-accept-payment-page.php deleted file mode 100644 index 05ebb64..0000000 --- a/PaymentTransactions/get-an-accept-payment-page.php +++ /dev/null @@ -1,60 +0,0 @@ -setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - - //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->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(); -?> diff --git a/PaymentTransactions/refund-transaction.php b/PaymentTransactions/refund-transaction.php index 3de5edf..7171066 100644 --- a/PaymentTransactions/refund-transaction.php +++ b/PaymentTransactions/refund-transaction.php @@ -1,16 +1,21 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - $refId = 'ref' . time(); + $merchantAuthentication->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(); @@ -23,6 +28,7 @@ function refundTransaction($amount){ $transactionRequest->setTransactionType( "refundTransaction"); $transactionRequest->setAmount($amount); $transactionRequest->setPayment($paymentOne); + $transactionRequest->setRefTransId($refTransId); $request = new AnetAPI\CreateTransactionRequest(); @@ -34,7 +40,7 @@ function refundTransaction($amount){ if ($response != null) { - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) + if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); @@ -79,5 +85,5 @@ function refundTransaction($amount){ return $response; } if(!defined('DONT_RUN_SAMPLES')) - refundTransaction( \SampleCode\Constants::SAMPLE_AMOUNT_REFUND); -?> \ No newline at end of file + refundTransaction( "2.23"); +?> diff --git a/PaymentTransactions/update-split-tender-group.php b/PaymentTransactions/update-split-tender-group.php index 2805bf6..e386750 100644 --- a/PaymentTransactions/update-split-tender-group.php +++ b/PaymentTransactions/update-split-tender-group.php @@ -1,20 +1,25 @@ setName( \SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - $refId = 'ref' . time(); + $merchantAuthentication->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->setRefId($refId); $request->setSplitTenderId("115901"); $request->setSplitTenderStatus("voided"); diff --git a/PaymentTransactions/void-transaction.php b/PaymentTransactions/void-transaction.php index 82af5ae..c2a4d3b 100644 --- a/PaymentTransactions/void-transaction.php +++ b/PaymentTransactions/void-transaction.php @@ -1,16 +1,21 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - $refId = 'ref' . time(); + $merchantAuthentication->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(); @@ -26,7 +31,7 @@ function voidTransaction($transactionid){ if ($response != null) { - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) + if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); diff --git a/PaypalExpressCheckout/authorization-and-capture-continue.php b/PaypalExpressCheckout/authorization-and-capture-continue.php deleted file mode 100644 index aff5f46..0000000 --- a/PaypalExpressCheckout/authorization-and-capture-continue.php +++ /dev/null @@ -1,85 +0,0 @@ -setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - - $payPalType=new AnetAPI\PayPalType(); - $payPalType->setPayerID($payerID); - - $paymentOne = new AnetAPI\PaymentType(); - $paymentOne->setPayPal($payPalType); - - // Create an authorize and capture continue 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() == \SampleCode\Constants::RESPONSE_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')) - payPalAuthorizeCaptureContinue("2241708986","6ZSCSYG33VP8Q"); -?> diff --git a/README.md b/README.md index 4b2b653..e929b5c 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,49 @@ -# Sample PHP Code for Authorize.Net -[![Build Status](https://travis-ci.org/AuthorizeNet/sample-code-php.png?branch=master)] -(https://travis-ci.org/AuthorizeNet/sample-code-php) +# 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 just like our API, which you can also try out directly here: http://developer.authorize.net/api/reference +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 so you can look at them to get a gist of how the method works, you can use the snippets to try in your own sample project, or you can run each sample from the command line. +## Using the Sample Code -##Running the Samples -Clone this repository. -Run "composer update" in the root directory. -Run the individual samples e.g. -```` -php PaymentTransactions/charge-credit-card.php -```` +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. -##What if I'm not using Composer? -We provide a custom `SPL` autoloader, just [download the SDK.](https://github.com/AuthorizeNet/sdk-php/releases): +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'; diff --git a/RecurringBilling/cancel-subscription.php b/RecurringBilling/cancel-subscription.php index bfe1adb..59f8553 100644 --- a/RecurringBilling/cancel-subscription.php +++ b/RecurringBilling/cancel-subscription.php @@ -1,16 +1,20 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId $refId = 'ref' . time(); $request = new AnetAPI\ARBCancelSubscriptionRequest(); @@ -41,6 +45,6 @@ function cancelSubscription($subscriptionId) { } if(!defined('DONT_RUN_SAMPLES')) - cancelSubscription("3056945"); + cancelSubscription("7087965"); ?> diff --git a/RecurringBilling/create-subscription-from-customer-profile.php b/RecurringBilling/create-subscription-from-customer-profile.php index 33c7419..8681182 100644 --- a/RecurringBilling/create-subscription-from-customer-profile.php +++ b/RecurringBilling/create-subscription-from-customer-profile.php @@ -1,18 +1,22 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + // Set the transaction's refId $refId = 'ref' . time(); // Subscription Type Info @@ -25,7 +29,7 @@ function createSubscriptionFromCustomerProfile($intervalLength, $customerProfile $paymentSchedule = new AnetAPI\PaymentScheduleType(); $paymentSchedule->setInterval($interval); - $paymentSchedule->setStartDate(new DateTime('2020-08-30')); + $paymentSchedule->setStartDate(new DateTime('2035-08-30')); $paymentSchedule->setTotalOccurrences("12"); $paymentSchedule->setTrialOccurrences("1"); diff --git a/RecurringBilling/create-subscription.php b/RecurringBilling/create-subscription.php index e635f9a..1bf6fba 100644 --- a/RecurringBilling/create-subscription.php +++ b/RecurringBilling/create-subscription.php @@ -1,18 +1,21 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + // Set the transaction's refId $refId = 'ref' . time(); // Subscription Type Info @@ -25,7 +28,7 @@ function createSubscription($intervalLength) { $paymentSchedule = new AnetAPI\PaymentScheduleType(); $paymentSchedule->setInterval($interval); - $paymentSchedule->setStartDate(new DateTime('2020-08-30')); + $paymentSchedule->setStartDate(new DateTime('2035-12-30')); $paymentSchedule->setTotalOccurrences("12"); $paymentSchedule->setTrialOccurrences("1"); @@ -35,7 +38,7 @@ function createSubscription($intervalLength) { $creditCard = new AnetAPI\CreditCardType(); $creditCard->setCardNumber("4111111111111111"); - $creditCard->setExpirationDate("2020-12"); + $creditCard->setExpirationDate("2038-12"); $payment = new AnetAPI\PaymentType(); $payment->setCreditCard($creditCard); diff --git a/RecurringBilling/get-list-of-subscriptions.php b/RecurringBilling/get-list-of-subscriptions.php index 74fdab8..72330e8 100644 --- a/RecurringBilling/get-list-of-subscriptions.php +++ b/RecurringBilling/get-list-of-subscriptions.php @@ -1,25 +1,28 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->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"); + $sorting->setOrderDescending(false); $paging = new AnetAPI\PagingType(); - $paging->setLimit("1000"); + $paging->setLimit("10"); $paging->setOffset("1"); $request = new AnetAPI\ARBGetSubscriptionListRequest(); @@ -32,23 +35,25 @@ function getListOfSubscriptions() { $controller = new AnetController\ARBGetSubscriptionListController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) - { - //echo "SUCCESS: Subscription Details:" . $response->getSubscriptionDetails() . "\n"; + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { + echo "SUCCESS: Subscription Details:" . "\n"; echo "Total Number In Results:" . $response->getTotalNumInResultSet() . "\n"; - } - else - { + 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')) +if (!defined('DONT_RUN_SAMPLES')) { getListOfSubscriptions(); -?> +} diff --git a/RecurringBilling/get-subscription-status.php b/RecurringBilling/get-subscription-status.php index 4b8d7fa..52796b0 100644 --- a/RecurringBilling/get-subscription-status.php +++ b/RecurringBilling/get-subscription-status.php @@ -1,17 +1,20 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + // Set the transaction's refId $refId = 'ref' . time(); $request = new AnetAPI\ARBGetSubscriptionStatusRequest(); diff --git a/RecurringBilling/get-subscription.php b/RecurringBilling/get-subscription.php index 35dcb11..23b0409 100644 --- a/RecurringBilling/get-subscription.php +++ b/RecurringBilling/get-subscription.php @@ -1,63 +1,72 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + function getSubscription($subscriptionId) + { + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); - $refId = 'ref' . time(); + // 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); + // 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); - // Controller - $controller = new AnetController\ARBGetSubscriptionController($request); + // Getting the response + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - // 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"; - } - 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"; + 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; + return $response; } if(!defined('DONT_RUN_SAMPLES')) - getSubscription("2930242"); + getSubscription("2942461"); ?> diff --git a/RecurringBilling/update-subscription.php b/RecurringBilling/update-subscription.php index 703b369..6729445 100644 --- a/RecurringBilling/update-subscription.php +++ b/RecurringBilling/update-subscription.php @@ -1,24 +1,27 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->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("2020-12"); + $creditCard->setExpirationDate("2038-12"); $payment = new AnetAPI\PaymentType(); $payment->setCreditCard($creditCard); diff --git a/SampleCodeList.txt b/SampleCodeList.txt index ef5fe79..5119f91 100644 --- a/SampleCodeList.txt +++ b/SampleCodeList.txt @@ -7,8 +7,8 @@ GetTransactionList,0,1 CreateAnApplePayTransaction,0,0 CreateAnAcceptTransaction,0,0 CreateAnAndroidPayTransaction,0,0 -DecryptVisaCheckoutData,0,1 -CreateVisaCheckoutTransaction,0,0 +decryptVisaSrcData,0,0 +createVisaSrcTransaction,0,0 CaptureFundsAuthorizedThroughAnotherChannel,1,1 AuthorizeCreditCard,1,1 DebitBankAccount,1,1 @@ -16,14 +16,14 @@ ChargeTokenizedCreditCard,0,0 PayPalAuthorizeOnly,1,1 GetListOfSubscriptions,0,1 GetUnsettledTransactionList,0,1 -GetBatchStatistics,0,1 -GetSettledBatchList,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,1 +GetCustomerProfileIds,0,0 GetCustomerProfile,1,1 GetAcceptCustomerProfilePage,1,1 GetCustomerPaymentProfile,1,1 @@ -40,8 +40,8 @@ CreditBankAccount,1,0 ChargeCustomerProfile,1,1 PayPalVoid,1,0 PayPalAuthorizeCapture,1,1 -PayPalAuthorizeCaptureContinue,1,1 -PayPalAuthorizeOnlyContinue,1,0 +PayPalAuthorizeCaptureContinued,1,1 +PayPalAuthorizeOnlyContinued,1,0 PayPalCredit,1,0 PayPalGetDetails,1,1 PayPalPriorAuthorizationCapture,1,0 @@ -55,3 +55,4 @@ ValidateCustomerPaymentProfile,1,0 GetMerchantDetails,0,1 UpdateHeldTransaction,1,0 GetAnAcceptPaymentPage,0,1 +CreateAnAcceptPaymentTransaction,0,0 diff --git a/Sha512/compute_trans_hashSHA2.php b/Sha512/compute_trans_hashSHA2.php new file mode 100644 index 0000000..fbf6e75 --- /dev/null +++ b/Sha512/compute_trans_hashSHA2.php @@ -0,0 +1,20 @@ + diff --git a/TestRunner.php b/TestRunner.php new file mode 100644 index 0000000..61c981c --- /dev/null +++ b/TestRunner.php @@ -0,0 +1,471 @@ +'); +} +$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; + } +} diff --git a/TransactionReporting/get-account-updater-job-details.php b/TransactionReporting/get-account-updater-job-details.php new file mode 100644 index 0000000..0d26eb5 --- /dev/null +++ b/TransactionReporting/get-account-updater-job-details.php @@ -0,0 +1,84 @@ +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(); +} diff --git a/TransactionReporting/get-account-updater-job-summary.php b/TransactionReporting/get-account-updater-job-summary.php new file mode 100644 index 0000000..444e894 --- /dev/null +++ b/TransactionReporting/get-account-updater-job-summary.php @@ -0,0 +1,57 @@ +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(); +} diff --git a/TransactionReporting/get-batch-statistics.php b/TransactionReporting/get-batch-statistics.php index def63e8..9a161c6 100644 --- a/TransactionReporting/get-batch-statistics.php +++ b/TransactionReporting/get-batch-statistics.php @@ -1,20 +1,21 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId $refId = 'ref' . time(); - - //Setting a valid batch Id for the Merchant - $batchId = "4532808"; // Creating a request $request = new AnetAPI\GetBatchStatisticsRequest(); @@ -61,4 +62,4 @@ function getBatchStatistics() { if(!defined('DONT_RUN_SAMPLES')) getBatchStatistics(); -?> \ No newline at end of file +?> diff --git a/TransactionReporting/get-customer-profile-transaction-list.php b/TransactionReporting/get-customer-profile-transaction-list.php new file mode 100644 index 0000000..69eb20c --- /dev/null +++ b/TransactionReporting/get-customer-profile-transaction-list.php @@ -0,0 +1,53 @@ +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"); +?> \ No newline at end of file diff --git a/TransactionReporting/get-merchant-details.php b/TransactionReporting/get-merchant-details.php index 1ec4714..1b20655 100644 --- a/TransactionReporting/get-merchant-details.php +++ b/TransactionReporting/get-merchant-details.php @@ -1,17 +1,20 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - + $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId $refId = 'ref' . time(); $request = new AnetAPI\GetMerchantDetailsRequest(); diff --git a/TransactionReporting/get-settled-batch-list.php b/TransactionReporting/get-settled-batch-list.php index 150512b..89292af 100644 --- a/TransactionReporting/get-settled-batch-list.php +++ b/TransactionReporting/get-settled-batch-list.php @@ -1,31 +1,29 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->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 - $firstSettlementDate=new DateTime("2015-08-25T06:00:00Z"); - // a date constructed from an ISO8601 format date string + // 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); - - // a date constructed manually - $lastSettlementDate=new DateTime(); - $lastSettlementDate->setDate(2015,9,20); - $lastSettlementDate->setTime(13,33,59); - $lastSettlementDate->setTimezone(new DateTimeZone('UTC')); $request->setLastSettlementDate($lastSettlementDate); $controller = new AnetController\GetSettledBatchListController ($request); @@ -39,7 +37,7 @@ function getSettledBatchList() { 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('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"; @@ -65,8 +63,17 @@ function getSettledBatchList() { 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(); + getSettledBatchList($firstSettlementDate, $lastSettlementDate); ?> diff --git a/TransactionReporting/get-transaction-details.php b/TransactionReporting/get-transaction-details.php index 89ef217..1822d78 100644 --- a/TransactionReporting/get-transaction-details.php +++ b/TransactionReporting/get-transaction-details.php @@ -1,17 +1,23 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - + $merchantAuthentication->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(); @@ -40,4 +46,4 @@ function getTransactionDetails($transactionId) { if(!defined('DONT_RUN_SAMPLES')) getTransactionDetails("2238968786"); -?> \ No newline at end of file +?> diff --git a/TransactionReporting/get-transaction-list.php b/TransactionReporting/get-transaction-list.php index db83004..ccf86c1 100644 --- a/TransactionReporting/get-transaction-list.php +++ b/TransactionReporting/get-transaction-list.php @@ -1,16 +1,20 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - + $merchantAuthentication->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 @@ -26,19 +30,19 @@ function getTransactionList() { 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 dispaly in this Batch."; - return ; - } - //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"; - } - } + 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"; diff --git a/TransactionReporting/get-unsettled-transaction-list.php b/TransactionReporting/get-unsettled-transaction-list.php index 2793fd8..45e9db8 100644 --- a/TransactionReporting/get-unsettled-transaction-list.php +++ b/TransactionReporting/get-unsettled-transaction-list.php @@ -1,16 +1,20 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - + $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId $refId = 'ref' . time(); diff --git a/VisaCheckout/create-visa-checkout-transaction.php b/VisaCheckout/create-visa-src-transaction.php similarity index 91% rename from VisaCheckout/create-visa-checkout-transaction.php rename to VisaCheckout/create-visa-src-transaction.php index f9debcf..1edcf11 100644 --- a/VisaCheckout/create-visa-checkout-transaction.php +++ b/VisaCheckout/create-visa-src-transaction.php @@ -1,16 +1,20 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->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 @@ -38,7 +42,7 @@ function createVisaCheckoutTransaction(){ if ($response != null) { - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) + if($response->getMessages()->getResultCode() == "Ok") { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) @@ -84,6 +88,6 @@ function createVisaCheckoutTransaction(){ } if(!defined('DONT_RUN_SAMPLES')) - createVisaCheckoutTransaction(); + createVisaSrcTransaction(); ?> diff --git a/VisaCheckout/decrypt-visa-checkout-data.php b/VisaCheckout/decrypt-visa-src-data.php similarity index 89% rename from VisaCheckout/decrypt-visa-checkout-data.php rename to VisaCheckout/decrypt-visa-src-data.php index 0f9b633..2b2b791 100644 --- a/VisaCheckout/decrypt-visa-checkout-data.php +++ b/VisaCheckout/decrypt-visa-src-data.php @@ -1,16 +1,20 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + $merchantAuthentication->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 @@ -42,6 +46,6 @@ function decryptVisaCheckoutData(){ } if(!defined('DONT_RUN_SAMPLES')) - decryptVisaCheckoutData(); + decryptVisaSrcData(); ?> diff --git a/composer.json b/composer.json index a0188d1..08f03a6 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,7 @@ { "require": { - "php": ">=5.5", + "php": ">=5.6", "ext-curl": "*", - "phpunit/phpunit": "~4.0", - "authorizenet/authorizenet": "1.9.2" - }, - "autoload": { - "classmap": ["constants"] + "authorizenet/authorizenet": ">=2.0 || <2.1" } } diff --git a/composer.json.sdk-dev b/composer.json.sdk-dev new file mode 100644 index 0000000..9caf00c --- /dev/null +++ b/composer.json.sdk-dev @@ -0,0 +1,11 @@ +{ + "require": { + "php": ">=5.6", + "ext-curl": "*", + "phpunit/phpunit": "~9.0||~9.5", + "authorizenet/authorizenet": ">=2.0 || <2.1" + }, + "autoload": { + "classmap": ["constants", "lib"] + } +} diff --git a/constants/Constants.php b/constants/Constants.php deleted file mode 100644 index d1ce2da..0000000 --- a/constants/Constants.php +++ /dev/null @@ -1,21 +0,0 @@ - - diff --git a/constants/SampleCodeConstants.php b/constants/SampleCodeConstants.php new file mode 100644 index 0000000..0cd03fd --- /dev/null +++ b/constants/SampleCodeConstants.php @@ -0,0 +1,9 @@ + + diff --git a/test-runner.php b/test-runner.php deleted file mode 100644 index e5ad2e5..0000000 --- a/test-runner.php +++ /dev/null @@ -1,406 +0,0 @@ -'); -} -$dirPath = $_SERVER['argv'][2]; -echo $dirPath; -if(substr($dirPath, -1) != "/") - $dirPath = $dirPath."/"; - -$directories = array( - 'CustomerProfiles/', - 'RecurringBilling/', - 'PaypalExpressCheckout/', - 'PaymentTransactions/', - 'TransactionReporting/', - 'MobileInappTransactions/', - 'VisaCheckout/' -); - -$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, 900000)/12); - } - //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"; - } - if($apiName && (false === strpos($apiName,SAMPLE_CODE_NAME_HEADING))) - { - - - echo "should run:".$shouldRun."\n"; - if("0" === $shouldRun) - { - echo ":Skipping " . $sampleMethodName . "\n"; - } - else - { - 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"; - - $response = call_user_func($sampleMethodName); - - if(($response != null) && ($response->getMessages()->getResultCode() == "Ok")) - break; - } - - //response must be successful - $this->assertNotNull($response); - $this->assertEquals($response->getMessages()->getResultCode(), "Ok"); - $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 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 runPayPalAuthorizeCaptureContinue() - { - $response = payPalAuthorizeCapture(self::getAmount()); - return payPalAuthorizeCaptureContinue($response->getTransactionResponse()->getTransId(), self::$payerID); - } - - public static function runPayPalAuthorizeOnlyContinue() - { - return payPalAuthorizeOnlyContinue(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()); - } - - public static function runGetTransactionDetails() - { - $response = authorizeCreditCard(self::getAmount()); - return getTransactionDetails($response->getTransactionResponse()->getTransId()); - } - - - 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; - } - - // public static function runUpdateCustomerProfile(){ - // $responseCustomerProfile = createCustomerProfile(self::getEmail()); - // $customerProfileId = $responseCustomerProfile->getCustomerProfileId(); - // $response = updateCustomerProfileById($customerProfileId); - // deleteCustomerProfile($customerProfileId); - // 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; - } - - public static function runGetAcceptCustomerProfilePage() - { - $response = createCustomerProfile(self::getEmail()); - $profileResponse = GetAcceptCustomerProfilePage($response->getCustomerProfileId()); - deleteCustomerProfile($response->getCustomerProfileId()); - - return $profileResponse; - } -}