贝宝第一次重定向崩溃,第二次成功重定向用户 [英] PayPal first redirect crash, second one redirect the user successfully

查看:122
本文介绍了贝宝第一次重定向崩溃,第二次成功重定向用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这几天,我在结帐时实施了 PayPal-Account-Payment 付款流程.在这一点上,一切正常.但是有时,当我尝试重定向客户以完成paypal.com上的订单时,我会收到一条错误消息.当我刷新页面并再次提交所有数据时,它将起作用.

these days, I implemented the PayPal-Account-Payment Payflow into my checkout. At this point everything works perfect. But sometimes I get an error when I try to redirect my customers to complete the order on paypal.com. When I refresh the page and submit all data again it works.

这是我当前的 PHP -代码:

$sdkConfig = array(
    "mode" => "LIVE"
);

$cred = new \PayPal\Auth\OAuthTokenCredential(<**>, <**>, $sdkConfig);

$apiContext = new \PayPal\Rest\ApiContext($cred, 'Request'.time());
$apiContext->setConfig($sdkConfig);

$payer = new \PayPal\Api\Payer();
$payer->setPaymentMethod("paypal");

$amount = new \PayPal\Api\Amount();
$amount->setCurrency("EUR");
$amount->setTotal($this->total);

$transaction = new \PayPal\Api\Transaction();
$transaction->setDescription("Complete your order.");
$transaction->setAmount($this->amount);
$transaction->setItemList($this->itemList);

$redirectUrls = new \PayPal\Api\RedirectUrls();
$redirectUrls->setReturnUrl("https://example.com/order/success/");
$redirectUrls->setCancelUrl("https://example.com/order/cancel/");

$payment = new \PayPal\Api\Payment();
$payment->setIntent("sale");
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
$payment->setTransactions(array($transaction));

$payment->create($apiContext);

$redirectUrl = $payment->links[1]["href"];

header("Location: ".$redirectUrl);

我有时在第一个电话上收到的错误: Fatal error: Cannot use object of type PayPal\Api\Links as array in /htdocs/lib/Checkout.php on line 503

The error I receive sometimes at the first call: Fatal error: Cannot use object of type PayPal\Api\Links as array in /htdocs/lib/Checkout.php on line 503

推荐答案

贝宝(Paypal)示例代码在获取付款对象的网址方面做了一些不同的操作:

The paypal sample code does something different to get the url form the payment object:

$payment->create($apiContext);
$approvalUrl = $payment->getApprovalLink();

猜测您的错误与直接访问付款->道具有关.

Guess your error has something todo with your direct access to payment->props.

这篇关于贝宝第一次重定向崩溃,第二次成功重定向用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆