Skip to content

Commit ff43565

Browse files
author
Greg White
committed
Additional testing charge-customer-profile.php. Fixed. Updated sample-code-ruby. Updated README
1 parent 1e83081 commit ff43565

3 files changed

Lines changed: 73 additions & 172 deletions

File tree

PaymentTransactions/charge-customer-profile.php

Lines changed: 68 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
1010
$refId = 'ref' . time();
1111

12+
// Create the payment data for a credit card
13+
$creditCard = new AnetAPI\CreditCardType();
14+
$creditCard->setCardNumber( "4111111111111111" );
15+
$creditCard->setExpirationDate( "2038-12");
16+
$paymentOne = new AnetAPI\PaymentType();
17+
$paymentOne->setCreditCard($creditCard);
18+
1219
// Bill To
1320
$billto = new AnetAPI\CustomerAddressType();
1421
$billto->setFirstName("Ellen");
@@ -20,30 +27,20 @@
2027
$billto->setZip("44628");
2128
$billto->setCountry("USA");
2229

23-
// Ship To
24-
$shipto = new AnetAPI\CustomerAddressType();
25-
$shipto->setFirstName("Ellen");
26-
$shipto->setLastName("Johnson");
27-
$shipto->setCompany("Souveniropolis");
28-
$shipto->setAddress("14 Main Street");
29-
$shipto->setCity("Pecan Springs");
30-
$shipto->setState("TX");
31-
$shipto->setZip("44628");
32-
$shipto->setCountry("USA");
3330

3431
// Create a Customer Profile Request
35-
// 1. create a Payment Profile
36-
// 2. create a Customer Profile
32+
// 1. create a Customer Payment Profile
33+
// 2. create a Customer Profile
3734
// 3. Submit a CreateCustomerProfile Request
38-
// 4. Validate Profiiel ID returned
35+
// 4. Validate the profile id returned
3936

4037
$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
4138

4239
$paymentprofile->setCustomerType('individual');
4340
$paymentprofile->setBillTo($billto);
44-
$paymentprofile->setShipToList($shipto);
45-
$paymentprofile->setPayment($paymentCreditCard);
41+
$paymentprofile->setPayment($paymentOne);
4642
$paymentprofiles[] = $paymentprofile;
43+
4744
$customerprofile = new AnetAPI\CustomerProfileType();
4845
$customerprofile->setDescription("Customer 2 Test PHP");
4946
$merchantCustomerId = time().rand(1,150);
@@ -59,20 +56,19 @@
5956
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
6057
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
6158
{
62-
echo "Create Profile SUCCESS: PROFILE ID : " . $response->getCustomerProfileId() . "\n";
63-
$profileId = $response->getCustomerProfileId();
64-
}
59+
echo "CreateCustomerProfileRequest SUCCESS: PROFILE ID : " . $response->getCustomerProfileId() . "\n";
60+
$customerProfileId = $response->getCustomerProfileId();
61+
}
6562
else
6663
{
67-
echo "Create Profile ERROR : Invalid response\n";
64+
echo "CreateCustomerProfileRequest ERROR : Invalid response\n";
6865
}
69-
70-
// Order info
66+
// Create a new order
7167
$order = new AnetAPI\OrderType();
7268
$order->setInvoiceNumber("102");
7369
$order->setDescription("Tennis Shirts");
7470

75-
// Line Item Info
71+
// Add line items
7672
$lineitem = new AnetAPI\LineItemType();
7773
$lineitem->setItemId("Shirts");
7874
$lineitem->setName("item2");
@@ -81,34 +77,75 @@
8177
$lineitem->setUnitPrice(22.89);
8278
$lineitem->setTaxable("Y");
8379

84-
// Tax info
80+
// Add new tax info
8581
$tax = new AnetAPI\ExtendedAmountType();
8682
$tax->setName("level 2 tax name");
8783
$tax->setAmount(6.50);
8884
$tax->setDescription("level 2 tax");
8985

90-
// Ship To
86+
// New Ship To
9187
$shipto = new AnetAPI\CustomerAddressType();
9288
$shipto->setFirstName("Mary");
9389
$shipto->setLastName("Smith");
94-
$shipto->setCompany("Tenis Shirts Are Us");
90+
$shipto->setCompany("Tennis Shirts Are Us");
9591
$shipto->setAddress("588 Willis Court");
9692
$shipto->setCity("Pecan Springs");
9793
$shipto->setState("TX");
9894
$shipto->setZip("44628");
9995
$shipto->setCountry("USA");
10096

97+
// Set a new bill to address
98+
$billto = new AnetAPI\CustomerAddressType();
99+
$billto->setFirstName("Mary");
100+
$billto->setLastName("Smith");
101+
$billto->setCompany("Tennis Shirts Are Us");
102+
$billto->setAddress("588 Willis Court");
103+
$billto->setCity("Pecan Springs");
104+
$billto->setState("TX");
105+
$billto->setZip("44628");
106+
$billto->setCountry("USA");
107+
108+
// Create additional payment data and add a new credit card
109+
$creditCard = new AnetAPI\CreditCardType();
110+
$creditCard->setCardNumber( "4007000000027" );
111+
$creditCard->setExpirationDate( "2038-12");
112+
$paymentTwo = new AnetAPI\PaymentType();
113+
$paymentTwo->setCreditCard($creditCard);
114+
115+
$request = new AnetAPI\CreateCustomerPaymentProfileRequest();
116+
$request->setMerchantAuthentication($merchantAuthentication);
117+
$request->setRefId( $refId);
118+
$request->setCustomerProfileId($customerProfileId);
119+
120+
$paymentprofile2 = new AnetAPI\CustomerPaymentProfileType();
121+
$paymentprofile2->setCustomerType('business');
122+
$paymentprofile2->setBillTo($billto);
123+
$paymentprofile2->setPayment($paymentTwo);
124+
$paymentprofiles2[] = $paymentprofile2;
125+
126+
$request->setPaymentProfile($paymentprofile2);
127+
$controller = new AnetController\CreateCustomerPaymentProfileController($request);
128+
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
129+
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
130+
{
131+
echo "CreateCustomerPaymentProfileRequest SUCCESS: PROFILE ID : " . $response->getCustomerPaymentProfileId() . "\n";
132+
$customerProfileId = $response->getCustomerPaymentProfileId();
133+
}
134+
else
135+
{
136+
echo "CreateCustomerPaymentProfileRequest ERROR : Invalid response\n";
137+
}
138+
101139
$transactionRequestType = new AnetAPI\TransactionRequestType();
102140
$transactionRequestType->setTransactionType( "authCaptureTransaction");
103141
$transactionRequestType->setAmount(100.50);
104-
$transactionRequestType->setProfile($profileId);
105-
//$transactionRequestType->setPayment($paymentBank);
142+
$transactionRequestType->setPayment($paymentprofile2->getPayment());
106143
$transactionRequestType->setOrder($order);
107144
$transactionRequestType->addToLineItems($lineitem);
108145
$transactionRequestType->setTax($tax);
109146
//$transactionRequestType->setPoNumber($ponumber);
110147
//$transactionRequestType->setCustomer($customer);
111-
//$transactionRequestType->setBillTo($billto);
148+
$transactionRequestType->setBillTo($billto);
112149
$transactionRequestType->setShipTo($shipto);
113150
$request = new AnetAPI\CreateTransactionRequest();
114151
$request->setMerchantAuthentication($merchantAuthentication);
@@ -121,9 +158,9 @@
121158
$tresponse = $response->getTransactionResponse();
122159
if (($tresponse != null) && ($tresponse->getResponseCode()=="1") )
123160
{
124-
echo "APPROVED :" . "\n";
125-
echo " AUTH CODE : " . $tresponse->getAuthCode() . "\n";
126-
echo " TRANS ID : " . $tresponse->getTransId() . "\n";
161+
echo "Charge Customer Profile APPROVED :" . "\n";
162+
echo " Charge Customer Profile AUTH CODE : " . $tresponse->getAuthCode() . "\n";
163+
echo " Charge Customer Profile TRANS ID : " . $tresponse->getTransId() . "\n";
127164
}
128165
elseif (($tresponse != null) && ($tresponse->getResponseCode()=="2") )
129166
{
@@ -139,4 +176,3 @@
139176
echo "no response returned";
140177
}
141178
?>
142-

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ The code samples are organized just like our API reference which you can access
1616

1717
06-05-2015 Greg White - Added create-customer-profile.php to test CreateCustomerProfile Transaction with capture-previously-authed-amount and other API’s that use a customer profile. Testing capture-previously-authed.
1818

19-
06-08-2015 Greg White - Additional testing charge-customer-profile.php and charge-tokenized-credit-card.php. Removed .idea and phplog from project directory
19+
06-08-2015 Greg White - Additional testing charge-customer-profile.php and charge-tokenized-credit-card.php. Removed .idea and phplog from project directory
20+
21+
06-08-2015 Greg White - Additional testing charge-customer-profile.php. Fixed. Updated sample-code-ruby.
22+
23+

charge-customer-profile.php

Lines changed: 0 additions & 139 deletions
This file was deleted.

0 commit comments

Comments
 (0)