cURL和paypal的新手......我做错了什么?

时间:2015-01-31 03:48:02

标签: php curl paypal

我没有运气联系paypal.com和我的cURL代码......它看起来不错吗?我对php和cURL都比较新。最近,我一直在收到错误6,但偶尔会遇到错误,但没有任何东西可以激活。我从目标中得不到任何回报。我是否正确设置了cURL选项?

$cmdstring =  "cmd=_cart&upload=1&business=registration@example.com";
$cmdstring .= "&custom=12-1,13-1";
$cmdstring .= urlencode("&notify_url=http://www.example.com/paypalipn.php");
$cmdstring .= "&return=http://www.example.com/checkout_complete.php";
$cmdstring .= "&rm=2";
$cmdstring .= "&cbt=Return%20to%20Example%202015%20website";
$cmdstring .= "&cancel_return=http://www.example.com/paypal_cancel.php";
$cmdstring .= "&lc=US";
$cmdstring .= urlencode("&currency_code=USD");

$curl_connection = curl_init("https://www.sandbox.example.com/cgi-bin/webscr");

curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_connection, CURLOPT_POST, true);

curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $cmdstring);

$result = curl_exec($curl_connection);

提前致谢

1 个答案:

答案 0 :(得分:0)

您正在构建的字符串是网站付款标准字符串。这些设计用于在相应买家的浏览器中转发。

以下302重定向到会话网址不能用于将买家转发给PayPal。您需要显示通过用户浏览器发布此信息的链接或按钮。

此外,您在该通话中缺少项目详细信息。 这是一个工作车上传HTML表单:

<form method="post" action="https://www.sandbox.paypal.com/cgi-bin/webscr" name="form1">
<input type="hidden" value="_cart" name="cmd">
<input type="hidden" value="1" name="upload">
<input type="hidden" value="KKZAQCGG9C5CJ" name="business">
<input type="hidden" value="EUR" name="currency_code">

<input type="hidden" value="http://localhost/return" name="return">
<input type="hidden" value="http://localhost/cancel" name="cancel_return">

<input type="hidden" value="Test Item 1" name="item_name_1">
<input type="hidden" value="2" name="quantity_1">
<input type="hidden" value="400" name="amount_1">
<input type="hidden" value="9.99" name="shipping_1">

<input type="hidden" value="Test Item 2" name="item_name_2">
<input type="hidden" value="1" name="quantity_2">
<input type="hidden" value="100" name="amount_2">

<input type="hidden" value="https://static.e-junkie.com/sslpic/90711.d81b6c23d4327edc88c0dcf78360d9e2.jpg" name="cpp_header_image">
<input type="submit" value="Buy Now" name="submit">
</form>