PHP Curl Paypal沙盒

是否可以使用CURL和PayPal的开发者沙盒?当我尝试这个代码,它在print_r($lines)中说;我需要登录到沙箱,如何让它发送我的浏览器cookie?

这段代码是http://leepeng.blogspot.com/2006/04/standard-paypal-php-integration.html

$orderno = $_SESSION["ss_last_orderno"];
    $ppAcc = "[SELLER HERE]";
    $at = "[AT HERE]"; //PDT Identity Token
    $url = "https://www.sandbox.paypal.com/cgi-bin/webscr"; //Test
    //$url = "https://www.paypal.com/cgi-bin/webscr"; //Live
    $tx = $_REQUEST['tx']; //this value is return by PayPal
    $cmd = "_notify-synch";
    $post = "tx=$tx&at=$at&cmd=$cmd";

    //Send request to PayPal server using CURL
    $ch = curl_init ($url);
    curl_setopt ($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt ($ch,CURLOPT_HEADER,0);
    curl_setopt ($ch,CURLOPT_TIMEOUT,30);
    curl_setopt ($ch,CURLOPT_POST,1);
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
    curl_setopt ($ch,CURLOPT_POSTFIELDS,$post);

    $result = curl_exec ($ch); //returned result is key-value pair string
    $error = curl_error($ch);

    if (curl_errno($ch) != 0) //CURL error
    exit("ERROR: Failed updating order. PayPal PDT service failed.");

    $longstr = str_replace("\r","",$result);
    $lines = split("\n",$longstr);
    print_r($lines);
    //parse the result string and store information to array
    if ($lines[0] == "SUCCESS") {
    //successful payment
    $ppInfo = array();
    for ($i=1; $i<count($lines); $i++) {
    $parts = split("=",$lines[$i]);
    if (count($parts)==2) {
    $ppInfo[$parts[0]] = urldecode($parts[1]);
    }
    }

    $curtime = gmdate("d/m/Y H:i:s");
    //capture the PayPal returned information as order remarks
    $oremarks =
    "##$curtime##\n".
    "PayPal Transaction Information...\n".
    "Txn Id: ".$ppInfo["txn_id"]."\n".
    "Txn Type: ".$ppInfo["txn_type"]."\n".
    "Item Number: ".$ppInfo["item_number"]."\n".
    "Payment Date: ".$ppInfo["payment_date"]."\n".
    "Payment Type: ".$ppInfo["payment_type"]."\n".
    "Payment Status: ".$ppInfo["payment_status"]."\n".
    "Currency: ".$ppInfo["mc_currency"]."\n".
    "Payment Gross: ".$ppInfo["payment_gross"]."\n".
    "Payment Fee: ".$ppInfo["payment_fee"]."\n".
    "Payer Email: ".$ppInfo["payer_email"]."\n".
    "Payer Id: ".$ppInfo["payer_id"]."\n".
    "Payer Name: ".$ppInfo["first_name"]." ".$ppInfo["last_name"]."\n".
    "Payer Status: ".$ppInfo["payer_status"]."\n".
    "Country: ".$ppInfo["residence_country"]."\n".
    "Business: ".$ppInfo["business"]."\n".
    "Receiver Email: ".$ppInfo["receiver_email"]."\n".
    "Receiver Id: ".$ppInfo["receiver_id"]."\n";

    //Update database using $orderno,set status to Paid
    //Send confirmation email to buyer and notification email to merchant
    //Redirect to thankyou page
    }

    //Payment failed
    else {

    print "Please try again...";
    //Delete order information
    //Redirect to failed page
    }
这应该工作:
$tid = $_GET['tx'];
$auth_token = "zzzzzzzzzzzzzzzzzzzz";
$paypal_url = "www.sandbox.paypal.com";

$url = "https://" . $paypal_url . "/cgi-bin/webscr";

$post_vars = "cmd=_notify-synch&tx=" . $tid . "&at=" . $auth_token;

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,1);
curl_setopt($ch,$post_vars);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,15);
curl_setopt($ch,true);
curl_setopt($ch,false);
curl_setopt($ch,CURLOPT_USERAGENT,'cURL/PHP');

$fetched = curl_exec($ch);



$lines = explode("\n",$fetched);
$keyarray = array();
if (strcmp ($lines[0],"SUCCESS") == 0) {
for ($i=1; $i<count($lines);$i++){
list($key,$val) = explode("=",$lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
$firstname = $keyarray['first_name'];
$lastname = $keyarray['last_name'];
$itemname = $keyarray['num_cart_items'];
$amount = $keyarray['mc_gross'];

echo ("<h2>Thank you for your purchase!</h2>");

}
else if (strcmp ($lines[0],"FAIL") == 0) {
    echo ("<h2>Sorry,something went wrong</h2>");

// log for manual investigation

}

约$_GET [‘tx’]查找停止工作后约5分钟

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


如何选择合适的 C++ Web 开发框架?
利用 C++ 框架构建高并发 Web 应用的策略
用 C++ 框架开发跨平台图形应用程序
golang框架中安全编码实践的最佳指南是什么?
golang框架与其他语言框架在设计理念上的区别有哪些?
C++ 图形框架与其他语言框架的比较
C++ 框架与其他 Web 开发框架的对比分析
使用 C++ 框架构建大型项目最佳实践
C++ 框架如何提高大型项目开发效率
C++ 框架中依赖注入的持续集成与部署工具
如何与社区协作和贡献到自定义 Golang 框架?
C++ 框架在大型项目中如何实现模块化开发
使用 C++ 框架开发跨平台 Web 应用
C++ 框架在大型项目中的优缺点
golang框架在性能上的优势体现在哪些方面?
C++ 框架在嵌入式系统内存优化中的优势
golang框架在人工智能与机器学习中的作用
如何扩展 Golang 框架以支持特定功能?
如何利用 Go Modules 和依赖项管理来自定义 Golang 框架?
Golang 框架中的性能优化技巧