|
4 | 4 | use net\authorize\api\controller as AnetController; |
5 | 5 | define("AUTHORIZENET_LOG_FILE", "phplog"); |
6 | 6 |
|
7 | | - // Put the values of the Payer ID and Ref. Transaction ID generated in Authorization and Capture |
8 | | - $payerID="6ZSCSYG33VP8Q"; |
9 | | - $refTransId="2241708986"; |
10 | | - |
11 | | - // Common setup for API credentials (with PayPal compatible merchant credentials) |
12 | | - $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); |
13 | | - $merchantAuthentication->setName("5KP3u95bQpv"); |
14 | | - $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); |
15 | | - |
16 | | - $payPalType=new AnetAPI\PayPalType(); |
17 | | - $payPalType->setPayerID($payerID); |
18 | | - |
19 | | - $paymentOne = new AnetAPI\PaymentType(); |
20 | | - $paymentOne->setPayPal($payPalType); |
21 | | - |
22 | | - // Create an authorize and capture continue transaction |
23 | | - $transactionRequestType = new AnetAPI\TransactionRequestType(); |
24 | | - $transactionRequestType->setTransactionType( "authCaptureContinueTransaction"); |
25 | | - $transactionRequestType->setPayment($paymentOne); |
26 | | - $transactionRequestType->setRefTransId($refTransId); |
27 | | - |
28 | | - $request = new AnetAPI\CreateTransactionRequest(); |
29 | | - $request->setMerchantAuthentication($merchantAuthentication); |
30 | | - $request->setTransactionRequest( $transactionRequestType); |
31 | | - $controller = new AnetController\CreateTransactionController($request); |
32 | | - $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); |
33 | | - |
34 | | - if ($response != null) |
35 | | - { |
36 | | - $tresponse = $response->getTransactionResponse(); |
37 | | - if (($tresponse != null)) |
38 | | - { |
39 | | - echo "Transaction Response...\n"; |
40 | | - echo "Received response code: ".$tresponse->getResponseCode()."\n"; |
41 | | - //Valid response codes: 1=Approved, 2=Declined, 3=Error, 5=Need Payer Consent |
42 | | - echo "Secure acceptance URL: ".$tresponse->getSecureAcceptance()->getSecureAcceptanceUrl()."\n"; |
43 | | - echo "Transaction ID: ".$tresponse->getTransId()."\n"; |
44 | | - } |
45 | | - else |
46 | | - echo "NULL transactionResponse Error\n"; |
47 | | - $messages=$response->getMessages(); |
48 | | - if (($messages != null)) |
| 7 | + function payPalAuthorizeCaptureContinue($refTransId, $payerID) { |
| 8 | + |
| 9 | + // Common setup for API credentials (with PayPal compatible merchant credentials) |
| 10 | + $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); |
| 11 | + $merchantAuthentication->setName("5KP3u95bQpv"); |
| 12 | + $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); |
| 13 | + |
| 14 | + $payPalType=new AnetAPI\PayPalType(); |
| 15 | + $payPalType->setPayerID($payerID); |
| 16 | + |
| 17 | + $paymentOne = new AnetAPI\PaymentType(); |
| 18 | + $paymentOne->setPayPal($payPalType); |
| 19 | + |
| 20 | + // Create an authorize and capture continue transaction |
| 21 | + $transactionRequestType = new AnetAPI\TransactionRequestType(); |
| 22 | + $transactionRequestType->setTransactionType( "authCaptureContinueTransaction"); |
| 23 | + $transactionRequestType->setPayment($paymentOne); |
| 24 | + $transactionRequestType->setRefTransId($refTransId); |
| 25 | + |
| 26 | + $request = new AnetAPI\CreateTransactionRequest(); |
| 27 | + $request->setMerchantAuthentication($merchantAuthentication); |
| 28 | + $request->setTransactionRequest( $transactionRequestType); |
| 29 | + $controller = new AnetController\CreateTransactionController($request); |
| 30 | + $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX); |
| 31 | + |
| 32 | + if ($response != null) |
49 | 33 | { |
50 | | - echo "Messages...\n"; |
51 | | - echo "Result code: ".$messages->getResultCode()."\n"; |
52 | | - $message0=$messages->getMessage()[0]; |
53 | | - if($message0!=null) |
54 | | - echo "Message: ".$message0->getCode().", ".$message0->getText()."\n"; |
| 34 | + $tresponse = $response->getTransactionResponse(); |
| 35 | + if (($tresponse != null)) |
| 36 | + { |
| 37 | + echo "Transaction Response...\n"; |
| 38 | + echo "Received response code: ".$tresponse->getResponseCode()."\n"; |
| 39 | + //Valid response codes: 1=Approved, 2=Declined, 3=Error, 5=Need Payer Consent |
| 40 | + echo "Secure acceptance URL: ".$tresponse->getSecureAcceptance()->getSecureAcceptanceUrl()."\n"; |
| 41 | + echo "Transaction ID: ".$tresponse->getTransId()."\n"; |
| 42 | + } |
| 43 | + else |
| 44 | + echo "NULL transactionResponse Error\n"; |
| 45 | + $messages=$response->getMessages(); |
| 46 | + if (($messages != null)) |
| 47 | + { |
| 48 | + echo "Messages...\n"; |
| 49 | + echo "Result code: ".$messages->getResultCode()."\n"; |
| 50 | + $message0=$messages->getMessage()[0]; |
| 51 | + if($message0!=null) |
| 52 | + echo "Message: ".$message0->getCode().", ".$message0->getText()."\n"; |
| 53 | + } |
| 54 | + else |
| 55 | + echo "NULL messages Error\n"; |
55 | 56 | } |
56 | 57 | else |
57 | | - echo "NULL messages Error\n"; |
| 58 | + echo "NULL response Error\n"; |
| 59 | + |
| 60 | + return $response; |
58 | 61 | } |
59 | | - else |
60 | | - echo "NULL response Error\n"; |
| 62 | + |
| 63 | + if(!defined(DONT_RUN_SAMPLES)) |
| 64 | + payPalAuthorizeCaptureContinue("2241708986","6ZSCSYG33VP8Q"); |
61 | 65 | ?> |
0 commit comments