Commit 68a2dd63 by Angel MAS

desceunto con paypal

parent 0a524135
...@@ -43,15 +43,15 @@ class CartController extends Controller ...@@ -43,15 +43,15 @@ class CartController extends Controller
public function __construct() public function __construct()
{ {
if (!\Session::has('cart')) { if (!\Session::has('cart')) {
\Session::put('cart', array()); \Session::put('cart', array());
} }
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$this->util = new Util(); $this->util = new Util();
} }
public function show() public function show()
{ {
$total = $this->total(); $total = $this->total();
$cart = \Session::get('cart'); $cart = \Session::get('cart');
...@@ -551,8 +551,7 @@ public function shipping() ...@@ -551,8 +551,7 @@ public function shipping()
$products = $sale->products; $products = $sale->products;
$addres = $client->shipping; $addres = $client->shipping;
$detail = ''; $detail = '';
$descuento = 0;
$apiContext = new ApiContext( $apiContext = new ApiContext(
new OAuthTokenCredential( new OAuthTokenCredential(
...@@ -599,17 +598,38 @@ public function shipping() ...@@ -599,17 +598,38 @@ public function shipping()
array_push($items, $item2); array_push($items, $item2);
if ($request->coupon != null) {
$data = $this->getDiscount($sale, $request->coupon);
if ($data['valid']) {
$descuento = $data['amount_unformated'];
$sale->total = $data['total_unformated'];
$sale->coupon = $request->coupon;
//Descuento en caso de haber
$item3 = new PaypalItem();
$item3->setName('Código de descuento: '.$request->coupon)
->setDescription('Código de descuento: '.$request->coupon)
->setCurrency('MXN')
->setQuantity(1)
->setPrice(($descuento * -1));
array_push($items, $item3);
}
}
$itemList = new ItemList(); $itemList = new ItemList();
$itemList->setItems($items); $itemList->setItems($items);
$details = new Details(); $details = new Details();
$details->setSubtotal($this->total() + $addres->shipping_price->cost); $details->setSubtotal(($this->total() + $addres->shipping_price->cost) - $descuento);
$amount = new \PayPal\Api\Amount(); $amount = new \PayPal\Api\Amount();
$amount->setCurrency("MXN") $amount->setCurrency("MXN")
->setTotal($this->total() + $addres->shipping_price->cost) ->setTotal(($this->total() + $addres->shipping_price->cost)-$descuento)
->setDetails($details); ->setDetails($details);
...@@ -665,6 +685,16 @@ public function shipping() ...@@ -665,6 +685,16 @@ public function shipping()
$sale->status = 3; $sale->status = 3;
$sale->transaction_id = null; $sale->transaction_id = null;
$sale->payment_type = 'Acordar con vendedor'; $sale->payment_type = 'Acordar con vendedor';
if ($request->coupon != null) {
$data = $this->getDiscount($sale, $request->coupon);
if ($data['valid']) {
$sale->total = $data['total_unformated'];
$sale->coupon = $request->coupon;
}
}
$sale->save(); $sale->save();
\Session::forget('client'); \Session::forget('client');
...@@ -731,7 +761,7 @@ public function shipping() ...@@ -731,7 +761,7 @@ public function shipping()
public function discount(Request $request) public function discount(Request $request)
{ {
$sale = Sale::find($request->total); $sale = Sale::find($request->total);
$data = $this->getDiscount($sale, $request->coupon); $data = $this->getDiscount($sale, $request->coupon);
return response() return response()
...@@ -762,7 +792,7 @@ public function shipping() ...@@ -762,7 +792,7 @@ public function shipping()
if ($coupon != null) { if ($coupon != null) {
if ($today <= $coupon->expiration) { if ($today <= $coupon->expiration) {
if ($this->total() >= $coupon->min_sale) { if ($total >= $coupon->min_sale) {
if ($coupon->type == 'Efectivo') { if ($coupon->type == 'Efectivo') {
$descuento = $coupon->value; $descuento = $coupon->value;
...@@ -778,23 +808,25 @@ public function shipping() ...@@ -778,23 +808,25 @@ public function shipping()
} else { } else {
$msg = 'Para aplicar este código de descuento tu compra minima debe ser de: ' $msg = 'Para aplicar este código de descuento tu compra minima debe ser de: '
.money_format('%(#10n',$coupon->min_sale); .money_format('%(#10n',$coupon->min_sale);
} }
} else{ } else{
$msg = 'Lo sentimos este código de descuento ya expiró :('; $msg = 'Lo sentimos este código de descuento ya expiró :(';
} }
}
$data = [ }
'valid'=>$valid,
'msg'=>$msg,
'amount'=>money_format('%(#10n',$descuento),
'total'=>money_format('%(#10n', (($total+$cost_shipping)-$descuento))
];
return $data; $data = [
} 'valid'=>$valid,
'msg'=>$msg,
'amount'=>money_format('%(#10n',$descuento),
'amount_unformated'=>$descuento,
'total'=>money_format('%(#10n', (($total+$cost_shipping)-$descuento)),
'total_unformated'=>($total+$cost_shipping)-$descuento
];
return $data;
}
} }
...@@ -10,6 +10,7 @@ setlocale(LC_MONETARY, 'en_US'); ...@@ -10,6 +10,7 @@ setlocale(LC_MONETARY, 'en_US');
- Numero de orden: # {{$order->id}} - Numero de orden: # {{$order->id}}
- Fecha: {{$order->created_at->format('d/m/Y')}} - Fecha: {{$order->created_at->format('d/m/Y')}}
- Forma de pago: {{$order->payment_type}} - Forma de pago: {{$order->payment_type}}
- Cupon de descuento: {{$order->coupon != null ? $order->coupon : 'N/A'}}
@endcomponent @endcomponent
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment