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.
Here is my current 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);
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