Commit 68a2dd63 by Angel MAS

desceunto con paypal

parent 0a524135
...@@ -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');
...@@ -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;
...@@ -791,10 +821,12 @@ public function shipping() ...@@ -791,10 +821,12 @@ public function shipping()
'valid'=>$valid, 'valid'=>$valid,
'msg'=>$msg, 'msg'=>$msg,
'amount'=>money_format('%(#10n',$descuento), 'amount'=>money_format('%(#10n',$descuento),
'total'=>money_format('%(#10n', (($total+$cost_shipping)-$descuento)) 'amount_unformated'=>$descuento,
'total'=>money_format('%(#10n', (($total+$cost_shipping)-$descuento)),
'total_unformated'=>($total+$cost_shipping)-$descuento
]; ];
return $data; 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