Skip to content

Commit 2fd4492

Browse files
authored
formatting and comments (AuthorizeNet#87)
* formatting and comments * formatting and comments * formatting and comments * formatting and comments * formatting and comments
1 parent 33f94e9 commit 2fd4492

7 files changed

Lines changed: 390 additions & 359 deletions
Lines changed: 71 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,84 @@
11
<?php
22
require 'vendor/autoload.php';
3+
34
use net\authorize\api\contract\v1 as AnetAPI;
45
use net\authorize\api\controller as AnetController;
56

67
define("AUTHORIZENET_LOG_FILE", "phplog");
78

8-
function createCustomerPaymentProfile($existingcustomerprofileid, $phoneNumber){
9-
// Common setup for API credentials
10-
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
11-
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
12-
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
13-
$refId = 'ref' . time();
9+
function createCustomerPaymentProfile($existingcustomerprofileid, $phoneNumber)
10+
{
11+
/* Create a merchantAuthenticationType object with authentication details
12+
retrieved from the constants file */
13+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
14+
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
15+
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
16+
17+
// Set the transaction's refId
18+
$refId = 'ref' . time();
19+
20+
// Create a Customer Profile Request
21+
// 1. (Optionally) create a Payment Profile
22+
// 2. (Optionally) create a Shipping Profile
23+
// 3. Create a Customer Profile (or specify an existing profile)
24+
// 4. Submit a CreateCustomerProfile Request
25+
// 5. Validate Profile ID returned
26+
27+
// Set credit card information for payment profile
28+
$creditCard = new AnetAPI\CreditCardType();
29+
$creditCard->setCardNumber("4242424242424242");
30+
$creditCard->setExpirationDate("2038-12");
31+
$creditCard->setCardCode("142");
32+
$paymentCreditCard = new AnetAPI\PaymentType();
33+
$paymentCreditCard->setCreditCard($creditCard);
34+
35+
// Create the Bill To info for new payment type
36+
$billto = new AnetAPI\CustomerAddressType();
37+
$billto->setFirstName("Ellen".$phoneNumber);
38+
$billto->setLastName("Johnson");
39+
$billto->setCompany("Souveniropolis");
40+
$billto->setAddress("14 Main Street");
41+
$billto->setCity("Pecan Springs");
42+
$billto->setState("TX");
43+
$billto->setZip("44628");
44+
$billto->setCountry("USA");
45+
$billto->setPhoneNumber($phoneNumber);
46+
$billto->setfaxNumber("999-999-9999");
47+
48+
// Create a new Customer Payment Profile object
49+
$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
50+
$paymentprofile->setCustomerType('individual');
51+
$paymentprofile->setBillTo($billto);
52+
$paymentprofile->setPayment($paymentCreditCard);
53+
$paymentprofile->setDefaultPaymentProfile(true);
54+
55+
$paymentprofiles[] = $paymentprofile;
56+
57+
// Assemble the complete transaction request
58+
$paymentprofilerequest = new AnetAPI\CreateCustomerPaymentProfileRequest();
59+
$paymentprofilerequest->setMerchantAuthentication($merchantAuthentication);
1460

15-
$creditCard = new AnetAPI\CreditCardType();
16-
$creditCard->setCardNumber( "4242424242424242");
17-
$creditCard->setExpirationDate( "2038-12");
18-
$creditCard->setCardCode( "142");
19-
$paymentCreditCard = new AnetAPI\PaymentType();
20-
$paymentCreditCard->setCreditCard($creditCard);
61+
// Add an existing profile id to the request
62+
$paymentprofilerequest->setCustomerProfileId($existingcustomerprofileid);
63+
$paymentprofilerequest->setPaymentProfile($paymentprofile);
64+
$paymentprofilerequest->setValidationMode("liveMode");
2165

22-
// Create the Bill To info for new payment type
23-
$billto = new AnetAPI\CustomerAddressType();
24-
$billto->setFirstName("Mrs Mary".$phoneNumber);
25-
$billto->setLastName("Doe");
26-
$billto->setCompany("My company");
27-
$billto->setAddress("123 Main St.");
28-
$billto->setCity("Bellevue");
29-
$billto->setState("WA");
30-
$billto->setZip("98004");
31-
$billto->setPhoneNumber($phoneNumber);
32-
$billto->setfaxNumber("999-999-9999");
33-
$billto->setCountry("USA");
66+
// Create the controller and get the response
67+
$controller = new AnetController\CreateCustomerPaymentProfileController($paymentprofilerequest);
68+
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
3469

35-
// Create a new Customer Payment Profile
36-
$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
37-
$paymentprofile->setCustomerType('individual');
38-
$paymentprofile->setBillTo($billto);
39-
$paymentprofile->setPayment($paymentCreditCard);
40-
$paymentprofile->setDefaultPaymentProfile(true);
70+
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) {
71+
echo "Create Customer Payment Profile SUCCESS: " . $response->getCustomerPaymentProfileId() . "\n";
72+
} else {
73+
echo "Create Customer Payment Profile: ERROR Invalid response\n";
74+
$errorMessages = $response->getMessages()->getMessage();
75+
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
4176

42-
$paymentprofiles[] = $paymentprofile;
77+
}
78+
return $response;
79+
}
4380

44-
// Submit a CreateCustomerPaymentProfileRequest to create a new Customer Payment Profile
45-
$paymentprofilerequest = new AnetAPI\CreateCustomerPaymentProfileRequest();
46-
$paymentprofilerequest->setMerchantAuthentication($merchantAuthentication);
47-
//Use an existing profile id
48-
$paymentprofilerequest->setCustomerProfileId( $existingcustomerprofileid );
49-
$paymentprofilerequest->setPaymentProfile( $paymentprofile );
50-
$paymentprofilerequest->setValidationMode("liveMode");
51-
$controller = new AnetController\CreateCustomerPaymentProfileController($paymentprofilerequest);
52-
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
53-
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
54-
{
55-
echo "Create Customer Payment Profile SUCCESS: " . $response->getCustomerPaymentProfileId() . "\n";
56-
}
57-
else
58-
{
59-
echo "Create Customer Payment Profile: ERROR Invalid response\n";
60-
$errorMessages = $response->getMessages()->getMessage();
61-
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
62-
63-
}
64-
return $response;
65-
}
66-
if(!defined('DONT_RUN_SAMPLES'))
67-
createCustomerPaymentProfile("1807545561","000-000-0009");
81+
if (!defined('DONT_RUN_SAMPLES')) {
82+
createCustomerPaymentProfile("1807545561", "000-000-0009");
83+
}
6884
?>

CustomerProfiles/create-customer-profile-from-transaction.php

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,49 @@
55

66
define("AUTHORIZENET_LOG_FILE", "phplog");
77

8-
function createCustomerProfileFromTransaction($transId= "2249066517")
9-
{
10-
// Common setup for API credentials
11-
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
12-
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
13-
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
8+
function createCustomerProfileFromTransaction($transId= "2249066517")
9+
{
10+
/* Create a merchantAuthenticationType object with authentication details
11+
retrieved from the constants file */
12+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
13+
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
14+
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
15+
16+
// Set the transaction's refId
17+
$refId = 'ref' . time();
1418

15-
$customerProfile = new AnetAPI\CustomerProfileBaseType();
16-
$customerProfile->setMerchantCustomerId("123212");
17-
$customerProfile->setEmail(rand(0,10000) . "@test" .".com");
18-
$customerProfile->setDescription(rand(0,10000) ."sample description");
19+
$customerProfile = new AnetAPI\CustomerProfileBaseType();
20+
$customerProfile->setMerchantCustomerId("123212");
21+
$customerProfile->setEmail(rand(0, 10000) . "@test" .".com");
22+
$customerProfile->setDescription(rand(0, 10000) ."sample description");
1923

20-
$request = new AnetAPI\CreateCustomerProfileFromTransactionRequest();
21-
$request->setMerchantAuthentication($merchantAuthentication);
22-
$request->setTransId($transId);
23-
// You can either specify the customer information in form of customerProfileBaseType object
24-
$request->setCustomer($customerProfile);
25-
// OR
26-
// You can just provide the customer Profile ID
27-
//$request->setCustomerProfileId("123343");
24+
$request = new AnetAPI\CreateCustomerProfileFromTransactionRequest();
25+
$request->setMerchantAuthentication($merchantAuthentication);
26+
$request->setTransId($transId);
2827

29-
$controller = new AnetController\CreateCustomerProfileFromTransactionController($request);
28+
// You can either specify the customer information in form of customerProfileBaseType object
29+
$request->setCustomer($customerProfile);
30+
// OR
31+
// You can just provide the customer Profile ID
32+
//$request->setCustomerProfileId("123343");
3033

31-
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
34+
$controller = new AnetController\CreateCustomerProfileFromTransactionController($request);
3235

33-
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
34-
{
35-
echo "SUCCESS: PROFILE ID : " . $response->getCustomerProfileId() . "\n";
36-
}
37-
else
38-
{
39-
echo "ERROR : Invalid response\n";
40-
$errorMessages = $response->getMessages()->getMessage();
41-
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
42-
}
43-
return $response;
44-
}
45-
//provide a transaction that has customer information
46-
if(!defined('DONT_RUN_SAMPLES'))
36+
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
37+
38+
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) {
39+
echo "SUCCESS: PROFILE ID : " . $response->getCustomerProfileId() . "\n";
40+
} else {
41+
echo "ERROR : Invalid response\n";
42+
$errorMessages = $response->getMessages()->getMessage();
43+
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
44+
}
45+
return $response;
46+
}
47+
48+
// Provide a transaction that has customer information
49+
if (!defined('DONT_RUN_SAMPLES')) {
4750
createCustomerProfileFromTransaction("2249066517");
51+
}
52+
4853
?>
Lines changed: 76 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,90 @@
11
<?php
22
require 'vendor/autoload.php';
3+
34
use net\authorize\api\contract\v1 as AnetAPI;
45
use net\authorize\api\controller as AnetController;
56

67
define("AUTHORIZENET_LOG_FILE", "phplog");
78

8-
function createCustomerProfileWithAcceptNonce($email){
9-
10-
// Common setup for API credentials
11-
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
12-
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
13-
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
14-
$refId = 'ref' . time();
9+
function createCustomerProfileWithAcceptNonce($email)
10+
{
11+
/* Create a merchantAuthenticationType object with authentication details
12+
retrieved from the constants file */
13+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
14+
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
15+
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
16+
17+
// Set the transaction's refId
18+
$refId = 'ref' . time();
19+
20+
// Create a Customer Profile Request
21+
// 1. (Optionally) create a Payment Profile
22+
// 2. (Optionally) create a Shipping Profile
23+
// 3. Create a Customer Profile (or specify an existing profile)
24+
// 4. Submit a CreateCustomerProfile Request
25+
// 5. Validate Profile ID returned
26+
27+
// Set the payment data for the payment profile to a token obtained from Accept.js
28+
$op = new AnetAPI\OpaqueDataType();
29+
$op->setDataDescriptor("COMMON.ACCEPT.INAPP.PAYMENT");
30+
$op->setDataValue("119eyJjb2RlIjoiNTBfMl8wNjAwMDUyN0JEODE4RjQxOUEyRjhGQkIxMkY0MzdGQjAxQUIwRTY2NjhFNEFCN0VENzE4NTUwMjlGRUU0M0JFMENERUIwQzM2M0ExOUEwMDAzNzlGRDNFMjBCODJEMDFCQjkyNEJDIiwidG9rZW4iOiI5NDkwMjMyMTAyOTQwOTk5NDA0NjAzIiwidiI6IjEuMSJ9");
31+
$paymentOne = new AnetAPI\PaymentType();
32+
$paymentOne->setOpaqueData($op);
33+
34+
35+
// Create the Bill To info for new payment type
36+
$billto = new AnetAPI\CustomerAddressType();
37+
$billto->setFirstName("Ellen");
38+
$billto->setLastName("Johnson");
39+
$billto->setCompany("Souveniropolis");
40+
$billto->setAddress("14 Main Street");
41+
$billto->setCity("Pecan Springs");
42+
$billto->setState("TX");
43+
$billto->setZip("44628");
44+
$billto->setCountry("USA");
45+
$billto->setPhoneNumber($phoneNumber);
46+
$billto->setfaxNumber("999-999-9999");
47+
48+
// Create a new Customer Payment Profile object
49+
$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
50+
$paymentprofile->setCustomerType('individual');
51+
$paymentprofile->setBillTo($billto);
52+
$paymentprofile->setPayment($paymentOne);
53+
$paymentprofile->setDefaultPaymentProfile(true);
54+
55+
$paymentprofiles[] = $paymentprofile;
1556

16-
// Create the payment data for an accept token
17-
$op = new AnetAPI\OpaqueDataType();
18-
$op->setDataDescriptor("COMMON.ACCEPT.INAPP.PAYMENT");
19-
$op->setDataValue("9475089993864215505001");
20-
$paymentOne = new AnetAPI\PaymentType();
21-
$paymentOne->setOpaqueData($op);
57+
// Create a new CustomerProfileType and add the payment profile object
58+
$customerprofile = new AnetAPI\CustomerProfileType();
59+
$customerprofile->setDescription("Customer Test PHP Accept Test");
2260

23-
// Create the Bill To info
24-
$billto = new AnetAPI\CustomerAddressType();
25-
$billto->setFirstName("Ellen");
26-
$billto->setLastName("Johnson");
27-
$billto->setCompany("Souveniropolis");
28-
$billto->setAddress("14 Main Street");
29-
$billto->setCity("Pecan Springs");
30-
$billto->setState("TX");
31-
$billto->setZip("44628");
32-
$billto->setCountry("USA");
33-
34-
// Create a Customer Profile Request
35-
// 1. create a Payment Profile
36-
// 2. create a Customer Profile
37-
// 3. Submit a CreateCustomerProfile Request
38-
// 4. Validate Profiiel ID returned
61+
$customerprofile->setMerchantCustomerId("M_".$email);
62+
$customerprofile->setEmail($email);
63+
$customerprofile->setPaymentProfiles($paymentprofiles);
3964

40-
$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
65+
// Assemble the complete transaction request
66+
$request = new AnetAPI\CreateCustomerProfileRequest();
67+
$request->setMerchantAuthentication($merchantAuthentication);
68+
$request->setRefId($refId);
69+
$request->setProfile($customerprofile);
4170

42-
$paymentprofile->setCustomerType('individual');
43-
$paymentprofile->setBillTo($billto);
44-
$paymentprofile->setPayment($paymentOne);
45-
$paymentprofiles[] = $paymentprofile;
46-
$customerprofile = new AnetAPI\CustomerProfileType();
47-
$customerprofile->setDescription("Customer Test PHP Accept Test");
71+
// Create the controller and get the response
72+
$controller = new AnetController\CreateCustomerProfileController($request);
73+
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
4874

49-
$customerprofile->setMerchantCustomerId("M_".$email);
50-
$customerprofile->setEmail($email);
51-
$customerprofile->setPaymentProfiles($paymentprofiles);
75+
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) {
76+
echo "Succesfully created customer profile : " . $response->getCustomerProfileId() . "\n";
77+
$paymentProfiles = $response->getCustomerPaymentProfileIdList();
78+
echo "SUCCESS: PAYMENT PROFILE ID : " . $paymentProfiles[0] . "\n";
79+
} else {
80+
echo "ERROR : Invalid response\n";
81+
$errorMessages = $response->getMessages()->getMessage();
82+
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
83+
}
84+
return $response;
85+
}
5286

53-
$request = new AnetAPI\CreateCustomerProfileRequest();
54-
$request->setMerchantAuthentication($merchantAuthentication);
55-
$request->setRefId( $refId);
56-
$request->setProfile($customerprofile);
57-
$controller = new AnetController\CreateCustomerProfileController($request);
58-
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
59-
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
60-
{
61-
echo "Succesfully create customer profile : " . $response->getCustomerProfileId() . "\n";
62-
$paymentProfiles = $response->getCustomerPaymentProfileIdList();
63-
echo "SUCCESS: PAYMENT PROFILE ID : " . $paymentProfiles[0] . "\n";
64-
}
65-
else
66-
{
67-
echo "ERROR : Invalid response\n";
68-
$errorMessages = $response->getMessages()->getMessage();
69-
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
70-
}
71-
return $response;
72-
}
73-
if(!defined('DONT_RUN_SAMPLES'))
74-
createCustomerProfileWithAcceptNonce("test123@test.com");
87+
if (!defined('DONT_RUN_SAMPLES')) {
88+
createCustomerProfileWithAcceptNonce("test123@test.com");
89+
}
7590
?>

0 commit comments

Comments
 (0)