From 99c30846addaf67106e23f73c2e69fa5ac192596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Sun, 1 Nov 2020 16:52:37 +0100 Subject: [PATCH] Stripe: Payments with tokens & error handling --- app/PaymentDrivers/Stripe/CreditCard.php | 20 ++++++++++++++++--- .../gateways/stripe/credit_card/pay.blade.php | 8 +++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/PaymentDrivers/Stripe/CreditCard.php b/app/PaymentDrivers/Stripe/CreditCard.php index 1de1cd6fa482..196fc09f696c 100644 --- a/app/PaymentDrivers/Stripe/CreditCard.php +++ b/app/PaymentDrivers/Stripe/CreditCard.php @@ -13,6 +13,7 @@ namespace App\PaymentDrivers\Stripe; use App\Events\Payment\PaymentWasCreated; +use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; @@ -159,14 +160,27 @@ class CreditCard { PaymentFailureMailer::dispatch($this->stripe->client, $server_response->cancellation_reason, $this->stripe->client->company, $server_response->amount); + PaymentFailureMailer::dispatch( + $this->stripe->client, + $server_response, + $this->stripe->client->company, + $server_response->amount + ); + $message = [ 'server_response' => $server_response, - 'data' => [], + 'data' => $this->stripe->payment_hash->data, ]; - SystemLogger::dispatch($message, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->stripe->client); + SystemLogger::dispatch( + $message, + SystemLog::CATEGORY_GATEWAY_RESPONSE, + SystemLog::EVENT_GATEWAY_FAILURE, + SystemLog::TYPE_STRIPE, + $this->stripe->client + ); - throw new \Exception('Failed to process the payment.', 1); + throw new PaymentFailed('Failed to process the payment.', 500); } private function storePaymentMethod(\Stripe\PaymentMethod $method, $payment_method_id, $customer) diff --git a/resources/views/portal/ninja2020/gateways/stripe/credit_card/pay.blade.php b/resources/views/portal/ninja2020/gateways/stripe/credit_card/pay.blade.php index 26c56a4f76c0..1704b7b17f41 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/credit_card/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/credit_card/pay.blade.php @@ -2,8 +2,8 @@ @section('gateway_head') - + @endsection @@ -12,7 +12,7 @@ @csrf - + @@ -26,9 +26,7 @@ @include('portal.ninja2020.gateways.includes.payment_details') - @if((int)$total['amount_with_fee'] == 0) - @include('portal.ninja2020.gateways.stripe.includes.pay_with_credit') - @elseif($token) + @if($token) @include('portal.ninja2020.gateways.stripe.includes.pay_with_token') @include('portal.ninja2020.gateways.includes.pay_now', ['id' => 'pay-now-with-token']) @else