|
7 | 7 |
|
8 | 8 | function getAnAcceptPaymentPage() |
9 | 9 | { |
10 | | - // Common setup for API credentials |
11 | | - $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); |
12 | | - $merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); |
13 | | - $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); |
| 10 | + // Common setup for API credentials |
| 11 | + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); |
| 12 | + $merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID); |
| 13 | + $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY); |
14 | 14 |
|
15 | | - //create a transaction |
16 | | - $transactionRequestType = new AnetAPI\TransactionRequestType(); |
17 | | - $transactionRequestType->setTransactionType( "authCaptureTransaction"); |
18 | | - $transactionRequestType->setAmount("12.23"); |
| 15 | + //create a transaction |
| 16 | + $transactionRequestType = new AnetAPI\TransactionRequestType(); |
| 17 | + $transactionRequestType->setTransactionType("authCaptureTransaction"); |
| 18 | + $transactionRequestType->setAmount("12.23"); |
19 | 19 |
|
20 | | - // Set Hosted Form options |
21 | | - $setting1 = new AnetAPI\SettingType(); |
22 | | - $setting1->setSettingName("hostedPaymentButtonOptions"); |
23 | | - $setting1->setSettingValue("{\"text\": \"Pay\"}"); |
| 20 | + // Set Hosted Form options |
| 21 | + $setting1 = new AnetAPI\SettingType(); |
| 22 | + $setting1->setSettingName("hostedPaymentButtonOptions"); |
| 23 | + $setting1->setSettingValue("{\"text\": \"Pay\"}"); |
24 | 24 |
|
25 | | - $setting2 = new AnetAPI\SettingType(); |
26 | | - $setting2->setSettingName("hostedPaymentOrderOptions"); |
27 | | - $setting2->setSettingValue("{\"show\": false}"); |
| 25 | + $setting2 = new AnetAPI\SettingType(); |
| 26 | + $setting2->setSettingName("hostedPaymentOrderOptions"); |
| 27 | + $setting2->setSettingValue("{\"show\": false}"); |
28 | 28 |
|
29 | | - $setting3 = new AnetAPI\SettingType(); |
30 | | - $setting3->setSettingName("hostedPaymentReturnOptions"); |
31 | | - $setting3->setSettingValue("{\"url\": \"https://mysite.com/receipt\", \"cancelUrl\": \"https://mysite.com/cancel\", \"showReceipt\": true}"); |
| 29 | + $setting3 = new AnetAPI\SettingType(); |
| 30 | + $setting3->setSettingName("hostedPaymentReturnOptions"); |
| 31 | + $setting3->setSettingValue("{\"url\": \"https://mysite.com/receipt\", \"cancelUrl\": \"https://mysite.com/cancel\", \"showReceipt\": true}"); |
32 | 32 |
|
33 | | - // Build transaction request |
34 | | - $request = new AnetAPI\GetHostedPaymentPageRequest(); |
35 | | - $request->setMerchantAuthentication($merchantAuthentication); |
36 | | - $request->setTransactionRequest($transactionRequestType); |
| 33 | + // Build transaction request |
| 34 | + $request = new AnetAPI\GetHostedPaymentPageRequest(); |
| 35 | + $request->setMerchantAuthentication($merchantAuthentication); |
| 36 | + $request->setTransactionRequest($transactionRequestType); |
37 | 37 |
|
38 | | - $request->addToHostedPaymentSettings($setting1); |
39 | | - $request->addToHostedPaymentSettings($setting2); |
40 | | - $request->addToHostedPaymentSettings($setting3); |
41 | | - |
42 | | - //execute request |
43 | | - $controller = new AnetController\GetHostedPaymentPageController($request); |
44 | | - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); |
45 | | - |
46 | | - if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) |
47 | | - { |
48 | | - echo $response->getToken()."\n"; |
49 | | - } |
50 | | - else |
51 | | - { |
52 | | - echo "ERROR : Failed to get hosted payment page token\n"; |
53 | | - $errorMessages = $response->getMessages()->getMessage(); |
54 | | - echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; |
55 | | - } |
56 | | - return $response; |
| 38 | + $request->addToHostedPaymentSettings($setting1); |
| 39 | + $request->addToHostedPaymentSettings($setting2); |
| 40 | + $request->addToHostedPaymentSettings($setting3); |
| 41 | + |
| 42 | + //execute request |
| 43 | + $controller = new AnetController\GetHostedPaymentPageController($request); |
| 44 | + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); |
| 45 | + |
| 46 | + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) |
| 47 | + { |
| 48 | + echo $response->getToken()."\n"; |
| 49 | + } |
| 50 | + else |
| 51 | + { |
| 52 | + echo "ERROR : Failed to get hosted payment page token\n"; |
| 53 | + $errorMessages = $response->getMessages()->getMessage(); |
| 54 | + echo "RESPONSE : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; |
| 55 | + } |
| 56 | + return $response; |
57 | 57 | } |
58 | 58 | if(!defined('DONT_RUN_SAMPLES')) |
59 | | - getAnAcceptPaymentPage(); |
| 59 | + getAnAcceptPaymentPage(); |
60 | 60 | ?> |
0 commit comments