Commit cd9c580b by Angel MAS

finaliza transaccion paypal

parent c9d38589
...@@ -25,6 +25,7 @@ use PayPal\Api\Amount; ...@@ -25,6 +25,7 @@ use PayPal\Api\Amount;
use PayPal\Api\Transaction; use PayPal\Api\Transaction;
use PayPal\Api\RedirectUrls; use PayPal\Api\RedirectUrls;
use PayPal\Api\Payment; use PayPal\Api\Payment;
use PayPal\Api\PaymentExecution;
use PayPal\Exception\PayPalConnectionException; use PayPal\Exception\PayPalConnectionException;
use PayPal\Api\Item as PaypalItem; use PayPal\Api\Item as PaypalItem;
use PayPal\Api\ItemList; use PayPal\Api\ItemList;
...@@ -403,8 +404,9 @@ class CartController extends Controller ...@@ -403,8 +404,9 @@ class CartController extends Controller
return $total; return $total;
} }
public function successPaypal() public function successPaypal(Request $request)
{ {
if (!\Session::has('client')) { if (!\Session::has('client')) {
return redirect()->route('cart.shipping'); return redirect()->route('cart.shipping');
} }
...@@ -413,6 +415,34 @@ class CartController extends Controller ...@@ -413,6 +415,34 @@ class CartController extends Controller
return redirect()->route('cart.shipping'); return redirect()->route('cart.shipping');
} }
$apiContext = new ApiContext(
new OAuthTokenCredential(
env('CLIENT_ID_PAYPAL'),
env('SECRET_PAYPAL')
)
);
$apiContext->setConfig(
array(
'log.LogEnabled' => true,
'log.FileName' => base_path().'/Paypal.log',
'log.LogLevel' => 'DEBUG',
'mode' => env('PAYPAL_MODE'),
)
);
$paymentId = $request->paymentId;
$payment = Payment::get($paymentId, $apiContext);
$execution = new PaymentExecution();
$execution->setPayerId($request->PayerID);
try {
$result = $payment->execute($execution, $apiContext);
if ($result->state == 'approved') {
$sale = Sale::find(\Session::get('sale')->id); $sale = Sale::find(\Session::get('sale')->id);
$client = $sale->client; $client = $sale->client;
$items = $sale->items; $items = $sale->items;
...@@ -431,6 +461,17 @@ class CartController extends Controller ...@@ -431,6 +461,17 @@ class CartController extends Controller
return redirect() return redirect()
->route('main.shop') ->route('main.shop')
->with('payment_approved', 'payment_approved'); ->with('payment_approved', 'payment_approved');
} else {
return redirect()
->route('cart.finish')
->with('paypal_fail',$result->state);
}
} catch (\PayPal\Exception\PayPalConnectionException $ex) {
return $ex->getData();
}
} }
......
...@@ -41,6 +41,14 @@ ...@@ -41,6 +41,14 @@
</script> </script>
@endif @endif
@if(Session::has('paypal_fail'))
<script type="text/javascript">
swal("Pago rechazado",
"Tuvimos problemas para procesar tu pago, verifica tus datos : {{Session::get('paypal_fail')}}",
"error")
</script>
@endif
@if(Session::has('payment_pending')) @if(Session::has('payment_pending'))
<script type="text/javascript"> <script type="text/javascript">
swal("Pago pendiente", "Estamos procesando tu pago, te notificaremos por correo el estatus", "warning") swal("Pago pendiente", "Estamos procesando tu pago, te notificaremos por correo el estatus", "warning")
......
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