From 548405c4d8abd0c7608927c0904ac68e1dcb43bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 26 Jul 2021 17:03:40 +0200 Subject: [PATCH] Refactor payment with credit card --- app/PaymentDrivers/Mollie/CreditCard.php | 38 +++++++++++++++++++----- routes/web.php | 1 + 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/app/PaymentDrivers/Mollie/CreditCard.php b/app/PaymentDrivers/Mollie/CreditCard.php index 63c425e2228a..c811f24fa0a7 100644 --- a/app/PaymentDrivers/Mollie/CreditCard.php +++ b/app/PaymentDrivers/Mollie/CreditCard.php @@ -4,12 +4,14 @@ namespace App\PaymentDrivers\Mollie; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; +use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\GatewayType; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; use App\PaymentDrivers\MolliePaymentDriver; +use App\Utils\Number; use Illuminate\Contracts\View\Factory; use Illuminate\View\View; @@ -48,17 +50,21 @@ class CreditCard */ public function paymentResponse(PaymentResponseRequest $request) { - $amount = number_format((float) $this->mollie->payment_hash->data->amount_with_fee, 2, '.', ''); + $this->mollie->payment_hash->withData('gateway_type_id', GatewayType::CREDIT_CARD); try { $payment = $this->mollie->gateway->payments->create([ 'amount' => [ 'currency' => $this->mollie->client->currency()->code, - 'value' => $amount, + 'value' => Number::formatValue($this->mollie->payment_hash->data->amount_with_fee, $this->mollie->client->currency()), ], 'description' => \sprintf('Hash: %s', $this->mollie->payment_hash->hash), 'redirectUrl' => 'https://webshop.example.org/order/12345/', - 'webhookUrl' => 'https://webshop.example.org/mollie-webhook/', + 'webhookUrl' => route('mollie.3ds_redirect', [ + 'company_key' => $this->mollie->client->company->company_key, + 'company_gateway_id' => $this->mollie->company_gateway->hashed_id, + 'hash' => $this->mollie->payment_hash->hash, + ]), 'cardToken' => $request->token, ]); @@ -72,12 +78,11 @@ class CreditCard } if ($payment->status === 'open') { - // Handle redirect payment + return redirect($payment->getCheckoutUrl()); } - - dd($payment); - } catch (\Exception $e) { + $this->processUnsuccessfulPayment($e); + throw new PaymentFailed($e->getMessage(), $e->getCode()); } } @@ -108,4 +113,23 @@ class CreditCard return redirect()->route('client.payments.show', ['payment' => $this->mollie->encodePrimaryKey($payment_record->id)]); } + + public function processUnsuccessfulPayment(\Exception $e) + { + PaymentFailureMailer::dispatch( + $this->mollie->client, + $e->getMessage(), + $this->mollie->client->company, + $this->mollie->payment_hash->data->amount_with_fee + ); + + SystemLogger::dispatch( + $e->getMessage(), + SystemLog::CATEGORY_GATEWAY_RESPONSE, + SystemLog::EVENT_GATEWAY_FAILURE, + SystemLog::TYPE_MOLLIE, + $this->mollie->client, + $this->mollie->client->company, + ); + } } diff --git a/routes/web.php b/routes/web.php index 3468a99ebbd9..8c3a8e85d0d3 100644 --- a/routes/web.php +++ b/routes/web.php @@ -42,3 +42,4 @@ Route::get('stripe/signup/{token}', 'StripeConnectController@initialize')->name( 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'); +Route::get('mollie/3ds_redirect/{company_key}/{company_gateway_id}/{hash}', 'Gateways\Mollie3dsController@index')->name('mollie.3ds_redirect');