Skip to content

Commit d6d9701

Browse files
author
brianmc
committed
Fixed sample for charging a profile
1 parent b98fd19 commit d6d9701

1 file changed

Lines changed: 9 additions & 135 deletions

File tree

PaymentTransactions/charge-customer-profile.php

Lines changed: 9 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -5,148 +5,22 @@
55
define("AUTHORIZENET_LOG_FILE", "phplog");
66
// Common setup for API credentials
77
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
8-
$merchantAuthentication->setName("556KThWQ6vf2");
9-
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
8+
$merchantAuthentication->setName("5KP3u95bQpv");
9+
$merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S");
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);
12+
$profileToCharge = new AnetAPI\CustomerProfilePaymentType();
13+
$profileToCharge->setCustomerProfileId("36731856");
14+
$paymentProfile = new AnetAPI\PaymentProfileType();
15+
$paymentProfile->setPaymentProfileId("33211899");
16+
$profileToCharge->setPaymentProfile($paymentProfile);
1817

19-
// Bill To
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-
31-
// Create a Customer Profile Request
32-
// 1. create a Customer Payment Profile
33-
// 2. create a Customer Profile
34-
// 3. Submit a CreateCustomerProfile Request
35-
// 4. Validate the profile id returned
36-
37-
$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
38-
39-
$paymentprofile->setCustomerType('individual');
40-
$paymentprofile->setBillTo($billto);
41-
$paymentprofile->setPayment($paymentOne);
42-
$paymentprofiles[] = $paymentprofile;
43-
44-
$customerprofile = new AnetAPI\CustomerProfileType();
45-
$customerprofile->setDescription("Customer 2 Test PHP");
46-
$merchantCustomerId = time().rand(1,150);
47-
$customerprofile->setMerchantCustomerId($merchantCustomerId);
48-
$customerprofile->setEmail("test2@domain.com");
49-
$customerprofile->setPaymentProfiles($paymentprofiles);
50-
51-
$request = new AnetAPI\CreateCustomerProfileRequest();
52-
$request->setMerchantAuthentication($merchantAuthentication);
53-
$request->setRefId( $refId);
54-
$request->setProfile($customerprofile);
55-
$controller = new AnetController\CreateCustomerProfileController($request);
56-
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
57-
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
58-
{
59-
echo "CreateCustomerProfileRequest SUCCESS: PROFILE ID : " . $response->getCustomerProfileId() . "\n";
60-
$customerProfileId = $response->getCustomerProfileId();
61-
}
62-
else
63-
{
64-
echo "CreateCustomerProfileRequest ERROR : Invalid response\n";
65-
}
66-
// Create a new order
67-
$order = new AnetAPI\OrderType();
68-
$order->setInvoiceNumber("102");
69-
$order->setDescription("Tennis Shirts");
70-
71-
// Add line items
72-
$lineitem = new AnetAPI\LineItemType();
73-
$lineitem->setItemId("Shirts");
74-
$lineitem->setName("item2");
75-
$lineitem->setDescription("tennis shirt");
76-
$lineitem->setQuantity("1");
77-
$lineitem->setUnitPrice(22.89);
78-
$lineitem->setTaxable("Y");
79-
80-
// Add new tax info
81-
$tax = new AnetAPI\ExtendedAmountType();
82-
$tax->setName("level 2 tax name");
83-
$tax->setAmount(6.50);
84-
$tax->setDescription("level 2 tax");
85-
86-
// New Ship To
87-
$shipto = new AnetAPI\CustomerAddressType();
88-
$shipto->setFirstName("Mary");
89-
$shipto->setLastName("Smith");
90-
$shipto->setCompany("Tennis Shirts Are Us");
91-
$shipto->setAddress("588 Willis Court");
92-
$shipto->setCity("Pecan Springs");
93-
$shipto->setState("TX");
94-
$shipto->setZip("44628");
95-
$shipto->setCountry("USA");
96-
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-
}
13818

13919
$transactionRequestType = new AnetAPI\TransactionRequestType();
14020
$transactionRequestType->setTransactionType( "authCaptureTransaction");
14121
$transactionRequestType->setAmount(100.50);
142-
$transactionRequestType->setPayment($paymentprofile2->getPayment());
143-
$transactionRequestType->setOrder($order);
144-
$transactionRequestType->addToLineItems($lineitem);
145-
$transactionRequestType->setTax($tax);
146-
//$transactionRequestType->setPoNumber($ponumber);
147-
//$transactionRequestType->setCustomer($customer);
148-
$transactionRequestType->setBillTo($billto);
149-
$transactionRequestType->setShipTo($shipto);
22+
$transactionRequestType->setProfile($profileToCharge);
23+
15024
$request = new AnetAPI\CreateTransactionRequest();
15125
$request->setMerchantAuthentication($merchantAuthentication);
15226
$request->setRefId( $refId);

0 commit comments

Comments
 (0)