JezK
Edit File: paypal-payment-test-verification.php
<?php //error_reporting(0); use PayPal\PayPalAPI\TransactionSearchReq; use PayPal\PayPalAPI\TransactionSearchRequestType; use PayPal\Service\PayPalAPIInterfaceServiceService; use PayPal\CoreComponentTypes\BasicAmountType; use PayPal\PayPalAPI\MassPayReq; use PayPal\PayPalAPI\MassPayRequestItemType; use PayPal\PayPalAPI\MassPayRequestType; //use PayPal\Service\PayPalAPIInterfaceServiceService; use PayPal\Auth\PPSignatureCredential; use PayPal\Auth\PPTokenAuthorization; require_once('./PPBootStrap.php'); /* * # TransactionSearch API The TransactionSearch API searches transaction history for transactions that meet the specified criteria. `Note: The maximum number of transactions that can be returned from a TransactionSearch API call is 100. This sample code uses Merchant PHP SDK to make API call */ /* * `TransactionSearchRequestType` which takes mandatory argument: * `Start Date` - The earliest transaction date at which to start the search. */ $response=array(); $response['message']='failed'; if($_SERVER['REQUEST_METHOD'] == 'POST') { $transactionId=$_POST['transactionId']; //transaction id from paypal response $type=$_POST['type']; //type of the transaction. 1-user cart payment, 2- vendor subscription payment //echo $transactionId; //$transactionId='2JV97241D7428434M';; $transactionSearchRequest = new TransactionSearchRequestType(); $transactionSearchRequest->StartDate = date('Y-m-d H:i:s+0000',strtotime("-1 days")); $transactionSearchRequest->EndDate = date('Y-m-d H:i:s+0000'); //echo $transactionSearchRequest->StartDate; //echo $transactionSearchRequest->EndDate; $transactionSearchRequest->TransactionID = $transactionId; $tranSearchReq = new TransactionSearchReq(); $tranSearchReq->TransactionSearchRequest = $transactionSearchRequest; /* * ## Creating service wrapper object Creating service wrapper object to make API call and loading Configuration::getAcctAndConfig() returns array that contains credential and config parameters */ $paypalService = new PayPalAPIInterfaceServiceService(Configuration::getAcctAndConfig()); try { /* wrap API method calls on the service object with a try catch */ $transactionSearchResponse = $paypalService->TransactionSearch($tranSearchReq); } catch (Exception $ex) { //include_once("../Error.php"); $response['message']='try_again'; //exit; } if(isset($transactionSearchResponse)) { $paypalTransactionID=$transactionSearchResponse->PaymentTransactions[0]->TransactionID; $transactionStatus=$transactionSearchResponse->PaymentTransactions[0]->Status; $transactionCurrencyId=$transactionSearchResponse->PaymentTransactions[0]->GrossAmount->currencyID; $transactionGrossAmount=$transactionSearchResponse->PaymentTransactions[0]->GrossAmount->value; $transactionFeeAmount=$transactionSearchResponse->PaymentTransactions[0]->FeeAmount->value; $transactionNetAmount=$transactionSearchResponse->PaymentTransactions[0]->NetAmount->value; if($paypalTransactionID == $transactionId && $transactionStatus == 'Completed') { echo "Payment Success"; } } } header('Content-type: application/json'); echo json_encode($response);