简体   繁体   English

paypal立即购买按钮生成(PHP)

[英]paypal buy now button generation (PHP)

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. 在此页面上,有一个Curl示例可以调用沙箱,但我也不知道如何将其转换为PHP Curl脚本。

https://developer.paypal.com/docs/classic/lifecycle/sb_calls/ 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? 有人可以帮我一下吗?

Here is a sample code for Express Checkout, change the credentials and work on it. 这是Express Checkout的示例代码,更改凭据并对其进行处理。 Here, you can pass necessary parameter with the values and you can call up which method you need on "&method" parameter. 在这里,您可以将必要的参数与值一起传递,并可以在“&method”参数上调用所需的方法。

<?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;
}?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM