PayPal第一次重定向崩溃,第二次重定向用户成功


PayPal first redirect crash, second one redirect the user successfully

这些天,我在结账时实施了PayPal-Account-Payment Payflow。在这一点上,一切都很完美。但有时当我尝试重定向客户以完成 paypal.com 订单时,我会收到错误。当我刷新页面并再次提交所有数据时,它可以工作。

这是我当前的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

PayPal示例代码执行一些不同的操作来获取来自付款对象的 url:

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

猜你的错误与你直接访问支付>道具有关。