diff --git a/app/Http/Controllers/WebpayPlusDeferredController.php b/app/Http/Controllers/WebpayPlusDeferredController.php new file mode 100644 index 0000000..62ca70d --- /dev/null +++ b/app/Http/Controllers/WebpayPlusDeferredController.php @@ -0,0 +1,95 @@ +transaction = new Transaction($option); + } + + public function create() + { + + $createTx = [ + 'buyOrder' => "O-" . rand(1, 10000), + "sessionId" => "S-" . (string)(rand(1, 10000)), + 'returnUrl' => url('/') . '/webpay-plus-diferido/commit', + 'amount' => rand(1000, 2000) + ]; + + + $resp = $this->transaction->create($createTx['buyOrder'], $createTx['sessionId'], $createTx['amount'], $createTx['returnUrl']); + return view('webpay-deferred.create', ["request" => $createTx, "respond" => $resp]); + } + public function commit(Request $request) + { + //Timeout + $view = 'webpay-deferred.timeout'; + $data = ["request" => $request]; + + //flujo error + if ($request->exists("TBK_TOKEN") && $request->exists("token_ws")) { + $view = 'webpay-deferred.error'; + } + //Pago abortado + elseif ($request->exists("TBK_TOKEN")) { + $view = 'webpay-deferred.error'; + } + //Flujo normal + elseif ($request->exists("token_ws")) { + $resp = $this->transaction->commit($request["token_ws"]); + $view = 'webpay-deferred.commit'; + $data = ["resp" => $resp, "token" => $request["token_ws"]]; + } + + return view($view, $data); + } + + public function capture(Request $request) + { + try { + $req = $request->except('_token'); + $resp = $this->transaction->capture($req["token"], $req["buyOrder"], $req["authorizationCode"], $req["amount"]); + } catch (\Exception $e) { + $resp = array( + 'msg' => $e->getMessage(), + 'code' => $e->getCode() + ); + return view('webpay-deferred.capture', ["resp" => $resp, "token" => $req["token"]]); + } + return view('webpay-deferred.capture', ["resp" => $resp, "token" => $req["token"]]); + } + + public function refund(Request $request) + { + try { + $req = $request->except('_token'); + $resp = $this->transaction->refund($req["token"], $req["amount"]); + } catch (\Exception $e) { + $resp = array( + 'msg' => $e->getMessage(), + 'code' => $e->getCode() + ); + return view('webpay-deferred.refund', ["resp" => $resp]); + } + return view('webpay-deferred.refund', ["resp" => $resp]); + } + + public function status(Request $request) + { + $token = $request["token"]; + $resp = $this->transaction->status($token); + return view('webpay-deferred.status', ["resp" => $resp, "req" => $request]); + } +} diff --git a/resources/views/components/menu.blade.php b/resources/views/components/menu.blade.php index de0170f..aab4155 100644 --- a/resources/views/components/menu.blade.php +++ b/resources/views/components/menu.blade.php @@ -2,10 +2,10 @@