Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's easy enough to use the TransactionSearch API to find a transaction by invoice number. All you need to do is send the INVNUM parameter along in the API call to PayPal.</p> <p>For example (based on PayPal's TransactionSearch PHP sample code): </p> <pre><code>&lt;?php /** TransactionSearch NVP example; last modified 08MAY23. * * Search your account history for transactions that meet the criteria you specify. */ $environment = 'sandbox'; // or 'beta-sandbox' or 'live' /** * Send HTTP POST Request * * @param string The API method name * @param string The POST Message fields in &amp;name=value pair format * @return array Parsed HTTP Response body */ function PPHttpPost($methodName_, $nvpStr_) { global $environment; // Set up your API credentials, PayPal end point, and API version. $API_UserName = urlencode('xxxxxxxxxxxx'); $API_Password = urlencode('yyyyyyyyy'); $API_Signature = urlencode('zzzzzzzzzzzzzzzzzzzzzzz'); $API_Endpoint = "https://api-3t.paypal.com/nvp"; if("sandbox" === $environment || "beta-sandbox" === $environment) { $API_Endpoint = "https://api-3t.$environment.paypal.com/nvp"; } $version = urlencode('84.0'); // Set the curl parameters. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $API_Endpoint); curl_setopt($ch, CURLOPT_VERBOSE, 1); // Turn off the server and peer verification (TrustManager Concept). curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); // Set the API operation, version, and API signature in the request. $nvpreq = "METHOD=$methodName_&amp;VERSION=$version&amp;PWD=$API_Password&amp;USER=$API_UserName&amp;SIGNATURE=$API_Signature$nvpStr_"; // Set the request as a POST FIELD for curl. curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq); // Get response from the server. $httpResponse = curl_exec($ch); if(!$httpResponse) { exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')'); } // Extract the response details. $httpResponseAr = explode("&amp;", $httpResponse); $httpParsedResponseAr = array(); foreach ($httpResponseAr as $i =&gt; $value) { $tmpAr = explode("=", $value); if(sizeof($tmpAr) &gt; 1) { $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1]; } } if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) { exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint."); } return $httpParsedResponseAr; } </code></pre> <p>Up to here it's all as usual. The only changes to the sample are here: </p> <pre><code>// Set request-specific fields. //$transactionID = urlencode('example_transaction_id'); $invoice = urlencode('1234'); // Add request-specific fields to the request string. //$nvpStr = "&amp;TRANSACTIONID=$transactionID"; $nvpStr = "&amp;INVNUM=$invoice"; </code></pre> <p>Here, by setting a proper STARTDATE: </p> <pre><code>// Set additional request-specific fields and add them to the request string. $startDateStr = "01/01/2010"; // in 'mm/dd/ccyy' format $endDateStr; // in 'mm/dd/ccyy' format if(isset($startDateStr)) { $start_time = strtotime($startDateStr); $iso_start = date('Y-m-d\T00:00:00\Z', $start_time); $nvpStr .= "&amp;STARTDATE=$iso_start"; } if(isset($endDateStr)&amp;&amp;$endDateStr!='') { $end_time = strtotime($endDateStr); $iso_end = date('Y-m-d\T24:00:00\Z', $end_time); $nvpStr .= "&amp;ENDDATE=$iso_end"; } // Execute the API operation; see the PPHttpPost function above. $httpParsedResponseAr = PPHttpPost('TransactionSearch', $nvpStr); </code></pre> <p>And here, by adding a simple if statement to trigger whether or not to return the full TransactionSearch API result, or only return the PayPal transaction ID (bla.php?view=minimal): </p> <pre><code>if($_GET['view'] != "minimal") { if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) { echo('TransactionSearch Completed Successfully: '.print_r($httpParsedResponseAr, true)); } else { echo('TransactionSearch failed: ' . print_r($httpParsedResponseAr, true)); } } else { // Output only the TransactionID echo $httpParsedResponseAr['L_TRANSACTIONID0']; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload