|
9 | 9 | $merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq"); |
10 | 10 | $refId = 'ref' . time(); |
11 | 11 |
|
| 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 | + |
12 | 19 | // Bill To |
13 | 20 | $billto = new AnetAPI\CustomerAddressType(); |
14 | 21 | $billto->setFirstName("Ellen"); |
|
20 | 27 | $billto->setZip("44628"); |
21 | 28 | $billto->setCountry("USA"); |
22 | 29 |
|
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"); |
33 | 30 |
|
34 | 31 | // 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 |
37 | 34 | // 3. Submit a CreateCustomerProfile Request |
38 | | - // 4. Validate Profiiel ID returned |
| 35 | + // 4. Validate the profile id returned |
39 | 36 |
|
40 | 37 | $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); |
41 | 38 |
|
42 | 39 | $paymentprofile->setCustomerType('individual'); |
43 | 40 | $paymentprofile->setBillTo($billto); |
44 | | - $paymentprofile->setShipToList($shipto); |
45 | | - $paymentprofile->setPayment($paymentCreditCard); |
| 41 | + $paymentprofile->setPayment($paymentOne); |
46 | 42 | $paymentprofiles[] = $paymentprofile; |
| 43 | + |
47 | 44 | $customerprofile = new AnetAPI\CustomerProfileType(); |
48 | 45 | $customerprofile->setDescription("Customer 2 Test PHP"); |
49 | 46 | $merchantCustomerId = time().rand(1,150); |
|
59 | 56 | $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); |
60 | 57 | if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) |
61 | 58 | { |
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 | + } |
65 | 62 | else |
66 | 63 | { |
67 | | - echo "Create Profile ERROR : Invalid response\n"; |
| 64 | + echo "CreateCustomerProfileRequest ERROR : Invalid response\n"; |
68 | 65 | } |
69 | | - |
70 | | - // Order info |
| 66 | + // Create a new order |
71 | 67 | $order = new AnetAPI\OrderType(); |
72 | 68 | $order->setInvoiceNumber("102"); |
73 | 69 | $order->setDescription("Tennis Shirts"); |
74 | 70 |
|
75 | | - // Line Item Info |
| 71 | + // Add line items |
76 | 72 | $lineitem = new AnetAPI\LineItemType(); |
77 | 73 | $lineitem->setItemId("Shirts"); |
78 | 74 | $lineitem->setName("item2"); |
|
81 | 77 | $lineitem->setUnitPrice(22.89); |
82 | 78 | $lineitem->setTaxable("Y"); |
83 | 79 |
|
84 | | - // Tax info |
| 80 | + // Add new tax info |
85 | 81 | $tax = new AnetAPI\ExtendedAmountType(); |
86 | 82 | $tax->setName("level 2 tax name"); |
87 | 83 | $tax->setAmount(6.50); |
88 | 84 | $tax->setDescription("level 2 tax"); |
89 | 85 |
|
90 | | - // Ship To |
| 86 | + // New Ship To |
91 | 87 | $shipto = new AnetAPI\CustomerAddressType(); |
92 | 88 | $shipto->setFirstName("Mary"); |
93 | 89 | $shipto->setLastName("Smith"); |
94 | | - $shipto->setCompany("Tenis Shirts Are Us"); |
| 90 | + $shipto->setCompany("Tennis Shirts Are Us"); |
95 | 91 | $shipto->setAddress("588 Willis Court"); |
96 | 92 | $shipto->setCity("Pecan Springs"); |
97 | 93 | $shipto->setState("TX"); |
98 | 94 | $shipto->setZip("44628"); |
99 | 95 | $shipto->setCountry("USA"); |
100 | 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 | + } |
| 138 | + |
101 | 139 | $transactionRequestType = new AnetAPI\TransactionRequestType(); |
102 | 140 | $transactionRequestType->setTransactionType( "authCaptureTransaction"); |
103 | 141 | $transactionRequestType->setAmount(100.50); |
104 | | - $transactionRequestType->setProfile($profileId); |
105 | | - //$transactionRequestType->setPayment($paymentBank); |
| 142 | + $transactionRequestType->setPayment($paymentprofile2->getPayment()); |
106 | 143 | $transactionRequestType->setOrder($order); |
107 | 144 | $transactionRequestType->addToLineItems($lineitem); |
108 | 145 | $transactionRequestType->setTax($tax); |
109 | 146 | //$transactionRequestType->setPoNumber($ponumber); |
110 | 147 | //$transactionRequestType->setCustomer($customer); |
111 | | - //$transactionRequestType->setBillTo($billto); |
| 148 | + $transactionRequestType->setBillTo($billto); |
112 | 149 | $transactionRequestType->setShipTo($shipto); |
113 | 150 | $request = new AnetAPI\CreateTransactionRequest(); |
114 | 151 | $request->setMerchantAuthentication($merchantAuthentication); |
|
121 | 158 | $tresponse = $response->getTransactionResponse(); |
122 | 159 | if (($tresponse != null) && ($tresponse->getResponseCode()=="1") ) |
123 | 160 | { |
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"; |
127 | 164 | } |
128 | 165 | elseif (($tresponse != null) && ($tresponse->getResponseCode()=="2") ) |
129 | 166 | { |
|
139 | 176 | echo "no response returned"; |
140 | 177 | } |
141 | 178 | ?> |
142 | | - |
|
0 commit comments