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

时间:2015-06-18 11:49:18

标签: php redirect paypal sdk payment-gateway

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

这是我当前的 PHP -Code:

$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

1 个答案:

答案 0 :(得分:0)

paypal示例代码执行不同的操作以使网址形成付款对象:

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

猜猜您的错误与您直接访问付款有关 - &gt;道具。