通过GET和cURL转发PayPal Sandbox数据



我试图通过一个贝宝交易的数据,而不是由贝宝建议的经典形式,但使用cURL。谁能给我解释一下为什么GET方法工作:

$fields = [
'business'          => 'xxxxxxxxxxxxxxxxx@business.example.com',
'cmd'               => '_xclick',
'return'            => 'https://www.examplemysite.com/thank_you.php',
'cancel_return'     => 'https://www.examplemysite.com/cart.php',
'notify_url'        => 'https://www.examplemysite.com/ipn.php',
'rm'                => '2',
'currency_code'     => 'EUR',
'lc'                => 'IT',
'cbt'               => 'Continua',
'shipping'          => $_POST['shipping'],
'cs'                => '1',
'item_name'         => $_POST['item_name'],
'amount'            => $_POST['amount'],
'custom'            => $_POST['custom'],
'first_name'        => $_POST['first_name'],
'last_name'         => $_POST['last_name'],
'address1'          => $_POST['address1'],
'city'              => $_POST['city'],
'state'             => $_POST['state'],
'zip'               => $_POST['zip'],
'note'              => $_POST['note'],
'email'             => $_POST['email']
];
$fields_string = http_build_query($fields);
header('Location: https://ipnpb.sandbox.paypal.com/cgi-bin/webscr?' . $fields_string);
exit;

,但它不工作,当我使用cURL?

$fields = [
'business'          => 'xxxxxxxxxxxxxxxxx@business.example.com',
'cmd'               => '_xclick',
'return'            => 'https://www.examplemysite.com/thank_you.php',
'cancel_return'     => 'https://www.examplemysite.com/cart.php',
'notify_url'        => 'https://www.examplemysite.com/ipn.php',
'rm'                => '2',
'currency_code'     => 'EUR',
'lc'                => 'IT',
'cbt'               => 'Continua',
'shipping'          => $_POST['shipping'],
'cs'                => '1',
'item_name'         => $_POST['item_name'],
'amount'            => $_POST['amount'],
'custom'            => $_POST['custom'],
'first_name'        => $_POST['first_name'],
'last_name'         => $_POST['last_name'],
'address1'          => $_POST['address1'],
'city'              => $_POST['city'],
'state'             => $_POST['state'],
'zip'               => $_POST['zip'],
'note'              => $_POST['note'],
'email'             => $_POST['email']
];
$fields_string = http_build_query($fields);
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

//execute post
$result = curl_exec($ch);
echo $result;

使用cURL,我看到,在地址栏,仍然是我的网站的地址(我改变了一些值的目的,但概念是,我应该看到paypal的url):

www.examplemysite.com/signin ?意图= checkout& ctxId = xo_ctx_XXXXXXXXXXXX& returnUri = % 2 fwebapps % 2 fhermes&状态= % 3 fflow % 3 d1-p % 26 ulreturn % 3 dtrue % 26牌% 3 d4ey4066234167522p % 26 useraction % 3 dcommit % 26 rm % 3 d2 % 26 mfid % 3 d1668497487713_32d532f25ea2c % 26 rcache % 3 d2 % 26 cookiebannervariant % 3 d1 % 26 targetservice4174 % 3 dxorouternodeweb& locale.x = it_IT& country.x =它;flowId = 4 ey4066234167522p

我正在尝试传递paypal交易的数据,而不是使用paypal建议的经典形式,而是使用cURL。

贝宝没有建议做标题重定向到ipnpb.sandbox.paypal.com。对于结帐,应该使用www.(sandbox.)paypal.com。Ipnpb仅用于ipn验证的ipn回发,这与您的代码无关。

此外,这样的网站支付标准集成不能使用curl完成。它需要重定向实际客户的浏览器以及交易信息(post/get字段)

要使用curl或类似的设置交易,您需要使用PayPal API,例如current/v2/checkout/orders。使用客户端id和secret首先获取access_token,然后创建订单。

一旦你能够成功地与PayPal API通信,最好的解决方案是在你的服务器上创建两条路由,并将它们与以下审批流程配对:https://developer.paypal.com/demo/checkout/#/pattern/server

IPN对于API集成来说不是必需的,捕获/执行响应会立即通知成功或失败以及事务信息。

相关内容

  • 没有找到相关文章

最新更新