From 8ca1b904d7f01b6624d16ffcf51c2e5fb8f618b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 31 May 2021 16:23:18 +0200 Subject: [PATCH 1/3] Refactor the redirect to specific route --- .../Gateways/Checkout3dsController.php | 24 +++++++++++++++++++ app/PaymentDrivers/CheckoutCom/CreditCard.php | 2 +- routes/web.php | 4 +++- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 app/Http/Controllers/Gateways/Checkout3dsController.php diff --git a/app/Http/Controllers/Gateways/Checkout3dsController.php b/app/Http/Controllers/Gateways/Checkout3dsController.php new file mode 100644 index 000000000000..461db33e0603 --- /dev/null +++ b/app/Http/Controllers/Gateways/Checkout3dsController.php @@ -0,0 +1,24 @@ +all(); + } +} diff --git a/app/PaymentDrivers/CheckoutCom/CreditCard.php b/app/PaymentDrivers/CheckoutCom/CreditCard.php index 44ea6023b68e..b30e37ca7404 100644 --- a/app/PaymentDrivers/CheckoutCom/CreditCard.php +++ b/app/PaymentDrivers/CheckoutCom/CreditCard.php @@ -144,7 +144,7 @@ class CreditCard if ($this->checkout->client->currency()->code == 'EUR' || $this->checkout->company_gateway->getConfigField('threeds')) { $payment->{'3ds'} = ['enabled' => true]; - $payment->{'success_url'} = route('payment_webhook', [ + $payment->{'success_url'} = route('checkout.3ds_redirect', [ 'company_key' => $this->checkout->client->company->company_key, 'company_gateway_id' => $this->checkout->company_gateway->hashed_id, 'hash' => $this->checkout->payment_hash->hash, diff --git a/routes/web.php b/routes/web.php index af15b87590b9..d044435abd99 100644 --- a/routes/web.php +++ b/routes/web.php @@ -36,4 +36,6 @@ Route::group(['middleware' => ['url_db']], function () { }); Route::get('stripe/signup/{token}', 'StripeConnectController@initialize')->name('stripe_connect.initialization'); -Route::get('stripe/completed', 'StripeConnectController@completed')->name('stripe_connect.return'); \ No newline at end of file +Route::get('stripe/completed', 'StripeConnectController@completed')->name('stripe_connect.return'); + +Route::get('checkout/3ds_redirect/{company_key}/{company_gateway_id}/{hash}', 'Gateways\Checkout3dsController@index')->name('checkout.3ds_redirect'); From 588aeefb357329896ca72f39da14854f68d3c6d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 31 May 2021 16:37:46 +0200 Subject: [PATCH 2/3] Moving logic for confirming the 3ds process into own method --- .../Gateways/Checkout3dsController.php | 8 +-- .../Checkout3ds/Checkout3dsRequest.php | 51 +++++++++++++++++++ .../Payments/PaymentWebhookRequest.php | 5 +- .../CheckoutComPaymentDriver.php | 6 +++ 4 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 app/Http/Requests/Gateways/Checkout3ds/Checkout3dsRequest.php diff --git a/app/Http/Controllers/Gateways/Checkout3dsController.php b/app/Http/Controllers/Gateways/Checkout3dsController.php index 461db33e0603..af6a4217f3f1 100644 --- a/app/Http/Controllers/Gateways/Checkout3dsController.php +++ b/app/Http/Controllers/Gateways/Checkout3dsController.php @@ -13,12 +13,14 @@ namespace App\Http\Controllers\Gateways; use App\Http\Controllers\Controller; -use Illuminate\Http\Request; +use App\Http\Requests\Gateways\Checkout3ds\Checkout3dsRequest; class Checkout3dsController extends Controller { - public function index(Request $request) + public function index(Checkout3dsRequest $request, string $company_key, string $company_gateway_id, string $hash) { - return $request->all(); + return $request->getCompanyGateway() + ->driver($request->getClient()) + ->process3dsConfirmation($request); } } diff --git a/app/Http/Requests/Gateways/Checkout3ds/Checkout3dsRequest.php b/app/Http/Requests/Gateways/Checkout3ds/Checkout3dsRequest.php new file mode 100644 index 000000000000..3b218f50548c --- /dev/null +++ b/app/Http/Requests/Gateways/Checkout3ds/Checkout3dsRequest.php @@ -0,0 +1,51 @@ +decodePrimaryKey($this->company_gateway_id)); + } + + public function getPaymentHash() + { + return PaymentHash::where('hash', $this->hash)->firstOrFail(); + } + + public function getClient() + { + return Client::findOrFail($this->getPaymentHash()->data->client_id); + } +} diff --git a/app/Http/Requests/Payments/PaymentWebhookRequest.php b/app/Http/Requests/Payments/PaymentWebhookRequest.php index 2642f2458e93..2fc33f6494f9 100644 --- a/app/Http/Requests/Payments/PaymentWebhookRequest.php +++ b/app/Http/Requests/Payments/PaymentWebhookRequest.php @@ -100,14 +100,15 @@ class PaymentWebhookRequest extends Request /** * Resolve client from payment hash. * - * @return null|\App\Models\Client + * @return null|\App\Models\Client|bool */ public function getClient() { $hash = $this->getPaymentHash(); - if($hash) + if($hash) { return Client::find($hash->data->client_id)->firstOrFail(); + } return false; } diff --git a/app/PaymentDrivers/CheckoutComPaymentDriver.php b/app/PaymentDrivers/CheckoutComPaymentDriver.php index 1e9b041fab22..df8609096582 100644 --- a/app/PaymentDrivers/CheckoutComPaymentDriver.php +++ b/app/PaymentDrivers/CheckoutComPaymentDriver.php @@ -13,6 +13,7 @@ namespace App\PaymentDrivers; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; +use App\Http\Requests\Gateways\Checkout3ds\Checkout3dsRequest; use App\Http\Requests\Payments\PaymentWebhookRequest; use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; @@ -287,6 +288,11 @@ class CheckoutComPaymentDriver extends BaseDriver } public function processWebhookRequest(PaymentWebhookRequest $request, Payment $payment = null) + { + return true; + } + + public function process3dsConfirmation(Checkout3dsRequest $request) { $this->init(); $this->setPaymentHash($request->getPaymentHash()); From 9119f57a35cf7af85c16887600765fdce445b3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Tue, 1 Jun 2021 11:54:15 +0200 Subject: [PATCH 3/3] Return JSON response if some of required records wasn't found --- .../Gateways/Checkout3dsController.php | 16 ++++++++++++++++ .../Gateways/Checkout3ds/Checkout3dsRequest.php | 12 +++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Gateways/Checkout3dsController.php b/app/Http/Controllers/Gateways/Checkout3dsController.php index af6a4217f3f1..4dbada72ad86 100644 --- a/app/Http/Controllers/Gateways/Checkout3dsController.php +++ b/app/Http/Controllers/Gateways/Checkout3dsController.php @@ -19,6 +19,22 @@ class Checkout3dsController extends Controller { public function index(Checkout3dsRequest $request, string $company_key, string $company_gateway_id, string $hash) { + if (!$request->getCompany()) { + return response()->json(['message' => 'Company record not found.', 'company_key' => $company_key]); + } + + if (!$request->getCompanyGateway()) { + return response()->json(['message' => 'Company gateway record not found.', 'company_gateway_id' => $company_gateway_id]); + } + + if (!$request->getPaymentHash()) { + return response()->json(['message' => 'Hash record not found.', 'hash' => $hash]); + } + + if (!$request->getClient()) { + return response()->json(['message' => 'Client record not found.']); + } + return $request->getCompanyGateway() ->driver($request->getClient()) ->process3dsConfirmation($request); diff --git a/app/Http/Requests/Gateways/Checkout3ds/Checkout3dsRequest.php b/app/Http/Requests/Gateways/Checkout3ds/Checkout3dsRequest.php index 3b218f50548c..021379542094 100644 --- a/app/Http/Requests/Gateways/Checkout3ds/Checkout3dsRequest.php +++ b/app/Http/Requests/Gateways/Checkout3ds/Checkout3dsRequest.php @@ -3,6 +3,7 @@ namespace App\Http\Requests\Gateways\Checkout3ds; use App\Models\Client; +use App\Models\Company; use App\Models\CompanyGateway; use App\Models\PaymentHash; use App\Utils\Traits\MakesHash; @@ -34,18 +35,23 @@ class Checkout3dsRequest extends FormRequest ]; } + public function getCompany() + { + return Company::where('company_key', $this->company_key)->first(); + } + public function getCompanyGateway() { - return CompanyGateway::findOrFail($this->decodePrimaryKey($this->company_gateway_id)); + return CompanyGateway::find($this->decodePrimaryKey($this->company_gateway_id)); } public function getPaymentHash() { - return PaymentHash::where('hash', $this->hash)->firstOrFail(); + return PaymentHash::where('hash', $this->hash)->first(); } public function getClient() { - return Client::findOrFail($this->getPaymentHash()->data->client_id); + return Client::find($this->getPaymentHash()->data->client_id); } }