i have a problem with complete payment with paypal, i have this error:
Got Http response code 400 when accessing http://ift.tt/1f12BzJ.
MY CONTROLLER
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$items = array();
$subtotal = 0;
$cart = \Session::get('cart'); // Get info by my session cart
$currency = 'EUR';
// i extract info by session cart and count the Subtotal
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;
}
// i calculated my $price_coupon and here i want make the discount.
// price coupon can be ZERO or >0
$subtotal_coupon = $subtotal - $price_coupon ;
$item_list = new ItemList();
$item_list->setItems($items);
// set up subtotal (with discount coupon)
$details = new Details();
$details->setSubtotal($subtotal_coupon)
->setShipping($get_session->shipping);
// here i calculated the total amount for paypal payment
// i extracted the price of shipping from my DB, so $get_session->shipping work well
$total = $subtotal_coupon + $get_session->shipping;
$amount = new Amount();
$amount->setCurrency($currency)
->setTotal($total)
->setDetails($details);
Important! if i don't add my coupon, it work well! like this:
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$items = array();
$subtotal = 0;
$cart = \Session::get('cart'); //get session cart
$currency = 'EUR';
// extract info by session cart
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;
}
// items
$item_list = new ItemList();
$item_list->setItems($items);
$details = new Details();
$details->setSubtotal($subtotal)
->setShipping($get_session->shipping);
$total = $subtotal + $get_session->shipping;
$amount = new Amount();
$amount->setCurrency($currency)
->setTotal($total)
->setDetails($details);
I don't know why when i add the calculation of discount COUPON, it give me a error.
Thank you for your help guys!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire