|
3 | 3 | use net\authorize\api\contract\v1 as AnetAPI; |
4 | 4 | use net\authorize\api\controller as AnetController; |
5 | 5 | 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(); |
11 | 14 |
|
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); |
18 | 21 |
|
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 |
35 | 38 |
|
36 | | - $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); |
| 39 | + $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); |
37 | 40 |
|
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); |
48 | 52 |
|
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; |
65 | 71 | } |
| 72 | + if(!defined(DONT_RUN_SAMPLES)) |
| 73 | + createCustomerProfile(); |
66 | 74 | ?> |
0 commit comments