From 3829dc610ce4829a76342393260840f4d2939e3c Mon Sep 17 00:00:00 2001 From: adavidw Date: Mon, 15 May 2017 12:14:35 -0600 Subject: [PATCH 1/5] formatting and comments --- .../create-customer-payment-profile.php | 123 +++++++++------- ...eate-customer-profile-from-transaction.php | 16 ++- ...ate-customer-profile-with-accept-nonce.php | 136 ++++++++++-------- CustomerProfiles/create-customer-profile.php | 136 ++++++++++-------- .../create-an-accept-transaction.php | 95 ++++++------ .../create-an-accept-payment-transaction.php | 99 ++++++------- 6 files changed, 315 insertions(+), 290 deletions(-) diff --git a/CustomerProfiles/create-customer-payment-profile.php b/CustomerProfiles/create-customer-payment-profile.php index b61c8d4..8829ef6 100644 --- a/CustomerProfiles/create-customer-payment-profile.php +++ b/CustomerProfiles/create-customer-payment-profile.php @@ -1,68 +1,83 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - $refId = 'ref' . time(); +function createCustomerPaymentProfile($existingcustomerprofileid, $phoneNumber){ + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); + + // Create a Customer Profile Request + // 1. (Optionally) create a Payment Profile + // 2. (Optionally) create a Shipping Profile + // 3. Create a Customer Profile (or specify an existing profile) + // 4. Submit a CreateCustomerProfile Request + // 5. Validate Profile ID returned + + // Set credit card information for payment profile + $creditCard = new AnetAPI\CreditCardType(); + $creditCard->setCardNumber("4242424242424242"); + $creditCard->setExpirationDate("2038-12"); + $creditCard->setCardCode("142"); + $paymentCreditCard = new AnetAPI\PaymentType(); + $paymentCreditCard->setCreditCard($creditCard); + + // Create the Bill To info for new payment type + $billto = new AnetAPI\CustomerAddressType(); + $billto->setFirstName("Ellen"); + $billto->setLastName("Johnson"); + $billto->setCompany("Souveniropolis"); + $billto->setAddress("14 Main Street"); + $billto->setCity("Pecan Springs"); + $billto->setState("TX"); + $billto->setZip("44628"); + $billto->setCountry("USA"); + $billto->setPhoneNumber($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); - $creditCard = new AnetAPI\CreditCardType(); - $creditCard->setCardNumber( "4242424242424242"); - $creditCard->setExpirationDate( "2038-12"); - $creditCard->setCardCode( "142"); - $paymentCreditCard = new AnetAPI\PaymentType(); - $paymentCreditCard->setCreditCard($creditCard); + // Add an existing profile id to the request + $paymentprofilerequest->setCustomerProfileId( $existingcustomerprofileid ); + $paymentprofilerequest->setPaymentProfile( $paymentprofile ); + $paymentprofilerequest->setValidationMode("liveMode"); - // Create the Bill To info for new payment type - $billto = new AnetAPI\CustomerAddressType(); - $billto->setFirstName("Mrs Mary".$phoneNumber); - $billto->setLastName("Doe"); - $billto->setCompany("My company"); - $billto->setAddress("123 Main St."); - $billto->setCity("Bellevue"); - $billto->setState("WA"); - $billto->setZip("98004"); - $billto->setPhoneNumber($phoneNumber); - $billto->setfaxNumber("999-999-9999"); - $billto->setCountry("USA"); + // Create the controller and get the response + $controller = new AnetController\CreateCustomerPaymentProfileController($paymentprofilerequest); + $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); - // Create a new Customer Payment Profile - $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); - $paymentprofile->setCustomerType('individual'); - $paymentprofile->setBillTo($billto); - $paymentprofile->setPayment($paymentCreditCard); - $paymentprofile->setDefaultPaymentProfile(true); + 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"; - $paymentprofiles[] = $paymentprofile; + } + return $response; +} - // Submit a CreateCustomerPaymentProfileRequest to create a new Customer Payment Profile - $paymentprofilerequest = new AnetAPI\CreateCustomerPaymentProfileRequest(); - $paymentprofilerequest->setMerchantAuthentication($merchantAuthentication); - //Use an existing profile id - $paymentprofilerequest->setCustomerProfileId( $existingcustomerprofileid ); - $paymentprofilerequest->setPaymentProfile( $paymentprofile ); - $paymentprofilerequest->setValidationMode("liveMode"); - $controller = new AnetController\CreateCustomerPaymentProfileController($paymentprofilerequest); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - echo "Create Customer Payment Profile SUCCESS: " . $response->getCustomerPaymentProfileId() . "\n"; - } - else - { - echo "Create Customer Payment Profile: ERROR Invalid response\n"; - $errorMessages = $response->getMessages()->getMessage(); - echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; - - } - return $response; - } - if(!defined('DONT_RUN_SAMPLES')) +if (!defined('DONT_RUN_SAMPLES')) { createCustomerPaymentProfile("1807545561","000-000-0009"); +} ?> diff --git a/CustomerProfiles/create-customer-profile-from-transaction.php b/CustomerProfiles/create-customer-profile-from-transaction.php index 86683e6..2759481 100644 --- a/CustomerProfiles/create-customer-profile-from-transaction.php +++ b/CustomerProfiles/create-customer-profile-from-transaction.php @@ -5,12 +5,16 @@ define("AUTHORIZENET_LOG_FILE", "phplog"); - function createCustomerProfileFromTransaction($transId= "2249066517") - { - // Common setup for API credentials - $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); - $merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); +function createCustomerProfileFromTransaction($transId= "2249066517"){ +{ + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); $customerProfile = new AnetAPI\CustomerProfileBaseType(); $customerProfile->setMerchantCustomerId("123212"); diff --git a/CustomerProfiles/create-customer-profile-with-accept-nonce.php b/CustomerProfiles/create-customer-profile-with-accept-nonce.php index 41ab983..f5b0213 100644 --- a/CustomerProfiles/create-customer-profile-with-accept-nonce.php +++ b/CustomerProfiles/create-customer-profile-with-accept-nonce.php @@ -1,75 +1,89 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - $refId = 'ref' . time(); +function createCustomerProfileWithAcceptNonce($email){ + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCode\Constants::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($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($paymentOne); + $paymentprofile->setDefaultPaymentProfile(true); + + $paymentprofiles[] = $paymentprofile; - // Create the payment data for an accept token - $op = new AnetAPI\OpaqueDataType(); - $op->setDataDescriptor("COMMON.ACCEPT.INAPP.PAYMENT"); - $op->setDataValue("9475089993864215505001"); - $paymentOne = new AnetAPI\PaymentType(); - $paymentOne->setOpaqueData($op); + // Create a new CustomerProfileType and add the payment profile object + $customerprofile = new AnetAPI\CustomerProfileType(); + $customerprofile->setDescription("Customer Test PHP Accept Test"); - // 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 + $customerprofile->setMerchantCustomerId("M_".$email); + $customerprofile->setEmail($email); + $customerprofile->setPaymentProfiles($paymentprofiles); - $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); + // Assemble the complete transaction request + $request = new AnetAPI\CreateCustomerProfileRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId($refId); + $request->setProfile($customerprofile); - $paymentprofile->setCustomerType('individual'); - $paymentprofile->setBillTo($billto); - $paymentprofile->setPayment($paymentOne); - $paymentprofiles[] = $paymentprofile; - $customerprofile = new AnetAPI\CustomerProfileType(); - $customerprofile->setDescription("Customer Test PHP Accept Test"); + // Create the controller and get the response + $controller = new AnetController\CreateCustomerProfileController($request); + $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); - $customerprofile->setMerchantCustomerId("M_".$email); - $customerprofile->setEmail($email); - $customerprofile->setPaymentProfiles($paymentprofiles); + 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 "Succesfully create customer profile : " . $response->getCustomerProfileId() . "\n"; - $paymentProfiles = $response->getCustomerPaymentProfileIdList(); - echo "SUCCESS: PAYMENT PROFILE ID : " . $paymentProfiles[0] . "\n"; - } - else - { - echo "ERROR : Invalid response\n"; - $errorMessages = $response->getMessages()->getMessage(); - echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; - } - return $response; - } - if(!defined('DONT_RUN_SAMPLES')) - createCustomerProfileWithAcceptNonce("test123@test.com"); +if (!defined('DONT_RUN_SAMPLES')) { + createCustomerProfileWithAcceptNonce("test123@test.com"); +} ?> diff --git a/CustomerProfiles/create-customer-profile.php b/CustomerProfiles/create-customer-profile.php index ffaf655..02d0d59 100644 --- a/CustomerProfiles/create-customer-profile.php +++ b/CustomerProfiles/create-customer-profile.php @@ -1,75 +1,89 @@ setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - $refId = 'ref' . time(); +function createCustomerProfile($email){ + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); + + // Set the transaction's refId + $refId = 'ref' . time(); + + // Create a Customer Profile Request + // 1. (Optionally) create a Payment Profile + // 2. (Optionally) create a Shipping Profile + // 3. Create a Customer Profile (or specify an existing profile) + // 4. Submit a CreateCustomerProfile Request + // 5. Validate Profile ID returned + + // Set credit card information for payment profile + $creditCard = new AnetAPI\CreditCardType(); + $creditCard->setCardNumber("4242424242424242"); + $creditCard->setExpirationDate("2038-12"); + $creditCard->setCardCode("142"); + $paymentCreditCard = new AnetAPI\PaymentType(); + $paymentCreditCard->setCreditCard($creditCard); + + // Create the Bill To info for new payment type + $billto = new AnetAPI\CustomerAddressType(); + $billto->setFirstName("Ellen"); + $billto->setLastName("Johnson"); + $billto->setCompany("Souveniropolis"); + $billto->setAddress("14 Main Street"); + $billto->setCity("Pecan Springs"); + $billto->setState("TX"); + $billto->setZip("44628"); + $billto->setCountry("USA"); + $billto->setPhoneNumber($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($paymentOne); + $paymentprofile->setDefaultPaymentProfile(true); - // 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); + $paymentprofiles[] = $paymentprofile; - // 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 new CustomerProfileType and add the payment profile object + $customerprofile = new AnetAPI\CustomerProfileType(); + $customerprofile->setDescription("Customer 2 Test PHP"); - $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); + $customerprofile->setMerchantCustomerId("M_".$email); + $customerprofile->setEmail($email); + $customerprofile->setPaymentProfiles($paymentprofiles); - $paymentprofile->setCustomerType('individual'); - $paymentprofile->setBillTo($billto); - $paymentprofile->setPayment($paymentCreditCard); - $paymentprofiles[] = $paymentprofile; - $customerprofile = new AnetAPI\CustomerProfileType(); - $customerprofile->setDescription("Customer 2 Test PHP"); + // Assemble the complete transaction request + $request = new AnetAPI\CreateCustomerProfileRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setRefId($refId); + $request->setProfile($customerprofile); - $customerprofile->setMerchantCustomerId("M_".$email); - $customerprofile->setEmail($email); - $customerprofile->setPaymentProfiles($paymentprofiles); + // 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 "Succesfully create customer profile : " . $response->getCustomerProfileId() . "\n"; - $paymentProfiles = $response->getCustomerPaymentProfileIdList(); - echo "SUCCESS: PAYMENT PROFILE ID : " . $paymentProfiles[0] . "\n"; - } - else - { - echo "ERROR : Invalid response\n"; - $errorMessages = $response->getMessages()->getMessage(); - echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; - } - return $response; - } - if(!defined('DONT_RUN_SAMPLES')) - createCustomerProfile("test123@test.com"); +if (!defined('DONT_RUN_SAMPLES')) { + createCustomerProfile("test123@test.com"); +} ?> diff --git a/MobileInappTransactions/create-an-accept-transaction.php b/MobileInappTransactions/create-an-accept-transaction.php index 35552bd..926614b 100644 --- a/MobileInappTransactions/create-an-accept-transaction.php +++ b/MobileInappTransactions/create-an-accept-transaction.php @@ -6,9 +6,10 @@ define("AUTHORIZENET_LOG_FILE", "phplog"); - function createAnAcceptTransaction($amount){ - // Create a merchantAuthenticationType object with authentication details - // retrieved from the constants file +function createAnAcceptTransaction($amount) +{ + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); $merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); @@ -68,64 +69,52 @@ function createAnAcceptTransaction($amount){ $request->setRefId($refId); $request->setTransactionRequest($transactionRequestType); - // Create the controller and get response + // Create the controller and get the response $controller = new AnetController\CreateTransactionController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); - if ($response != null) - { - // Check to see if the API request was successfully received and acted upon - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_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 ($response != null) { + // Check to see if the API request was successfully received and acted upon + if ($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_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->getMessages() != null) { + echo " Successfully created transaction with Transaction ID: " . $tresponse->getTransId() . "\n"; + echo " Transaction Response Code: " . $tresponse->getResponseCode() . "\n"; + echo " Message Code: " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Auth Code: " . $tresponse->getAuthCode() . "\n"; + echo " Description: " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } else { + echo "Transaction Failed \n"; + if ($tresponse->getErrors() != null) { + echo " Error Code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + // Or, print errors if the API request wasn't successful + } else { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); - if($tresponse != null && $tresponse->getErrors() != null) - { - echo " Error Code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; - echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; - } - else - { - echo " Error Code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; - echo " Error Message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; - } - } - } - else - { - echo "No response returned \n"; + if ($tresponse != null && $tresponse->getErrors() != null) { + echo " Error Code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } else { + echo " Error Code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error Message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } + } else { + echo "No response returned \n"; } return $response; - } +} - if(!defined('DONT_RUN_SAMPLES')) +if (!defined('DONT_RUN_SAMPLES')) { CreateAnAcceptTransaction(\SampleCode\Constants::SAMPLE_AMOUNT); +} ?> diff --git a/PaymentTransactions/create-an-accept-payment-transaction.php b/PaymentTransactions/create-an-accept-payment-transaction.php index 683b725..beba8f0 100644 --- a/PaymentTransactions/create-an-accept-payment-transaction.php +++ b/PaymentTransactions/create-an-accept-payment-transaction.php @@ -6,9 +6,10 @@ define("AUTHORIZENET_LOG_FILE", "phplog"); - function createAnAcceptPaymentTransaction($amount){ - // Create a merchantAuthenticationType object with authentication details - // retrieved from the constants file +function createAnAcceptPaymentTransaction($amount) +{ + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); $merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); @@ -68,64 +69,52 @@ function createAnAcceptPaymentTransaction($amount){ $request->setRefId($refId); $request->setTransactionRequest($transactionRequestType); - // Create the controller and get response + // Create the controller and get the response $controller = new AnetController\CreateTransactionController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); - if ($response != null) - { - // Check to see if the API request was successfully received and acted upon - if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_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 ($response != null) { + // Check to see if the API request was successfully received and acted upon + if ($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_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->getMessages() != null) { + echo " Successfully created transaction with Transaction ID: " . $tresponse->getTransId() . "\n"; + echo " Transaction Response Code: " . $tresponse->getResponseCode() . "\n"; + echo " Message Code: " . $tresponse->getMessages()[0]->getCode() . "\n"; + echo " Auth Code: " . $tresponse->getAuthCode() . "\n"; + echo " Description: " . $tresponse->getMessages()[0]->getDescription() . "\n"; + } else { + echo "Transaction Failed \n"; + if ($tresponse->getErrors() != null) { + echo " Error Code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } + } + // Or, print errors if the API request wasn't successful + } else { + echo "Transaction Failed \n"; + $tresponse = $response->getTransactionResponse(); - if($tresponse != null && $tresponse->getErrors() != null) - { - echo " Error Code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; - echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; - } - else - { - echo " Error Code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; - echo " Error Message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; - } - } - } - else - { - echo "No response returned \n"; + if ($tresponse != null && $tresponse->getErrors() != null) { + echo " Error Code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n"; + echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n"; + } else { + echo " Error Code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; + echo " Error Message : " . $response->getMessages()->getMessage()[0]->getText() . "\n"; + } + } + } else { + echo "No response returned \n"; } return $response; - } +} - if(!defined('DONT_RUN_SAMPLES')) - CreateAnAcceptPaymentTransaction(\SampleCode\Constants::SAMPLE_AMOUNT); -?> +if (!defined('DONT_RUN_SAMPLES')) { + CreateAnAcceptTransaction(\SampleCode\Constants::SAMPLE_AMOUNT); +} +?> \ No newline at end of file From 9b1ac4ea0f40f7cc5e48362025f763a8d03c7e27 Mon Sep 17 00:00:00 2001 From: adavidw Date: Mon, 15 May 2017 12:29:30 -0600 Subject: [PATCH 2/5] formatting and comments --- ...eate-customer-profile-from-transaction.php | 59 ++++++++++--------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/CustomerProfiles/create-customer-profile-from-transaction.php b/CustomerProfiles/create-customer-profile-from-transaction.php index 2759481..86a6eec 100644 --- a/CustomerProfiles/create-customer-profile-from-transaction.php +++ b/CustomerProfiles/create-customer-profile-from-transaction.php @@ -5,7 +5,7 @@ define("AUTHORIZENET_LOG_FILE", "phplog"); -function createCustomerProfileFromTransaction($transId= "2249066517"){ +function createCustomerProfileFromTransaction($transId= "2249066517") { /* Create a merchantAuthenticationType object with authentication details retrieved from the constants file */ @@ -16,37 +16,38 @@ function createCustomerProfileFromTransaction($transId= "2249066517"){ // Set the transaction's refId $refId = 'ref' . time(); - $customerProfile = new AnetAPI\CustomerProfileBaseType(); - $customerProfile->setMerchantCustomerId("123212"); - $customerProfile->setEmail(rand(0,10000) . "@test" .".com"); - $customerProfile->setDescription(rand(0,10000) ."sample description"); + $customerProfile = new AnetAPI\CustomerProfileBaseType(); + $customerProfile->setMerchantCustomerId("123212"); + $customerProfile->setEmail(rand(0,10000) . "@test" .".com"); + $customerProfile->setDescription(rand(0,10000) ."sample description"); - $request = new AnetAPI\CreateCustomerProfileFromTransactionRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setTransId($transId); - // You can either specify the customer information in form of customerProfileBaseType object - $request->setCustomer($customerProfile); - // OR - // You can just provide the customer Profile ID - //$request->setCustomerProfileId("123343"); + $request = new AnetAPI\CreateCustomerProfileFromTransactionRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setTransId($transId); - $controller = new AnetController\CreateCustomerProfileFromTransactionController($request); + // You can either specify the customer information in form of customerProfileBaseType object + $request->setCustomer($customerProfile); + // OR + // You can just provide the customer Profile ID + //$request->setCustomerProfileId("123343"); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); + $controller = new AnetController\CreateCustomerProfileFromTransactionController($request); - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - echo "SUCCESS: PROFILE ID : " . $response->getCustomerProfileId() . "\n"; - } - else - { - echo "ERROR : Invalid response\n"; - $errorMessages = $response->getMessages()->getMessage(); - echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; - } - return $response; - } - //provide a transaction that has customer information - if(!defined('DONT_RUN_SAMPLES')) + $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); + + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { + echo "SUCCESS: PROFILE ID : " . $response->getCustomerProfileId() . "\n"; + } else { + echo "ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + return $response; +} + +// Provide a transaction that has customer information +if (!defined('DONT_RUN_SAMPLES')) { createCustomerProfileFromTransaction("2249066517"); +} + ?> From 013f40714a01de0f62f5c0ab662e862b1ccecaa0 Mon Sep 17 00:00:00 2001 From: adavidw Date: Mon, 15 May 2017 12:46:04 -0600 Subject: [PATCH 3/5] formatting and comments --- .../create-customer-payment-profile.php | 9 +- ...eate-customer-profile-from-transaction.php | 4 +- ...ate-customer-profile-with-accept-nonce.php | 3 +- CustomerProfiles/create-customer-profile.php | 5 +- .../create-customer-shipping-address.php | 82 ++++++++++--------- 5 files changed, 54 insertions(+), 49 deletions(-) diff --git a/CustomerProfiles/create-customer-payment-profile.php b/CustomerProfiles/create-customer-payment-profile.php index 8829ef6..fe32a3e 100644 --- a/CustomerProfiles/create-customer-payment-profile.php +++ b/CustomerProfiles/create-customer-payment-profile.php @@ -6,7 +6,8 @@ define("AUTHORIZENET_LOG_FILE", "phplog"); -function createCustomerPaymentProfile($existingcustomerprofileid, $phoneNumber){ +function createCustomerPaymentProfile($existingcustomerprofileid, $phoneNumber) +{ /* Create a merchantAuthenticationType object with authentication details retrieved from the constants file */ $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); @@ -58,8 +59,8 @@ function createCustomerPaymentProfile($existingcustomerprofileid, $phoneNumber){ $paymentprofilerequest->setMerchantAuthentication($merchantAuthentication); // Add an existing profile id to the request - $paymentprofilerequest->setCustomerProfileId( $existingcustomerprofileid ); - $paymentprofilerequest->setPaymentProfile( $paymentprofile ); + $paymentprofilerequest->setCustomerProfileId($existingcustomerprofileid); + $paymentprofilerequest->setPaymentProfile($paymentprofile); $paymentprofilerequest->setValidationMode("liveMode"); // Create the controller and get the response @@ -78,6 +79,6 @@ function createCustomerPaymentProfile($existingcustomerprofileid, $phoneNumber){ } if (!defined('DONT_RUN_SAMPLES')) { - createCustomerPaymentProfile("1807545561","000-000-0009"); + createCustomerPaymentProfile("1807545561", "000-000-0009"); } ?> diff --git a/CustomerProfiles/create-customer-profile-from-transaction.php b/CustomerProfiles/create-customer-profile-from-transaction.php index 86a6eec..6b4ae51 100644 --- a/CustomerProfiles/create-customer-profile-from-transaction.php +++ b/CustomerProfiles/create-customer-profile-from-transaction.php @@ -18,8 +18,8 @@ function createCustomerProfileFromTransaction($transId= "2249066517") $customerProfile = new AnetAPI\CustomerProfileBaseType(); $customerProfile->setMerchantCustomerId("123212"); - $customerProfile->setEmail(rand(0,10000) . "@test" .".com"); - $customerProfile->setDescription(rand(0,10000) ."sample description"); + $customerProfile->setEmail(rand(0, 10000) . "@test" .".com"); + $customerProfile->setDescription(rand(0, 10000) ."sample description"); $request = new AnetAPI\CreateCustomerProfileFromTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); diff --git a/CustomerProfiles/create-customer-profile-with-accept-nonce.php b/CustomerProfiles/create-customer-profile-with-accept-nonce.php index f5b0213..9a72398 100644 --- a/CustomerProfiles/create-customer-profile-with-accept-nonce.php +++ b/CustomerProfiles/create-customer-profile-with-accept-nonce.php @@ -6,7 +6,8 @@ define("AUTHORIZENET_LOG_FILE", "phplog"); -function createCustomerProfileWithAcceptNonce($email){ +function createCustomerProfileWithAcceptNonce($email) +{ /* Create a merchantAuthenticationType object with authentication details retrieved from the constants file */ $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); diff --git a/CustomerProfiles/create-customer-profile.php b/CustomerProfiles/create-customer-profile.php index 02d0d59..1708ec1 100644 --- a/CustomerProfiles/create-customer-profile.php +++ b/CustomerProfiles/create-customer-profile.php @@ -6,7 +6,8 @@ define("AUTHORIZENET_LOG_FILE", "phplog"); -function createCustomerProfile($email){ +function createCustomerProfile($email) +{ /* Create a merchantAuthenticationType object with authentication details retrieved from the constants file */ $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); @@ -41,7 +42,7 @@ function createCustomerProfile($email){ $billto->setState("TX"); $billto->setZip("44628"); $billto->setCountry("USA"); - $billto->setPhoneNumber($phoneNumber); + $billto->setPhoneNumber("888-888-8888"); $billto->setfaxNumber("999-999-9999"); // Create a new Customer Payment Profile object diff --git a/CustomerProfiles/create-customer-shipping-address.php b/CustomerProfiles/create-customer-shipping-address.php index 7ee5536..d1f9579 100644 --- a/CustomerProfiles/create-customer-shipping-address.php +++ b/CustomerProfiles/create-customer-shipping-address.php @@ -5,49 +5,51 @@ define("AUTHORIZENET_LOG_FILE", "phplog"); - function createCustomerShippingAddress($existingcustomerprofileid = "36152127", - $phoneNumber="000-000-0000") - { - // Common setup for API credentials - $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); - $merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); +function createCustomerShippingAddress($existingcustomerprofileid = "36152127", + $phoneNumber="000-000-0000" +) { + /* Create a merchantAuthenticationType object with authentication details + retrieved from the constants file */ + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); + $merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); + $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); - // Use An existing customer profile id for this merchant name and transaction key + // Set the transaction's refId + $refId = 'ref' . time(); + + // Use An existing customer profile id for this merchant name and transaction key - // Create the customer shipping address - $customershippingaddress = new AnetAPI\CustomerAddressType(); - $customershippingaddress->setFirstName("James"); - $customershippingaddress->setLastName("White"); - $customershippingaddress->setCompany("Addresses R Us"); - $customershippingaddress->setAddress(rand() . " North Spring Street"); - $customershippingaddress->setCity("Toms River"); - $customershippingaddress->setState("NJ"); - $customershippingaddress->setZip("08753"); - $customershippingaddress->setCountry("USA"); - $customershippingaddress->setPhoneNumber($phoneNumber); - $customershippingaddress->setFaxNumber("999-999-9999"); + // Create the customer shipping address + $customershippingaddress = new AnetAPI\CustomerAddressType(); + $customershippingaddress->setFirstName("James"); + $customershippingaddress->setLastName("White"); + $customershippingaddress->setCompany("Addresses R Us"); + $customershippingaddress->setAddress(rand() . " North Spring Street"); + $customershippingaddress->setCity("Toms River"); + $customershippingaddress->setState("NJ"); + $customershippingaddress->setZip("08753"); + $customershippingaddress->setCountry("USA"); + $customershippingaddress->setPhoneNumber($phoneNumber); + $customershippingaddress->setFaxNumber("999-999-9999"); - // Create a new customer shipping address for an existing customer profile + // Create a new customer shipping address for an existing customer profile - $request = new AnetAPI\CreateCustomerShippingAddressRequest(); - $request->setMerchantAuthentication($merchantAuthentication); - $request->setCustomerProfileId($existingcustomerprofileid); - $request->setAddress($customershippingaddress); - $controller = new AnetController\CreateCustomerShippingAddressController($request); - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) - { - echo "Create Customer Shipping Address SUCCESS: ADDRESS ID : " . $response-> getCustomerAddressId() . "\n"; - } - else - { - echo "Create Customer Shipping Address ERROR : Invalid response\n"; - $errorMessages = $response->getMessages()->getMessage(); - echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; - } - return $response; - } - if(!defined('DONT_RUN_SAMPLES')) + $request = new AnetAPI\CreateCustomerShippingAddressRequest(); + $request->setMerchantAuthentication($merchantAuthentication); + $request->setCustomerProfileId($existingcustomerprofileid); + $request->setAddress($customershippingaddress); + $controller = new AnetController\CreateCustomerShippingAddressController($request); + $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) { + echo "Create Customer Shipping Address SUCCESS: ADDRESS ID : " . $response-> getCustomerAddressId() . "\n"; + } else { + echo "Create Customer Shipping Address ERROR : Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + return $response; +} +if (!defined('DONT_RUN_SAMPLES')) { createCustomerShippingAddress(); +} ?> From 629e54a5a6f365a4be6d7bdcfc6d3159be064400 Mon Sep 17 00:00:00 2001 From: adavidw Date: Mon, 15 May 2017 12:57:02 -0600 Subject: [PATCH 4/5] formatting and comments --- CustomerProfiles/create-customer-profile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CustomerProfiles/create-customer-profile.php b/CustomerProfiles/create-customer-profile.php index 1708ec1..4857207 100644 --- a/CustomerProfiles/create-customer-profile.php +++ b/CustomerProfiles/create-customer-profile.php @@ -49,7 +49,7 @@ function createCustomerProfile($email) $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); $paymentprofile->setCustomerType('individual'); $paymentprofile->setBillTo($billto); - $paymentprofile->setPayment($paymentOne); + $paymentprofile->setPayment($paymentCreditCard); $paymentprofile->setDefaultPaymentProfile(true); $paymentprofiles[] = $paymentprofile; From 245185e1396c3e8dd55083743ddff2dbbc84f143 Mon Sep 17 00:00:00 2001 From: adavidw Date: Mon, 15 May 2017 14:45:04 -0600 Subject: [PATCH 5/5] formatting and comments --- CustomerProfiles/create-customer-payment-profile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CustomerProfiles/create-customer-payment-profile.php b/CustomerProfiles/create-customer-payment-profile.php index fe32a3e..451a641 100644 --- a/CustomerProfiles/create-customer-payment-profile.php +++ b/CustomerProfiles/create-customer-payment-profile.php @@ -34,7 +34,7 @@ function createCustomerPaymentProfile($existingcustomerprofileid, $phoneNumber) // Create the Bill To info for new payment type $billto = new AnetAPI\CustomerAddressType(); - $billto->setFirstName("Ellen"); + $billto->setFirstName("Ellen".$phoneNumber); $billto->setLastName("Johnson"); $billto->setCompany("Souveniropolis"); $billto->setAddress("14 Main Street");