我有方法支付paypal这个错误。
错误:
PayPalHttpConnection.php第178行中的PayPalConnectionException:得到 访问时的Http响应代码400 https://api.sandbox.paypal.com/v1/payments/payment
我的PaypalController
- 在没有将优惠券价格插入数组
的情况下运作良好
我的PaypalController
public function postPayment(Request $request)
{
// i deleted validation form
// i deleted how i get price shipping
// $cart is my session with all products
// i take my price coupon from my DB and not from my session
$cart = $request->session()->get('cart');
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$items = array();
$subtotal = 0 ;
$cart = \Session::get('cart'); //ottenere tutta l'informazione dalla session cart
$currency = 'EUR';
foreach($cart as $producto){
$item = new Item();
$item->setName($producto->name)
->setCurrency($currency)
->setDescription($producto->extract)
->setQuantity($producto->quantity)
->setPrice($producto->price);
$items[] = $item;
$subtotal += $producto->quantity * $producto->price;
}
$item_list = new ItemList();
$item_list->setItems($items);
$details = new Details();
$details->setSubtotal($subtotal)
->setShipping($get_ship_total);
// I need insert my price coupon discount ( it can be 0 or >0)
$total = $subtotal + $get_ship_total - $price_coupon;
$amount = new Amount();
$amount->setCurrency($currency)
->setTotal($total)
->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($item_list)
->setDescription('Order ecommerce');
$redirect_urls = new RedirectUrls();
$redirect_urls->setReturnUrl(\URL::route('payment.status'))
->setCancelUrl(\URL::route('payment.status'));
$payment = new Payment();
$payment->setIntent('Sale')
->setPayer($payer)
->setRedirectUrls($redirect_urls)
->setTransactions(array($transaction));
try {
$payment->create($this->_api_context);
} catch (\PayPal\Exception\PPConnectionException $ex) {
if (\Config::get('app.debug')) {
echo "Exception: " . $ex->getMessage() . PHP_EOL;
$err_data = json_decode($ex->getData(), true);
exit;
} else {
die('Ups! error');
}
}
foreach($payment->getLinks() as $link) {
if($link->getRel() == 'approval_url') {
$redirect_url = $link->getHref();
break;
}
}
\Session::put('paypal_payment_id', $payment->getId());
if(isset($redirect_url)) {
return \Redirect::away($redirect_url);
}
return \Redirect::route('cart-show')
->with('message', 'Ups! Error .');
}
} // fine metodo
我试着做一些测试: - 贝宝工作顺利如果我删除$ price_coupon:
$ total = $ subtotal + $ get_ship_total - $ price_coupon;
可能是数组的问题,我读了一个问题like this,但我没有解决这个问题。
也许因为subTotal + taxshipping - 优惠券没有正确加总!
感谢您的帮助!