2015-06-18 99 views
0

這幾天,我實現了PayPal-Account-Payment Payflow到我的結帳。在這一點上,一切都很完美。但是,當我嘗試重定向我的客戶以完成paypal.com上的訂單時,有時會出現錯誤。當我刷新頁面並再次提交所有數據時,它可以正常工作。PayPal第一次重定向崩潰,第二次重定向用戶

這是我目前的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

+0

您是否得到了解決方案?我面臨同樣的問題。 –

回答

0

PayPal的示例代碼不同的東西,以便獲得url形成付款對象:

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

猜猜你的錯誤有些東西用喲你可以直接訪問付款 - >道具。