2016-06-08 66 views
0

第一次在laravel中做paypal集成。我試圖添加項目和totaltax的小計的細節,我有這個控制器。Laravel PayPal在交易中添加PayPal :: details()時出錯

$payer = PayPal::Payer(); 
$payer->setPaymentMethod('paypal'); 

$item1 = PayPal::item(); 
item1->setName('Item1 name') 
->setDescription('item1 description') 
->setCurrency('USD') 
->setQuantity(1) 
->setPrice(35); 

$item2 = PayPal::item(); 
$item2->setName('Item2 name') 
->setDescription('item2 description') 
->setCurrency('USD') 
->setQuantity(1) 
->setPrice(300); 

$itemList = PayPal::itemList(); 
$itemList->setItems(array($item1,$item2)); 

$details = PayPal::Details(); 
$details->setShipping(1); 
$details->setTax(10);  
$details->setSubtotal(17.5); 

$amount = PayPal::Amount(); 
$amount->setCurrency('USD'); 
$amount->setTotal(335) 
->setDetails($details); 

$transaction = PayPal::Transaction(); 
$transaction->setAmount($amount); 
$transaction->setItemList($itemList); 
$transaction->setDescription('What are you selling?'); 


$redirectUrls = PayPal:: RedirectUrls(); 
$redirectUrls->setReturnUrl(action('paypal_Controller\[email protected]')); 
$redirectUrls->setCancelUrl(action('paypal_Controller\[email protected]')); 


$payment = PayPal::Payment(); 
$payment->setIntent('sale'); 
$payment->setPayer($payer); 
$payment->setRedirectUrls($redirectUrls); 
$payment->setTransactions(array($transaction)); 

$response = $payment->create($this->_apiContext); 
$redirectUrl = $response->links[1]->href; 

return Redirect::to($redirectUrl); 

我得到這個錯誤:

PayPalConnectionException in PayPalHttpConnection.php line 177: Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment .

但是當我刪除->setDetails($details),它的工作原理,但沒有小計。

回答

0

我發現貝寶只接受正確的計算。 如果你想添加totaltax你需要添加 - > setTax()每個項目。

$item1 = PayPal::item(); 
$item1->setName('Item1 Name') 
->setDescription('Item1 Description') 
->setCurrency('USD') 
->setQuantity('2') 
->setTax(2.0) 
->setPrice('350'); 

$item2 = PayPal::item(); 
$item2->setName('Item2 Name') 
->setDescription('Item2 Description') 
->setCurrency('USD') 
->setQuantity('1') 
->setTax(0) 
->setPrice('300'); 

然後計算必須correct.item1稅=(2.0×2)+ ITEM2稅= 0 totaltax = 4.0 ITEM1價格=(350 * 2)+ ITEM2價格= 300小計= 1000

$details = PayPal::details(); 
$details->setShipping('0'); 
$details->setTax(4.0);  
$details->setSubtotal('1000'); 

運費+ totaltax +小計= 1004.0

$amount = PayPal::Amount(); 
$amount->setCurrency('USD'); 
$amount->setTotal(1004.0); 
$amount->setDetails($details); 

希望它會幫助別人。 :)