From 9662d9af9226b19ec2276c941783a798d6138176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 16 Dec 2020 13:47:10 +0100 Subject: [PATCH] Update webhooks for Checkout: - Update api.php -> gateway_key => company_gateway_id - Pass correct reference to url in CreditCard.php - Update PaymentWebhookController.php to support new company_gateway_id - Update PaymentWebhookRequest.php to resolve company gateway from correct input --- app/Http/Controllers/PaymentWebhookController.php | 2 +- app/Http/Requests/Payments/PaymentWebhookRequest.php | 7 ++++++- app/PaymentDrivers/CheckoutCom/CreditCard.php | 2 +- routes/api.php | 6 ++++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/PaymentWebhookController.php b/app/Http/Controllers/PaymentWebhookController.php index b32afa1d4c11..cdd517c2ece8 100644 --- a/app/Http/Controllers/PaymentWebhookController.php +++ b/app/Http/Controllers/PaymentWebhookController.php @@ -21,7 +21,7 @@ class PaymentWebhookController extends Controller $this->middleware('guest'); } - public function __invoke(PaymentWebhookRequest $request, string $gateway_key, string $company_key) + public function __invoke(PaymentWebhookRequest $request, string $company_gateway_id, string $company_key) { return $request->getCompanyGateway() ->driver($request->getClient()) diff --git a/app/Http/Requests/Payments/PaymentWebhookRequest.php b/app/Http/Requests/Payments/PaymentWebhookRequest.php index f4704559aac8..4286be1ec83e 100644 --- a/app/Http/Requests/Payments/PaymentWebhookRequest.php +++ b/app/Http/Requests/Payments/PaymentWebhookRequest.php @@ -18,9 +18,12 @@ use App\Models\Company; use App\Models\CompanyGateway; use App\Models\Payment; use App\Models\PaymentHash; +use App\Utils\Traits\MakesHash; class PaymentWebhookRequest extends Request { + use MakesHash; + public function authorize() { return true; @@ -41,7 +44,7 @@ class PaymentWebhookRequest extends Request */ public function getCompanyGateway(): ?CompanyGateway { - return CompanyGateway::where('gateway_key', $this->gateway_key)->firstOrFail(); + return CompanyGateway::find($this->decodePrimaryKey($this->company_gateway_id))->firstOrFail(); } /** @@ -55,6 +58,8 @@ class PaymentWebhookRequest extends Request if ($this->query('hash')) { return PaymentHash::where('hash', $this->query('hash'))->firstOrFail(); } + + return null; } /** diff --git a/app/PaymentDrivers/CheckoutCom/CreditCard.php b/app/PaymentDrivers/CheckoutCom/CreditCard.php index f5b51eb52b09..5b7a75369744 100644 --- a/app/PaymentDrivers/CheckoutCom/CreditCard.php +++ b/app/PaymentDrivers/CheckoutCom/CreditCard.php @@ -129,7 +129,7 @@ class CreditCard $payment->{'3ds'} = ['enabled' => true]; $payment->{'success_url'} = route('payment_webhook', [ - 'gateway_key' => $this->checkout->company_gateway->gateway_key, + 'company_gateway_id' => $this->checkout->company_gateway->hashed_id, 'company_key' => $this->checkout->client->company->company_key, 'hash' => $this->checkout->payment_hash->hash, ]); diff --git a/routes/api.php b/routes/api.php index 609f364eab58..06aaafe67a6f 100644 --- a/routes/api.php +++ b/routes/api.php @@ -11,6 +11,8 @@ | */ +use Illuminate\Support\Facades\Route; + Route::group(['middleware' => ['api_secret_check']], function () { Route::post('api/v1/signup', 'AccountController@store')->name('signup.submit'); Route::post('api/v1/oauth_login', 'Auth\LoginController@oauthApiLogin'); @@ -170,7 +172,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a Route::post('preimport', 'ImportController@preimport')->name('import.preimport'); Route::post('import', 'ImportController@import')->name('import.import'); - + /* Route::resource('tasks', 'TaskController'); // name = (tasks. index / create / show / update / destroy / edit @@ -183,6 +185,6 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a Route::post('support/messages/send', 'Support\Messages\SendingController'); }); -Route::match(['get', 'post'], 'payment_webhook/{gateway_key}/{company_key}', 'PaymentWebhookController')->name('payment_webhook'); +Route::match(['get', 'post'], 'payment_webhook/{company_gateway_id}/{company_key}', 'PaymentWebhookController')->name('payment_webhook'); Route::fallback('BaseController@notFound');