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 new file mode 100644 index 0000000..45de70f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,35 @@ +language: php + +matrix: + include: + - php: 5.6 + env: PHPUNIT_VERSION=5.6.* + dist: trusty + - php: 7.0 + env: PHPUNIT_VERSION=5.6.* + dist: trusty + - php: 7.1 + env: PHPUNIT_VERSION=5.7.* + dist: trusty + - php: 7.2 + env: PHPUNIT_VERSION=8.5.* + dist: bionic + - php: 7.3 + env: PHPUNIT_VERSION=9.5.* + dist: bionic + - php: 7.4 + env: PHPUNIT_VERSION=9.5.* + dist: bionic + - php: 8.0 + env: PHPUNIT_VERSION=9.5.* + dist: bionic + +sudo: false + +before_script: + - composer require "phpunit/phpunit:${PHPUNIT_VERSION}" --no-update + - composer update --prefer-dist + +script: + - phpunit TestRunner.php . + 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/AcceptSuite/get-accept-customer-profile-page.php b/AcceptSuite/get-accept-customer-profile-page.php new file mode 100644 index 0000000..e784f06 --- /dev/null +++ b/AcceptSuite/get-accept-customer-profile-page.php @@ -0,0 +1,51 @@ +setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); + + // Use an existing payment profile ID for this Merchant name and Transaction key + + $setting = new AnetAPI\SettingType(); + $setting->setSettingName("hostedProfileReturnUrl"); + $setting->setSettingValue("https://returnurl.com/return/"); + + //$alist = new AnetAPI\ArrayOfSettingType(); + //$alist->addToSetting($setting); + + $request = new AnetAPI\GetHostedProfilePageRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setCustomerProfileId($customerprofileid); + $request->addToHostedProfileSettings($setting); + + $controller = new AnetController\GetHostedProfilePageController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) + { + echo $response->getToken()."\n"; + } + else + { + echo "ERROR : Failed to get hosted profile page\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + return $response; + } + if(!defined('DONT_RUN_SAMPLES')) + getAcceptCustomerProfilePage(); +?> 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/ApplePayTransactions/create-an-apple-pay-transaction.php b/ApplePayTransactions/create-an-apple-pay-transaction.php deleted file mode 100644 index 3d2581d..0000000 --- a/ApplePayTransactions/create-an-apple-pay-transaction.php +++ /dev/null @@ -1,52 +0,0 @@ -setName("5KP3u95bQpv"); -$merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); -$refId = 'ref' . time(); - -$op = new AnetAPI\OpaqueDataType(); -$op->setDataDescriptor("COMMON.APPLE.INAPP.PAYMENT"); -$op->setDataValue("eyJkYXRhIjoiQkRQTldTdE1tR2V3UVVXR2c0bzdFXC9qKzFjcTFUNzhxeVU4NGI2N2l0amNZSTh3UFlBT2hzaGpoWlBycWRVcjRYd1BNYmo0emNHTWR5KysxSDJWa1BPWStCT01GMjV1YjE5Y1g0bkN2a1hVVU9UakRsbEIxVGdTcjhKSFp4Z3A5ckNnc1NVZ2JCZ0tmNjBYS3V0WGY2YWpcL284WkliS25yS1E4U2gwb3VMQUtsb1VNbit2UHU0K0E3V0tycXJhdXo5SnZPUXA2dmhJcStIS2pVY1VOQ0lUUHlGaG1PRXRxK0grdzB2UmExQ0U2V2hGQk5uQ0hxenpXS2NrQlwvMG5xTFpSVFliRjBwK3Z5QmlWYVdIZWdoRVJmSHhSdGJ6cGVjelJQUHVGc2ZwSFZzNDhvUExDXC9rXC8xTU5kNDdrelwvcEhEY1JcL0R5NmFVTStsTmZvaWx5XC9RSk4rdFMzbTBIZk90SVNBUHFPbVhlbXZyNnhKQ2pDWmxDdXcwQzltWHpcL29iSHBvZnVJRVM4cjljcUdHc1VBUERwdzdnNjQybTRQendLRitIQnVZVW5lV0RCTlNEMnU2amJBRzMiLCJ2ZXJzaW9uIjoiRUNfdjEiLCJoZWFkZXIiOnsiYXBwbGljYXRpb25EYXRhIjoiOTRlZTA1OTMzNWU1ODdlNTAxY2M0YmY5MDYxM2UwODE0ZjAwYTdiMDhiYzdjNjQ4ZmQ4NjVhMmFmNmEyMmNjMiIsInRyYW5zYWN0aW9uSWQiOiJjMWNhZjVhZTcyZjAwMzlhODJiYWQ5MmI4MjgzNjM3MzRmODViZjJmOWNhZGYxOTNkMWJhZDlkZGNiNjBhNzk1IiwiZXBoZW1lcmFsUHVibGljS2V5IjoiTUlJQlN6Q0NBUU1HQnlxR1NNNDlBZ0V3Z2ZjQ0FRRXdMQVlIS29aSXpqMEJBUUloQVBcL1wvXC9cLzhBQUFBQkFBQUFBQUFBQUFBQUFBQUFcL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL01Gc0VJUFwvXC9cL1wvOEFBQUFCQUFBQUFBQUFBQUFBQUFBQVwvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cLzhCQ0JheGpYWXFqcVQ1N1BydlZWMm1JYThaUjBHc014VHNQWTd6ancrSjlKZ1N3TVZBTVNkTmdpRzV3U1RhbVo0NFJPZEpyZUJuMzZRQkVFRWF4ZlI4dUVzUWtmNHZPYmxZNlJBOG5jRGZZRXQ2ek9nOUtFNVJkaVl3cFpQNDBMaVwvaHBcL200N242MHA4RDU0V0s4NHpWMnN4WHM3THRrQm9ONzlSOVFJaEFQXC9cL1wvXC84QUFBQUFcL1wvXC9cL1wvXC9cL1wvXC9cLys4NXZxdHB4ZWVoUE81eXNMOFl5VlJBZ0VCQTBJQUJHbStnc2wwUFpGVFwva0RkVVNreHd5Zm84SnB3VFFRekJtOWxKSm5tVGw0REdVdkFENEdzZUdqXC9wc2hCWjBLM1RldXFEdFwvdERMYkUrOFwvbTB5Q21veHc9IiwicHVibGljS2V5SGFzaCI6IlwvYmI5Q05DMzZ1QmhlSEZQYm1vaEI3T28xT3NYMkora0pxdjQ4ek9WVmlRPSJ9LCJzaWduYXR1cmUiOiJNSUlEUWdZSktvWklodmNOQVFjQ29JSURNekNDQXk4Q0FRRXhDekFKQmdVckRnTUNHZ1VBTUFzR0NTcUdTSWIzRFFFSEFhQ0NBaXN3Z2dJbk1JSUJsS0FEQWdFQ0FoQmNsK1BmMytVNHBrMTNuVkQ5bndRUU1Ba0dCU3NPQXdJZEJRQXdKekVsTUNNR0ExVUVBeDRjQUdNQWFBQnRBR0VBYVFCQUFIWUFhUUJ6QUdFQUxnQmpBRzhBYlRBZUZ3MHhOREF4TURFd05qQXdNREJhRncweU5EQXhNREV3TmpBd01EQmFNQ2N4SlRBakJnTlZCQU1lSEFCakFHZ0FiUUJoQUdrQVFBQjJBR2tBY3dCaEFDNEFZd0J2QUcwd2daOHdEUVlKS29aSWh2Y05BUUVCQlFBRGdZMEFNSUdKQW9HQkFOQzgra2d0Z212V0YxT3pqZ0ROcmpURUJSdW9cLzVNS3ZsTTE0NnBBZjdHeDQxYmxFOXc0ZklYSkFEN0ZmTzdRS2pJWFlOdDM5ckx5eTd4RHdiXC81SWtaTTYwVFoyaUkxcGo1NVVjOGZkNGZ6T3BrM2Z0WmFRR1hOTFlwdEcxZDlWN0lTODJPdXA5TU1vMUJQVnJYVFBITmNzTTk5RVBVblBxZGJlR2M4N20wckFnTUJBQUdqWERCYU1GZ0dBMVVkQVFSUk1FK0FFSFpXUHJXdEpkN1laNDMxaENnN1lGU2hLVEFuTVNVd0l3WURWUVFESGh3QVl3Qm9BRzBBWVFCcEFFQUFkZ0JwQUhNQVlRQXVBR01BYndCdGdoQmNsK1BmMytVNHBrMTNuVkQ5bndRUU1Ba0dCU3NPQXdJZEJRQURnWUVBYlVLWUNrdUlLUzlRUTJtRmNNWVJFSW0ybCtYZzhcL0pYditHQlZRSmtPS29zY1k0aU5ERkFcL2JRbG9nZjlMTFU4NFRId05SbnN2VjNQcnY3UlRZODFncTBkdEM4elljQWFBa0NISUkzeXFNbko0QU91NkVPVzlrSmsyMzJnU0U3V2xDdEhiZkxTS2Z1U2dRWDhLWFFZdVpMazJScjYzTjhBcFhzWHdCTDNjSjB4Z2VBd2dkMENBUUV3T3pBbk1TVXdJd1lEVlFRREhod0FZd0JvQUcwQVlRQnBBRUFBZGdCcEFITUFZUUF1QUdNQWJ3QnRBaEJjbCtQZjMrVTRwazEzblZEOW53UVFNQWtHQlNzT0F3SWFCUUF3RFFZSktvWklodmNOQVFFQkJRQUVnWUJhSzNFbE9zdGJIOFdvb3NlREFCZitKZ1wvMTI5SmNJYXdtN2M2VnhuN1phc05iQXEzdEF0OFB0eSt1UUNnc3NYcVprTEE3a3oyR3pNb2xOdHY5d1ltdTlVandhcjFQSFlTK0JcL29Hbm96NTkxd2phZ1hXUnowbk1vNXkzTzFLelgwZDhDUkhBVmE4OFNyVjFhNUpJaVJldjNvU3RJcXd2NXh1WmxkYWc2VHI4dz09In0="); -$paymentOne = new AnetAPI\PaymentType(); -$paymentOne->setOpaqueData($op); - -//create a transaction -$transactionRequestType = new AnetAPI\TransactionRequestType(); -$transactionRequestType->setTransactionType( "authCaptureTransaction"); -$transactionRequestType->setAmount(151); -$transactionRequestType->setPayment($paymentOne); - -$request = new AnetAPI\CreateTransactionRequest(); -$request->setMerchantAuthentication($merchantAuthentication); -$request->setRefId( $refId); -$request->setTransactionRequest( $transactionRequestType); - -$controller = new AnetController\CreateTransactionController($request); -$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - -if ($response != null) -{ - $tresponse = $response->getTransactionResponse(); - - if (($tresponse != null) && ($tresponse->getResponseCode()=="1") ) - { - echo " AUTH CODE : " . $tresponse->getAuthCode() . "\n"; - echo " TRANS ID : " . $tresponse->getTransId() . "\n"; - } - else - { - echo "ERROR : Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - } -} -else -{ - echo "Null response"; -} -?> diff --git a/CustomerProfiles/create-customer-payment-profile.php b/CustomerProfiles/create-customer-payment-profile.php index 501b524..3c3812f 100644 --- a/CustomerProfiles/create-customer-payment-profile.php +++ b/CustomerProfiles/create-customer-payment-profile.php @@ -1,60 +1,84 @@ setName("556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); - $refId = 'ref' . time(); - //Use an existing profile id - $existingcustomerprofileid = "35858366"; - - $creditCard = new AnetAPI\CreditCardType(); - $creditCard->setCardNumber( "4012888818888" ); - $creditCard->setExpirationDate( "2038-11"); - $creditCard->setCardCode( "123"); - $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->setCompany("My company"); - $billto->setAddress("123 Main St."); - $billto->setCity("Bellevue"); - $billto->setState("WA"); - $billto->setZip("98004"); - $billto->setPhoneNumber("000-000-0000"); - $billto->setfaxNumber("999-999-9999"); - $billto->setCountry("USA"); - - // Create a new Customer Payment Profile - $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); - $paymentprofile->setCustomerType('individual'); - $paymentprofile->setBillTo($billto); - $paymentprofile->setPayment($paymentCreditCard); - - $paymentprofiles[] = $paymentprofile; - - // Submit a CreateCustomerPaymentProfileRequest to create a new Customer Payment Profile - $paymentprofilerequest = new AnetAPI\CreateCustomerPaymentProfileRequest(); - $paymentprofilerequest->setMerchantAuthentication($merchantAuthentication); - $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"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - - } + +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(); + + // Create a Customer Profile Request + // 1. (Optionally) create a Payment Profile + // 2. (Optionally) create a Shipping Profile + // 3. Create a Customer Profile (or specify an existing profile) + // 4. Submit a CreateCustomerProfile Request + // 5. Validate Profile ID returned + + // Set credit card information for payment profile + $creditCard = new AnetAPI\CreditCardType(); + $creditCard->setCardNumber("4242424242424242"); + $creditCard->setExpirationDate("2038-12"); + $creditCard->setCardCode("142"); + $paymentCreditCard = new AnetAPI\PaymentType(); + $paymentCreditCard->setCreditCard($creditCard); + + // Create the Bill To info for new payment type + $billto = new AnetAPI\CustomerAddressType(); + $billto->setFirstName("Ellen".$phoneNumber); + $billto->setLastName("Johnson"); + $billto->setCompany("Souveniropolis"); + $billto->setAddress("14 Main Street"); + $billto->setCity("Pecan Springs"); + $billto->setState("TX"); + $billto->setZip("44628"); + $billto->setCountry("USA"); + $billto->setPhoneNumber($phoneNumber); + $billto->setfaxNumber("999-999-9999"); + + // Create a new Customer Payment Profile object + $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); + $paymentprofile->setCustomerType('individual'); + $paymentprofile->setBillTo($billto); + $paymentprofile->setPayment($paymentCreditCard); + $paymentprofile->setDefaultPaymentProfile(true); + + $paymentprofiles[] = $paymentprofile; + + // Assemble the complete transaction request + $paymentprofilerequest = new AnetAPI\CreateCustomerPaymentProfileRequest(); + $paymentprofilerequest->setMerchantAuthentication($merchantAuthentication); + + // Add an existing profile id to the request + $paymentprofilerequest->setCustomerProfileId($existingcustomerprofileid); + $paymentprofilerequest->setPaymentProfile($paymentprofile); + $paymentprofilerequest->setValidationMode("liveMode"); + + // Create the controller and get the response + $controller = new AnetController\CreateCustomerPaymentProfileController($paymentprofilerequest); + $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { + echo "Create Customer Payment Profile SUCCESS: " . $response->getCustomerPaymentProfileId() . "\n"; + } else { + echo "Create Customer Payment Profile: ERROR Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + + } + return $response; +} + +if (!defined('DONT_RUN_SAMPLES')) { + createCustomerPaymentProfile("1929905607", "000-000-0009"); +} ?> diff --git a/CustomerProfiles/create-customer-profile-from-transaction.php b/CustomerProfiles/create-customer-profile-from-transaction.php index 8490804..fa9c002 100644 --- a/CustomerProfiles/create-customer-profile-from-transaction.php +++ b/CustomerProfiles/create-customer-profile-from-transaction.php @@ -1,30 +1,54 @@ setName("556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); + +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"); + + $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("2235382051"); + $controller = new AnetController\CreateCustomerProfileFromTransactionController($request); - $controller = new AnetController\CreateCustomerProfileFromTransactionController($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: 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"); +} - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - echo "SUCCESS: PROFILE ID : " . $response->getCustomerProfileId() . "\n"; - } - else - { - echo "ERROR : Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - } ?> diff --git a/CustomerProfiles/create-customer-profile-with-accept-nonce.php b/CustomerProfiles/create-customer-profile-with-accept-nonce.php new file mode 100644 index 0000000..abce577 --- /dev/null +++ b/CustomerProfiles/create-customer-profile-with-accept-nonce.php @@ -0,0 +1,90 @@ +setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); + + // Create a Customer Profile Request + // 1. (Optionally) create a Payment Profile + // 2. (Optionally) create a Shipping Profile + // 3. Create a Customer Profile (or specify an existing profile) + // 4. Submit a CreateCustomerProfile Request + // 5. Validate Profile ID returned + + // Set the payment data for the payment profile to a token obtained from Accept.js + $op = new AnetAPI\OpaqueDataType(); + $op->setDataDescriptor("COMMON.ACCEPT.INAPP.PAYMENT"); + $op->setDataValue("119eyJjb2RlIjoiNTBfMl8wNjAwMDUyN0JEODE4RjQxOUEyRjhGQkIxMkY0MzdGQjAxQUIwRTY2NjhFNEFCN0VENzE4NTUwMjlGRUU0M0JFMENERUIwQzM2M0ExOUEwMDAzNzlGRDNFMjBCODJEMDFCQjkyNEJDIiwidG9rZW4iOiI5NDkwMjMyMTAyOTQwOTk5NDA0NjAzIiwidiI6IjEuMSJ9"); + $paymentOne = new AnetAPI\PaymentType(); + $paymentOne->setOpaqueData($op); + + + // Create the Bill To info for new payment type + $billto = new AnetAPI\CustomerAddressType(); + $billto->setFirstName("Ellen"); + $billto->setLastName("Johnson"); + $billto->setCompany("Souveniropolis"); + $billto->setAddress("14 Main Street"); + $billto->setCity("Pecan Springs"); + $billto->setState("TX"); + $billto->setZip("44628"); + $billto->setCountry("USA"); + $billto->setPhoneNumber(123-123-1234); + $billto->setfaxNumber("999-999-9999"); + + // Create a new Customer Payment Profile object + $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); + $paymentprofile->setCustomerType('individual'); + $paymentprofile->setBillTo($billto); + $paymentprofile->setPayment($paymentOne); + $paymentprofile->setDefaultPaymentProfile(true); + + $paymentprofiles[] = $paymentprofile; + + // Create a new CustomerProfileType and add the payment profile object + $customerprofile = new AnetAPI\CustomerProfileType(); + $customerprofile->setDescription("Customer Test PHP Accept Test"); + + $customerprofile->setMerchantCustomerId("M_".$email); + $customerprofile->setEmail($email); + $customerprofile->setPaymentProfiles($paymentprofiles); + + // Assemble the complete transaction request + $request = new AnetAPI\CreateCustomerProfileRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId($refId); + $request->setProfile($customerprofile); + + // Create the controller and get the response + $controller = new AnetController\CreateCustomerProfileController($request); + $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { + echo "Succesfully created customer profile : " . $response->getCustomerProfileId() . "\n"; + $paymentProfiles = $response->getCustomerPaymentProfileIdList(); + echo "SUCCESS: PAYMENT PROFILE ID : " . $paymentProfiles[0] . "\n"; + } else { + echo "ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + return $response; +} + +if (!defined('DONT_RUN_SAMPLES')) { + createCustomerProfileWithAcceptNonce("test123@test.com"); +} +?> diff --git a/CustomerProfiles/create-customer-profile.php b/CustomerProfiles/create-customer-profile.php index 0ced164..49fb43f 100644 --- a/CustomerProfiles/create-customer-profile.php +++ b/CustomerProfiles/create-customer-profile.php @@ -1,66 +1,106 @@ setName("556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); - $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); +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 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 + // Create a Customer Profile Request + // 1. (Optionally) create a Payment Profile + // 2. (Optionally) create a Shipping Profile + // 3. Create a Customer Profile (or specify an existing profile) + // 4. Submit a CreateCustomerProfile Request + // 5. Validate Profile ID returned + + // Set credit card information for payment profile + $creditCard = new AnetAPI\CreditCardType(); + $creditCard->setCardNumber("4242424242424242"); + $creditCard->setExpirationDate("2038-12"); + $creditCard->setCardCode("142"); + $paymentCreditCard = new AnetAPI\PaymentType(); + $paymentCreditCard->setCreditCard($creditCard); + + // Create the Bill To info for new payment type + $billTo = new AnetAPI\CustomerAddressType(); + $billTo->setFirstName("Ellen"); + $billTo->setLastName("Johnson"); + $billTo->setCompany("Souveniropolis"); + $billTo->setAddress("14 Main Street"); + $billTo->setCity("Pecan Springs"); + $billTo->setState("TX"); + $billTo->setZip("44628"); + $billTo->setCountry("USA"); + $billTo->setPhoneNumber("888-888-8888"); + $billTo->setfaxNumber("999-999-9999"); + + // Create a customer shipping address + $customerShippingAddress = new AnetAPI\CustomerAddressType(); + $customerShippingAddress->setFirstName("James"); + $customerShippingAddress->setLastName("White"); + $customerShippingAddress->setCompany("Addresses R Us"); + $customerShippingAddress->setAddress(rand() . " North Spring Street"); + $customerShippingAddress->setCity("Toms River"); + $customerShippingAddress->setState("NJ"); + $customerShippingAddress->setZip("08753"); + $customerShippingAddress->setCountry("USA"); + $customerShippingAddress->setPhoneNumber("888-888-8888"); + $customerShippingAddress->setFaxNumber("999-999-9999"); + + // Create an array of any shipping addresses + $shippingProfiles[] = $customerShippingAddress; - $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); - $paymentprofile->setCustomerType('individual'); - $paymentprofile->setBillTo($billto); - $paymentprofile->setPayment($paymentCreditCard); - $paymentprofiles[] = $paymentprofile; - $customerprofile = new AnetAPI\CustomerProfileType(); - $customerprofile->setDescription("Customer 2 Test PHP"); - $merchantCustomerId = time().rand(1,150); - $customerprofile->setMerchantCustomerId($merchantCustomerId); - $customerprofile->setEmail("test2@domain.com"); - $customerprofile->setPaymentProfiles($paymentprofiles); + // 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; +} - $request = new AnetAPI\CreateCustomerProfileRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setRefId( $refId); - $request->setProfile($customerprofile); - $controller = new AnetController\CreateCustomerProfileController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - echo "SUCCESS: PROFILE ID : " . $response->getCustomerProfileId() . "\n"; - echo "SUCCESS: PAYMENT PROFILE ID : " . $response->getCustomerPaymentProfileIdList()[0] . "\n"; - } - else - { - echo "ERROR : Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - - } -?> +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 a33c725..3044353 100644 --- a/CustomerProfiles/create-customer-shipping-address.php +++ b/CustomerProfiles/create-customer-shipping-address.php @@ -1,44 +1,56 @@ setName("556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); + +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); + + // Set the transaction's refId + $refId = 'ref' . time(); + + // Use An existing customer profile id for this merchant name and transaction key - // An existing customer profile id for this merchant name and transaction key - $existingcustomerprofileid = "35872074"; + // 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("000-000-0000"); - $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"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - } + $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 352f466..ce3e6ca 100644 --- a/CustomerProfiles/delete-customer-payment-profile.php +++ b/CustomerProfiles/delete-customer-payment-profile.php @@ -1,31 +1,43 @@ setName("556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); - - // An existing payment profile ID for this Merchant name and Transaction key - // - $customerprofileid = "10000"; - $customerpaymentprofileid = "20000"; - - $request = new AnetAPI\DeleteCustomerPaymentProfileRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setCustomerProfileId($customerprofileid); - $request->setCustomerPaymentProfileId($customerpaymentprofileid); - $controller = new AnetController\DeleteCustomerPaymentProfileController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - echo "SUCCESS: Delete Customer Payment Profile SUCCESS :" . "\n"; - } - else - { - echo "ERROR : Delete Customer Payment Profile: Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; + +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 + + $request = new AnetAPI\DeleteCustomerPaymentProfileRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setCustomerProfileId($customerProfileId); + $request->setCustomerPaymentProfileId($customerpaymentprofileid); + $controller = new AnetController\DeleteCustomerPaymentProfileController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) + { + echo "SUCCESS: Delete Customer Payment Profile SUCCESS :" . "\n"; + } + else + { + echo "ERROR : Delete Customer Payment Profile: Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + return $response; } + if(!defined('DONT_RUN_SAMPLES')) + deleteCustomerPaymentProfile(); ?> diff --git a/CustomerProfiles/delete-customer-profile.php b/CustomerProfiles/delete-customer-profile.php index 4bd07fc..ee918cc 100644 --- a/CustomerProfiles/delete-customer-profile.php +++ b/CustomerProfiles/delete-customer-profile.php @@ -1,81 +1,43 @@ setName("556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); - $refId = 'ref' . time(); - - // Create the payment data for a credit card - $creditCard = new AnetAPI\CreditCardType(); - $creditCard->setCardNumber( "4111111111111111" ); - $creditCard->setExpirationDate( "2038-12"); - $paymentCreditCard = new AnetAPI\PaymentType(); - $paymentCreditCard->setCreditCard($creditCard); - - // Create the Bill To info - $billto = new AnetAPI\CustomerAddressType(); - $billto->setFirstName("Ellen"); - $billto->setLastName("Johnson"); - $billto->setCompany("Souveniropolis"); - $billto->setAddress("14 Main Street"); - $billto->setCity("Pecan Springs"); - $billto->setState("TX"); - $billto->setZip("44628"); - $billto->setCountry("USA"); - // Create a Customer Profile Request - // 1. create a Payment Profile - // 2. create a Customer Profile - // 3. Submit a CreateCustomerProfile Request - - $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); - - $paymentprofile->setCustomerType('individual'); - $paymentprofile->setBillTo($billto); - $paymentprofile->setPayment($paymentCreditCard); - $paymentprofiles[] = $paymentprofile; - $customerprofile = new AnetAPI\CustomerProfileType(); - $customerprofile->setDescription("Create Customer Profile Request Test for PHP"); - $merchantCustomerId = time().rand(1,150); - $customerprofile->setMerchantCustomerId($merchantCustomerId); - $customerprofile->setEmail("customerprofile@domain.com"); - $customerprofile->setPaymentProfiles($paymentprofiles); - - $request = new AnetAPI\CreateCustomerProfileRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setRefId( $refId); - $request->setProfile($customerprofile); - $controller = new AnetController\CreateCustomerProfileController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - echo "SUCCESS: CreateCustomerProfile PROFILE ID : " . $response->getCustomerProfileId() . "\n"; - - $profileidcreated = $response->getCustomerProfileId(); - } - else - { - echo "ERROR : CreateCustomerProfile: Invalid response\n"; - } - // Delete an existing customer profile - $request = new AnetAPI\DeleteCustomerProfileRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setCustomerProfileId( $profileidcreated ); - - $controller = new AnetController\DeleteCustomerProfileController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - echo "DeleteCustomerProfile SUCCESS : " . "\n"; - } - else - { - echo "ERROR : DeleteCustomerProfile: Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - +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(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setCustomerProfileId( $customerProfileId ); + + $controller = new AnetController\DeleteCustomerProfileController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) + { + echo "DeleteCustomerProfile SUCCESS : " . "\n"; + } + else + { + echo "ERROR : DeleteCustomerProfile: Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + + return $response; } + + if(!defined('DONT_RUN_SAMPLES')) + deleteCustomerProfile("1929905651"); ?> diff --git a/CustomerProfiles/delete-customer-shipping-address.php b/CustomerProfiles/delete-customer-shipping-address.php index ae85c7d..d3f2ccc 100644 --- a/CustomerProfiles/delete-customer-shipping-address.php +++ b/CustomerProfiles/delete-customer-shipping-address.php @@ -1,32 +1,43 @@ setName("556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); + +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 + $request = new AnetAPI\DeleteCustomerShippingAddressRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setCustomerProfileId($customerprofileid); + $request->setCustomerAddressId($customeraddressid); - // Use an existing customer profile and address id for this merchant name and transaction key - $customerprofileid = "35894174"; - $customeraddressid = "32445389"; - - // Delete an existing customer shipping address for an existing customer profile - $request = new AnetAPI\DeleteCustomerShippingAddressRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setCustomerProfileId($customerprofileid); - $request->setCustomerAddressId($customeraddressid); - - $controller = new AnetController\DeleteCustomerShippingAddressController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - echo "Delete Customer Shipping Address SUCCESS:" . "\n"; - } - else - { - echo "Delete Customer Shipping Address ERROR : Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; + $controller = new AnetController\DeleteCustomerShippingAddressController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) + { + echo "Delete Customer Shipping Address SUCCESS" . "\n"; + } + else + { + echo "Delete Customer Shipping Address ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + return $response; } + if(!defined('DONT_RUN_SAMPLES')) + deleteCustomerShippingAddress(); ?> diff --git a/CustomerProfiles/get-customer-payment-profile-list.php b/CustomerProfiles/get-customer-payment-profile-list.php index e42b7cc..51da3b3 100644 --- a/CustomerProfiles/get-customer-payment-profile-list.php +++ b/CustomerProfiles/get-customer-payment-profile-list.php @@ -1,72 +1,76 @@ - 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; +} - use net\authorize\api\contract\v1 as AnetAPI; - use net\authorize\api\controller as AnetController; - - define("AUTHORIZENET_LOG_FILE", "phplog"); - - // Common setup for API credentials (merchant) - $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); - $merchantAuthentication->setName("5KP3u95bQpv"); - $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); - $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"; - echo "Message Code: " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; - echo "Message Text: " . $response->getMessages()->getMessage()[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"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - } - } - else - { - // Failed to get the response - echo "NULL Response Error"; - } -?> +if (!defined('DONT_RUN_SAMPLES')) { + getCustomerPaymentProfileList(); +} diff --git a/CustomerProfiles/get-customer-payment-profile.php b/CustomerProfiles/get-customer-payment-profile.php index e4d6ff0..6e056a5 100644 --- a/CustomerProfiles/get-customer-payment-profile.php +++ b/CustomerProfiles/get-customer-payment-profile.php @@ -1,44 +1,64 @@ - setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); -// Common setup for API credentials (merchant) -$merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); -$merchantAuthentication->setName("5KP3u95bQpv"); -$merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); -$refId = 'ref' . time(); + //request requires customerProfileId and customerPaymentProfileId + $request = new AnetAPI\GetCustomerPaymentProfileRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId( $refId); + $request->setCustomerProfileId($customerProfileId); + $request->setCustomerPaymentProfileId($customerPaymentProfileId); -//request requires customerProfileId and customerPaymentProfileId -$request = new AnetAPI\GetCustomerPaymentProfileRequest(); -$request->setMerchantAuthentication($merchantAuthentication); -$request->setRefId( $refId); -$request->setCustomerProfileId("36731856"); -$request->setCustomerPaymentProfileId("33211899"); + $controller = new AnetController\GetCustomerPaymentProfileController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + if(($response != null)){ + if ($response->getMessages()->getResultCode() == "Ok") + { + echo "GetCustomerPaymentProfile SUCCESS: " . "\n"; + echo "Customer Payment Profile Id: " . $response->getPaymentProfile()->getCustomerPaymentProfileId() . "\n"; + echo "Customer Payment Profile Billing Address: " . $response->getPaymentProfile()->getbillTo()->getAddress(). "\n"; + echo "Customer Payment Profile Card Last 4 " . $response->getPaymentProfile()->getPayment()->getCreditCard()->getCardNumber(). "\n"; -$controller = new AnetController\GetCustomerPaymentProfileController($request); -$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); -if(($response != null)){ - if ($response->getMessages()->getResultCode() == "Ok") - { - echo "GetCustomerPaymentProfile SUCCESS: " . "\n"; - echo "Customer Payment Profile Id: " . $response->getPaymentProfile()->getCustomerPaymentProfileId() . "\n"; - echo "Customer Payment Profile Billing Address: " . $response->getPaymentProfile()->getbillTo()->getAddress(). "\n"; - echo "Customer Payment Profile Card Last 4 " . $response->getPaymentProfile()->getPayment()->getCreditCard()->getCardNumber(). "\n"; + if($response->getPaymentProfile()->getSubscriptionIds() != null) + { + if($response->getPaymentProfile()->getSubscriptionIds() != null) + { - } - else - { - echo "GetCustomerPaymentProfile ERROR : Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - } -} -else{ - echo "NULL Response Error"; + echo "List of subscriptions:"; + foreach($response->getPaymentProfile()->getSubscriptionIds() as $subscriptionid) + echo $subscriptionid . "\n"; + } + } + } + else + { + echo "GetCustomerPaymentProfile ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + } + else{ + echo "NULL Response Error"; + } + return $response; } +if(!defined('DONT_RUN_SAMPLES')) + getCustomerPaymentProfile(); ?> diff --git a/CustomerProfiles/get-customer-profile-ids.php b/CustomerProfiles/get-customer-profile-ids.php index 0851f9f..20b68a0 100644 --- a/CustomerProfiles/get-customer-profile-ids.php +++ b/CustomerProfiles/get-customer-profile-ids.php @@ -1,28 +1,41 @@ setName("556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); - $refId = 'ref' . time(); + +function getCustomerProfileIds() +{ + /* 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(); - // Get all existing customer profile ID's - $request = new AnetAPI\GetCustomerProfileIdsRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $controller = new AnetController\GetCustomerProfileIdsController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - echo "GetCustomerProfileId's SUCCESS: " . "\n"; - $profileIds[] = $response->getIds(); - echo "There are " . count($profileIds[0]) . " Customer Profile ID's for this Merchant Name and Transaction Key" . "\n"; - } - else - { - echo "GetCustomerProfileId's ERROR : Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; + // Get all existing customer profile ID's + $request = new AnetAPI\GetCustomerProfileIdsRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $controller = new AnetController\GetCustomerProfileIdsController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) + { + echo "GetCustomerProfileId's SUCCESS: " . "\n"; + $profileIds[] = $response->getIds(); + echo "There are " . count($profileIds[0]) . " Customer Profile ID's for this Merchant Name and Transaction Key" . "\n"; + } + else + { + echo "GetCustomerProfileId's ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + return $response; } + if(!defined('DONT_RUN_SAMPLES')) + getCustomerProfileIds(); ?> diff --git a/CustomerProfiles/get-customer-profile.php b/CustomerProfiles/get-customer-profile.php index b450add..c69efc6 100644 --- a/CustomerProfiles/get-customer-profile.php +++ b/CustomerProfiles/get-customer-profile.php @@ -1,86 +1,112 @@ setName("556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); - $refId = 'ref' . time(); + +function getCustomerProfile() +{ + /* 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 the payment data for a credit card + $creditCard = new AnetAPI\CreditCardType(); + $creditCard->setCardNumber( "4111111111111111" ); + $creditCard->setExpirationDate("2038-12"); + $paymentCreditCard = new AnetAPI\PaymentType(); + $paymentCreditCard->setCreditCard($creditCard); - // Create the Bill To info - $billto = new AnetAPI\CustomerAddressType(); - $billto->setFirstName("Ellen"); - $billto->setLastName("Johnson"); - $billto->setCompany("Souveniropolis"); - $billto->setAddress("14 Main Street"); - $billto->setCity("Pecan Springs"); - $billto->setState("TX"); - $billto->setZip("44628"); - $billto->setCountry("USA"); + // Create 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 + // Create a Customer Profile Request + // 1. create a Payment Profile + // 2. create a Customer Profile + // 3. Submit a CreateCustomerProfile Request + // 4. Validate Profiiel ID returned - $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); + $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); - $paymentprofile->setCustomerType('individual'); - $paymentprofile->setBillTo($billto); - $paymentprofile->setPayment($paymentCreditCard); - $paymentprofiles[] = $paymentprofile; - $customerprofile = new AnetAPI\CustomerProfileType(); - $customerprofile->setDescription("Customer 2 Test PHP"); - $merchantCustomerId = time().rand(1,150); - $customerprofile->setMerchantCustomerId($merchantCustomerId); - $customerprofile->setEmail("test2@domain.com"); - $customerprofile->setPaymentProfiles($paymentprofiles); + $paymentprofile->setCustomerType('individual'); + $paymentprofile->setBillTo($billto); + $paymentprofile->setPayment($paymentCreditCard); + $paymentprofiles[] = $paymentprofile; + $customerprofile = new AnetAPI\CustomerProfileType(); + $customerprofile->setDescription("Customer 2 Test PHP"); + $merchantCustomerId = time().rand(1,150); + $customerprofile->setMerchantCustomerId($merchantCustomerId); + $customerprofile->setEmail("test2@domain.com"); + $customerprofile->setPaymentProfiles($paymentprofiles); - $request = new AnetAPI\CreateCustomerProfileRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setRefId( $refId); - $request->setProfile($customerprofile); - $controller = new AnetController\CreateCustomerProfileController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - echo "SUCCESS: CreateCustomerProfile PROFILE ID : " . $response->getCustomerProfileId() . "\n"; + $request = new AnetAPI\CreateCustomerProfileRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId( $refId); + $request->setProfile($customerprofile); + $controller = new AnetController\CreateCustomerProfileController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) + { + echo "SUCCESS: CreateCustomerProfile PROFILE ID : " . $response->getCustomerProfileId() . "\n"; - $profileIdRequested = $response->getCustomerProfileId(); - } - else - { - echo "ERROR : CreateCustomerProfile: Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - } - // Retrieve an existing customer profile along with all the associated payment profiles and shipping addresses + $profileIdRequested = $response->getCustomerProfileId(); + } + else + { + echo "ERROR : CreateCustomerProfile: Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + // Retrieve an existing customer profile along with all the associated payment profiles and shipping addresses - $request = new AnetAPI\GetCustomerProfileRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setCustomerProfileId($profileIdRequested); - $controller = new AnetController\GetCustomerProfileController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - echo "GetCustomerProfile SUCCESS : " . "\n"; - $profileSelected = $response->getProfile(); - $paymentProfilesSelected = $profileSelected->getPaymentProfiles(); - echo "Profile Has " . count($paymentProfilesSelected). " Payment Profiles" . "\n"; + $request = new AnetAPI\GetCustomerProfileRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setCustomerProfileId($profileIdRequested); + $controller = new AnetController\GetCustomerProfileController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) + { + echo "GetCustomerProfile SUCCESS : " . "\n"; + $profileSelected = $response->getProfile(); + $paymentProfilesSelected = $profileSelected->getPaymentProfiles(); + echo "Profile Has " . count($paymentProfilesSelected). " Payment Profiles" . "\n"; + + if($response->getSubscriptionIds() != null) + { + if($response->getSubscriptionIds() != null) + { + echo "List of subscriptions:"; + foreach($response->getSubscriptionIds() as $subscriptionid) + echo $subscriptionid . "\n"; + } + } + } + else + { + echo "ERROR : GetCustomerProfile: Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + return $response; } - else + if(!defined('DONT_RUN_SAMPLES')) { - echo "ERROR : GetCustomerProfile: Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; + getCustomerProfile(); } ?> diff --git a/CustomerProfiles/get-customer-shipping-address.php b/CustomerProfiles/get-customer-shipping-address.php index d06fa04..1e1b541 100644 --- a/CustomerProfiles/get-customer-shipping-address.php +++ b/CustomerProfiles/get-customer-shipping-address.php @@ -1,44 +1,69 @@ setName("5KP3u95bQpv"); - $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); + +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; + $customerAddressId = $customeraddressid; - // An existing customer profile id and shipping address id for this merchant name and transaction key - $customerProfileId = "36731856"; - $customerAddressId = "35850995"; + $request = new AnetAPI\GetCustomerShippingAddressRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setCustomerProfileId($customerProfileId); + $request->setCustomerAddressId($customerAddressId); + + $controller = new AnetController\GetCustomerShippingAddressController($request); + + //Retrieving existing customer shipping address + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) + { + echo "Get Customer Shipping Address SUCCESS" . "\n"; + echo " FirstName : " . $response->getAddress()->getFirstName() . "\n"; + echo " LastName : " . $response->getAddress()->getLastName() . "\n"; + echo " Company : " . $response->getAddress()->getCompany() . "\n"; + echo " Address : " . $response->getAddress()->getAddress() . "\n"; + echo " City : " . $response->getAddress()->getCity() . "\n"; + echo " State : " . $response->getAddress()->getState() . "\n"; + echo " Zip : " . $response->getAddress()->getZip() . "\n"; + echo " Country : " . $response->getAddress()->getCountry() . "\n"; + echo " Phone Number : " . $response->getAddress()->getPhoneNumber() . "\n"; + echo " FAX Number : " . $response->getAddress()->getFaxNumber() . "\n"; + echo "Customer AddressId : " . $response->getAddress()->getCustomerAddressId() . "\n"; - $request = new AnetAPI\GetCustomerShippingAddressRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setCustomerProfileId($customerProfileId); - $request->setCustomerAddressId($customerAddressId); - - $controller = new AnetController\GetCustomerShippingAddressController($request); - - //Retrieving existing customer shipping address - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - echo "Get Customer Shipping Address SUCCESS" . "\n"; - echo " FirstName : " . $response->getAddress()->getFirstName() . "\n"; - echo " LastName : " . $response->getAddress()->getLastName() . "\n"; - echo " Company : " . $response->getAddress()->getCompany() . "\n"; - echo " Address : " . $response->getAddress()->getAddress() . "\n"; - echo " City : " . $response->getAddress()->getCity() . "\n"; - echo " State : " . $response->getAddress()->getState() . "\n"; - echo " Zip : " . $response->getAddress()->getZip() . "\n"; - echo " Country : " . $response->getAddress()->getCountry() . "\n"; - echo " Phone Number : " . $response->getAddress()->getPhoneNumber() . "\n"; - echo " FAX Number : " . $response->getAddress()->getFaxNumber() . "\n"; - echo "Customer AddressId : " . $response->getAddress()->getCustomerAddressId() . "\n"; - } - else - { - echo "Get Customer Shipping Address ERROR : Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; + if($response->getSubscriptionIds() != null) + { + if($response->getSubscriptionIds() != null) + { + + echo "List of subscriptions:"; + foreach($response->getSubscriptionIds() as $subscriptionid) + echo $subscriptionid . "\n"; + } + } + } + else + { + echo "Get Customer Shipping Address ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + return $response; } + if(!defined('DONT_RUN_SAMPLES')) + getCustomerShippingAddress("36152127","36976566"); ?> diff --git a/CustomerProfiles/get-hosted-profile-page.php b/CustomerProfiles/get-hosted-profile-page.php deleted file mode 100644 index 81441af..0000000 --- a/CustomerProfiles/get-hosted-profile-page.php +++ /dev/null @@ -1,44 +0,0 @@ -setName("3Zw3Ru9nx"); - $merchantAuthentication->setTransactionKey("7Tbj6T3a9cPq4A5d"); - - // An existing payment profile ID for this Merchant name and Transaction key - // - $customerprofileid = "37680862"; - $customerpaymentprofileid = "34249159"; - - $setting = new AnetAPI\SettingType(); - $setting->setSettingName("hostedProfileReturnUrl"); - $setting->setSettingValue("https://returnurl.com/return/"); - - //$alist = new AnetAPI\ArrayOfSettingType(); - //$alist->addToSetting($setting); - - $request = new AnetAPI\GetHostedProfilePageRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setCustomerProfileId($customerprofileid); - $request->addToHostedProfileSettings($setting); - - $controller = new AnetController\GetHostedProfilePageController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - echo $response->getMessages()->getMessage()[0]->getCode()."\n"; - echo $response->getMessages()->getMessage()[0]->getText()."\n"; - - echo $response->getToken()."\n"; - } - else - { - echo "ERROR : Failed to get hosted profile page\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - } -?> \ No newline at end of file diff --git a/CustomerProfiles/update-customer-payment-profile.php b/CustomerProfiles/update-customer-payment-profile.php index 9f87d04..484d5e5 100644 --- a/CustomerProfiles/update-customer-payment-profile.php +++ b/CustomerProfiles/update-customer-payment-profile.php @@ -1,89 +1,95 @@ setName("5KP3u95bQpv"); - $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); - $refId = 'ref' . time(); - - //Set profile ids of profile to be updated - $request = new AnetAPI\UpdateCustomerPaymentProfileRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setCustomerProfileId("36731856"); - $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( "XXXX1111" ); - $creditCard->setExpirationDate( "XXXX"); - $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"); +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(); + + $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("33211899"); - $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("36731856"); - $getRequest->setCustomerPaymentProfileId("33211899"); + $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"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - } - } - else{ - echo "NULL Response Error"; - } + return $response; +} - } - else - { - echo "Update Customer Payment Profile: ERROR Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - } +if(!defined('DONT_RUN_SAMPLES')) + updateCustomerPaymentProfile(); ?> diff --git a/CustomerProfiles/update-customer-profile.php b/CustomerProfiles/update-customer-profile.php index a3ca29d..4a2c708 100644 --- a/CustomerProfiles/update-customer-profile.php +++ b/CustomerProfiles/update-customer-profile.php @@ -1,105 +1,119 @@ setName("556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); - $refId = 'ref' . time(); + +function updateCustomerProfile() +{ + /* 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 the payment data for a credit card + $creditCard = new AnetAPI\CreditCardType(); + $creditCard->setCardNumber( "4111111111111111" ); + $creditCard->setExpirationDate("2038-12"); + $paymentCreditCard = new AnetAPI\PaymentType(); + $paymentCreditCard->setCreditCard($creditCard); - // Create the Bill To info - $billto = new AnetAPI\CustomerAddressType(); - $billto->setFirstName("Ellen"); - $billto->setLastName("Johnson"); - $billto->setCompany("Souveniropolis"); - $billto->setAddress("14 Main Street"); - $billto->setCity("Pecan Springs"); - $billto->setState("TX"); - $billto->setZip("44628"); - $billto->setCountry("USA"); - - // Create a Customer Profile Request - // 1. create a Payment Profile - // 2. create a Customer Profile - // 3. Submit a CreateCustomerProfile Request - // 4. Validate Profiiel ID returned + // Create the Bill To info + $billto = new AnetAPI\CustomerAddressType(); + $billto->setFirstName("Ellen"); + $billto->setLastName("Johnson"); + $billto->setCompany("Souveniropolis"); + $billto->setAddress("14 Main Street"); + $billto->setCity("Pecan Springs"); + $billto->setState("TX"); + $billto->setZip("44628"); + $billto->setCountry("USA"); + + // Create a Customer Profile Request + // 1. create a Payment Profile + // 2. create a Customer Profile + // 3. Submit a CreateCustomerProfile Request + // 4. Validate Profiiel ID returned - $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); + $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); - $paymentprofile->setCustomerType('individual'); - $paymentprofile->setBillTo($billto); - $paymentprofile->setPayment($paymentCreditCard); - $paymentprofiles[] = $paymentprofile; - $customerprofile = new AnetAPI\CustomerProfileType(); - $customerprofile->setDescription("Update Customer Profile Request Test for PHP"); - $merchantCustomerId = time().rand(1,150); - $customerprofile->setMerchantCustomerId($merchantCustomerId); - $customerprofile->setEmail("customerprofile@domain.com"); - $customerprofile->setPaymentProfiles($paymentprofiles); + $paymentprofile->setCustomerType('individual'); + $paymentprofile->setBillTo($billto); + $paymentprofile->setPayment($paymentCreditCard); + $paymentprofiles[] = $paymentprofile; + $customerprofile = new AnetAPI\CustomerProfileType(); + $customerprofile->setDescription("Update Customer Profile Request Test for PHP"); + $merchantCustomerId = time().rand(1,150); + $customerprofile->setMerchantCustomerId($merchantCustomerId); + $customerprofile->setEmail(rand(0,10000) . "@test.com"); + $customerprofile->setPaymentProfiles($paymentprofiles); - $request = new AnetAPI\CreateCustomerProfileRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setRefId( $refId); - $request->setProfile($customerprofile); - $controller = new AnetController\CreateCustomerProfileController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - echo "SUCCESS: CreateCustomerProfile PROFILE ID : " . $response->getCustomerProfileId() . "\n"; + $request = new AnetAPI\CreateCustomerProfileRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId( $refId); + $request->setProfile($customerprofile); + $controller = new AnetController\CreateCustomerProfileController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) + { + echo "SUCCESS: CreateCustomerProfile PROFILE ID : " . $response->getCustomerProfileId() . "\n"; - $profileidcreated = $response->getCustomerProfileId(); - } - else - { - echo "ERROR : CreateCustomerProfile: Invalid response\n"; - } - // Update an existing customer profile + $profileidcreated = $response->getCustomerProfileId(); + } + else + { + echo "ERROR : CreateCustomerProfile: Invalid response\n"; + } + // Update an existing customer profile - $updatecustomerprofile = new AnetAPI\CustomerProfileExType(); - $updatecustomerprofile->setCustomerProfileId($profileidcreated); - $updatecustomerprofile->setDescription("Updated existing Profile Request"); - $updatecustomerprofile->setEmail("updatecustomerprofile@domain.com"); + $updatecustomerprofile = new AnetAPI\CustomerProfileExType(); + $updatecustomerprofile->setCustomerProfileId($profileidcreated); + $updatecustomerprofile->setDescription("Updated existing Profile Request"); + $updatecustomerprofile->setEmail("updated".rand(0,10000)."@test.com"); - $request = new AnetAPI\UpdateCustomerProfileRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setProfile($updatecustomerprofile); + $request = new AnetAPI\UpdateCustomerProfileRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setProfile($updatecustomerprofile); - $controller = new AnetController\UpdateCustomerProfileController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - echo "UpdateCustomerProfile SUCCESS : " . "\n"; - // Validate the description and e-mail that was updated - $request = new AnetAPI\GetCustomerProfileRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setCustomerProfileId($profileidcreated ); - $controller = new AnetController\GetCustomerProfileController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - echo "Get updated CustomerProfile SUCCESS : " . "\n"; - $profileselected = $response->getProfile(); - echo "Updated Customer Profile Customer description : " . $profileselected->getDescription() . "\n"; - echo "Updated Customer Profile EMail description : " . $profileselected->getEmail() . "\n"; - } - else - { - echo "ERROR : GetCustomerProfile: Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - } - } - else - { - echo "ERROR : UpdateCustomerProfile: Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; + $controller = new AnetController\UpdateCustomerProfileController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) + { + echo "UpdateCustomerProfile SUCCESS : " . "\n"; + // Validate the description and e-mail that was updated + $request = new AnetAPI\GetCustomerProfileRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setCustomerProfileId($profileidcreated ); + $controller = new AnetController\GetCustomerProfileController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) + { + echo "Get updated CustomerProfile SUCCESS : " . "\n"; + $profileselected = $response->getProfile(); + echo "Updated Customer Profile Customer description : " . $profileselected->getDescription() . "\n"; + echo "Updated Customer Profile EMail description : " . $profileselected->getEmail() . "\n"; + } + else + { + echo "ERROR : GetCustomerProfile: Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + } + else + { + echo "ERROR : UpdateCustomerProfile: Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + return $response; } + if(!defined('DONT_RUN_SAMPLES')) + updateCustomerProfile(); ?> diff --git a/CustomerProfiles/update-customer-shipping-address.php b/CustomerProfiles/update-customer-shipping-address.php index 98c6422..36ad6ad 100644 --- a/CustomerProfiles/update-customer-shipping-address.php +++ b/CustomerProfiles/update-customer-shipping-address.php @@ -1,15 +1,24 @@ setName("556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); + +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 = "35843932"; + $existingcustomerprofileid = $customerprofileid; // Create the customer shipping address $customershippingaddress = new AnetAPI\CustomerAddressExType(); @@ -23,6 +32,7 @@ $customershippingaddress->setCountry("USA"); $customershippingaddress->setPhoneNumber("201-000-0000"); $customershippingaddress->setFaxNumber("973-999-9999"); + $customershippingaddress->setCustomerAddressId($customeraddressid); // Update an existing customer shipping address for an existing customer profile $request = new AnetAPI\UpdateCustomerShippingAddressRequest(); @@ -33,11 +43,16 @@ $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { - echo "Update Customer Shipping Address SUCCESS:" . "\n"; + echo "Update Customer Shipping Address SUCCESS.\n"; } else { echo "Update Customer Shipping Address ERROR : Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; } + return $response; + } + if(!defined('DONT_RUN_SAMPLES')) + updateCustomerShippingAddress( "1929905607","901116911"); ?> diff --git a/CustomerProfiles/validate-customer-payment-profile.php b/CustomerProfiles/validate-customer-payment-profile.php index 4e8cd27..ca57209 100644 --- a/CustomerProfiles/validate-customer-payment-profile.php +++ b/CustomerProfiles/validate-customer-payment-profile.php @@ -1,24 +1,32 @@ setName("3Zw3Ru9nx"); - $merchantAuthentication->setTransactionKey("7Tbj6T3a9cPq4A5d"); - - // An existing payment profile ID for this Merchant name and Transaction key - // - $customerprofileid = "37680862"; - $customerpaymentprofileid = "34249159"; +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 $validationmode = "testMode"; $request = new AnetAPI\ValidateCustomerPaymentProfileRequest(); + $request->setMerchantAuthentication($merchantAuthentication); - $request->setCustomerProfileId($customerprofileid); - $request->setCustomerPaymentProfileId($customerpaymentprofileid); + $request->setCustomerProfileId($customerProfileId); + $request->setCustomerPaymentProfileId($customerPaymentProfileId); $request->setValidationMode($validationmode); $controller = new AnetController\ValidateCustomerPaymentProfileController($request); @@ -26,11 +34,17 @@ if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { - echo $response->getMessages()->getMessage()[0]->getText(); + $validationMessages = $response->getMessages()->getMessage(); + echo "Response : " . $validationMessages[0]->getCode() . " " .$validationMessages[0]->getText() . "\n"; } else { echo "ERROR : Validate Customer Payment Profile: Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + return $response; } + if(!defined('DONT_RUN_SAMPLES')) + validateCustomerPaymentProfile(); ?> diff --git a/FraudManagement/approve-or-decline-held-transaction.php b/FraudManagement/approve-or-decline-held-transaction.php new file mode 100644 index 0000000..c3e6df5 --- /dev/null +++ b/FraudManagement/approve-or-decline-held-transaction.php @@ -0,0 +1,82 @@ +setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); + + //create a transaction + $transactionRequestType = new AnetAPI\HeldTransactionRequestType(); + $transactionRequestType->setAction("approve"); //other possible value: decline + $transactionRequestType->setRefTransId("60012148205"); + + + $request = new AnetAPI\UpdateHeldTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setHeldTransactionRequest( $transactionRequestType); + $controller = new AnetController\UpdateHeldTransactionController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + + if ($response != null) + { + if($response->getMessages()->getResultCode() == "Ok") + { + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) + { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n"; + echo "Charge Credit Card TRANS ID : " . $tresponse->getTransId() . "\n"; + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } + else + { + echo "Transaction Failed \n"; + if($tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + } + else + { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + if($tresponse != null && $tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + else + { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } + } + else + { + echo "No response returned \n"; + } + + return $response; + } + if(!defined('DONT_RUN_SAMPLES')) + approveOrDeclineHeldTransaction(); +?> diff --git a/FraudManagement/get-held-transaction-list.php b/FraudManagement/get-held-transaction-list.php new file mode 100644 index 0000000..9405614 --- /dev/null +++ b/FraudManagement/get-held-transaction-list.php @@ -0,0 +1,56 @@ +setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); + + + $request = new AnetAPI\GetUnsettledTransactionListRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setStatus("pendingApproval"); + + + $controller = new AnetController\GetUnsettledTransactionListController($request); + + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) + { + if(null != $response->getTransactions()) + { + foreach($response->getTransactions() as $tx) + { + echo "SUCCESS: TransactionID: " . $tx->getTransId() . "\n"; + } + } + else{ + echo "No suspicious transactions for the merchant." . "\n"; + } + } + else + { + echo "ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + + return $response; + } + + if(!defined('DONT_RUN_SAMPLES')) + getHeldTransactionList(); + +?> 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 new file mode 100644 index 0000000..175a0a4 --- /dev/null +++ b/MobileInAppTransactions/create-an-android-pay-transaction.php @@ -0,0 +1,90 @@ +setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); + + $op = new AnetAPI\OpaqueDataType(); + $op->setDataDescriptor("COMMON.ANDROID.INAPP.PAYMENT"); + $op->setDataValue("eyJkYXRhIjoiQkRQTldTdE1tR2V3UVVXR2c0bzdFXC9qKzFjcTFUNzhxeVU4NGI2N2l0amNZSTh3UFlBT2hzaGpoWlBycWRVcjRYd1BNYmo0emNHTWR5KysxSDJWa1BPWStCT01GMjV1YjE5Y1g0bkN2a1hVVU9UakRsbEIxVGdTcjhKSFp4Z3A5ckNnc1NVZ2JCZ0tmNjBYS3V0WGY2YWpcL284WkliS25yS1E4U2gwb3VMQUtsb1VNbit2UHU0K0E3V0tycXJhdXo5SnZPUXA2dmhJcStIS2pVY1VOQ0lUUHlGaG1PRXRxK0grdzB2UmExQ0U2V2hGQk5uQ0hxenpXS2NrQlwvMG5xTFpSVFliRjBwK3Z5QmlWYVdIZWdoRVJmSHhSdGJ6cGVjelJQUHVGc2ZwSFZzNDhvUExDXC9rXC8xTU5kNDdrelwvcEhEY1JcL0R5NmFVTStsTmZvaWx5XC9RSk4rdFMzbTBIZk90SVNBUHFPbVhlbXZyNnhKQ2pDWmxDdXcwQzltWHpcL29iSHBvZnVJRVM4cjljcUdHc1VBUERwdzdnNjQybTRQendLRitIQnVZVW5lV0RCTlNEMnU2amJBRzMiLCJ2ZXJzaW9uIjoiRUNfdjEiLCJoZWFkZXIiOnsiYXBwbGljYXRpb25EYXRhIjoiOTRlZTA1OTMzNWU1ODdlNTAxY2M0YmY5MDYxM2UwODE0ZjAwYTdiMDhiYzdjNjQ4ZmQ4NjVhMmFmNmEyMmNjMiIsInRyYW5zYWN0aW9uSWQiOiJjMWNhZjVhZTcyZjAwMzlhODJiYWQ5MmI4MjgzNjM3MzRmODViZjJmOWNhZGYxOTNkMWJhZDlkZGNiNjBhNzk1IiwiZXBoZW1lcmFsUHVibGljS2V5IjoiTUlJQlN6Q0NBUU1HQnlxR1NNNDlBZ0V3Z2ZjQ0FRRXdMQVlIS29aSXpqMEJBUUloQVBcL1wvXC9cLzhBQUFBQkFBQUFBQUFBQUFBQUFBQUFcL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL01Gc0VJUFwvXC9cL1wvOEFBQUFCQUFBQUFBQUFBQUFBQUFBQVwvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cLzhCQ0JheGpYWXFqcVQ1N1BydlZWMm1JYThaUjBHc014VHNQWTd6ancrSjlKZ1N3TVZBTVNkTmdpRzV3U1RhbVo0NFJPZEpyZUJuMzZRQkVFRWF4ZlI4dUVzUWtmNHZPYmxZNlJBOG5jRGZZRXQ2ek9nOUtFNVJkaVl3cFpQNDBMaVwvaHBcL200N242MHA4RDU0V0s4NHpWMnN4WHM3THRrQm9ONzlSOVFJaEFQXC9cL1wvXC84QUFBQUFcL1wvXC9cL1wvXC9cL1wvXC9cLys4NXZxdHB4ZWVoUE81eXNMOFl5VlJBZ0VCQTBJQUJHbStnc2wwUFpGVFwva0RkVVNreHd5Zm84SnB3VFFRekJtOWxKSm5tVGw0REdVdkFENEdzZUdqXC9wc2hCWjBLM1RldXFEdFwvdERMYkUrOFwvbTB5Q21veHc9IiwicHVibGljS2V5SGFzaCI6IlwvYmI5Q05DMzZ1QmhlSEZQYm1vaEI3T28xT3NYMkora0pxdjQ4ek9WVmlRPSJ9LCJzaWduYXR1cmUiOiJNSUlEUWdZSktvWklodmNOQVFjQ29JSURNekNDQXk4Q0FRRXhDekFKQmdVckRnTUNHZ1VBTUFzR0NTcUdTSWIzRFFFSEFhQ0NBaXN3Z2dJbk1JSUJsS0FEQWdFQ0FoQmNsK1BmMytVNHBrMTNuVkQ5bndRUU1Ba0dCU3NPQXdJZEJRQXdKekVsTUNNR0ExVUVBeDRjQUdNQWFBQnRBR0VBYVFCQUFIWUFhUUJ6QUdFQUxnQmpBRzhBYlRBZUZ3MHhOREF4TURFd05qQXdNREJhRncweU5EQXhNREV3TmpBd01EQmFNQ2N4SlRBakJnTlZCQU1lSEFCakFHZ0FiUUJoQUdrQVFBQjJBR2tBY3dCaEFDNEFZd0J2QUcwd2daOHdEUVlKS29aSWh2Y05BUUVCQlFBRGdZMEFNSUdKQW9HQkFOQzgra2d0Z212V0YxT3pqZ0ROcmpURUJSdW9cLzVNS3ZsTTE0NnBBZjdHeDQxYmxFOXc0ZklYSkFEN0ZmTzdRS2pJWFlOdDM5ckx5eTd4RHdiXC81SWtaTTYwVFoyaUkxcGo1NVVjOGZkNGZ6T3BrM2Z0WmFRR1hOTFlwdEcxZDlWN0lTODJPdXA5TU1vMUJQVnJYVFBITmNzTTk5RVBVblBxZGJlR2M4N20wckFnTUJBQUdqWERCYU1GZ0dBMVVkQVFSUk1FK0FFSFpXUHJXdEpkN1laNDMxaENnN1lGU2hLVEFuTVNVd0l3WURWUVFESGh3QVl3Qm9BRzBBWVFCcEFFQUFkZ0JwQUhNQVlRQXVBR01BYndCdGdoQmNsK1BmMytVNHBrMTNuVkQ5bndRUU1Ba0dCU3NPQXdJZEJRQURnWUVBYlVLWUNrdUlLUzlRUTJtRmNNWVJFSW0ybCtYZzhcL0pYditHQlZRSmtPS29zY1k0aU5ERkFcL2JRbG9nZjlMTFU4NFRId05SbnN2VjNQcnY3UlRZODFncTBkdEM4elljQWFBa0NISUkzeXFNbko0QU91NkVPVzlrSmsyMzJnU0U3V2xDdEhiZkxTS2Z1U2dRWDhLWFFZdVpMazJScjYzTjhBcFhzWHdCTDNjSjB4Z2VBd2dkMENBUUV3T3pBbk1TVXdJd1lEVlFRREhod0FZd0JvQUcwQVlRQnBBRUFBZGdCcEFITUFZUUF1QUdNQWJ3QnRBaEJjbCtQZjMrVTRwazEzblZEOW53UVFNQWtHQlNzT0F3SWFCUUF3RFFZSktvWklodmNOQVFFQkJRQUVnWUJhSzNFbE9zdGJIOFdvb3NlREFCZitKZ1wvMTI5SmNJYXdtN2M2VnhuN1phc05iQXEzdEF0OFB0eSt1UUNnc3NYcVprTEE3a3oyR3pNb2xOdHY5d1ltdTlVandhcjFQSFlTK0JcL29Hbm96NTkxd2phZ1hXUnowbk1vNXkzTzFLelgwZDhDUkhBVmE4OFNyVjFhNUpJaVJldjNvU3RJcXd2NXh1WmxkYWc2VHI4dz09In0="); + $paymentOne = new AnetAPI\PaymentType(); + $paymentOne->setOpaqueData($op); + + //create a transaction + $transactionRequestType = new AnetAPI\TransactionRequestType(); + $transactionRequestType->setTransactionType( "authCaptureTransaction"); + $transactionRequestType->setAmount(151); + $transactionRequestType->setPayment($paymentOne); + + $request = new AnetAPI\CreateTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId( $refId); + $request->setTransactionRequest( $transactionRequestType); + + $controller = new AnetController\CreateTransactionController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if ($response != null) + { + if($response->getMessages()->getResultCode() == "Ok") + { + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) + { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + echo " AUTH CODE : " . $tresponse->getAuthCode() . "\n"; + echo " TRANS ID : " . $tresponse->getTransId() . "\n"; + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } + else + { + echo "Transaction Failed \n"; + if($tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + } + else + { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + if($tresponse != null && $tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + else + { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } + } + else + { + echo "No response returned \n"; + } + + return $response; +} + +if(!defined('DONT_RUN_SAMPLES')) + createAnAndroidPayTransaction(); +?> diff --git a/MobileInAppTransactions/create-an-apple-pay-transaction.php b/MobileInAppTransactions/create-an-apple-pay-transaction.php new file mode 100644 index 0000000..4a8006a --- /dev/null +++ b/MobileInAppTransactions/create-an-apple-pay-transaction.php @@ -0,0 +1,91 @@ +setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); + + $op = new AnetAPI\OpaqueDataType(); + $op->setDataDescriptor("COMMON.APPLE.INAPP.PAYMENT"); + $op->setDataValue("eyJkYXRhIjoiQkRQTldTdE1tR2V3UVVXR2c0bzdFXC9qKzFjcTFUNzhxeVU4NGI2N2l0amNZSTh3UFlBT2hzaGpoWlBycWRVcjRYd1BNYmo0emNHTWR5KysxSDJWa1BPWStCT01GMjV1YjE5Y1g0bkN2a1hVVU9UakRsbEIxVGdTcjhKSFp4Z3A5ckNnc1NVZ2JCZ0tmNjBYS3V0WGY2YWpcL284WkliS25yS1E4U2gwb3VMQUtsb1VNbit2UHU0K0E3V0tycXJhdXo5SnZPUXA2dmhJcStIS2pVY1VOQ0lUUHlGaG1PRXRxK0grdzB2UmExQ0U2V2hGQk5uQ0hxenpXS2NrQlwvMG5xTFpSVFliRjBwK3Z5QmlWYVdIZWdoRVJmSHhSdGJ6cGVjelJQUHVGc2ZwSFZzNDhvUExDXC9rXC8xTU5kNDdrelwvcEhEY1JcL0R5NmFVTStsTmZvaWx5XC9RSk4rdFMzbTBIZk90SVNBUHFPbVhlbXZyNnhKQ2pDWmxDdXcwQzltWHpcL29iSHBvZnVJRVM4cjljcUdHc1VBUERwdzdnNjQybTRQendLRitIQnVZVW5lV0RCTlNEMnU2amJBRzMiLCJ2ZXJzaW9uIjoiRUNfdjEiLCJoZWFkZXIiOnsiYXBwbGljYXRpb25EYXRhIjoiOTRlZTA1OTMzNWU1ODdlNTAxY2M0YmY5MDYxM2UwODE0ZjAwYTdiMDhiYzdjNjQ4ZmQ4NjVhMmFmNmEyMmNjMiIsInRyYW5zYWN0aW9uSWQiOiJjMWNhZjVhZTcyZjAwMzlhODJiYWQ5MmI4MjgzNjM3MzRmODViZjJmOWNhZGYxOTNkMWJhZDlkZGNiNjBhNzk1IiwiZXBoZW1lcmFsUHVibGljS2V5IjoiTUlJQlN6Q0NBUU1HQnlxR1NNNDlBZ0V3Z2ZjQ0FRRXdMQVlIS29aSXpqMEJBUUloQVBcL1wvXC9cLzhBQUFBQkFBQUFBQUFBQUFBQUFBQUFcL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL01Gc0VJUFwvXC9cL1wvOEFBQUFCQUFBQUFBQUFBQUFBQUFBQVwvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cLzhCQ0JheGpYWXFqcVQ1N1BydlZWMm1JYThaUjBHc014VHNQWTd6ancrSjlKZ1N3TVZBTVNkTmdpRzV3U1RhbVo0NFJPZEpyZUJuMzZRQkVFRWF4ZlI4dUVzUWtmNHZPYmxZNlJBOG5jRGZZRXQ2ek9nOUtFNVJkaVl3cFpQNDBMaVwvaHBcL200N242MHA4RDU0V0s4NHpWMnN4WHM3THRrQm9ONzlSOVFJaEFQXC9cL1wvXC84QUFBQUFcL1wvXC9cL1wvXC9cL1wvXC9cLys4NXZxdHB4ZWVoUE81eXNMOFl5VlJBZ0VCQTBJQUJHbStnc2wwUFpGVFwva0RkVVNreHd5Zm84SnB3VFFRekJtOWxKSm5tVGw0REdVdkFENEdzZUdqXC9wc2hCWjBLM1RldXFEdFwvdERMYkUrOFwvbTB5Q21veHc9IiwicHVibGljS2V5SGFzaCI6IlwvYmI5Q05DMzZ1QmhlSEZQYm1vaEI3T28xT3NYMkora0pxdjQ4ek9WVmlRPSJ9LCJzaWduYXR1cmUiOiJNSUlEUWdZSktvWklodmNOQVFjQ29JSURNekNDQXk4Q0FRRXhDekFKQmdVckRnTUNHZ1VBTUFzR0NTcUdTSWIzRFFFSEFhQ0NBaXN3Z2dJbk1JSUJsS0FEQWdFQ0FoQmNsK1BmMytVNHBrMTNuVkQ5bndRUU1Ba0dCU3NPQXdJZEJRQXdKekVsTUNNR0ExVUVBeDRjQUdNQWFBQnRBR0VBYVFCQUFIWUFhUUJ6QUdFQUxnQmpBRzhBYlRBZUZ3MHhOREF4TURFd05qQXdNREJhRncweU5EQXhNREV3TmpBd01EQmFNQ2N4SlRBakJnTlZCQU1lSEFCakFHZ0FiUUJoQUdrQVFBQjJBR2tBY3dCaEFDNEFZd0J2QUcwd2daOHdEUVlKS29aSWh2Y05BUUVCQlFBRGdZMEFNSUdKQW9HQkFOQzgra2d0Z212V0YxT3pqZ0ROcmpURUJSdW9cLzVNS3ZsTTE0NnBBZjdHeDQxYmxFOXc0ZklYSkFEN0ZmTzdRS2pJWFlOdDM5ckx5eTd4RHdiXC81SWtaTTYwVFoyaUkxcGo1NVVjOGZkNGZ6T3BrM2Z0WmFRR1hOTFlwdEcxZDlWN0lTODJPdXA5TU1vMUJQVnJYVFBITmNzTTk5RVBVblBxZGJlR2M4N20wckFnTUJBQUdqWERCYU1GZ0dBMVVkQVFSUk1FK0FFSFpXUHJXdEpkN1laNDMxaENnN1lGU2hLVEFuTVNVd0l3WURWUVFESGh3QVl3Qm9BRzBBWVFCcEFFQUFkZ0JwQUhNQVlRQXVBR01BYndCdGdoQmNsK1BmMytVNHBrMTNuVkQ5bndRUU1Ba0dCU3NPQXdJZEJRQURnWUVBYlVLWUNrdUlLUzlRUTJtRmNNWVJFSW0ybCtYZzhcL0pYditHQlZRSmtPS29zY1k0aU5ERkFcL2JRbG9nZjlMTFU4NFRId05SbnN2VjNQcnY3UlRZODFncTBkdEM4elljQWFBa0NISUkzeXFNbko0QU91NkVPVzlrSmsyMzJnU0U3V2xDdEhiZkxTS2Z1U2dRWDhLWFFZdVpMazJScjYzTjhBcFhzWHdCTDNjSjB4Z2VBd2dkMENBUUV3T3pBbk1TVXdJd1lEVlFRREhod0FZd0JvQUcwQVlRQnBBRUFBZGdCcEFITUFZUUF1QUdNQWJ3QnRBaEJjbCtQZjMrVTRwazEzblZEOW53UVFNQWtHQlNzT0F3SWFCUUF3RFFZSktvWklodmNOQVFFQkJRQUVnWUJhSzNFbE9zdGJIOFdvb3NlREFCZitKZ1wvMTI5SmNJYXdtN2M2VnhuN1phc05iQXEzdEF0OFB0eSt1UUNnc3NYcVprTEE3a3oyR3pNb2xOdHY5d1ltdTlVandhcjFQSFlTK0JcL29Hbm96NTkxd2phZ1hXUnowbk1vNXkzTzFLelgwZDhDUkhBVmE4OFNyVjFhNUpJaVJldjNvU3RJcXd2NXh1WmxkYWc2VHI4dz09In0="); + $paymentOne = new AnetAPI\PaymentType(); + $paymentOne->setOpaqueData($op); + + //create a transaction + $transactionRequestType = new AnetAPI\TransactionRequestType(); + $transactionRequestType->setTransactionType( "authCaptureTransaction"); + $transactionRequestType->setAmount(151); + $transactionRequestType->setPayment($paymentOne); + + $request = new AnetAPI\CreateTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId( $refId); + $request->setTransactionRequest( $transactionRequestType); + + $controller = new AnetController\CreateTransactionController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + + if ($response != null) + { + if($response->getMessages()->getResultCode() == "Ok") + { + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) + { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + echo " AUTH CODE : " . $tresponse->getAuthCode() . "\n"; + echo " TRANS ID : " . $tresponse->getTransId() . "\n"; + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } + else + { + echo "Transaction Failed \n"; + if($tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + } + else + { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + if($tresponse != null && $tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + else + { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } + } + else + { + echo "No response returned \n"; + } + + return $response; +} + +if(!defined('DONT_RUN_SAMPLES')) + createAnApplePayTransaction(); +?> diff --git a/MobileInAppTransactions/create-google-pay-transaction.php b/MobileInAppTransactions/create-google-pay-transaction.php new file mode 100644 index 0000000..75ecc36 --- /dev/null +++ b/MobileInAppTransactions/create-google-pay-transaction.php @@ -0,0 +1,113 @@ +setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + $refId = 'ref' . time(); + + $opaqueData = new AnetAPI\OpaqueDataType(); + $opaqueData->setDataDescriptor("COMMON.GOOGLE.INAPP.PAYMENT"); + $opaqueData->setDataValue("1234567890ABCDEF1111AAAA2222BBBB3333CCCC4444DDDD5555EEEE6666FFFF7777888899990000"); + $paymentType = new AnetAPI\PaymentType(); + $paymentType->setOpaqueData($opaqueData); + + $lineItem = new AnetAPI\LineItemType(); + $lineItem->setItemId("1"); + $lineItem->setName("vase"); + $lineItem->setDescription("Cannes logo"); + $lineItem->setQuantity(18); + $lineItem->setUnitPrice(45.00); + + $lineItemsArray = array(); + $lineItemsArray[0] = $lineItem; + + $tax = new AnetAPI\ExtendedAmountType(); + $tax->setAmount(5.00); + $tax->setName("level2 tax name"); + $tax->setDescription("level2 tax"); + + $userField = new AnetAPI\UserFieldType(); + $userFields = array(); + + $userField->setName("UserDefinedFieldName1"); + $userField->setValue("UserDefinedFieldValue1"); + $userFields[0] = $userField; + + $userField->setName("UserDefinedFieldName2"); + $userField->setValue("UserDefinedFieldValue2"); + $userFields[1] = $userField; + + $transactionRequestType = new AnetAPI\TransactionRequestType(); + $transactionRequestType->setTransactionType("authCaptureTransaction"); + $transactionRequestType->setAmount(151); + $transactionRequestType->setPayment($paymentType); + + $request = new AnetAPI\CreateTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId($refId); + $request->setTransactionRequest( $transactionRequestType); + + $controller = new AnetController\CreateTransactionController($request); + $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); + + + if ($response != null) + { + if($response->getMessages()->getResultCode() == "Ok") + { + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) + { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + echo " AUTH CODE : " . $tresponse->getAuthCode() . "\n"; + echo " TRANS ID : " . $tresponse->getTransId() . "\n"; + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } + else + { + echo "Transaction Failed \n"; + if($tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + } + else + { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + if($tresponse != null && $tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + else + { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } + } + else + { + echo "No response returned \n"; + } + + return $response; +} + +if(!defined('DONT_RUN_SAMPLES')) + createGooglePayTransaction(); +?> 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 new file mode 100644 index 0000000..5252c27 --- /dev/null +++ b/PayPalExpressCheckout/authorization-and-capture.php @@ -0,0 +1,93 @@ +setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); + + $payPalType=new AnetAPI\PayPalType(); + $payPalType->setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); + $payPalType->setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); + + $paymentOne = new AnetAPI\PaymentType(); + $paymentOne->setPayPal($payPalType); + + // Create an authorize and capture transaction + $transactionRequestType = new AnetAPI\TransactionRequestType(); + $transactionRequestType->setTransactionType( "authCaptureTransaction"); + $transactionRequestType->setPayment($paymentOne); + $transactionRequestType->setAmount($amount); + + $request = new AnetAPI\CreateTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setTransactionRequest( $transactionRequestType); + $controller = new AnetController\CreateTransactionController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if ($response != null) + { + if($response->getMessages()->getResultCode() == "Ok") + { + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) + { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + //Valid response codes: 1=Approved, 2=Declined, 3=Error, 5=Need Payer Consent + echo "Secure acceptance URL: ".$tresponse->getSecureAcceptance()->getSecureAcceptanceUrl()."\n"; + echo "Transaction ID: ".$tresponse->getTransId()."\n"; + + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } + else + { + echo "Transaction Failed \n"; + if($tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + } + else + { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + + + if($tresponse != null && $tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + else + { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } + } + else + { + echo "No response returned \n"; + } + + return $response; + } + + if(!defined('DONT_RUN_SAMPLES')) + payPalAuthorizeCapture(12.322); +?> 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 new file mode 100644 index 0000000..32fd18e --- /dev/null +++ b/PayPalExpressCheckout/authorization-only.php @@ -0,0 +1,93 @@ +setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); + + // Create the payment data for a paypal account + $payPalType = new AnetAPI\PayPalType(); + $payPalType->setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); + $payPalType->setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); + $paymentOne = new AnetAPI\PaymentType(); + $paymentOne->setPayPal($payPalType); + + //create a auth-only transaction + $transactionRequestType = new AnetAPI\TransactionRequestType(); + $transactionRequestType->setTransactionType( "authOnlyTransaction"); + $transactionRequestType->setAmount($amount); + $transactionRequestType->setPayment($paymentOne); + + $request = new AnetAPI\CreateTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId( $refId); + $request->setTransactionRequest( $transactionRequestType); + + $controller = new AnetController\CreateTransactionController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if ($response != null) + { + if($response->getMessages()->getResultCode() == "Ok") + { + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) + { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + echo "Received response code: ".$tresponse->getResponseCode()."\n"; + //Valid response codes: 1=Approved, 2=Declined, 3=Error, 5=Need Payer Consent\n"; + echo "Secure acceptance URL: ".$tresponse->getSecureAcceptance()->getSecureAcceptanceUrl()."\n"; + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } + else + { + echo "Transaction Failed \n"; + if($tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + } + else + { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + if($tresponse != null && $tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + else + { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } + } + else + { + echo "No response returned \n"; + } + + return $response; +} + +if(!defined('DONT_RUN_SAMPLES')) + payPalAuthorizeOnly(23.34); + +?> diff --git a/PayPalExpressCheckout/credit.php b/PayPalExpressCheckout/credit.php new file mode 100644 index 0000000..498eba8 --- /dev/null +++ b/PayPalExpressCheckout/credit.php @@ -0,0 +1,98 @@ +setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); + + //use transaction of already settled paypal checkout transaction + $refTransId = $transactionId; + + // Create the payment data for a paypal account + $payPalType = new AnetAPI\PayPalType(); + $payPalType->setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); + $payPalType->setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); + $paymentOne = new AnetAPI\PaymentType(); + $paymentOne->setPayPal($payPalType); + + //create a refund transaction + $transactionRequestType = new AnetAPI\TransactionRequestType(); + $transactionRequestType->setTransactionType( "refundTransaction"); + $transactionRequestType->setAmount(181); + $transactionRequestType->setPayment($paymentOne); + ///refTransId of successfully settled transaction + $transactionRequestType->setRefTransId($refTransId); + + $request = new AnetAPI\CreateTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId( $refId); + $request->setTransactionRequest( $transactionRequestType); + + $controller = new AnetController\CreateTransactionController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if ($response != null) + { + if($response->getMessages()->getResultCode() == "Ok") + { + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) + { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + echo "Credit SUCCESS AUTH CODE : " . $tresponse->getAuthCode() . "\n"; + echo "Credit TRANS ID : " . $tresponse->getTransId() . "\n"; + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } + else + { + echo "Transaction Failed \n"; + if($tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + } + else + { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + if($tresponse != null && $tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + else + { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } + } + else + { + echo "No response returned \n"; + } + + return $response; +} + +if(!defined('DONT_RUN_SAMPLES')){ + //use transaction id of already settled transaction + payPalCredit("2241762126"); +} +?> diff --git a/PayPalExpressCheckout/get-details.php b/PayPalExpressCheckout/get-details.php new file mode 100644 index 0000000..4a81b70 --- /dev/null +++ b/PayPalExpressCheckout/get-details.php @@ -0,0 +1,116 @@ +setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); + + //create a transaction of type get details + $transactionRequestType = new AnetAPI\TransactionRequestType(); + $transactionRequestType->setTransactionType( "getDetailsTransaction"); + + //replace following transaction ID with your transaction ID for which the details are required + $transactionRequestType->setRefTransId($transactionId); + + // Create the payment data for a paypal account + $payPalType = new AnetAPI\PayPalType(); + $payPalType->setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); + $payPalType->setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); + $paymentOne = new AnetAPI\PaymentType(); + $paymentOne->setPayPal($payPalType); + + $transactionRequestType->setPayment($paymentOne); + + //create a transaction request + $request = new AnetAPI\CreateTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId( $refId); + $request->setTransactionRequest( $transactionRequestType); + + $controller = new AnetController\CreateTransactionController($request); + + //execute the api call to get transaction details + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if ($response != null) + { + if($response->getMessages()->getResultCode() == "Ok") + { + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) + { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + echo "Transaction Response...\n"; + echo "Received response code: ".$tresponse->getResponseCode()."\n"; + echo "Transaction ID: ".$tresponse->getTransId()."\n"; + //Valid response codes: 1=Approved, 2=Declined, 3=Error, 5=Need Payer Consent + if(null != $tresponse->getSecureAcceptance()) + { + echo "Payer ID : " . $tresponse->getSecureAcceptance()->getPayerID() . "\n"; + } + + //parse the shipping information from response + $shipping_response = $tresponse->getShipTo(); + if(null != $shipping_response) + { + echo "Shipping address : " . $shipping_response->getAddress() . ", " . $shipping_response->getCity() + . ", " . $shipping_response->getState() . ", " . $shipping_response->getCountry() . "\n"; + } + + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } + else + { + echo "Transaction Failed \n"; + if($tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + } + else + { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + if($tresponse != null && $tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + else + { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } + } + else + { + echo "No response returned \n"; + } + + return $response; + } + +if(!defined('DONT_RUN_SAMPLES')) + payPalGetDetails("60007107304"); + +?> \ No newline at end of file diff --git a/PayPalExpressCheckout/prior-authorization-capture.php b/PayPalExpressCheckout/prior-authorization-capture.php new file mode 100644 index 0000000..432d0fe --- /dev/null +++ b/PayPalExpressCheckout/prior-authorization-capture.php @@ -0,0 +1,93 @@ +setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); + + $payPalType = new AnetAPI\PayPalType(); + $payPalType->setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); + $payPalType->setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); + + $paymentType = new AnetAPI\PaymentType(); + $paymentType->setPayPal($payPalType); + + $transactionRequest = new AnetAPI\TransactionRequestType(); + $transactionRequest->setTransactionType("priorAuthCaptureTransaction"); + $transactionRequest->setPayment($paymentType); + $transactionRequest->setAmount(floatval(19.45)); + $transactionRequest->setRefTransId($transactionId); + + $request = new AnetAPI\CreateTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId( $refId); + $request->setTransactionRequest($transactionRequest); + + $controller = new AnetController\CreateTransactionController($request); + + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if ($response != null) + { + if($response->getMessages()->getResultCode() == "Ok") + { + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) + { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + echo "Prior Authorization capture AUTH CODE : " . $tresponse->getAuthCode() . "\n"; + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } + else + { + echo "Transaction Failed \n"; + if($tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + } + else + { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + if($tresponse != null && $tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + else + { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } + } + else + { + echo "No response returned \n"; + } + + return $response; + } + + if(!defined('DONT_RUN_SAMPLES')) + { + payPalPriorAuthorizationCapture("2249863278"); + } +?> \ No newline at end of file diff --git a/PayPalExpressCheckout/void.php b/PayPalExpressCheckout/void.php new file mode 100644 index 0000000..bb6e242 --- /dev/null +++ b/PayPalExpressCheckout/void.php @@ -0,0 +1,91 @@ +setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); + + $payPalType = new AnetAPI\PayPalType(); + $payPalType->setSuccessUrl(""); + $payPalType->setCancelUrl(""); + + $paymentType = new AnetAPI\PaymentType(); + $paymentType->setPayPal($payPalType); + + $transactionRequest = new AnetAPI\TransactionRequestType(); + $transactionRequest->setTransactionType("voidTransaction"); + $transactionRequest->setPayment($paymentType); + $transactionRequest->setRefTransId($transactionId); + + $request = new AnetAPI\CreateTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId( $refId); + $request->setTransactionRequest($transactionRequest); + + $controller = new AnetController\CreateTransactionController($request); + + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if ($response != null) + { + if($response->getMessages()->getResultCode() == "Ok") + { + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) + { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + echo "Void transaction SUCCESS TRANS ID : " . $tresponse->getTransId() . "\n"; + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } + else + { + echo "Transaction Failed \n"; + if($tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + } + else + { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + if($tresponse != null && $tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + else + { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } + } + else + { + echo "No response returned \n"; + } + + return $response; + } + + if(!defined('DONT_RUN_SAMPLES')) + payPalVoid("2241706281"); + + ?> \ No newline at end of file diff --git a/PaymentTransactions/authorize-credit-card.php b/PaymentTransactions/authorize-credit-card.php index 90c55bb..10c8198 100644 --- a/PaymentTransactions/authorize-credit-card.php +++ b/PaymentTransactions/authorize-credit-card.php @@ -1,56 +1,133 @@ setName("5KP3u95bQpv"); - $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); - $refId = 'ref' . time(); - - // Create the payment data for a credit card - $creditCard = new AnetAPI\CreditCardType(); - $creditCard->setCardNumber( "4111111111111111" ); - $creditCard->setExpirationDate( "2038-12"); - $paymentOne = new AnetAPI\PaymentType(); - $paymentOne->setCreditCard($creditCard); - - //create a transaction - $transactionRequestType = new AnetAPI\TransactionRequestType(); - $transactionRequestType->setTransactionType( "authOnlyTransaction"); - $transactionRequestType->setAmount(151); - $transactionRequestType->setPayment($paymentOne); - - $request = new AnetAPI\CreateTransactionRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setRefId( $refId); - $request->setTransactionRequest( $transactionRequestType); - - $controller = new AnetController\CreateTransactionController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - - if ($response != null) - { - $tresponse = $response->getTransactionResponse(); - - if (($tresponse != null) && ($tresponse->getResponseCode()=="1") ) - { - echo " AUTH CODE : " . $tresponse->getAuthCode() . "\n"; - echo " TRANS ID : " . $tresponse->getTransId() . "\n"; - } - else - { - echo "ERROR : " . $tresponse->getResponseCode() . "\n"; - } +function authorizeCreditCard($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); - } - else - { - echo "No response returned"; - } + // Set the transaction's refId + $refId = 'ref' . time(); + + // Create the payment data for a credit card + $creditCard = new AnetAPI\CreditCardType(); + $creditCard->setCardNumber("4111111111111111"); + $creditCard->setExpirationDate("2038-12"); + $creditCard->setCardCode("123"); + + // Add the payment data to a paymentType object + $paymentOne = new AnetAPI\PaymentType(); + $paymentOne->setCreditCard($creditCard); + + // Create order information + $order = new AnetAPI\OrderType(); + $order->setInvoiceNumber("10101"); + $order->setDescription("Golf Shirts"); + + // Set the customer's Bill To address + $customerAddress = new AnetAPI\CustomerAddressType(); + $customerAddress->setFirstName("Ellen"); + $customerAddress->setLastName("Johnson"); + $customerAddress->setCompany("Souveniropolis"); + $customerAddress->setAddress("14 Main Street"); + $customerAddress->setCity("Pecan Springs"); + $customerAddress->setState("TX"); + $customerAddress->setZip("44628"); + $customerAddress->setCountry("USA"); + + // Set the customer's identifying information + $customerData = new AnetAPI\CustomerDataType(); + $customerData->setType("individual"); + $customerData->setId("99999456654"); + $customerData->setEmail("EllenJohnson@example.com"); + + // Add values for transaction settings + $duplicateWindowSetting = new AnetAPI\SettingType(); + $duplicateWindowSetting->setSettingName("duplicateWindow"); + $duplicateWindowSetting->setSettingValue("60"); + + // Add some merchant defined fields. These fields won't be stored with the transaction, + // but will be echoed back in the response. + $merchantDefinedField1 = new AnetAPI\UserFieldType(); + $merchantDefinedField1->setName("customerLoyaltyNum"); + $merchantDefinedField1->setValue("1128836273"); + + $merchantDefinedField2 = new AnetAPI\UserFieldType(); + $merchantDefinedField2->setName("favoriteColor"); + $merchantDefinedField2->setValue("blue"); + + // Create a TransactionRequestType object and add the previous objects to it + $transactionRequestType = new AnetAPI\TransactionRequestType(); + $transactionRequestType->setTransactionType("authOnlyTransaction"); + $transactionRequestType->setAmount($amount); + $transactionRequestType->setOrder($order); + $transactionRequestType->setPayment($paymentOne); + $transactionRequestType->setBillTo($customerAddress); + $transactionRequestType->setCustomer($customerData); + $transactionRequestType->addToTransactionSettings($duplicateWindowSetting); + $transactionRequestType->addToUserFields($merchantDefinedField1); + $transactionRequestType->addToUserFields($merchantDefinedField2); + + // Assemble the complete transaction request + $request = new AnetAPI\CreateTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId($refId); + $request->setTransactionRequest($transactionRequestType); + + // Create the controller and get the response + $controller = new AnetController\CreateTransactionController($request); + $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); + + + if ($response != null) { + // Check to see if the API request was successfully received and acted upon + if ($response->getMessages()->getResultCode() == "Ok") { + // Since the API request was successful, look for a transaction response + // and parse it to display the results of authorizing the card + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) { + echo " Successfully created transaction with Transaction ID: " . $tresponse->getTransId() . "\n"; + echo " Transaction Response Code: " . $tresponse->getResponseCode() . "\n"; + echo " Message Code: " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Auth Code: " . $tresponse->getAuthCode() . "\n"; + echo " Description: " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } else { + echo "Transaction Failed \n"; + if ($tresponse->getErrors() != null) { + echo " Error Code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + // Or, print errors if the API request wasn't successful + } else { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getErrors() != null) { + echo " Error Code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } else { + echo " Error Code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error Message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } + } else { + echo "No response returned \n"; + } + + return $response; +} +if (!defined('DONT_RUN_SAMPLES')) { + authorizeCreditCard("2.23"); +} ?> \ 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 1e00a81..8879a05 100644 --- a/PaymentTransactions/capture-funds-authorized-through-another-channel.php +++ b/PaymentTransactions/capture-funds-authorized-through-another-channel.php @@ -1,55 +1,91 @@ setName("556KThWQ6vf2"); -$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); -$refId = "123456"; +define("AUTHORIZENET_LOG_FILE", "phplog"); -$creditCard = new AnetAPI\CreditCardType(); -$creditCard->setCardNumber( "4111111111111111"); -$creditCard->setExpirationDate( "2038-12"); +function captureFundsAuthorizedThroughAnotherChannel($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(); -$paymentOne = new AnetAPI\PaymentType(); -$paymentOne->setCreditCard($creditCard); + $creditCard = new AnetAPI\CreditCardType(); + $creditCard->setCardNumber("4111111111111111"); + $creditCard->setExpirationDate("2038-12"); -$transactionRequestType = new AnetAPI\TransactionRequestType(); -$transactionRequestType->setTransactionType("captureOnlyTransaction"); -$transactionRequestType->setAmount(5.00); -$transactionRequestType->setPayment($paymentOne); + $paymentOne = new AnetAPI\PaymentType(); + $paymentOne->setCreditCard($creditCard); -//Auth code of the previously authorized amount -$transactionRequestType->setAuthCode("ROHNFQ"); + $transactionRequestType = new AnetAPI\TransactionRequestType(); + $transactionRequestType->setTransactionType("captureOnlyTransaction"); + $transactionRequestType->setAmount($amount); + $transactionRequestType->setPayment($paymentOne); + //Auth code of the previously authorized amount + $transactionRequestType->setAuthCode("ROHNFQ"); -$request = new AnetAPI\CreateTransactionRequest(); -$request->setMerchantAuthentication($merchantAuthentication); -$request->setTransactionRequest( $transactionRequestType); + $request = new AnetAPI\CreateTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setTransactionRequest( $transactionRequestType); -$controller = new AnetController\CreateTransactionController($request); -$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + $controller = new AnetController\CreateTransactionController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); -if ($response != null) -{ - $tresponse = $response->getTransactionResponse(); - if (($tresponse != null) && ($tresponse->getResponseCode()=="1") ) + if ($response != null) { - echo "Successful." . "\n"; - echo "Capture funds authorized through another channel TRANS ID : " . $tresponse->getTransId() . "\n"; + if($response->getMessages()->getResultCode() == "Ok") + { + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) + { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + echo "Successful." . "\n"; + echo "Capture funds authorized through another channel TRANS ID : " . $tresponse->getTransId() . " Amount : $amount \n"; + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } + else + { + echo "Transaction Failed \n"; + if($tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + } + else + { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + if($tresponse != null && $tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + else + { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } } else { - echo "Capture funds authorized through another channel ERROR: Invalid response\n"; - echo "Response Code: " . $response->getMessages()->getMessage()[0]->getCode() . " Response Text: " .$response->getMessages()->getMessage()[0]->getText() . "\n"; + echo "No response returned \n"; } + + return $response; } -else -{ - echo "Capture funds authorized through another channel NULL Response Error\n"; -} +if(!defined('DONT_RUN_SAMPLES')) + captureFundsAuthorizedThroughAnotherChannel((rand(1, 999)/12*12)); ?> diff --git a/PaymentTransactions/capture-previously-authorized-amount.php b/PaymentTransactions/capture-previously-authorized-amount.php index ec6db61..de19ffd 100644 --- a/PaymentTransactions/capture-previously-authorized-amount.php +++ b/PaymentTransactions/capture-previously-authorized-amount.php @@ -1,91 +1,83 @@ setName("556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); - $refId = "123456"; + function capturePreviouslyAuthorizedAmount($transactionid) +{ + /* 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"); + // Now capture the previously authorized amount + echo "Capturing the Authorization with transaction ID : " . $transactionid . "\n"; + $transactionRequestType = new AnetAPI\TransactionRequestType(); + $transactionRequestType->setTransactionType("priorAuthCaptureTransaction"); + $transactionRequestType->setRefTransId($transactionid); - //$creditCard->setCardCode("999"); - $paymentOne = new AnetAPI\PaymentType(); - $paymentOne->setCreditCard($creditCard); + + $request = new AnetAPI\CreateTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setTransactionRequest( $transactionRequestType); - // First Authorize the amount - $transactionRequestType = new AnetAPI\TransactionRequestType(); - $transactionRequestType->setTransactionType("priorAuthCaptureTransaction"); - $transactionRequestType->setAmount(5.00); - $transactionRequestType->setPayment($paymentOne); - - - $request = new AnetAPI\CreateTransactionRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setTransactionRequest( $transactionRequestType); - - $controller = new AnetController\CreateTransactionController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - - $authTransId = "0"; - - if ($response != null) - { - $tresponse = $response->getTransactionResponse(); - $authTransId = $tresponse->getTransId(); - - if (($tresponse != null) && ($tresponse->getResponseCode()=="1") ) + $controller = new AnetController\CreateTransactionController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if ($response != null) { - echo "AUTH CODE : " . $tresponse->getAuthCode() . "\n"; - echo "TRANS ID : " . $authTransId . "\n"; + if($response->getMessages()->getResultCode() == "Ok") + { + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) + { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + echo "Successful." . "\n"; + echo "Capture Previously Authorized Amount, Trans ID : " . $tresponse->getRefTransId() . "\n"; + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } + else + { + echo "Transaction Failed \n"; + if($tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + } + else + { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + if($tresponse != null && $tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + else + { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } } else { - echo "Authorization : Invalid response\n"; + echo "No response returned \n"; } - } - else - { - echo "Authorization NULL Response Error\n"; - } - - // Now capture the previously authorized amount - echo "Capturing the Authorization with transaction ID : " . $authTransId . "\n"; - $transactionRequestType = new AnetAPI\TransactionRequestType(); - $transactionRequestType->setTransactionType("priorAuthCaptureTransaction"); - $transactionRequestType->setAmount(5.00); - $transactionRequestType->setRefTransId($authTransId); - - $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) - { - $tresponse = $response->getTransactionResponse(); - if (($tresponse != null) && ($tresponse->getResponseCode()=="1") ) - { - echo "Successful." . "\n"; - echo "Capture Previously Authorized Amount TRANS ID : " . $tresponse->getTransId() . "\n"; - } - else - { - echo " Capture Previously Authorized Amount: Invalid response\n"; - } - } - else - { - echo "Capture Previously Authorized Amount NULL Response Error\n"; + return $response; } + if(!defined('DONT_RUN_SAMPLES')) + capturePreviouslyAuthorizedAmount(60007076002); ?> diff --git a/PaymentTransactions/charge-credit-card.php b/PaymentTransactions/charge-credit-card.php index 99f4757..c05df53 100644 --- a/PaymentTransactions/charge-credit-card.php +++ b/PaymentTransactions/charge-credit-card.php @@ -1,109 +1,132 @@ setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); - // Common setup for API credentials - $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); - $merchantAuthentication->setName("556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); - $refId = 'ref' . time(); - - // Create the payment data for a credit card - $creditCard = new AnetAPI\CreditCardType(); - $creditCard->setCardNumber( "4111111111111111" ); - $creditCard->setExpirationDate( "2038-12"); - $paymentOne = new AnetAPI\PaymentType(); - $paymentOne->setCreditCard($creditCard); - - // Order info - $order = new AnetAPI\OrderType(); - $order->setInvoiceNumber("101"); - $order->setDescription("Golf Shirts"); - - // Line Item Info - $lineitem = new AnetAPI\LineItemType(); - $lineitem->setItemId("Shirts"); - $lineitem->setName("item1"); - $lineitem->setDescription("golf shirt"); - $lineitem->setQuantity("1"); - $lineitem->setUnitPrice(20.95); - $lineitem->setTaxable(false); - - // Tax info - $tax = new AnetAPI\ExtendedAmountType(); - $tax->setName("level 2 tax name"); - $tax->setAmount(4.50); - $tax->setDescription("level 2 tax"); - - // Customer info - $customer = new AnetAPI\CustomerDataType(); - $customer->setId("15"); - $customer->setEmail("foo@example.com"); - - // PO Number - $ponumber = "15"; - //Ship To Info - $shipto = new AnetAPI\NameAndAddressType(); - $shipto->setFirstName("Bayles"); - $shipto->setLastName("China"); - $shipto->setCompany("Thyme for Tea"); - $shipto->setAddress("12 Main Street"); - $shipto->setCity("Pecan Springs"); - $shipto->setState("TX"); - $shipto->setZip("44628"); - $shipto->setCountry("USA"); - - // Bill To - $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 transaction - $transactionRequestType = new AnetAPI\TransactionRequestType(); - $transactionRequestType->setTransactionType( "authCaptureTransaction"); - $transactionRequestType->setAmount(151.51); - $transactionRequestType->setPayment($paymentOne); - $transactionRequestType->setOrder($order); - $transactionRequestType->addToLineItems($lineitem); - $transactionRequestType->setTax($tax); - $transactionRequestType->setPoNumber($ponumber); - $transactionRequestType->setCustomer($customer); - $transactionRequestType->setBillTo($billto); - $transactionRequestType->setShipTo($shipto); - - $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) - { - $tresponse = $response->getTransactionResponse(); - - if (($tresponse != null) && ($tresponse->getResponseCode()=="1") ) - { - echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n"; - echo "Charge Credit Card TRANS ID : " . $tresponse->getTransId() . "\n"; - } - else - { - echo "Charge Credit Card ERROR : Invalid response\n"; - } + // 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); - } - else - { - echo "Charge Credit card Null response returned"; - } -?> + + if ($response != null) { + // Check to see if the API request was successfully received and acted upon + if ($response->getMessages()->getResultCode() == "Ok") { + // Since the API request was successful, look for a transaction response + // and parse it to display the results of authorizing the card + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) { + echo " Successfully created transaction with Transaction ID: " . $tresponse->getTransId() . "\n"; + echo " Transaction Response Code: " . $tresponse->getResponseCode() . "\n"; + echo " Message Code: " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Auth Code: " . $tresponse->getAuthCode() . "\n"; + echo " Description: " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } else { + echo "Transaction Failed \n"; + if ($tresponse->getErrors() != null) { + echo " Error Code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + // Or, print errors if the API request wasn't successful + } else { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getErrors() != null) { + echo " Error Code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } else { + echo " Error Code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error Message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } + } else { + echo "No response returned \n"; + } + + return $response; +} + +if (!defined('DONT_RUN_SAMPLES')) { + chargeCreditCard("2.23"); +} diff --git a/PaymentTransactions/charge-customer-profile.php b/PaymentTransactions/charge-customer-profile.php index 594459e..7482001 100644 --- a/PaymentTransactions/charge-customer-profile.php +++ b/PaymentTransactions/charge-customer-profile.php @@ -1,52 +1,89 @@ setName("5KP3u95bQpv"); - $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); - $refId = 'ref' . time(); - - $profileToCharge = new AnetAPI\CustomerProfilePaymentType(); - $profileToCharge->setCustomerProfileId("36731856"); - $paymentProfile = new AnetAPI\PaymentProfileType(); - $paymentProfile->setPaymentProfileId("33211899"); - $profileToCharge->setPaymentProfile($paymentProfile); - - - $transactionRequestType = new AnetAPI\TransactionRequestType(); - $transactionRequestType->setTransactionType( "authCaptureTransaction"); - $transactionRequestType->setAmount(100.50); - $transactionRequestType->setProfile($profileToCharge); - - $request = new AnetAPI\CreateTransactionRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setRefId( $refId); - $request->setTransactionRequest( $transactionRequestType); - $controller = new AnetController\CreateTransactionController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - if ($response != null) - { - $tresponse = $response->getTransactionResponse(); - if (($tresponse != null) && ($tresponse->getResponseCode()=="1") ) - { - echo "Charge Customer Profile APPROVED :" . "\n"; - echo " Charge Customer Profile AUTH CODE : " . $tresponse->getAuthCode() . "\n"; - echo " Charge Customer Profile TRANS ID : " . $tresponse->getTransId() . "\n"; - } - elseif (($tresponse != null) && ($tresponse->getResponseCode()=="2") ) + +function chargeCustomerProfile($profileid, $paymentprofileid, $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(); + + $profileToCharge = new AnetAPI\CustomerProfilePaymentType(); + $profileToCharge->setCustomerProfileId($profileid); + $paymentProfile = new AnetAPI\PaymentProfileType(); + $paymentProfile->setPaymentProfileId($paymentprofileid); + $profileToCharge->setPaymentProfile($paymentProfile); + + $transactionRequestType = new AnetAPI\TransactionRequestType(); + $transactionRequestType->setTransactionType( "authCaptureTransaction"); + $transactionRequestType->setAmount($amount); + $transactionRequestType->setProfile($profileToCharge); + + $request = new AnetAPI\CreateTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId( $refId); + $request->setTransactionRequest( $transactionRequestType); + $controller = new AnetController\CreateTransactionController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if ($response != null) { - echo "ERROR" . "\n"; + if($response->getMessages()->getResultCode() == "Ok") + { + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) + { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + echo "Charge Customer Profile APPROVED :" . "\n"; + echo " Charge Customer Profile AUTH CODE : " . $tresponse->getAuthCode() . "\n"; + echo " Charge Customer Profile TRANS ID : " . $tresponse->getTransId() . "\n"; + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } + else + { + echo "Transaction Failed \n"; + if($tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + } + else + { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + if($tresponse != null && $tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + else + { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } } - elseif (($tresponse != null) && ($tresponse->getResponseCode()=="4") ) + else { - echo "ERROR: HELD FOR REVIEW:" . "\n"; + echo "No response returned \n"; } + + return $response; } - else - { - echo "no response returned"; - } + + if(!defined('DONT_RUN_SAMPLES')) + chargeCustomerProfile("36731856","32689274",12.23); ?> diff --git a/PaymentTransactions/charge-tokenized-credit-card.php b/PaymentTransactions/charge-tokenized-credit-card.php index 6995709..7b11b1d 100644 --- a/PaymentTransactions/charge-tokenized-credit-card.php +++ b/PaymentTransactions/charge-tokenized-credit-card.php @@ -1,54 +1,94 @@ setName("556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); - $refId = 'ref' . time(); +function chargeTokenizedCreditCard($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"); - //Set the cryptogram - $creditCard->setCryptogram("EjRWeJASNFZ4kBI0VniQEjRWeJA="); - - $paymentOne = new AnetAPI\PaymentType(); - $paymentOne->setCreditCard($creditCard); - - //create a transaction - $transactionRequestType = new AnetAPI\TransactionRequestType(); - $transactionRequestType->setTransactionType("authCaptureTransaction"); - $transactionRequestType->setAmount(151.22); - $transactionRequestType->setPayment($paymentOne); + // Create the payment data for a credit card + $creditCard = new AnetAPI\CreditCardType(); + $creditCard->setCardNumber("4111111111111111"); + $creditCard->setExpirationDate("2038-12"); + // Set the token specific info + $creditCard->setIsPaymentToken(true); + $creditCard->setCryptogram("EjRWeJASNFZ4kBI0VniQEjRWeJA="); + + $paymentOne = new AnetAPI\PaymentType(); + $paymentOne->setCreditCard($creditCard); + + //create a transaction + $transactionRequestType = new AnetAPI\TransactionRequestType(); + $transactionRequestType->setTransactionType("authCaptureTransaction"); + $transactionRequestType->setAmount($amount); + $transactionRequestType->setPayment($paymentOne); - $request = new AnetAPI\CreateTransactionRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setRefId( $refId); - $request->setTransactionRequest( $transactionRequestType); - $controller = new AnetController\CreateTransactionController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - - if ($response != null) - { - $tresponse = $response->getTransactionResponse(); - if (($tresponse != null) && ($tresponse->getResponseCode()=="1") ) + $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) { - echo "Charge Tokenized Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n"; - echo "Charge Tokenized Credit Card TRANS ID : " . $tresponse->getTransId() . "\n"; + if($response->getMessages()->getResultCode() == "Ok") + { + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) + { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + echo "Charge Tokenized Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n"; + echo "Charge Tokenized Credit Card TRANS ID : " . $tresponse->getTransId() . "\n"; + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } + else + { + echo "Transaction Failed \n"; + if($tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + } + else + { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + if($tresponse != null && $tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + else + { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } } else { - echo "Charge Tokenized Credit Card ERROR : Invalid response\n"; + echo "No response returned \n"; } + + return $response; } - else - { - echo "Charge Tokenized Credit Card Null response returned"; - } + if(!defined('DONT_RUN_SAMPLES')) + chargeTokenizedCreditCard(12.23); ?> diff --git a/PaymentTransactions/create-chase-pay-transaction.php b/PaymentTransactions/create-chase-pay-transaction.php new file mode 100644 index 0000000..ccf1b02 --- /dev/null +++ b/PaymentTransactions/create-chase-pay-transaction.php @@ -0,0 +1,98 @@ +setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); + + // Create the payment data for a credit card + $creditCard = new AnetAPI\CreditCardType(); + $creditCard->setCardNumber("4111111111111111"); + $creditCard->setExpirationDate("2038-12"); + $creditCard->setCardCode("999"); + // Set the token specific info + $creditCard->setIsPaymentToken(true); + $creditCard->setCryptogram("EjRWeJASNFZ4kBI0VniQEjRWeJA="); + $creditCard->setTokenRequestorName("CHASE_PAY"); + $creditCard->setTokenRequestorId("12345678901"); + $creditCard->setTokenRequestorEci("07"); + + $paymentOne = new AnetAPI\PaymentType(); + $paymentOne->setCreditCard($creditCard); + + //create a transaction + $transactionRequestType = new AnetAPI\TransactionRequestType(); + $transactionRequestType->setTransactionType("authCaptureTransaction"); + $transactionRequestType->setAmount($amount); + $transactionRequestType->setPayment($paymentOne); + + + $request = new AnetAPI\CreateTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId( $refId); + $request->setTransactionRequest( $transactionRequestType); + $controller = new AnetController\CreateTransactionController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if ($response != null) + { + if($response->getMessages()->getResultCode() == "Ok") + { + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) + { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + echo "Charge Tokenized Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n"; + echo "Charge Tokenized Credit Card TRANS ID : " . $tresponse->getTransId() . "\n"; + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } + else + { + echo "Transaction Failed \n"; + if($tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + } + else + { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + if($tresponse != null && $tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + else + { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } + } + else + { + echo "No response returned \n"; + } + + return $response; + } + if(!defined('DONT_RUN_SAMPLES')) + createChasePayTransaction(12.23); +?> diff --git a/PaymentTransactions/credit-bank-account.php b/PaymentTransactions/credit-bank-account.php index 80305d3..b68f771 100644 --- a/PaymentTransactions/credit-bank-account.php +++ b/PaymentTransactions/credit-bank-account.php @@ -1,60 +1,94 @@ setName("556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); - $refId = 'ref' . time(); - // Create the payment data for a Bank Account - $bankAccount = new AnetAPI\BankAccountType(); - $bankAccount->setRoutingNumber('125000024'); - $bankAccount->setAccountNumber('12345678'); - $bankAccount->setNameOnAccount('John Doe'); - - $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 - - $transactionRequestType = new AnetAPI\TransactionRequestType(); - $transactionRequestType->setTransactionType( "refundTransaction"); - $transactionRequestType->setAmount(250.75); - $transactionRequestType->setPayment($paymentBank); - $transactionRequestType->setOrder($order); - $request = new AnetAPI\CreateTransactionRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setRefId( $refId); - $request->setTransactionRequest( $transactionRequestType); - $controller = new AnetController\CreateTransactionController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - if ($response != null) - { - $tresponse = $response->getTransactionResponse(); - if (($tresponse != null) && ($tresponse->getResponseCode()=="1") ) - { - echo "Credit Bank Account APPROVED :" . "\n"; - echo "Credit Bank Account AUTH CODE : " . $tresponse->getAuthCode() . "\n"; - echo "Credit Bank Account TRANS ID : " . $tresponse->getTransId() . "\n"; - } - elseif (($tresponse != null) && ($tresponse->getResponseCode()=="2") ) - { - echo "Credit Bank Account ERROR : DECLINED" . "\n"; - } - elseif (($tresponse != null) && ($tresponse->getResponseCode()=="4") ) - { - echo "Credit Bank Account ERROR: HELD FOR REVIEW:" . "\n"; + +function creditBankAccount($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(); + + //Generate random bank account number + $randomAccountNumber= rand(100000000,9999999999); + + // Create the payment data for a Bank Account + $bankAccount = new AnetAPI\BankAccountType(); + $bankAccount->setAccountType('checking'); + // see eCheck documentation for proper echeck type to use for each situation + //$bankAccount->setEcheckType('WEB'); + $bankAccount->setRoutingNumber('122000661'); //('122235821'); //('125008547'); + $bankAccount->setAccountNumber($randomAccountNumber); + $bankAccount->setNameOnAccount('John Doe'); + $bankAccount->setBankName('Wells Fargo Bank NA'); + + $paymentBank= new AnetAPI\PaymentType(); + $paymentBank->setBankAccount($bankAccount); + + // Order info + $order = new AnetAPI\OrderType(); + $order->setInvoiceNumber("101"); + $order->setDescription("Golf Shirts"); + + //create a bank credit transaction + + $transactionRequestType = new AnetAPI\TransactionRequestType(); + $transactionRequestType->setTransactionType("refundTransaction"); + $transactionRequestType->setAmount($amount); + $transactionRequestType->setPayment($paymentBank); + $transactionRequestType->setOrder($order); + $request = new AnetAPI\CreateTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId($refId); + $request->setTransactionRequest($transactionRequestType); + $controller = new AnetController\CreateTransactionController($request); + $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if ($response != null) { + if ($response->getMessages()->getResultCode() == "Ok") { + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + echo "Credit Bank Account APPROVED :" . "\n"; + echo "Credit Bank Account AUTH CODE : " . $tresponse->getAuthCode() . "\n"; + echo "Credit Bank Account TRANS ID : " . $tresponse->getTransId() . "\n"; + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } else { + echo "Transaction Failed \n"; + if ($tresponse->getErrors() != null) { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + } else { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + if ($tresponse != null && $tresponse->getErrors() != null) { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } else { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } + } else { + echo "No response returned \n"; } - } - else - { - echo "Credit Bank Account No response returned"; - } -?> + + return $response; +} + +if (!defined('DONT_RUN_SAMPLES')) { + creditBankAccount(5.29); +} + diff --git a/PaymentTransactions/debit-bank-account.php b/PaymentTransactions/debit-bank-account.php index d6930da..6d50388 100644 --- a/PaymentTransactions/debit-bank-account.php +++ b/PaymentTransactions/debit-bank-account.php @@ -1,66 +1,95 @@ -setName("556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); - $refId = 'ref' . time(); +function debitBankAccount($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 Bank Account - $bankAccount = new AnetAPI\BankAccountType(); - //$bankAccount->setAccountType('CHECKING'); - $bankAccount->setEcheckType('WEB'); - $bankAccount->setRoutingNumber('121042882'); - $bankAccount->setAccountNumber('123456789123'); - $bankAccount->setNameOnAccount('Jane Doe'); - $bankAccount->setBankName('Bank of the Earth'); + //Generate random bank account number + $randomAccountNumber= rand(100000000,9999999999); - $paymentBank= new AnetAPI\PaymentType(); - $paymentBank->setBankAccount($bankAccount); + // Create the payment data for a Bank Account + $bankAccount = new AnetAPI\BankAccountType(); + $bankAccount->setAccountType('checking'); + // see eCheck documentation for proper echeck type to use for each situation + $bankAccount->setEcheckType('WEB'); + $bankAccount->setRoutingNumber('122000661'); + $bankAccount->setAccountNumber(rand(10000,999999999999)); - //create a debit card Bank transaction - - $transactionRequestType = new AnetAPI\TransactionRequestType(); - $transactionRequestType->setTransactionType( "authCaptureTransaction"); - $transactionRequestType->setAmount(250.75); - $transactionRequestType->setPayment($paymentBank); + $bankAccount->setNameOnAccount('John Doe'); + $bankAccount->setBankName('Wells Fargo Bank NA'); - $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) - { - $tresponse = $response->getTransactionResponse(); - if (($tresponse != null) && ($tresponse->getResponseCode()=="1") ) - { - echo "Debit Bank Account APPROVED :" . "\n"; - echo " Debit Bank Account AUTH CODE : " . $tresponse->getAuthCode() . "\n"; - echo " Debit Banlk Account TRANS ID : " . $tresponse->getTransId() . "\n"; - } - elseif (($tresponse != null) && ($tresponse->getResponseCode()=="2") ) - { - echo "Debit Bank Account ERROR : DECLINED" . "\n"; - echo "Error : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; - } - elseif (($tresponse != null) && ($tresponse->getResponseCode()=="4") ) - { - echo "Debit Bank Account ERROR: HELD FOR REVIEW:" . "\n"; - } - else - { - echo "Debit Bank Account 3 response returned"; + $paymentBank= new AnetAPI\PaymentType(); + $paymentBank->setBankAccount($bankAccount); + + // Order info + $order = new AnetAPI\OrderType(); + $order->setInvoiceNumber("101"); + $order->setDescription("Golf Shirts"); + + //create a bank debit transaction + + $transactionRequestType = new AnetAPI\TransactionRequestType(); + $transactionRequestType->setTransactionType("authCaptureTransaction"); + $transactionRequestType->setAmount($amount); + $transactionRequestType->setPayment($paymentBank); + $transactionRequestType->setOrder($order); + $request = new AnetAPI\CreateTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId($refId); + $request->setTransactionRequest($transactionRequestType); + $controller = new AnetController\CreateTransactionController($request); + $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if ($response != null) { + if ($response->getMessages()->getResultCode() == "Ok") { + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + echo " Debit Bank Account APPROVED :" . "\n"; + echo " Debit Bank Account AUTH CODE : " . $tresponse->getAuthCode() . "\n"; + echo " Debit Bank Account TRANS ID : " . $tresponse->getTransId() . "\n"; + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } else { + echo "Transaction Failed \n"; + if ($tresponse->getErrors() != null) { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + } else { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + if ($tresponse != null && $tresponse->getErrors() != null) { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } else { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } + } else { + echo "No response returned \n"; } - } - else - { - echo "Debit Bank Account Null response returned"; - } -?> + + return $response; +} + +if (!defined('DONT_RUN_SAMPLES')) { + debitBankAccount(5.29); +} diff --git a/PaymentTransactions/refund-transaction.php b/PaymentTransactions/refund-transaction.php index 02078ff..7171066 100644 --- a/PaymentTransactions/refund-transaction.php +++ b/PaymentTransactions/refund-transaction.php @@ -1,45 +1,89 @@ setName("556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); - $refId = 'ref' . time(); - // Create the payment data for a credit card - $creditCard = new AnetAPI\CreditCardType(); - $creditCard->setCardNumber( "4111111111111111" ); - $creditCard->setExpirationDate( "2038-12"); - $paymentOne = new AnetAPI\PaymentType(); - $paymentOne->setCreditCard($creditCard); - //create a transaction - $transactionRequestType = new AnetAPI\TransactionRequestType(); - $transactionRequestType->setTransactionType( "refundTransaction"); - $transactionRequestType->setAmount(151.21); - $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) - { - $tresponse = $response->getTransactionResponse(); - if (($tresponse != null) && ($tresponse->getResponseCode()=="1") ) + +function refundTransaction($refTransId, $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("0015"); + $creditCard->setExpirationDate("XXXX"); + $paymentOne = new AnetAPI\PaymentType(); + $paymentOne->setCreditCard($creditCard); + //create a transaction + $transactionRequest = new AnetAPI\TransactionRequestType(); + $transactionRequest->setTransactionType( "refundTransaction"); + $transactionRequest->setAmount($amount); + $transactionRequest->setPayment($paymentOne); + $transactionRequest->setRefTransId($refTransId); + + + $request = new AnetAPI\CreateTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId($refId); + $request->setTransactionRequest( $transactionRequest); + $controller = new AnetController\CreateTransactionController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if ($response != null) { - echo "Refund SUCCESS: " . $tresponse->getTransId() . "\n"; + if($response->getMessages()->getResultCode() == "Ok") + { + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) + { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + echo "Refund SUCCESS: " . $tresponse->getTransId() . "\n"; + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } + else + { + echo "Transaction Failed \n"; + if($tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + } + else + { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + if($tresponse != null && $tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + else + { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } } else { - echo "Refund ERROR : " . $tresponse->getResponseCode() . "\n"; + echo "No response returned \n"; } - - } - else - { - echo "Refund Null response returned"; + + return $response; } + if(!defined('DONT_RUN_SAMPLES')) + refundTransaction( "2.23"); ?> diff --git a/PaymentTransactions/update-split-tender-group.php b/PaymentTransactions/update-split-tender-group.php index 5f9d78b..e386750 100644 --- a/PaymentTransactions/update-split-tender-group.php +++ b/PaymentTransactions/update-split-tender-group.php @@ -1,30 +1,46 @@ setName( "8V4xFm3z"); - $merchantAuthentication->setTransactionKey("655AS4Ek7TJ42snq"); - $request = new AnetAPI\UpdateSplitTenderGroupRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setSplitTenderId("116468"); - $request->setSplitTenderStatus("voided"); +function updateSplitTenderGroup() +{ + /* 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 = new AnetAPI\UpdateSplitTenderGroupRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId($refId); + $request->setSplitTenderId("115901"); + $request->setSplitTenderStatus("voided"); - $controller = new AnetController\UpdateSplitTenderGroupController($request); + $controller = new AnetController\UpdateSplitTenderGroupController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - echo "SUCCESS : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - } - else - { - echo "ERROR : Invalid response\n"; - echo "Response Code : " . $response->getMessages()->getMessage()[0]->getCode() . " Resposne text: " .$response->getMessages()->getMessage()[0]->getText() . "\n"; + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) + { + $errorMessages = $response->getMessages()->getMessage(); + echo "SUCCESS Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + else + { + echo "ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + return $response; } - ?> \ No newline at end of file + + if(!defined('DONT_RUN_SAMPLES')) + updateSplitTenderGroup(); + ?> diff --git a/PaymentTransactions/void-transaction.php b/PaymentTransactions/void-transaction.php index 0e9b60b..c2a4d3b 100644 --- a/PaymentTransactions/void-transaction.php +++ b/PaymentTransactions/void-transaction.php @@ -1,45 +1,81 @@ setName("556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); - $refId = 'ref' . time(); - // Create the payment data for a credit card - $creditCard = new AnetAPI\CreditCardType(); - $creditCard->setCardNumber( "4111111111111111" ); - $creditCard->setExpirationDate( "2038-12"); - $paymentOne = new AnetAPI\PaymentType(); - $paymentOne->setCreditCard($creditCard); - //create a transaction - $transactionRequestType = new AnetAPI\TransactionRequestType(); - $transactionRequestType->setTransactionType( "voidTransaction"); - $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) - { - $tresponse = $response->getTransactionResponse(); - if (($tresponse != null) && ($tresponse->getResponseCode()=="1") ) + +function voidTransaction($transactionid) +{ + /* 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\TransactionRequestType(); + $transactionRequestType->setTransactionType( "voidTransaction"); + $transactionRequestType->setRefTransId($transactionid); + + $request = new AnetAPI\CreateTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId($refId); + $request->setTransactionRequest( $transactionRequestType); + $controller = new AnetController\CreateTransactionController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if ($response != null) { - echo "Void transaction SUCCESS AUTH CODE: " . $tresponse->getAuthCode() . "\n"; - echo "Void transaction SUCCESS TRANS ID : " . $tresponse->getTransId() . "\n"; + if($response->getMessages()->getResultCode() == "Ok") + { + $tresponse = $response->getTransactionResponse(); + + if ($tresponse != null && $tresponse->getMessages() != null) + { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + echo " Void transaction SUCCESS AUTH CODE: " . $tresponse->getAuthCode() . "\n"; + echo " Void transaction SUCCESS TRANS ID : " . $tresponse->getTransId() . "\n"; + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } + else + { + echo "Transaction Failed \n"; + if($tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + } + else + { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + if($tresponse != null && $tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + else + { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } } else { - echo "void transaction ERROR : " . $tresponse->getResponseCode() . "\n"; + echo "No response returned \n"; } - - } - else - { - echo "Void transaction Null esponse returned"; + + return $response; } + if(!defined('DONT_RUN_SAMPLES')) + voidTransaction("60009605785"); ?> diff --git a/PaypalExpressCheckout/authorization-and-capture-continue.php b/PaypalExpressCheckout/authorization-and-capture-continue.php deleted file mode 100644 index 5341865..0000000 --- a/PaypalExpressCheckout/authorization-and-capture-continue.php +++ /dev/null @@ -1,61 +0,0 @@ -setName("5KP3u95bQpv"); - $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); - - $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) - { - $tresponse = $response->getTransactionResponse(); - if (($tresponse != null)) - { - echo "Transaction Response...\n"; - echo "Received 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"; - } - else - echo "NULL transactionResponse Error\n"; - $messages=$response->getMessages(); - if (($messages != null)) - { - echo "Messages...\n"; - echo "Result code: ".$messages->getResultCode()."\n"; - $message0=$messages->getMessage()[0]; - if($message0!=null) - echo "Message: ".$message0->getCode().", ".$message0->getText()."\n"; - } - else - echo "NULL messages Error\n"; - } - else - echo "NULL response Error\n"; -?> diff --git a/PaypalExpressCheckout/authorization-and-capture.php b/PaypalExpressCheckout/authorization-and-capture.php deleted file mode 100644 index 59cdaaa..0000000 --- a/PaypalExpressCheckout/authorization-and-capture.php +++ /dev/null @@ -1,46 +0,0 @@ -setName("5KP3u95bQpv"); - $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); - - $payPalType=new AnetAPI\PayPalType(); - $payPalType->setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); - $payPalType->setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); - - $paymentOne = new AnetAPI\PaymentType(); - $paymentOne->setPayPal($payPalType); - - // Create an authorize and capture transaction - $transactionRequestType = new AnetAPI\TransactionRequestType(); - $transactionRequestType->setTransactionType( "authCaptureTransaction"); - $transactionRequestType->setPayment($paymentOne); - $transactionRequestType->setAmount(151); - - $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) - { - $tresponse = $response->getTransactionResponse(); - if (($tresponse != null)) - { - echo "Received 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"; - } - else - echo "NULL transactionResponse Error\n"; - } - else - echo "NULL response Error\n"; -?> diff --git a/PaypalExpressCheckout/authorization-only-continued.php b/PaypalExpressCheckout/authorization-only-continued.php deleted file mode 100644 index f490050..0000000 --- a/PaypalExpressCheckout/authorization-only-continued.php +++ /dev/null @@ -1,63 +0,0 @@ -setName("5KP3u95bQpv"); - $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); - $refId = 'ref' . time(); - - $paypal_type = new AnetAPI\PayPalType(); - $paypal_type->setPayerID("JJLRRB29QC7RU"); - $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("2241711631"); - $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) - { - $tresponse = $response->getTransactionResponse(); - - if (($tresponse != null) && ($tresponse->getResponseCode()=="1") ) - { - //echo " RESULT CODE : " . $response->getResultCode() . "\n"; - echo " TRANS ID : " . $tresponse->getTransId() . "\n"; - echo "Payer ID : " . $tresponse->getSecureAcceptance()->getPayerID(); - } - else - { - //print_r($tresponse); - echo "ERROR : " . $tresponse->getResponseCode() . "\n"; - } - - } - else - { - echo "No response returned"; - } - -?> diff --git a/PaypalExpressCheckout/authorization-only.php b/PaypalExpressCheckout/authorization-only.php deleted file mode 100644 index 94c0d9d..0000000 --- a/PaypalExpressCheckout/authorization-only.php +++ /dev/null @@ -1,51 +0,0 @@ -setName("5KP3u95bQpv"); -$merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); -$refId = 'ref' . time(); - -// Create the payment data for a paypal account -$payPalType = new AnetAPI\PayPalType(); -$payPalType->setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); -$payPalType->setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); -$paymentOne = new AnetAPI\PaymentType(); -$paymentOne->setPayPal($payPalType); - -//create a auth-only transaction -$transactionRequestType = new AnetAPI\TransactionRequestType(); -$transactionRequestType->setTransactionType( "authOnlyTransaction"); -$transactionRequestType->setAmount(921); -$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)) -{ - $tresponse = $response->getTransactionResponse(); - if (($tresponse != null)&& ($response->getMessages()->getResultCode()=="Ok")) - { - echo "Received response code: ".$tresponse->getResponseCode()."\n"; - //Valid response codes: 1=Approved, 2=Declined, 3=Error, 5=Need Payer Consent\n"; - echo "Secure acceptance URL: ".$tresponse->getSecureAcceptance()->getSecureAcceptanceUrl()."\n"; - } - else{ - echo "ERROR : " . $tresponse->getResponseCode() . "\n"; - } -} -else - echo "NULL response Error\n"; -?> diff --git a/PaypalExpressCheckout/credit.php b/PaypalExpressCheckout/credit.php deleted file mode 100644 index 9894449..0000000 --- a/PaypalExpressCheckout/credit.php +++ /dev/null @@ -1,60 +0,0 @@ -setName("mbld_api_-g9yGXH6"); -// $merchantAuthentication->setTransactionKey("8b948Sk5Tk5jBB6w"); -$merchantAuthentication->setName("5KP3u95bQpv"); -$merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); - -$refId = 'ref' . time(); -$refTransId = "2241762126"; - -// Create the payment data for a paypal account -$payPalType = new AnetAPI\PayPalType(); -$payPalType->setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); -$payPalType->setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); -$paymentOne = new AnetAPI\PaymentType(); -$paymentOne->setPayPal($payPalType); - -//create a refund transaction -$transactionRequestType = new AnetAPI\TransactionRequestType(); -$transactionRequestType->setTransactionType( "refundTransaction"); -$transactionRequestType->setAmount(181); -$transactionRequestType->setPayment($paymentOne); -///refTransId of successfully settled transaction -$transactionRequestType->setRefTransId($refTransId); - -$request = new AnetAPI\CreateTransactionRequest(); -$request->setMerchantAuthentication($merchantAuthentication); -$request->setRefId( $refId); -$request->setTransactionRequest( $transactionRequestType); - -$controller = new AnetController\CreateTransactionController($request); -$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - -if ($response != null) -{ - $tresponse = $response->getTransactionResponse(); - - if (($tresponse != null)&& ($response->getMessages()->getResultCode()=="Ok")) - { - echo "Credit SUCCESS AUTH CODE : " . $tresponse->getAuthCode() . "\n"; - echo "Credit TRANS ID : " . $tresponse->getTransId() . "\n"; - } - else - { - echo "Credit ERROR : " . $tresponse->getResponseCode() . "\n"; - } -} -else -{ - echo "No response returned"; -} -?> diff --git a/PaypalExpressCheckout/get-details.php b/PaypalExpressCheckout/get-details.php deleted file mode 100644 index 4893a9f..0000000 --- a/PaypalExpressCheckout/get-details.php +++ /dev/null @@ -1,66 +0,0 @@ -setName("5KP3u95bQpv"); - $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); - - $refId = 'ref' . time(); - - //create a transaction of type get details - $transactionRequestType = new AnetAPI\TransactionRequestType(); - $transactionRequestType->setTransactionType( "getDetailsTransaction"); - - //replace following transaction ID with your transaction ID for which the details are required - $transactionRequestType->setRefTransId("2241687090"); - - //create a transaction request - $request = new AnetAPI\CreateTransactionRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setRefId( $refId); - $request->setTransactionRequest( $transactionRequestType); - - $controller = new AnetController\CreateTransactionController($request); - - //execute the api call to get transaction details - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - - if ($response != null) - { - $tresponse = $response->getTransactionResponse(); - - if($tresponse != null) - { - if ($tresponse->getResponseCode()=="1") - { - //parse the shipping information from response - $shipping_response = $tresponse->getShipTo(); - echo "Shipping address : " . $shipping_response->getAddress() . ", " . $shipping_response->getCity() - . ", " . $shipping_response->getState() . ", " . $shipping_response->getCountry() . "\n"; - - echo "Payer ID : " . $tresponse->getSecureAcceptance()->getPayerID(); - } - else - { - echo "ERROR : " . $tresponse->getResponseCode() . "\n"; - } - } - else - { - echo "No response returned"; - } - } - else - { - echo "No response returned"; - } - -?> \ No newline at end of file diff --git a/PaypalExpressCheckout/prior-authorization-capture.php b/PaypalExpressCheckout/prior-authorization-capture.php deleted file mode 100644 index 63653c0..0000000 --- a/PaypalExpressCheckout/prior-authorization-capture.php +++ /dev/null @@ -1,51 +0,0 @@ -setName("5KP3u95bQpv"); - $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); - $refId = 'ref' . time(); - - $payPalType = new AnetAPI\PayPalType(); - $payPalType->setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); - $payPalType->setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262"); - - $paymentType = new AnetAPI\PaymentType(); - $paymentType->setPayPal($payPalType); - - $transactionRequest = new AnetAPI\TransactionRequestType(); - $transactionRequest->setTransactionType("priorAuthCaptureTransaction"); - $transactionRequest->setPayment($paymentType); - $transactionRequest->setAmount(floatval(19.45)); - $transactionRequest->setRefTransId(2241687191); - - $request = new AnetAPI\CreateTransactionRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setRefId( $refId); - $request->setTransactionRequest($transactionRequest); - - $controller = new AnetController\CreateTransactionController($request); - - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - $tresponse = $response->getTransactionResponse(); - if (($tresponse != null) && ($tresponse->getResponseCode()=="1") ) - { - echo "Prior Authorization capture AUTH CODE : " . $tresponse->getAuthCode() . "\n"; - } - else - { - echo "Prior Authorization capture ERROR : Invalid response\n"; - } - } - else - { - echo "PriorAuthorizationCapture ERROR : Invalid response\n"; - } - -?> \ No newline at end of file diff --git a/PaypalExpressCheckout/void.php b/PaypalExpressCheckout/void.php deleted file mode 100644 index 48f5b8e..0000000 --- a/PaypalExpressCheckout/void.php +++ /dev/null @@ -1,50 +0,0 @@ -setName("5KP3u95bQpv"); - $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); - $refId = 'ref' . time(); - - $payPalType = new AnetAPI\PayPalType(); - $payPalType->setSuccessUrl(""); - $payPalType->setCancelUrl(""); - - $paymentType = new AnetAPI\PaymentType(); - $paymentType->setPayPal($payPalType); - - $transactionRequest = new AnetAPI\TransactionRequestType(); - $transactionRequest->setTransactionType("voidTransaction"); - $transactionRequest->setPayment($paymentType); - $transactionRequest->setRefTransId(2241706281); - - $request = new AnetAPI\CreateTransactionRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setRefId( $refId); - $request->setTransactionRequest($transactionRequest); - - $controller = new AnetController\CreateTransactionController($request); - - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - - if ($response != null) - { - $tresponse = $response->getTransactionResponse(); - if (($tresponse != null) && ($tresponse->getResponseCode()=="1") ) - { - echo "Void transaction SUCCESS TRANS ID : " . $tresponse->getTransId() . "\n"; - } - else - { - echo "Void transaction ERROR : " . $tresponse->getResponseCode() . "\n"; - } - } - else - { - echo "Void transaction Null esponse returned"; - } - - ?> \ No newline at end of file diff --git a/README.md b/README.md index e0b2158..e929b5c 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,50 @@ -# Sample PHP Code for Authorize.Net +# 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. -The samples are organized just like our API, which you can also try out directly here: http://developer.authorize.net/api/reference +This repository contains working code samples which demonstrate PHP integration with the [Authorize.Net PHP SDK](https://github.com/AuthorizeNet/sdk-php). +The samples are organized into categories and common usage examples, just like our [API Reference Guide](http://developer.authorize.net/api/reference). Our API Reference Guide is an interactive reference for the Authorize.Net API. It explains the request and response parameters for each API method and has embedded code windows to allow you to send actual requests right within the API Reference Guide. -##Using the Sample Code -The samples are all completely independent and self-contained 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. + +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 ef08ad9..59f8553 100644 --- a/RecurringBilling/cancel-subscription.php +++ b/RecurringBilling/cancel-subscription.php @@ -1,33 +1,50 @@ setName( "556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); - - $refId = 'ref' . time(); - - $request = new AnetAPI\ARBCancelSubscriptionRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setRefId($refId); - $request->setSubscriptionId("100748"); - - $controller = new AnetController\ARBCancelSubscriptionController($request); - - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) - { - echo "SUCCESS" . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - } - else - { - echo "ERROR : Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - + define("AUTHORIZENET_LOG_FILE", "phplog"); + +function cancelSubscription($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); + + // Set the transaction's refId + $refId = 'ref' . time(); + + $request = new AnetAPI\ARBCancelSubscriptionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId($refId); + $request->setSubscriptionId($subscriptionId); + + $controller = new AnetController\ARBCancelSubscriptionController($request); + + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) + { + $successMessages = $response->getMessages()->getMessage(); + echo "SUCCESS : " . $successMessages[0]->getCode() . " " .$successMessages[0]->getText() . "\n"; + + } + else + { + echo "ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + + } + + return $response; + } - ?> + + if(!defined('DONT_RUN_SAMPLES')) + cancelSubscription("7087965"); + +?> diff --git a/RecurringBilling/create-subscription-from-customer-profile.php b/RecurringBilling/create-subscription-from-customer-profile.php new file mode 100644 index 0000000..8681182 --- /dev/null +++ b/RecurringBilling/create-subscription-from-customer-profile.php @@ -0,0 +1,72 @@ +setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); + + // Subscription Type Info + $subscription = new AnetAPI\ARBSubscriptionType(); + $subscription->setName("Sample Subscription"); + + $interval = new AnetAPI\PaymentScheduleType\IntervalAType(); + $interval->setLength($intervalLength); + $interval->setUnit("days"); + + $paymentSchedule = new AnetAPI\PaymentScheduleType(); + $paymentSchedule->setInterval($interval); + $paymentSchedule->setStartDate(new DateTime('2035-08-30')); + $paymentSchedule->setTotalOccurrences("12"); + $paymentSchedule->setTrialOccurrences("1"); + + $subscription->setPaymentSchedule($paymentSchedule); + $subscription->setAmount(rand(1,99999)/12.0*12); + $subscription->setTrialAmount("0.00"); + + $profile = new AnetAPI\CustomerProfileIdType(); + $profile->setCustomerProfileId($customerProfileId); + $profile->setCustomerPaymentProfileId($customerPaymentProfileId); + $profile->setCustomerAddressId($customerAddressId); + + $subscription->setProfile($profile); + + $request = new AnetAPI\ARBCreateSubscriptionRequest(); + $request->setmerchantAuthentication($merchantAuthentication); + $request->setRefId($refId); + $request->setSubscription($subscription); + $controller = new AnetController\ARBCreateSubscriptionController($request); + + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) + { + echo "SUCCESS: Subscription ID : " . $response->getSubscriptionId() . "\n"; + } + else + { + echo "ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + + return $response; + } + + if(!defined('DONT_RUN_SAMPLES')) + createSubscriptionFromCustomerProfile( \SampleCode\Constants::SUBSCRIPTION_INTERVAL_DAYS, "247150", "215472", "189691"); + +?> diff --git a/RecurringBilling/create-subscription.php b/RecurringBilling/create-subscription.php index 01925d7..1bf6fba 100644 --- a/RecurringBilling/create-subscription.php +++ b/RecurringBilling/create-subscription.php @@ -1,64 +1,83 @@ setName( "556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); + + define("AUTHORIZENET_LOG_FILE", "phplog"); - $refId = 'ref' . time(); +function createSubscription($intervalLength) +{ + /* 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(); - // Subscription Type Info - $subscription = new AnetAPI\ARBSubscriptionType(); - $subscription->setName("Sample Subscription"); + // Subscription Type Info + $subscription = new AnetAPI\ARBSubscriptionType(); + $subscription->setName("Sample Subscription"); - $interval = new AnetAPI\PaymentScheduleType\IntervalAType(); - $interval->setLength("1"); - $interval->setUnit("months"); + $interval = new AnetAPI\PaymentScheduleType\IntervalAType(); + $interval->setLength($intervalLength); + $interval->setUnit("days"); - $paymentSchedule = new AnetAPI\PaymentScheduleType(); - $paymentSchedule->setInterval($interval); - $paymentSchedule->setStartDate(new DateTime('2020-08-30')); - $paymentSchedule->setTotalOccurrences("12"); - $paymentSchedule->setTrialOccurrences("1"); + $paymentSchedule = new AnetAPI\PaymentScheduleType(); + $paymentSchedule->setInterval($interval); + $paymentSchedule->setStartDate(new DateTime('2035-12-30')); + $paymentSchedule->setTotalOccurrences("12"); + $paymentSchedule->setTrialOccurrences("1"); - $subscription->setPaymentSchedule($paymentSchedule); - $subscription->setAmount("10.29"); - $subscription->setTrialAmount("0.00"); - - $creditCard = new AnetAPI\CreditCardType(); - $creditCard->setCardNumber("4111111111111111"); - $creditCard->setExpirationDate("2020-12"); + $subscription->setPaymentSchedule($paymentSchedule); + $subscription->setAmount(rand(1,99999)/12.0*12); + $subscription->setTrialAmount("0.00"); + + $creditCard = new AnetAPI\CreditCardType(); + $creditCard->setCardNumber("4111111111111111"); + $creditCard->setExpirationDate("2038-12"); - $payment = new AnetAPI\PaymentType(); - $payment->setCreditCard($creditCard); + $payment = new AnetAPI\PaymentType(); + $payment->setCreditCard($creditCard); + $subscription->setPayment($payment); - $subscription->setPayment($payment); + $order = new AnetAPI\OrderType(); + $order->setInvoiceNumber("1234354"); + $order->setDescription("Description of the subscription"); + $subscription->setOrder($order); + + $billTo = new AnetAPI\NameAndAddressType(); + $billTo->setFirstName("John"); + $billTo->setLastName("Smith"); - $billTo = new AnetAPI\NameAndAddressType(); - $billTo->setFirstName("John"); - $billTo->setLastName("Smith"); + $subscription->setBillTo($billTo); - $subscription->setBillTo($billTo); + $request = new AnetAPI\ARBCreateSubscriptionRequest(); + $request->setmerchantAuthentication($merchantAuthentication); + $request->setRefId($refId); + $request->setSubscription($subscription); + $controller = new AnetController\ARBCreateSubscriptionController($request); - $request = new AnetAPI\ARBCreateSubscriptionRequest(); - $request->setmerchantAuthentication($merchantAuthentication); - $request->setRefId($refId); - $request->setSubscription($subscription); - $controller = new AnetController\ARBCreateSubscriptionController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) + { + echo "SUCCESS: Subscription ID : " . $response->getSubscriptionId() . "\n"; + } + else + { + echo "ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - echo "SUCCESS: Subscription ID : " . $response->getSubscriptionId() . "\n"; - } - else - { - echo "ERROR : Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; + return $response; } + + if(!defined('DONT_RUN_SAMPLES')) + createSubscription(23); + ?> diff --git a/RecurringBilling/get-list-of-subscriptions.php b/RecurringBilling/get-list-of-subscriptions.php index 17ce681..72330e8 100644 --- a/RecurringBilling/get-list-of-subscriptions.php +++ b/RecurringBilling/get-list-of-subscriptions.php @@ -1,45 +1,59 @@ setName( "556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); - - $refId = 'ref' . time(); - - $sorting = new AnetAPI\ARBGetSubscriptionListSortingType(); - $sorting->setOrderBy("id"); - $sorting->setOrderDescending("false"); - - $paging = new AnetAPI\PagingType(); - $paging->setLimit("1000"); - $paging->setOffset("1"); - - $request = new AnetAPI\ARBGetSubscriptionListRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setRefId($refId); - $request->setSearchType("subscriptionInactive"); - $request->setSorting($sorting); - $request->setPaging($paging); - - - $controller = new AnetController\ARBGetSubscriptionListController($request); - - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) - { - echo "SUCCESS: Subscription Details:" . $response->getSubscriptionDetails() . "\n"; - echo "Total Number In Results:" . $response->getTotalNumInResultSet() . "\n"; - } - else - { - echo "ERROR : Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - - } - ?> + define("AUTHORIZENET_LOG_FILE", "phplog"); + +function getListOfSubscriptions() +{ + /* 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(); + + $sorting = new AnetAPI\ARBGetSubscriptionListSortingType(); + $sorting->setOrderBy("id"); + $sorting->setOrderDescending(false); + + $paging = new AnetAPI\PagingType(); + $paging->setLimit("10"); + $paging->setOffset("1"); + + $request = new AnetAPI\ARBGetSubscriptionListRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId($refId); + $request->setSearchType("subscriptionInactive"); + $request->setSorting($sorting); + $request->setPaging($paging); + + + $controller = new AnetController\ARBGetSubscriptionListController($request); + + $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) { + echo "SUCCESS: Subscription Details:" . "\n"; + echo "Total Number In Results:" . $response->getTotalNumInResultSet() . "\n"; + if ($response->getTotalNumInResultSet() > 0) { + foreach ($response->getSubscriptionDetails() as $subscriptionDetails) { + echo "Subscription ID: " . $subscriptionDetails->getId() . "\n"; + } + } + } else { + echo "ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + + return $response; +} + +if (!defined('DONT_RUN_SAMPLES')) { + getListOfSubscriptions(); +} diff --git a/RecurringBilling/get-subscription-status.php b/RecurringBilling/get-subscription-status.php index 4754eb6..52796b0 100644 --- a/RecurringBilling/get-subscription-status.php +++ b/RecurringBilling/get-subscription-status.php @@ -1,33 +1,46 @@ setName( "556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); - - $refId = 'ref' . time(); - - $request = new AnetAPI\ARBGetSubscriptionStatusRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setRefId($refId); - $request->setSubscriptionId("100748"); - - $controller = new AnetController\ARBGetSubscriptionStatusController($request); - - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) - { - echo "SUCCESS: Subscription Status : " . $response->getStatus() . "\n"; - } - else - { - echo "ERROR : Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - + define("AUTHORIZENET_LOG_FILE", "phplog"); + +function getSubscriptionStatus($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); + + // Set the transaction's refId + $refId = 'ref' . time(); + + $request = new AnetAPI\ARBGetSubscriptionStatusRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId($refId); + $request->setSubscriptionId($subscriptionId); + + $controller = new AnetController\ARBGetSubscriptionStatusController($request); + + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) + { + echo "SUCCESS: Subscription Status : " . $response->getStatus() . "\n"; + } + else + { + echo "ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + + return $response; } - ?> + + if(!defined('DONT_RUN_SAMPLES')) + getSubscriptionStatus("3056948"); + +?> diff --git a/RecurringBilling/get-subscription.php b/RecurringBilling/get-subscription.php index 91e7dea..23b0409 100644 --- a/RecurringBilling/get-subscription.php +++ b/RecurringBilling/get-subscription.php @@ -1,53 +1,72 @@ setName( "556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); - - $refId = 'ref' . time(); - - // Creating the API Request with required parameters - $request = new AnetAPI\ARBGetSubscriptionRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setRefId($refId); - $request->setSubscriptionId("2930242"); - - // Controller - $controller = new AnetController\ARBGetSubscriptionController($request); - - // Getting the response - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - - if ($response != null) - { - if($response->getMessages()->getResultCode() == "Ok") - { - // Success - echo "SUCCESS: GetSubscription:" . "\n"; - // Displaying the details - echo "Subscription Name: " . $response->getSubscription()->getName(). "\n"; - echo "Subscription amount: " . $response->getSubscription()->getAmount(). "\n"; - echo "Subscription status: " . $response->getSubscription()->getStatus(). "\n"; - echo "Subscription Description: " . $response->getSubscription()->getProfile()->getDescription(). "\n"; - echo "Customer Profile ID: " . $response->getSubscription()->getProfile()->getCustomerProfileId() . "\n"; - } - else - { - // Error - echo "ERROR : Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - + 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); + + // Set the transaction's refId + $refId = 'ref' . time(); + + // Creating the API Request with required parameters + $request = new AnetAPI\ARBGetSubscriptionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId($refId); + $request->setSubscriptionId($subscriptionId); + $request->setIncludeTransactions(true); + + // Controller + $controller = new AnetController\ARBGetSubscriptionController($request); + + // Getting the response + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if ($response != null) + { + if($response->getMessages()->getResultCode() == "Ok") + { + // Success + echo "SUCCESS: GetSubscription:" . "\n"; + // Displaying the details + echo "Subscription Name: " . $response->getSubscription()->getName(). "\n"; + echo "Subscription amount: " . $response->getSubscription()->getAmount(). "\n"; + echo "Subscription status: " . $response->getSubscription()->getStatus(). "\n"; + echo "Subscription Description: " . $response->getSubscription()->getProfile()->getDescription(). "\n"; + echo "Customer Profile ID: " . $response->getSubscription()->getProfile()->getCustomerProfileId() . "\n"; + echo "Customer payment Profile ID: ". $response->getSubscription()->getProfile()->getPaymentProfile()->getCustomerPaymentProfileId() . "\n"; + $transactions = $response->getSubscription()->getArbTransactions(); + if($transactions != null){ + foreach ($transactions as $transaction) { + echo "Transaction ID : ".$transaction->getTransId()." -- ".$transaction->getResponse()." -- Pay Number : ".$transaction->getPayNum()."\n"; + } } + } + else + { + // Error + echo "ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + } + else + { + // Failed to get response + echo "Null Response Error"; + } + + return $response; } - else - { - // Failed to get response - echo "Null Response Error"; - } + + if(!defined('DONT_RUN_SAMPLES')) + getSubscription("2942461"); ?> diff --git a/RecurringBilling/update-subscription.php b/RecurringBilling/update-subscription.php index fba101e..6729445 100644 --- a/RecurringBilling/update-subscription.php +++ b/RecurringBilling/update-subscription.php @@ -1,44 +1,68 @@ setName( "556KThWQ6vf2"); - $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); + define("AUTHORIZENET_LOG_FILE", "phplog"); - $refId = 'ref' . time(); +function updateSubscription($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); + + // Set the transaction's refId + $refId = 'ref' . time(); - $subscription = new AnetAPI\ARBSubscriptionType(); + $subscription = new AnetAPI\ARBSubscriptionType(); - $creditCard = new AnetAPI\CreditCardType(); - $creditCard->setCardNumber("4111111111111111"); - $creditCard->setExpirationDate("2020-12"); + $creditCard = new AnetAPI\CreditCardType(); + $creditCard->setCardNumber("4111111111111111"); + $creditCard->setExpirationDate("2038-12"); - $payment = new AnetAPI\PaymentType(); - $payment->setCreditCard($creditCard); + $payment = new AnetAPI\PaymentType(); + $payment->setCreditCard($creditCard); - $subscription->setPayment($payment); + //set profile information + $profile = new AnetAPI\CustomerProfileIdType(); + $profile->setCustomerProfileId("121212"); + $profile->setCustomerPaymentProfileId("131313"); + $profile->setCustomerAddressId("141414"); - $request = new AnetAPI\ARBUpdateSubscriptionRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setRefId($refId); - $request->setSubscriptionId("100748"); - $request->setSubscription($subscription); + $subscription->setPayment($payment); - $controller = new AnetController\ARBUpdateSubscriptionController($request); + //set customer profile information + //$subscription->setProfile($profile); + + $request = new AnetAPI\ARBUpdateSubscriptionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId($refId); + $request->setSubscriptionId($subscriptionId); + $request->setSubscription($subscription); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - echo "SUCCESS" . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - } - else - { - echo "ERROR : Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; + $controller = new AnetController\ARBUpdateSubscriptionController($request); + + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) + { + $errorMessages = $response->getMessages()->getMessage(); + echo "SUCCESS Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + + } + else + { + echo "ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + + return $response; } - ?> + + if(!defined('DONT_RUN_SAMPLES')) + updateSubscription("3056948"); +?> diff --git a/SampleCodeList.txt b/SampleCodeList.txt new file mode 100644 index 0000000..5119f91 --- /dev/null +++ b/SampleCodeList.txt @@ -0,0 +1,58 @@ +SampleCodeName,IsDependent,ShouldRun +ChargeCreditCard,1,1 +CreateSubscription,1,1 +CreateSubscriptionFromCustomerProfile,1,1 +GetCustomerPaymentProfileList,0,1 +GetTransactionList,0,1 +CreateAnApplePayTransaction,0,0 +CreateAnAcceptTransaction,0,0 +CreateAnAndroidPayTransaction,0,0 +decryptVisaSrcData,0,0 +createVisaSrcTransaction,0,0 +CaptureFundsAuthorizedThroughAnotherChannel,1,1 +AuthorizeCreditCard,1,1 +DebitBankAccount,1,1 +ChargeTokenizedCreditCard,0,0 +PayPalAuthorizeOnly,1,1 +GetListOfSubscriptions,0,1 +GetUnsettledTransactionList,0,1 +GetBatchStatistics,1,1 +GetSettledBatchList,1,1 +UpdateSplitTenderGroup,0,1 +UpdateCustomerShippingAddress,1,1 +UpdateCustomerProfile,0,1 +UpdateCustomerPaymentProfile,1,1 +GetCustomerShippingAddress,1,1 +GetCustomerProfileIds,0,0 +GetCustomerProfile,1,1 +GetAcceptCustomerProfilePage,1,1 +GetCustomerPaymentProfile,1,1 +DeleteCustomerShippingAddress,1,1 +DeleteCustomerProfile,1,1 +DeleteCustomerPaymentProfile,1,1 +CreateCustomerShippingAddress,1,1 +CreateCustomerProfileFromTransaction,0,0 +GetTransactionDetails,1,1 +CapturePreviouslyAuthorizedgetAmount,1,0 +RefundTransaction,1,0 +VoidTransaction,1,1 +CreditBankAccount,1,0 +ChargeCustomerProfile,1,1 +PayPalVoid,1,0 +PayPalAuthorizeCapture,1,1 +PayPalAuthorizeCaptureContinued,1,1 +PayPalAuthorizeOnlyContinued,1,0 +PayPalCredit,1,0 +PayPalGetDetails,1,1 +PayPalPriorAuthorizationCapture,1,0 +CancelSubscription,1,1 +GetSubscriptionStatus,1,1 +GetSubscription,1,1 +UpdateSubscription,1,1 +CreateCustomerProfile,1,1 +CreateCustomerPaymentProfile,1,1 +ValidateCustomerPaymentProfile,1,0 +GetMerchantDetails,0,1 +UpdateHeldTransaction,1,0 +GetAnAcceptPaymentPage,0,1 +CreateAnAcceptPaymentTransaction,0,0 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 4f9caad..9a161c6 100644 --- a/TransactionReporting/get-batch-statistics.php +++ b/TransactionReporting/get-batch-statistics.php @@ -1,54 +1,65 @@ setName( "5KP3u95bQpv"); - $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); - $refId = 'ref' . time(); + define("AUTHORIZENET_LOG_FILE", "phplog"); - //Setting a valid batch Id for the Merchant - $batchId = "4532808"; - - // Creating a request - $request = new AnetAPI\GetBatchStatisticsRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setBatchId($batchId); +function getBatchStatistics($batchId = "7927817") //only shows results for batches not older than 6 months +{ + /* 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); - //Creating the controller - $controller = new AnetController\GetBatchStatisticsController($request); + // Set the transaction's refId + $refId = 'ref' . time(); + + // Creating a request + $request = new AnetAPI\GetBatchStatisticsRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setBatchId($batchId); + + //Creating the controller + $controller = new AnetController\GetBatchStatisticsController($request); - //Retrieving response - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + //Retrieving response + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) - { - echo "SUCCESS: Successfully got the list of subscriptions : \n\n"; - echo "Batch ID : " . $response->getBatch()->getBatchId() . "\n"; - echo "Settlement Time : " . date_format($response->getBatch()->getSettlementTimeUTC(),"Y/m/d H:i:s") . "\n"; - echo "Settlement state : " . $response->getBatch()->getSettlementState() . "\n"; - echo "Payment Method : " . $response->getBatch()->getPaymentMethod() . "\n"; - echo "Statistic Details:"; - //Displaying the details of each transaction in the list - foreach ($response->getBatch()->getStatistics() as $statistics) - { - echo " Account Type : " . $statistics->getAccountType() . "\n"; - echo " Charge Amount : " . $statistics->getChargeAmount() . "\n"; - echo " Charge Count : " . $statistics->getChargeCount() . "\n"; - echo " Refund Amount : " . $statistics->getRefundAmount() . "\n"; - echo " Refund Count : " . $statistics->getRefundCount() . "\n"; - echo " Void Count : " . $statistics->getRefundCount() . "\n"; - echo " Decline Count : " . $statistics->getRefundCount() . "\n"; - echo " Error Count : " . $statistics->getRefundCount() . "\n"; - } - } - else - { - echo "ERROR : Failed to get the batch statistics\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) + { + echo "SUCCESS: Successfully got the list of subscriptions : \n\n"; + echo "Batch ID : " . $response->getBatch()->getBatchId() . "\n"; + echo "Settlement Time : " . date_format($response->getBatch()->getSettlementTimeUTC(),"Y/m/d H:i:s") . "\n"; + echo "Settlement state : " . $response->getBatch()->getSettlementState() . "\n"; + echo "Payment Method : " . $response->getBatch()->getPaymentMethod() . "\n"; + echo "Statistic Details:"; + //Displaying the details of each transaction in the list + foreach ($response->getBatch()->getStatistics() as $statistics) + { + echo " Account Type : " . $statistics->getAccountType() . "\n"; + echo " Charge Amount : " . $statistics->getChargeAmount() . "\n"; + echo " Charge Count : " . $statistics->getChargeCount() . "\n"; + echo " Refund Amount : " . $statistics->getRefundAmount() . "\n"; + echo " Refund Count : " . $statistics->getRefundCount() . "\n"; + echo " Void Count : " . $statistics->getRefundCount() . "\n"; + echo " Decline Count : " . $statistics->getRefundCount() . "\n"; + echo " Error Count : " . $statistics->getRefundCount() . "\n"; + } + } + else + { + echo "ERROR : Failed to get the batch statistics\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + + return $response; } - ?> \ No newline at end of file + + if(!defined('DONT_RUN_SAMPLES')) + getBatchStatistics(); + +?> 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 new file mode 100644 index 0000000..1b20655 --- /dev/null +++ b/TransactionReporting/get-merchant-details.php @@ -0,0 +1,52 @@ +setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); + + $request = new AnetAPI\GetMerchantDetailsRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + + $controller = new AnetController\GetMerchantDetailsController($request); + + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) + { + echo "SUCCESS: Merchant Name:" . $response->getMerchantName() . "\n"; + echo " Gateway Id:" . $response->getGatewayId(). "\n"; + + foreach ($response->getProcessors() as $processor) { + echo " ->Name : " . $processor->getName() . "\n"; + } + + foreach ($response->getCurrencies() as $currency) { + echo " ->Currency : " . $currency . "\n"; + } + } + else + { + echo "ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + + return $response; + } + + if(!defined('DONT_RUN_SAMPLES')) + getMerchantDetails(); +?> diff --git a/TransactionReporting/get-settled-batch-list.php b/TransactionReporting/get-settled-batch-list.php index b241992..89292af 100644 --- a/TransactionReporting/get-settled-batch-list.php +++ b/TransactionReporting/get-settled-batch-list.php @@ -1,62 +1,79 @@ setName( "5KP3u95bQpv"); - $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); + define("AUTHORIZENET_LOG_FILE", "phplog"); + +function getSettledBatchList($firstSettlementDate, $lastSettlementDate) +{ + /* 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 = new AnetAPI\GetSettledBatchListRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setIncludeStatistics(true); + + // Both the first and last dates must be in the same time zone + // The time between first and last dates, inclusively, cannot exceed 31 days. + $request->setFirstSettlementDate($firstSettlementDate); + $request->setLastSettlementDate($lastSettlementDate); - $request = new AnetAPI\GetSettledBatchListRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setIncludeStatistics(true); + $controller = new AnetController\GetSettledBatchListController ($request); + + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) + { + foreach($response->getBatchList() as $batch) + { + echo "\n\n"; + echo "Batch ID: " . $batch->getBatchId() . "\n"; + echo "Batch settled on (UTC): " . $batch->getSettlementTimeUTC()->format('r') . "\n"; + echo "Batch settled on (Local): " . $batch->getSettlementTimeLocal()->format('D, d M Y H:i:s') . "\n"; + echo "Batch settlement state: " . $batch->getSettlementState() . "\n"; + echo "Batch market type: " . $batch->getMarketType() . "\n"; + echo "Batch product: " . $batch->getProduct() . "\n"; + foreach($batch->getStatistics() as $statistics) + { + echo "Account type: ".$statistics->getAccountType()."\n"; + echo "Total charge amount: ".$statistics->getChargeAmount()."\n"; + echo "Charge count: ".$statistics->getChargeCount()."\n"; + echo "Refund amount: ".$statistics->getRefundAmount()."\n"; + echo "Refund count: ".$statistics->getRefundCount()."\n"; + echo "Void count: ".$statistics->getVoidCount()."\n"; + echo "Decline count: ".$statistics->getDeclineCount()."\n"; + echo "Error amount: ".$statistics->getErrorCount()."\n"; + } + } + } + else + { + echo "ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + + return $response; + } // both the first and last dates must be in the same time zone - $firstSettlementDate=new DateTime("2015-08-25T06:00:00Z"); // a date constructed from an ISO8601 format date string - $request->setFirstSettlementDate($firstSettlementDate); - + $firstSettlementDate=new DateTime("2018-01-23T06:00:00Z"); // a date constructed manually $lastSettlementDate=new DateTime(); - $lastSettlementDate->setDate(2015,9,20); + $lastSettlementDate->setDate(2018,2,19); $lastSettlementDate->setTime(13,33,59); $lastSettlementDate->setTimezone(new DateTimeZone('UTC')); - $request->setLastSettlementDate($lastSettlementDate); - - $controller = new AnetController\GetSettledBatchListController ($request); - - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) - { - foreach($response->getBatchList() as $batch) - { - echo "\n\n"; - echo "Batch ID: " . $batch->getBatchId() . "\n"; - echo "Batch settled on (UTC): " . $batch->getSettlementTimeUTC()->format('r') . "\n"; - echo "Batch settled on (Local): " . $batch->getSettlementTimeLocal()->format('r') . "\n"; - echo "Batch settlement state: " . $batch->getSettlementState() . "\n"; - echo "Batch market type: " . $batch->getMarketType() . "\n"; - echo "Batch product: " . $batch->getProduct() . "\n"; - foreach($batch->getStatistics() as $statistics) - { - echo "Account type: ".$statistics->getAccountType()."\n"; - echo "Total charge amount: ".$statistics->getChargeAmount()."\n"; - echo "Charge count: ".$statistics->getChargeCount()."\n"; - echo "Refund amount: ".$statistics->getRefundAmount()."\n"; - echo "Refund count: ".$statistics->getRefundCount()."\n"; - echo "Void count: ".$statistics->getVoidCount()."\n"; - echo "Decline count: ".$statistics->getDeclineCount()."\n"; - echo "Error amount: ".$statistics->getErrorCount()."\n"; - } - } - } - else - { - echo "ERROR : Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - } - ?> + if(!defined('DONT_RUN_SAMPLES')) + getSettledBatchList($firstSettlementDate, $lastSettlementDate); + +?> diff --git a/TransactionReporting/get-transaction-details.php b/TransactionReporting/get-transaction-details.php index b48de44..1822d78 100644 --- a/TransactionReporting/get-transaction-details.php +++ b/TransactionReporting/get-transaction-details.php @@ -1,36 +1,49 @@ setName( "5KP3u95bQpv"); - $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); - - $refId = 'ref' . time(); + define("AUTHORIZENET_LOG_FILE", "phplog"); +function getTransactionDetails($transactionId) +{ + /* 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 + // The refId is a Merchant-assigned reference ID for the request. + // If included in the request, this value is included in the response. + // This feature might be especially useful for multi-threaded applications. + $refId = 'ref' . time(); - $request = new AnetAPI\GetTransactionDetailsRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setTransId("2238968786"); + $request = new AnetAPI\GetTransactionDetailsRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setTransId($transactionId); + $controller = new AnetController\GetTransactionDetailsController($request); - $controller = new AnetController\GetTransactionDetailsController($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: Transaction Status:" . $response->getTransaction()->getTransactionStatus() . "\n"; + echo " Auth Amount:" . $response->getTransaction()->getAuthAmount() . "\n"; + echo " Trans ID:" . $response->getTransaction()->getTransId() . "\n"; + } + else + { + echo "ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) - { - echo "SUCCESS: Transaction Status:" . $response->getTransaction()->getTransactionStatus() . "\n"; - echo " Auth Amount:" . $response->getTransaction()->getAuthAmount() . "\n"; - echo " Trans ID:" . $response->getTransaction()->getTransId() . "\n"; - } - else - { - echo "ERROR : Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - + return $response; } - ?> + + if(!defined('DONT_RUN_SAMPLES')) + getTransactionDetails("2238968786"); +?> diff --git a/TransactionReporting/get-transaction-list.php b/TransactionReporting/get-transaction-list.php index 3e63fe6..ccf86c1 100644 --- a/TransactionReporting/get-transaction-list.php +++ b/TransactionReporting/get-transaction-list.php @@ -1,46 +1,58 @@ setName( "5KP3u95bQpv"); - $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); + define("AUTHORIZENET_LOG_FILE", "phplog"); - $refId = 'ref' . time(); +function getTransactionList() +{ + /* 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 request's refId + $refId = 'ref' . time(); - //Setting a valid batch Id for the Merchant - $batchId = "4606008"; - $request = new AnetAPI\GetTransactionListRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setBatchId($batchId); + //Setting a valid batch Id for the Merchant + $batchId = "4606008"; + $request = new AnetAPI\GetTransactionListRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setBatchId($batchId); - $controller = new AnetController\GetTransactionListController($request); + $controller = new AnetController\GetTransactionListController($request); - //Retrieving transaction list for the given Batch Id - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + //Retrieving transaction list for the given Batch Id + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) - { - echo "SUCCESS: Get Transaction List for BatchID : " . $batchId . "\n\n"; - if ($response->getTransactions() == null) { - echo "No Transaction to 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"; - } - } - else - { - echo "ERROR : Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) + { + echo "SUCCESS: Get Transaction List for BatchID : " . $batchId . "\n\n"; + if ($response->getTransactions() == null) { + echo "No Transaction to display in this Batch."; + return $response; + } + //Displaying the details of each transaction in the list + foreach ($response->getTransactions() as $transaction) { + echo " ->Transaction Id : " . $transaction->getTransId() . "\n"; + echo " Submitted on (Local) : " . date_format($transaction->getSubmitTimeLocal(), 'Y-m-d H:i:s') . "\n"; + echo " Status : " . $transaction->getTransactionStatus() . "\n"; + echo " Settle amount : " . number_format($transaction->getSettleAmount(), 2, '.', '') . "\n"; + } + } + else + { + echo "ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + + return $response; } - ?> \ No newline at end of file + + if(!defined('DONT_RUN_SAMPLES')) + getTransactionList(); +?> \ No newline at end of file diff --git a/TransactionReporting/get-unsettled-transaction-list.php b/TransactionReporting/get-unsettled-transaction-list.php index 2592470..45e9db8 100644 --- a/TransactionReporting/get-unsettled-transaction-list.php +++ b/TransactionReporting/get-unsettled-transaction-list.php @@ -1,37 +1,55 @@ setName( "5KP3u95bQpv"); - $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); + define("AUTHORIZENET_LOG_FILE", "phplog"); + +function getUnsettledTransactionList() +{ + /* 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(); - $refId = 'ref' . time(); + $request = new AnetAPI\GetUnsettledTransactionListRequest(); + $request->setMerchantAuthentication($merchantAuthentication); - $request = new AnetAPI\GetUnsettledTransactionListRequest(); - $request->setMerchantAuthentication($merchantAuthentication); + $controller = new AnetController\GetUnsettledTransactionListController($request); - $controller = new AnetController\GetUnsettledTransactionListController($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")) + { + if(null != $response->getTransactions()) + { + foreach($response->getTransactions() as $tx) + { + echo "SUCCESS: TransactionID: " . $tx->getTransId() . "\n"; + } + } + else{ + echo "No unsettled transactions for the merchant." . "\n"; + } + } + else + { + echo "ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) - { - foreach($response->getTransactions() as $tx) - { - echo "SUCCESS: TransactionID: " . $tx->getTransId() . "\n"; - } - - } - else - { - echo "ERROR : Invalid response\n"; - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; - + return $response; } - ?> + + if(!defined('DONT_RUN_SAMPLES')) + getUnsettledTransactionList(); + +?> diff --git a/VisaCheckout/create-visa-checkout-transaction.php b/VisaCheckout/create-visa-checkout-transaction.php deleted file mode 100644 index 5727bb1..0000000 --- a/VisaCheckout/create-visa-checkout-transaction.php +++ /dev/null @@ -1,58 +0,0 @@ -setName("5KP3u95bQpv"); - $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); - $refId = 'ref' . time(); - - // Create the payment data from a Visa Checkout blob - $op = new AnetAPI\OpaqueDataType(); - $op->setDataDescriptor("COMMON.VCO.ONLINE.PAYMENT"); - $op->setDataValue("4Ng5pzJ6DXfAvLSzVauN9KTufx5lTHhFlnuIr248N3fjtyHrHqMuhOkB1BLiSjKWeTM9+BNj3+9nY56d7CsUfIuvVSTaJRhQQSex1dS2Y2Y+/cA5U+3D1pg5YtTmDVUGlsu1simAd3huwPnwD+CG6O8Ml0AmXvYHntmL3vFaJomadMQBy27k8Dbh5eplPBwyawKUVJ7GqTyKLe8aOYkBUHT5ANWkq2hlGps44BOoDHZ26JWjHdorBZtVIqMK1SIyW4Dih5c/Y//w2toA8WBTPILIvt4h6HPPvWZMZCHCqom9D2k4WGH5+BCEY2jHI7gfYV6xRx54i5vitsYTKm3CyA0C5+l0FNDkfUFHDvVUG9FVzRWVd0TXYhDwfa2pcfI68eYvkEfeT+ZNJ24ZXKPrJo6KZ3x6eZAhzgAMFiC+tPsiygb2zQy5PVoYoBIGj/NGNRqmhZTOEajcO3ZjWxfAnLZAmvMi+pEwJCMmuIY4qRU3RfcaXhAoaUPpDxqrSxR1m+CUKYVdt3nnnQeVaVqf+RaeV9cyFJvILeBPXTBVC50AckVLS37UuBWgWaWcchjRPk9mriDu2KlHQwdR4zu0jnLh4i3tbxV416QBcYLO6AF2Ixlm3GzqGE6QcVssgFCUAhklBWGNLP62O1jtyV4NgTD36QhvHEHby7o4XBB+mjlY6xSEXR+IW9u64AzfDCsTxWiAOE65le6cSk4NDV8DrtYeIozILivWu6wFSpy1gMfiDot4Ndv3C9xCFvH0Bzlky7NoZrvSolKTVNTs8W8UqMFV19qGl6SRaNUEhCqgso/FkdO0eGXFMdQPuP11wQzK/9F3yB9gS2rpXi9sy8DrCqnJ9EXMmliSstKuQl5+yfGc8K3Urot3t+BmNoOvzM9Aha/PzmbLnuKBN6/DUbIw5mhNMCvIA1ByispKpjeV682jl4uslkRsitGLcIOBREFXvGaLxRb37HJkXCHk+jorpDz7LUQhVkClN+hW0vXtgdHQFCIOL7uREdbvk6BZbQlFsuVEKGZxPbKPEJfqMbH54B4a4P5XNQHm4Yt4haH4T0JuYgzoSo76uuXD3g5IuUvy7x8Ykuja1rwW/k//SZAiGaZraRIIAEnzHiUP8dcufb/RonHGnJcYXIEWeIF1lX980bDA+H4vlO8/nN/Mj+EL6tT95MfRDiQHUW69qkqotQd7FJ5uWT+NtetzqDsN5s3sIhwkLKIn9EDLIav5v4SXKxkG+ycMJmGFcfhs7Td9O6hl+Om/JD3he3rgfClaFi/ZR7AVY6fWbAAm9QftKijQ6rskPDYL9Y3gVSA9rdduSg97fUHC+FdfyQXGH552cDLs2ZgzYw6KluXHEuwhACgNotxToPYTTdZxxNr1vPoqYCqHDL2dL8dkuO59/sbZE1m4ektKvUC2wz0UdTDVbHN8HSrLPn2hf/xQp5bKeDDjYkWvNKuwy+aug9H+Uu/m1LuPK/YdogVv9l25y/c2Qbj3dAJ9xTuKjmiJLKlRh4SUI9+05HjDF+i84AoUZ8LuC7LGtrN8ReYIktLhaXq9+XDh5fv4NYhnuYgWkUioKtx1dmfOMHjpLm4aE8Ra1gpJQcZAgwnqYubQvnYy0nY4VaykNix7m3vZwItpKOLqxDYxa3q0qUw25X9zafAM61kPW6EP+4idPzHNww6r1FD4Ihq644dCnCXwoSQ531DW6oAPot8iLZ/xXwoWwrW05k9t2RHjjLbw1L5r1CKgShJQfX7nkJxfGyuw1RmqoQDuNt/tj9M/dHOnoPnOYZZN0JX+Al8PI5zs+LLajw1imu9YcSpwMz3ZlfQqTfI0fjSCc8Is6qVYDMvKD0TweY4hiIxkzs+RyQmPgIeIWqf7Su5+RcnXitb3OuFibBGCjdDeG0ESG8qeiBQKZ3wEyZG09eDAfhuUR5kfZCG4Q01u2YDoRzObxLd8Ruf7HNvtefucFLubciWvOSzbDUisoz0wwOSgJGHucC3IR+1mb/4gz/dI2wvWFInhKcQz4ivkuHaFj8XwvZMcpkwPKtg3pRGTleX/gfjbHcx2VcWRcMPdlDMgTgst9ouN763TZUHHLxjECyB9pkLrR1nhG0cS/aig8Bq1+AH7tvl1wLVxm1Z77DVX4aUIxBH2YUcOgpe6mrWFi6LK3im4/grZECsL/XC4tsTEHjO/U3SazUuhP+6LiCYqp50+3zZf3RpWlxZoYjm5SJ9VIWabocO/Ef26G38lKottW1XsSQUan7myYFFyeyon2hnufzMuxpyXTJ7TLekXCi2gLYbGjldgiRmGShPXzSar+hC2"); - $op->setDataKey("JxAB39A9yUsf6wMD0jwGKCuY7mmzWaeEj85MH02AfKGUxOkJ00JK+o8vGG55cUF9voYU4QQ1Jec4p6nKmsxXmTREEaJwmQErotD4fpcFOyoqWTLMZfslrkHgiqbwru/V"); - $paymentOne = new AnetAPI\PaymentType(); - $paymentOne->setOpaqueData($op); - - //create a transaction - $transactionRequestType = new AnetAPI\TransactionRequestType(); - $transactionRequestType->setTransactionType( "authCaptureTransaction"); - $transactionRequestType->setAmount(151); - $transactionRequestType->setCallId("9004180129978687101"); - $transactionRequestType->setPayment($paymentOne); - - $request = new AnetAPI\CreateTransactionRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setRefId( $refId); - $request->setTransactionRequest( $transactionRequestType); - - $controller = new AnetController\CreateTransactionController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - - if ($response != null) - { - $tresponse = $response->getTransactionResponse(); - - if (($tresponse != null) && ($tresponse->getResponseCode()=="1") ) - { - echo " AUTH CODE : " . $tresponse->getAuthCode() . "\n"; - echo " TRANS ID : " . $tresponse->getTransId() . "\n"; - } - else - { - echo "BAD NEWS : " . $tresponse->getResponseCode() . "\n"; - } - - } - else - { - echo "REALLY BAD NEWS : "; - } - -?> diff --git a/VisaCheckout/create-visa-src-transaction.php b/VisaCheckout/create-visa-src-transaction.php new file mode 100644 index 0000000..1edcf11 --- /dev/null +++ b/VisaCheckout/create-visa-src-transaction.php @@ -0,0 +1,93 @@ +setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); + + // Create the payment data from a Visa Checkout blob + $op = new AnetAPI\OpaqueDataType(); + $op->setDataDescriptor("COMMON.VCO.ONLINE.PAYMENT"); + $op->setDataValue("4Ng5pzJ6DXfAvLSzVauN9KTufx5lTHhFlnuIr248N3fjtyHrHqMuhOkB1BLiSjKWeTM9+BNj3+9nY56d7CsUfIuvVSTaJRhQQSex1dS2Y2Y+/cA5U+3D1pg5YtTmDVUGlsu1simAd3huwPnwD+CG6O8Ml0AmXvYHntmL3vFaJomadMQBy27k8Dbh5eplPBwyawKUVJ7GqTyKLe8aOYkBUHT5ANWkq2hlGps44BOoDHZ26JWjHdorBZtVIqMK1SIyW4Dih5c/Y//w2toA8WBTPILIvt4h6HPPvWZMZCHCqom9D2k4WGH5+BCEY2jHI7gfYV6xRx54i5vitsYTKm3CyA0C5+l0FNDkfUFHDvVUG9FVzRWVd0TXYhDwfa2pcfI68eYvkEfeT+ZNJ24ZXKPrJo6KZ3x6eZAhzgAMFiC+tPsiygb2zQy5PVoYoBIGj/NGNRqmhZTOEajcO3ZjWxfAnLZAmvMi+pEwJCMmuIY4qRU3RfcaXhAoaUPpDxqrSxR1m+CUKYVdt3nnnQeVaVqf+RaeV9cyFJvILeBPXTBVC50AckVLS37UuBWgWaWcchjRPk9mriDu2KlHQwdR4zu0jnLh4i3tbxV416QBcYLO6AF2Ixlm3GzqGE6QcVssgFCUAhklBWGNLP62O1jtyV4NgTD36QhvHEHby7o4XBB+mjlY6xSEXR+IW9u64AzfDCsTxWiAOE65le6cSk4NDV8DrtYeIozILivWu6wFSpy1gMfiDot4Ndv3C9xCFvH0Bzlky7NoZrvSolKTVNTs8W8UqMFV19qGl6SRaNUEhCqgso/FkdO0eGXFMdQPuP11wQzK/9F3yB9gS2rpXi9sy8DrCqnJ9EXMmliSstKuQl5+yfGc8K3Urot3t+BmNoOvzM9Aha/PzmbLnuKBN6/DUbIw5mhNMCvIA1ByispKpjeV682jl4uslkRsitGLcIOBREFXvGaLxRb37HJkXCHk+jorpDz7LUQhVkClN+hW0vXtgdHQFCIOL7uREdbvk6BZbQlFsuVEKGZxPbKPEJfqMbH54B4a4P5XNQHm4Yt4haH4T0JuYgzoSo76uuXD3g5IuUvy7x8Ykuja1rwW/k//SZAiGaZraRIIAEnzHiUP8dcufb/RonHGnJcYXIEWeIF1lX980bDA+H4vlO8/nN/Mj+EL6tT95MfRDiQHUW69qkqotQd7FJ5uWT+NtetzqDsN5s3sIhwkLKIn9EDLIav5v4SXKxkG+ycMJmGFcfhs7Td9O6hl+Om/JD3he3rgfClaFi/ZR7AVY6fWbAAm9QftKijQ6rskPDYL9Y3gVSA9rdduSg97fUHC+FdfyQXGH552cDLs2ZgzYw6KluXHEuwhACgNotxToPYTTdZxxNr1vPoqYCqHDL2dL8dkuO59/sbZE1m4ektKvUC2wz0UdTDVbHN8HSrLPn2hf/xQp5bKeDDjYkWvNKuwy+aug9H+Uu/m1LuPK/YdogVv9l25y/c2Qbj3dAJ9xTuKjmiJLKlRh4SUI9+05HjDF+i84AoUZ8LuC7LGtrN8ReYIktLhaXq9+XDh5fv4NYhnuYgWkUioKtx1dmfOMHjpLm4aE8Ra1gpJQcZAgwnqYubQvnYy0nY4VaykNix7m3vZwItpKOLqxDYxa3q0qUw25X9zafAM61kPW6EP+4idPzHNww6r1FD4Ihq644dCnCXwoSQ531DW6oAPot8iLZ/xXwoWwrW05k9t2RHjjLbw1L5r1CKgShJQfX7nkJxfGyuw1RmqoQDuNt/tj9M/dHOnoPnOYZZN0JX+Al8PI5zs+LLajw1imu9YcSpwMz3ZlfQqTfI0fjSCc8Is6qVYDMvKD0TweY4hiIxkzs+RyQmPgIeIWqf7Su5+RcnXitb3OuFibBGCjdDeG0ESG8qeiBQKZ3wEyZG09eDAfhuUR5kfZCG4Q01u2YDoRzObxLd8Ruf7HNvtefucFLubciWvOSzbDUisoz0wwOSgJGHucC3IR+1mb/4gz/dI2wvWFInhKcQz4ivkuHaFj8XwvZMcpkwPKtg3pRGTleX/gfjbHcx2VcWRcMPdlDMgTgst9ouN763TZUHHLxjECyB9pkLrR1nhG0cS/aig8Bq1+AH7tvl1wLVxm1Z77DVX4aUIxBH2YUcOgpe6mrWFi6LK3im4/grZECsL/XC4tsTEHjO/U3SazUuhP+6LiCYqp50+3zZf3RpWlxZoYjm5SJ9VIWabocO/Ef26G38lKottW1XsSQUan7myYFFyeyon2hnufzMuxpyXTJ7TLekXCi2gLYbGjldgiRmGShPXzSar+hC2"); + $op->setDataKey("JxAB39A9yUsf6wMD0jwGKCuY7mmzWaeEj85MH02AfKGUxOkJ00JK+o8vGG55cUF9voYU4QQ1Jec4p6nKmsxXmTREEaJwmQErotD4fpcFOyoqWTLMZfslrkHgiqbwru/V"); + $paymentOne = new AnetAPI\PaymentType(); + $paymentOne->setOpaqueData($op); + + //create a transaction + $transactionRequestType = new AnetAPI\TransactionRequestType(); + $transactionRequestType->setTransactionType( "authCaptureTransaction"); + $transactionRequestType->setAmount(76); + $transactionRequestType->setCallId("9004180129978687101"); + $transactionRequestType->setPayment($paymentOne); + + $request = new AnetAPI\CreateTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId( $refId); + $request->setTransactionRequest( $transactionRequestType); + + $controller = new AnetController\CreateTransactionController($request); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if ($response != null) + { + if($response->getMessages()->getResultCode() == "Ok") + { + $tresponse = $response->getTransactionResponse(); + if ($tresponse != null && $tresponse->getMessages() != null) + { + echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n"; + echo " AUTH CODE : " . $tresponse->getAuthCode() . "\n"; + echo " TRANS ID : " . $tresponse->getTransId() . "\n"; + echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } + else + { + echo "Transaction Failed \n"; + if($tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + } + else + { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); + if($tresponse != null && $tresponse->getErrors() != null) + { + echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + else + { + echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } + } + else + { + echo "No response returned \n"; + } + + return $response; + } + + if(!defined('DONT_RUN_SAMPLES')) + createVisaSrcTransaction(); + +?> diff --git a/VisaCheckout/decrypt-visa-checkout-data.php b/VisaCheckout/decrypt-visa-checkout-data.php deleted file mode 100644 index fbc0a38..0000000 --- a/VisaCheckout/decrypt-visa-checkout-data.php +++ /dev/null @@ -1,41 +0,0 @@ -setName("5KP3u95bQpv"); - $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); - $refId = 'ref' . time(); - - // Create the payment data from a Visa Checkout blob - $op = new AnetAPI\OpaqueDataType(); - $op->setDataDescriptor("COMMON.VCO.ONLINE.PAYMENT"); - $op->setDataValue("4Ng5pzJ6DXfAvLSzVauN9KTufx5lTHhFlnuIr248N3fjtyHrHqMuhOkB1BLiSjKWeTM9+BNj3+9nY56d7CsUfIuvVSTaJRhQQSex1dS2Y2Y+/cA5U+3D1pg5YtTmDVUGlsu1simAd3huwPnwD+CG6O8Ml0AmXvYHntmL3vFaJomadMQBy27k8Dbh5eplPBwyawKUVJ7GqTyKLe8aOYkBUHT5ANWkq2hlGps44BOoDHZ26JWjHdorBZtVIqMK1SIyW4Dih5c/Y//w2toA8WBTPILIvt4h6HPPvWZMZCHCqom9D2k4WGH5+BCEY2jHI7gfYV6xRx54i5vitsYTKm3CyA0C5+l0FNDkfUFHDvVUG9FVzRWVd0TXYhDwfa2pcfI68eYvkEfeT+ZNJ24ZXKPrJo6KZ3x6eZAhzgAMFiC+tPsiygb2zQy5PVoYoBIGj/NGNRqmhZTOEajcO3ZjWxfAnLZAmvMi+pEwJCMmuIY4qRU3RfcaXhAoaUPpDxqrSxR1m+CUKYVdt3nnnQeVaVqf+RaeV9cyFJvILeBPXTBVC50AckVLS37UuBWgWaWcchjRPk9mriDu2KlHQwdR4zu0jnLh4i3tbxV416QBcYLO6AF2Ixlm3GzqGE6QcVssgFCUAhklBWGNLP62O1jtyV4NgTD36QhvHEHby7o4XBB+mjlY6xSEXR+IW9u64AzfDCsTxWiAOE65le6cSk4NDV8DrtYeIozILivWu6wFSpy1gMfiDot4Ndv3C9xCFvH0Bzlky7NoZrvSolKTVNTs8W8UqMFV19qGl6SRaNUEhCqgso/FkdO0eGXFMdQPuP11wQzK/9F3yB9gS2rpXi9sy8DrCqnJ9EXMmliSstKuQl5+yfGc8K3Urot3t+BmNoOvzM9Aha/PzmbLnuKBN6/DUbIw5mhNMCvIA1ByispKpjeV682jl4uslkRsitGLcIOBREFXvGaLxRb37HJkXCHk+jorpDz7LUQhVkClN+hW0vXtgdHQFCIOL7uREdbvk6BZbQlFsuVEKGZxPbKPEJfqMbH54B4a4P5XNQHm4Yt4haH4T0JuYgzoSo76uuXD3g5IuUvy7x8Ykuja1rwW/k//SZAiGaZraRIIAEnzHiUP8dcufb/RonHGnJcYXIEWeIF1lX980bDA+H4vlO8/nN/Mj+EL6tT95MfRDiQHUW69qkqotQd7FJ5uWT+NtetzqDsN5s3sIhwkLKIn9EDLIav5v4SXKxkG+ycMJmGFcfhs7Td9O6hl+Om/JD3he3rgfClaFi/ZR7AVY6fWbAAm9QftKijQ6rskPDYL9Y3gVSA9rdduSg97fUHC+FdfyQXGH552cDLs2ZgzYw6KluXHEuwhACgNotxToPYTTdZxxNr1vPoqYCqHDL2dL8dkuO59/sbZE1m4ektKvUC2wz0UdTDVbHN8HSrLPn2hf/xQp5bKeDDjYkWvNKuwy+aug9H+Uu/m1LuPK/YdogVv9l25y/c2Qbj3dAJ9xTuKjmiJLKlRh4SUI9+05HjDF+i84AoUZ8LuC7LGtrN8ReYIktLhaXq9+XDh5fv4NYhnuYgWkUioKtx1dmfOMHjpLm4aE8Ra1gpJQcZAgwnqYubQvnYy0nY4VaykNix7m3vZwItpKOLqxDYxa3q0qUw25X9zafAM61kPW6EP+4idPzHNww6r1FD4Ihq644dCnCXwoSQ531DW6oAPot8iLZ/xXwoWwrW05k9t2RHjjLbw1L5r1CKgShJQfX7nkJxfGyuw1RmqoQDuNt/tj9M/dHOnoPnOYZZN0JX+Al8PI5zs+LLajw1imu9YcSpwMz3ZlfQqTfI0fjSCc8Is6qVYDMvKD0TweY4hiIxkzs+RyQmPgIeIWqf7Su5+RcnXitb3OuFibBGCjdDeG0ESG8qeiBQKZ3wEyZG09eDAfhuUR5kfZCG4Q01u2YDoRzObxLd8Ruf7HNvtefucFLubciWvOSzbDUisoz0wwOSgJGHucC3IR+1mb/4gz/dI2wvWFInhKcQz4ivkuHaFj8XwvZMcpkwPKtg3pRGTleX/gfjbHcx2VcWRcMPdlDMgTgst9ouN763TZUHHLxjECyB9pkLrR1nhG0cS/aig8Bq1+AH7tvl1wLVxm1Z77DVX4aUIxBH2YUcOgpe6mrWFi6LK3im4/grZECsL/XC4tsTEHjO/U3SazUuhP+6LiCYqp50+3zZf3RpWlxZoYjm5SJ9VIWabocO/Ef26G38lKottW1XsSQUan7myYFFyeyon2hnufzMuxpyXTJ7TLekXCi2gLYbGjldgiRmGShPXzSar+hC2"); - $op->setDataKey("JxAB39A9yUsf6wMD0jwGKCuY7mmzWaeEj85MH02AfKGUxOkJ00JK+o8vGG55cUF9voYU4QQ1Jec4p6nKmsxXmTREEaJwmQErotD4fpcFOyoqWTLMZfslrkHgiqbwru/V"); - - //create a decrypt request - $decryptRequest = new AnetAPI\DecryptPaymentDataRequest(); - $decryptRequest->setRefId( $refId); - $decryptRequest->setMerchantAuthentication($merchantAuthentication); - $decryptRequest->setOpaqueData($op); - $decryptRequest->setCallId("9004180129978687101"); - - - $controller = new AnetController\DecryptPaymentDataController($decryptRequest); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - - if ($response != null) - { - if ($response->getMessages()->getResultCode() == "Ok") - { - echo "Card Number : " . $response->getCardInfo()->getCardNumber() . "\n"; - echo "Amount : " . $response->getPaymentDetails()->getAmount() . "\n"; - } - } - -?> diff --git a/VisaCheckout/decrypt-visa-src-data.php b/VisaCheckout/decrypt-visa-src-data.php new file mode 100644 index 0000000..2b2b791 --- /dev/null +++ b/VisaCheckout/decrypt-visa-src-data.php @@ -0,0 +1,51 @@ +setName(\SampleCodeConstants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); + + // Create the payment data from a Visa Checkout blob + $op = new AnetAPI\OpaqueDataType(); + $op->setDataDescriptor("COMMON.VCO.ONLINE.PAYMENT"); + $op->setDataValue("4Ng5pzJ6DXfAvLSzVauN9KTufx5lTHhFlnuIr248N3fjtyHrHqMuhOkB1BLiSjKWeTM9+BNj3+9nY56d7CsUfIuvVSTaJRhQQSex1dS2Y2Y+/cA5U+3D1pg5YtTmDVUGlsu1simAd3huwPnwD+CG6O8Ml0AmXvYHntmL3vFaJomadMQBy27k8Dbh5eplPBwyawKUVJ7GqTyKLe8aOYkBUHT5ANWkq2hlGps44BOoDHZ26JWjHdorBZtVIqMK1SIyW4Dih5c/Y//w2toA8WBTPILIvt4h6HPPvWZMZCHCqom9D2k4WGH5+BCEY2jHI7gfYV6xRx54i5vitsYTKm3CyA0C5+l0FNDkfUFHDvVUG9FVzRWVd0TXYhDwfa2pcfI68eYvkEfeT+ZNJ24ZXKPrJo6KZ3x6eZAhzgAMFiC+tPsiygb2zQy5PVoYoBIGj/NGNRqmhZTOEajcO3ZjWxfAnLZAmvMi+pEwJCMmuIY4qRU3RfcaXhAoaUPpDxqrSxR1m+CUKYVdt3nnnQeVaVqf+RaeV9cyFJvILeBPXTBVC50AckVLS37UuBWgWaWcchjRPk9mriDu2KlHQwdR4zu0jnLh4i3tbxV416QBcYLO6AF2Ixlm3GzqGE6QcVssgFCUAhklBWGNLP62O1jtyV4NgTD36QhvHEHby7o4XBB+mjlY6xSEXR+IW9u64AzfDCsTxWiAOE65le6cSk4NDV8DrtYeIozILivWu6wFSpy1gMfiDot4Ndv3C9xCFvH0Bzlky7NoZrvSolKTVNTs8W8UqMFV19qGl6SRaNUEhCqgso/FkdO0eGXFMdQPuP11wQzK/9F3yB9gS2rpXi9sy8DrCqnJ9EXMmliSstKuQl5+yfGc8K3Urot3t+BmNoOvzM9Aha/PzmbLnuKBN6/DUbIw5mhNMCvIA1ByispKpjeV682jl4uslkRsitGLcIOBREFXvGaLxRb37HJkXCHk+jorpDz7LUQhVkClN+hW0vXtgdHQFCIOL7uREdbvk6BZbQlFsuVEKGZxPbKPEJfqMbH54B4a4P5XNQHm4Yt4haH4T0JuYgzoSo76uuXD3g5IuUvy7x8Ykuja1rwW/k//SZAiGaZraRIIAEnzHiUP8dcufb/RonHGnJcYXIEWeIF1lX980bDA+H4vlO8/nN/Mj+EL6tT95MfRDiQHUW69qkqotQd7FJ5uWT+NtetzqDsN5s3sIhwkLKIn9EDLIav5v4SXKxkG+ycMJmGFcfhs7Td9O6hl+Om/JD3he3rgfClaFi/ZR7AVY6fWbAAm9QftKijQ6rskPDYL9Y3gVSA9rdduSg97fUHC+FdfyQXGH552cDLs2ZgzYw6KluXHEuwhACgNotxToPYTTdZxxNr1vPoqYCqHDL2dL8dkuO59/sbZE1m4ektKvUC2wz0UdTDVbHN8HSrLPn2hf/xQp5bKeDDjYkWvNKuwy+aug9H+Uu/m1LuPK/YdogVv9l25y/c2Qbj3dAJ9xTuKjmiJLKlRh4SUI9+05HjDF+i84AoUZ8LuC7LGtrN8ReYIktLhaXq9+XDh5fv4NYhnuYgWkUioKtx1dmfOMHjpLm4aE8Ra1gpJQcZAgwnqYubQvnYy0nY4VaykNix7m3vZwItpKOLqxDYxa3q0qUw25X9zafAM61kPW6EP+4idPzHNww6r1FD4Ihq644dCnCXwoSQ531DW6oAPot8iLZ/xXwoWwrW05k9t2RHjjLbw1L5r1CKgShJQfX7nkJxfGyuw1RmqoQDuNt/tj9M/dHOnoPnOYZZN0JX+Al8PI5zs+LLajw1imu9YcSpwMz3ZlfQqTfI0fjSCc8Is6qVYDMvKD0TweY4hiIxkzs+RyQmPgIeIWqf7Su5+RcnXitb3OuFibBGCjdDeG0ESG8qeiBQKZ3wEyZG09eDAfhuUR5kfZCG4Q01u2YDoRzObxLd8Ruf7HNvtefucFLubciWvOSzbDUisoz0wwOSgJGHucC3IR+1mb/4gz/dI2wvWFInhKcQz4ivkuHaFj8XwvZMcpkwPKtg3pRGTleX/gfjbHcx2VcWRcMPdlDMgTgst9ouN763TZUHHLxjECyB9pkLrR1nhG0cS/aig8Bq1+AH7tvl1wLVxm1Z77DVX4aUIxBH2YUcOgpe6mrWFi6LK3im4/grZECsL/XC4tsTEHjO/U3SazUuhP+6LiCYqp50+3zZf3RpWlxZoYjm5SJ9VIWabocO/Ef26G38lKottW1XsSQUan7myYFFyeyon2hnufzMuxpyXTJ7TLekXCi2gLYbGjldgiRmGShPXzSar+hC2"); + $op->setDataKey("JxAB39A9yUsf6wMD0jwGKCuY7mmzWaeEj85MH02AfKGUxOkJ00JK+o8vGG55cUF9voYU4QQ1Jec4p6nKmsxXmTREEaJwmQErotD4fpcFOyoqWTLMZfslrkHgiqbwru/V"); + + //create a decrypt request + $decryptRequest = new AnetAPI\DecryptPaymentDataRequest(); + $decryptRequest->setRefId( $refId); + $decryptRequest->setMerchantAuthentication($merchantAuthentication); + $decryptRequest->setOpaqueData($op); + $decryptRequest->setCallId("9004180129978687101"); + + + $controller = new AnetController\DecryptPaymentDataController($decryptRequest); + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if ($response != null) + { + if ($response->getMessages()->getResultCode() == "Ok") + { + echo "Card Number : " . $response->getCardInfo()->getCardNumber() . "\n"; + echo "Amount : " . $response->getPaymentDetails()->getAmount() . "\n"; + } + } + return $response; + } + + if(!defined('DONT_RUN_SAMPLES')) + decryptVisaSrcData(); + +?> diff --git a/composer.json b/composer.json index c849bec..08f03a6 100644 --- a/composer.json +++ b/composer.json @@ -1,18 +1,7 @@ { - "require": { - "php": ">=5.2.0", + "php": ">=5.6", "ext-curl": "*", - "authorizenet/authorizenet": "1.8.6.2", - "jms/serializer": "xsd2php-dev as 0.18.0" -}, -"require-dev": { - "goetas/xsd2php": "2.*@dev", - "goetas/xsd-reader": "2.*@dev" -}, -"repositories": [{ - "type": "vcs", - "url": "https://github.com/goetas/serializer.git" - }] - + "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/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/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..19a10f4 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,43 @@ + + + + + + . + + + + + + ./lib + + ./vendor + ./tests + ./build + + + + + + + + + + + + + + + + + + + + + + + +