|
1 | | - |
2 | 1 | <?php |
3 | 2 | require 'vendor/autoload.php'; |
4 | 3 |
|
5 | 4 | use net\authorize\api\contract\v1 as AnetAPI; |
6 | 5 | use net\authorize\api\controller as AnetController; |
7 | 6 |
|
| 7 | + define("AUTHORIZENET_LOG_FILE", "phplog"); |
| 8 | + |
8 | 9 | function getCustomerPaymentProfileList() |
9 | 10 | { |
10 | | - // Common setup for API credentials (merchant) |
11 | | - $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); |
12 | | - $merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); |
13 | | - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); |
14 | | - $refId = 'ref' . time(); |
15 | | - |
16 | | - //Setting the paging |
17 | | - $paging = new AnetAPI\PagingType(); |
18 | | - $paging->setLimit("1000"); |
19 | | - $paging->setOffset("1"); |
20 | | - |
21 | | - //Setting the sorting |
22 | | - $sorting = new AnetAPI\CustomerPaymentProfileSortingType(); |
23 | | - $sorting->setOrderBy("id"); |
24 | | - $sorting->setOrderDescending("false"); |
| 11 | + // Common setup for API credentials (merchant) |
| 12 | + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); |
| 13 | + $merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); |
| 14 | + $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); |
| 15 | + $refId = 'ref' . time(); |
| 16 | + |
| 17 | + //Setting the paging |
| 18 | + $paging = new AnetAPI\PagingType(); |
| 19 | + $paging->setLimit("1000"); |
| 20 | + $paging->setOffset("1"); |
| 21 | + |
| 22 | + //Setting the sorting |
| 23 | + $sorting = new AnetAPI\CustomerPaymentProfileSortingType(); |
| 24 | + $sorting->setOrderBy("id"); |
| 25 | + $sorting->setOrderDescending("false"); |
| 26 | + |
| 27 | + //Creating the request with the required parameters |
| 28 | + $request = new AnetAPI\GetCustomerPaymentProfileListRequest(); |
| 29 | + $request->setMerchantAuthentication($merchantAuthentication); |
| 30 | + $request->setRefId($refId); |
| 31 | + $request->setPaging($paging); |
| 32 | + $request->setSorting($sorting); |
| 33 | + $request->setSearchType("cardsExpiringInMonth"); |
| 34 | + $request->setMonth("2020-12"); |
25 | 35 |
|
26 | | - //Creating the request with the required parameters |
27 | | - $request = new AnetAPI\GetCustomerPaymentProfileListRequest(); |
28 | | - $request->setMerchantAuthentication($merchantAuthentication); |
29 | | - $request->setRefId($refId); |
30 | | - $request->setPaging($paging); |
31 | | - $request->setSorting($sorting); |
32 | | - $request->setSearchType("cardsExpiringInMonth"); |
33 | | - $request->setMonth("2020-12"); |
34 | | - |
35 | | - // Controller |
36 | | - $controller = new AnetController\GetCustomerPaymentProfileListController($request); |
37 | | - // Getting the response |
38 | | - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); |
39 | | - |
40 | | - if(($response != null)) |
41 | | - { |
42 | | - if ($response->getMessages()->getResultCode() == "Ok") |
| 36 | + // Controller |
| 37 | + $controller = new AnetController\GetCustomerPaymentProfileListController($request); |
| 38 | + // Getting the response |
| 39 | + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); |
| 40 | + |
| 41 | + if(($response != null)) |
43 | 42 | { |
44 | | - // Success |
45 | | - echo "GetCustomerPaymentProfileList SUCCESS: " . "\n"; |
46 | | - echo "Message Code: " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; |
47 | | - echo "Message Text: " . $response->getMessages()->getMessage()[0]->getText() . "\n"; |
48 | | - echo "Total number of Results in the result set" . $response->getTotalNumInResultSet() . "\n"; |
49 | | - // Displaying the customer payment profile list |
50 | | - foreach($response->getPaymentProfiles() as $paymentProfile ) |
| 43 | + if ($response->getMessages()->getResultCode() == "Ok") |
51 | 44 | { |
52 | | - echo "\nCustomer Profile id: " . $paymentProfile->getCustomerProfileId() . "\n"; |
53 | | - echo "Payment profile id: " . $paymentProfile->getCustomerPaymentProfileId() . "\n"; |
54 | | - echo "Credit Card Number: " . $paymentProfile->getPayment()->getCreditCard()->getCardNumber() . "\n"; |
55 | | - if($paymentProfile->getBillTo() != null) |
56 | | - echo "First Name in Billing Address: " . $paymentProfile->getBillTo()->getFirstName() . "\n"; |
| 45 | + // Success |
| 46 | + echo "GetCustomerPaymentProfileList SUCCESS: " . "\n"; |
| 47 | + echo "Message Code: " . $response->getMessages()->getMessage()[0]->getCode() . "\n"; |
| 48 | + echo "Message Text: " . $response->getMessages()->getMessage()[0]->getText() . "\n"; |
| 49 | + echo "Total number of Results in the result set" . $response->getTotalNumInResultSet() . "\n"; |
| 50 | + // Displaying the customer payment profile list |
| 51 | + foreach($response->getPaymentProfiles() as $paymentProfile ) |
| 52 | + { |
| 53 | + echo "\nCustomer Profile id: " . $paymentProfile->getCustomerProfileId() . "\n"; |
| 54 | + echo "Payment profile id: " . $paymentProfile->getCustomerPaymentProfileId() . "\n"; |
| 55 | + echo "Credit Card Number: " . $paymentProfile->getPayment()->getCreditCard()->getCardNumber() . "\n"; |
| 56 | + if($paymentProfile->getBillTo() != null) |
| 57 | + echo "First Name in Billing Address: " . $paymentProfile->getBillTo()->getFirstName() . "\n"; |
| 58 | + } |
| 59 | + } |
| 60 | + else |
| 61 | + { |
| 62 | + // Error |
| 63 | + echo "GetCustomerPaymentProfileList ERROR : Invalid response\n"; |
| 64 | + echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; |
57 | 65 | } |
58 | 66 | } |
59 | 67 | else |
60 | 68 | { |
61 | | - // Error |
62 | | - echo "GetCustomerPaymentProfileList ERROR : Invalid response\n"; |
63 | | - echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n"; |
| 69 | + // Failed to get the response |
| 70 | + echo "NULL Response Error"; |
64 | 71 | } |
65 | | - } |
66 | | - else |
67 | | - { |
68 | | - // Failed to get the response |
69 | | - echo "NULL Response Error"; |
70 | | - } |
71 | | - return $response; |
| 72 | + return $response; |
72 | 73 | } |
73 | 74 | if(!defined('DONT_RUN_SAMPLES')) |
74 | 75 | getCustomerPaymentProfileList(); |
|
0 commit comments