0

I am trying to generate a sandbox paypal button on the fly so I dont have to manually make a bunch of buttons.

Im finding their docs terrible since half of their instructions dont fit their sites now, and that its impossible to find answers since everything is outdated.

On this page there is a Curl example to make a call to the sandbox but I also dont know how I can convert that to a PHP Curl script.

https://developer.paypal.com/docs/classic/lifecycle/sb_calls/

curl https://api-3t.sandbox.paypal.com/nvp \
-s \
--insecure \
-d USER=YourUserID \
-d PWD=YourPassword \
-d SIGNATURE=YourSignature \
-d METHOD=SetExpressCheckout \
-d VERSION=98 \
-d PAYMENTREQUEST_0_AMT=10 \
-d PAYMENTREQUEST_0_CURRENCYCODE=USD \
-d PAYMENTREQUEST_0_PAYMENTACTION=SALE \
-d cancelUrl=http://www.example.com/cancel.html \
-d returnUrl=http://www.example.com/success.html

Could someone shed some light for me please?

Craig
  • 1,648
  • 1
  • 20
  • 45
  • What have you tried so far? Have you checked here: http://php.net/curl – miken32 Mar 23 '17 at 03:39
  • For fast and efficient results, use Postman. [Importing cURL commands](https://www.getpostman.com/docs/importing_curl) and then [generate the code snippet](https://www.getpostman.com/docs/code_snippets) – ʰᵈˑ Apr 24 '17 at 09:10

1 Answers1

0

Here is a sample code for Express Checkout, change the credentials and work on it. Here, you can pass necessary parameter with the values and you can call up which method you need on "&method" parameter.

<?php

$url = "https://api-3t.paypal.com/nvp";
   //$url = "https://api-3t.sandbox.paypal.com/nvp";
 $nvps = 
  "&USER=XXXXXXXx"
   ."&PWD=XXXXXXXX"
    ."&SIGNATURE=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";



  if(!isset($token)) {  

   $nvpset= $nvps

 ."&returnurl=http://localhost/training/ec_return.php"
 ."&cancelurl=http://localhost/training/ec_call.php"
 ."&localecode=US"
 ."&SOLUTIONTYPE=Sole"
 ."&method=SetExpressCheckout"
 ."&version=204.0"    
 ."&paymentrequest_0_currencycode=USD"
 ."&addroverride=1"
 ."&noshipping=2"
 ."&PAYMENTREQUEST_0_SHIPTONAME= James Costerton"
."&PAYMENTREQUEST_0_SHIPTOSTREET=3929 Coburn Hollow Road"
."&PAYMENTREQUEST_0_SHIPTOCITY=London"
."&PAYMENTREQUEST_0_SHIPTOSTATE="
."&PAYMENTREQUEST_0_SHIPTOZIP=SE23 1NX"
."&PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE=GB"
."&PAYMENTREQUEST_n_SHIPTOPHONENUM=309-374-5347"
 ."&paymentrequest_0_amt=1.00";




$response = RunAPICall($nvpset); 
echo '<pre>';
print_r($response);
}

function RunAPICall($nvps){
 global $url;
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL,$url);
 curl_setopt($ch, CURLOPT_VERBOSE, 1);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
 curl_setopt($ch, CURLOPT_SSLVERSION,6);
 curl_setopt($ch, CURLOPT_TIMEOUT, 45);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS,$nvps);


 $result = curl_exec($ch);
 $httpResponseAr = explode("&", strtoupper($result));
$httpParsedResponseAr = array();
foreach ($httpResponseAr as $value) {
    $tmpAr = explode("=", $value);
    if(sizeof($tmpAr) > 1) {
        $httpParsedResponseAr[$tmpAr[0]] = urldecode($tmpAr[1]);
    }
}

curl_close ($ch); 
return $httpParsedResponseAr;
}?>
Ansi Vict
  • 66
  • 5