Skip to content

Commit b40d1e9

Browse files
committed
Test Runner initial commit.
Two samples : create-customer-profile create-customer-payment-profile runner files: test-runner.php & SamplesCodeList.txt
1 parent 9d6060f commit b40d1e9

18 files changed

+618
-413
lines changed

CustomerProfiles/create-customer-payment-profile.php

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,63 @@
33
use net\authorize\api\contract\v1 as AnetAPI;
44
use net\authorize\api\controller as AnetController;
55
define("AUTHORIZENET_LOG_FILE", "phplog");
6-
// Common setup for API credentials
7-
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
8-
$merchantAuthentication->setName("556KThWQ6vf2");
9-
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
10-
$refId = 'ref' . time();
11-
//Use an existing profile id
12-
$existingcustomerprofileid = "35858366";
6+
7+
function createCustomerPaymentProfile($existingcustomerprofileid, $phoneNumber){
8+
// Common setup for API credentials
9+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
10+
$merchantAuthentication->setName("556KThWQ6vf2");
11+
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
12+
$refId = 'ref' . time();
1313

14-
$creditCard = new AnetAPI\CreditCardType();
15-
$creditCard->setCardNumber( "4012888818888" );
16-
$creditCard->setExpirationDate( "2038-11");
17-
$creditCard->setCardCode( "123");
18-
$paymentCreditCard = new AnetAPI\PaymentType();
19-
$paymentCreditCard->setCreditCard($creditCard);
14+
$creditCard = new AnetAPI\CreditCardType();
15+
$creditCard->setCardNumber( "4242424242424242" );
16+
$creditCard->setExpirationDate( "2038-11");
17+
$creditCard->setCardCode( "142");
18+
$paymentCreditCard = new AnetAPI\PaymentType();
19+
$paymentCreditCard->setCreditCard($creditCard);
2020

21-
// Create the Bill To info for new payment type
22-
$billto = new AnetAPI\CustomerAddressType();
23-
$billto->setFirstName("Mrs Mary");
24-
$billto->setLastName("Doe");
25-
$billto->setCompany("My company");
26-
$billto->setAddress("123 Main St.");
27-
$billto->setCity("Bellevue");
28-
$billto->setState("WA");
29-
$billto->setZip("98004");
30-
$billto->setPhoneNumber("000-000-0000");
31-
$billto->setfaxNumber("999-999-9999");
32-
$billto->setCountry("USA");
21+
// Create the Bill To info for new payment type
22+
$billto = new AnetAPI\CustomerAddressType();
23+
$billto->setFirstName("Mrs Mary");
24+
$billto->setLastName("Doe");
25+
$billto->setCompany("My company");
26+
$billto->setAddress("123 Main St.");
27+
$billto->setCity("Bellevue");
28+
$billto->setState("WA");
29+
$billto->setZip("98004");
30+
$billto->setPhoneNumber("000-000-0000");
31+
$billto->setfaxNumber("999-999-9999");
32+
$billto->setCountry("USA");
3333

34-
// Create a new Customer Payment Profile
35-
$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
36-
$paymentprofile->setCustomerType('individual');
37-
$paymentprofile->setBillTo($billto);
38-
$paymentprofile->setPayment($paymentCreditCard);
34+
// Create a new Customer Payment Profile
35+
$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
36+
$paymentprofile->setCustomerType('individual');
37+
$paymentprofile->setBillTo($billto);
38+
$paymentprofile->setPayment($paymentCreditCard);
3939

40-
$paymentprofiles[] = $paymentprofile;
40+
$paymentprofiles[] = $paymentprofile;
4141

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

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

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,35 @@
33
use net\authorize\api\contract\v1 as AnetAPI;
44
use net\authorize\api\controller as AnetController;
55
define("AUTHORIZENET_LOG_FILE", "phplog");
6-
// Common setup for API credentials
7-
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
8-
$merchantAuthentication->setName("556KThWQ6vf2");
9-
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
6+
7+
function createCustomerProfileFromTransaction()
8+
{
9+
// Common setup for API credentials
10+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
11+
$merchantAuthentication->setName("556KThWQ6vf2");
12+
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
1013

1114

1215

13-
$request = new AnetAPI\CreateCustomerProfileFromTransactionRequest();
14-
$request->setMerchantAuthentication($merchantAuthentication);
15-
$request->setTransId("2235382051");
16+
$request = new AnetAPI\CreateCustomerProfileFromTransactionRequest();
17+
$request->setMerchantAuthentication($merchantAuthentication);
18+
$request->setTransId("2238251168");
1619

17-
$controller = new AnetController\CreateCustomerProfileFromTransactionController($request);
20+
$controller = new AnetController\CreateCustomerProfileFromTransactionController($request);
1821

19-
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
22+
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
2023

21-
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
22-
{
23-
echo "SUCCESS: PROFILE ID : " . $response->getCustomerProfileId() . "\n";
24-
}
25-
else
26-
{
27-
echo "ERROR : Invalid response\n";
28-
echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";
24+
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
25+
{
26+
echo "SUCCESS: PROFILE ID : " . $response->getCustomerProfileId() . "\n";
27+
}
28+
else
29+
{
30+
echo "ERROR : Invalid response\n";
31+
echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";
32+
}
33+
return $response;
2934
}
35+
if(!defined(DONT_RUN_SAMPLES))
36+
createCustomerProfileFromTransaction();
3037
?>

CustomerProfiles/create-customer-profile.php

Lines changed: 62 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,72 @@
33
use net\authorize\api\contract\v1 as AnetAPI;
44
use net\authorize\api\controller as AnetController;
55
define("AUTHORIZENET_LOG_FILE", "phplog");
6-
// Common setup for API credentials
7-
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
8-
$merchantAuthentication->setName("556KThWQ6vf2");
9-
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
10-
$refId = 'ref' . time();
6+
7+
function createCustomerProfile($merchantCustomerId=-1){
8+
9+
// Common setup for API credentials
10+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
11+
$merchantAuthentication->setName("556KThWQ6vf2");
12+
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
13+
$refId = 'ref' . time();
1114

12-
// Create the payment data for a credit card
13-
$creditCard = new AnetAPI\CreditCardType();
14-
$creditCard->setCardNumber( "4111111111111111" );
15-
$creditCard->setExpirationDate( "2038-12");
16-
$paymentCreditCard = new AnetAPI\PaymentType();
17-
$paymentCreditCard->setCreditCard($creditCard);
15+
// Create the payment data for a credit card
16+
$creditCard = new AnetAPI\CreditCardType();
17+
$creditCard->setCardNumber( "4111111111111111" );
18+
$creditCard->setExpirationDate( "2038-12");
19+
$paymentCreditCard = new AnetAPI\PaymentType();
20+
$paymentCreditCard->setCreditCard($creditCard);
1821

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

36-
$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
39+
$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
3740

38-
$paymentprofile->setCustomerType('individual');
39-
$paymentprofile->setBillTo($billto);
40-
$paymentprofile->setPayment($paymentCreditCard);
41-
$paymentprofiles[] = $paymentprofile;
42-
$customerprofile = new AnetAPI\CustomerProfileType();
43-
$customerprofile->setDescription("Customer 2 Test PHP");
44-
$merchantCustomerId = time().rand(1,150);
45-
$customerprofile->setMerchantCustomerId($merchantCustomerId);
46-
$customerprofile->setEmail("[email protected]");
47-
$customerprofile->setPaymentProfiles($paymentprofiles);
41+
$paymentprofile->setCustomerType('individual');
42+
$paymentprofile->setBillTo($billto);
43+
$paymentprofile->setPayment($paymentCreditCard);
44+
$paymentprofiles[] = $paymentprofile;
45+
$customerprofile = new AnetAPI\CustomerProfileType();
46+
$customerprofile->setDescription("Customer 2 Test PHP");
47+
if(-1 == $merchantCustomerId)
48+
$merchantCustomerId=time().rand(1,150);
49+
$customerprofile->setMerchantCustomerId($merchantCustomerId);
50+
$customerprofile->setEmail("[email protected]");
51+
$customerprofile->setPaymentProfiles($paymentprofiles);
4852

49-
$request = new AnetAPI\CreateCustomerProfileRequest();
50-
$request->setMerchantAuthentication($merchantAuthentication);
51-
$request->setRefId( $refId);
52-
$request->setProfile($customerprofile);
53-
$controller = new AnetController\CreateCustomerProfileController($request);
54-
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
55-
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
56-
{
57-
echo "SUCCESS: PROFILE ID : " . $response->getCustomerProfileId() . "\n";
58-
echo "SUCCESS: PAYMENT PROFILE ID : " . $response->getCustomerPaymentProfileIdList()[0] . "\n";
59-
}
60-
else
61-
{
62-
echo "ERROR : Invalid response\n";
63-
echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";
64-
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+
echo "SUCCESS: PAYMENT PROFILE ID : " . $response->getCustomerPaymentProfileIdList()[0] . "\n";
63+
}
64+
else
65+
{
66+
echo "ERROR : Invalid response\n";
67+
echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";
68+
69+
}
70+
return $response;
6571
}
72+
if(!defined(DONT_RUN_SAMPLES))
73+
createCustomerProfile();
6674
?>

CustomerProfiles/create-customer-shipping-address.php

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,47 @@
33
use net\authorize\api\contract\v1 as AnetAPI;
44
use net\authorize\api\controller as AnetController;
55
define("AUTHORIZENET_LOG_FILE", "phplog");
6-
// Common setup for API credentials
7-
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
8-
$merchantAuthentication->setName("556KThWQ6vf2");
9-
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
6+
function createCustomerShippingAddress($existingcustomerprofileid = "35872074")
7+
{
8+
// Common setup for API credentials
9+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
10+
$merchantAuthentication->setName("556KThWQ6vf2");
11+
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
1012

11-
// An existing customer profile id for this merchant name and transaction key
12-
$existingcustomerprofileid = "35872074";
13+
// Use An existing customer profile id for this merchant name and transaction key
1314

14-
// Create the customer shipping address
15-
$customershippingaddress = new AnetAPI\CustomerAddressType();
16-
$customershippingaddress->setFirstName("James");
17-
$customershippingaddress->setLastName("White");
18-
$customershippingaddress->setCompany("Addresses R Us");
19-
$customershippingaddress->setAddress(rand() . " North Spring Street");
20-
$customershippingaddress->setCity("Toms River");
21-
$customershippingaddress->setState("NJ");
22-
$customershippingaddress->setZip("08753");
23-
$customershippingaddress->setCountry("USA");
24-
$customershippingaddress->setPhoneNumber("000-000-0000");
25-
$customershippingaddress->setFaxNumber("999-999-9999");
15+
// Create the customer shipping address
16+
$customershippingaddress = new AnetAPI\CustomerAddressType();
17+
$customershippingaddress->setFirstName("James");
18+
$customershippingaddress->setLastName("White");
19+
$customershippingaddress->setCompany("Addresses R Us");
20+
$customershippingaddress->setAddress(rand() . " North Spring Street");
21+
$customershippingaddress->setCity("Toms River");
22+
$customershippingaddress->setState("NJ");
23+
$customershippingaddress->setZip("08753");
24+
$customershippingaddress->setCountry("USA");
25+
$customershippingaddress->setPhoneNumber("000-000-0000");
26+
$customershippingaddress->setFaxNumber("999-999-9999");
2627

27-
// Create a new customer shipping address for an existing customer profile
28+
// Create a new customer shipping address for an existing customer profile
2829

29-
$request = new AnetAPI\CreateCustomerShippingAddressRequest();
30-
$request->setMerchantAuthentication($merchantAuthentication);
31-
$request->setCustomerProfileId($existingcustomerprofileid);
32-
$request->setAddress($customershippingaddress);
33-
$controller = new AnetController\CreateCustomerShippingAddressController($request);
34-
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
35-
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
36-
{
37-
echo "Create Customer Shipping Address SUCCESS: ADDRESS ID : " . $response-> getCustomerAddressId() . "\n";
38-
}
39-
else
40-
{
41-
echo "Create Customer Shipping Address ERROR : Invalid response\n";
42-
echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";
30+
$request = new AnetAPI\CreateCustomerShippingAddressRequest();
31+
$request->setMerchantAuthentication($merchantAuthentication);
32+
$request->setCustomerProfileId($existingcustomerprofileid);
33+
$request->setAddress($customershippingaddress);
34+
$controller = new AnetController\CreateCustomerShippingAddressController($request);
35+
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
36+
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
37+
{
38+
echo "Create Customer Shipping Address SUCCESS: ADDRESS ID : " . $response-> getCustomerAddressId() . "\n";
39+
}
40+
else
41+
{
42+
echo "Create Customer Shipping Address ERROR : Invalid response\n";
43+
echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";
44+
}
45+
return $response;
4346
}
47+
if(!defined(DONT_RUN_SAMPLES))
48+
createCustomerShippingAddress();
4449
?>

0 commit comments

Comments
 (0)