From 28463ca565ce9c42230e066254415d1c3d486aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 23 Jun 2021 14:52:54 +0200 Subject: [PATCH] Add "complete verification" button in the ACH verification email --- .../Gateways/ACHVerificationNotification.php | 9 ++++++- app/PaymentDrivers/Stripe/ACH.php | 24 +++++++++++++++---- .../ach-verification-notification.blade.php | 2 ++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/app/Mail/Gateways/ACHVerificationNotification.php b/app/Mail/Gateways/ACHVerificationNotification.php index 3c507a434fae..322e6b96e2c8 100644 --- a/app/Mail/Gateways/ACHVerificationNotification.php +++ b/app/Mail/Gateways/ACHVerificationNotification.php @@ -25,14 +25,21 @@ class ACHVerificationNotification extends Mailable */ public $company; + /** + * @var string + */ + public $url; + /** * Create a new message instance. * * @return void */ - public function __construct(Company $company) + public function __construct(Company $company, string $url) { $this->company = $company; + + $this->url = $url; } /** diff --git a/app/PaymentDrivers/Stripe/ACH.php b/app/PaymentDrivers/Stripe/ACH.php index 3068ed710e83..302e91284b58 100644 --- a/app/PaymentDrivers/Stripe/ACH.php +++ b/app/PaymentDrivers/Stripe/ACH.php @@ -68,7 +68,7 @@ class ACH $client_gateway_token = $this->storePaymentMethod($source, $request->input('method'), $customer); $mailer = new NinjaMailerObject(); - $mailer->mailable = new ACHVerificationNotification(auth('contact')->user()->client->company); + $mailer->mailable = new ACHVerificationNotification(auth('contact')->user()->client->company, route('client.payment_methods.verification', ['payment_method' => $client_gateway_token->hashed_id, 'method' => GatewayType::BANK_TRANSFER])); $mailer->company = auth('contact')->user()->client->company; $mailer->settings = auth('contact')->user()->client->company->settings; $mailer->to_user = auth('contact')->user(); @@ -80,6 +80,12 @@ class ACH public function verificationView(ClientGatewayToken $token) { + if (isset($token->meta->state) && $token->meta->state === 'authorized') { + return redirect() + ->route('client.payment_methods.show', $token->hashed_id) + ->with('message', __('texts.payment_method_verified')); + } + $data = [ 'token' => $token, 'gateway' => $this->stripe, @@ -88,8 +94,14 @@ class ACH return render('gateways.stripe.ach.verify', $data); } - public function processVerification(VerifyPaymentMethodRequest $request, ClientGatewayToken $token) + public function processVerification($request, ClientGatewayToken $token) { + if (isset($token->meta->state) && $token->meta->state === 'authorized') { + return redirect() + ->route('client.payment_methods.show', $token->hashed_id) + ->with('message', __('texts.payment_method_verified')); + } + $this->stripe->init(); $bank_account = Customer::retrieveSource($request->customer, $request->source, $this->stripe->stripe_connect_auth); @@ -97,12 +109,14 @@ class ACH try { $bank_account->verify(['amounts' => request()->transactions]); - $token->meta->verified_at = now(); + $meta = $token->meta; + $meta->state = 'authorized'; + $token->meta = $meta; $token->save(); return redirect() - ->route('client.invoices.index') - ->with('success', __('texts.payment_method_verified')); + ->route('client.payment_methods.show', $token->hashed_id) + ->with('message', __('texts.payment_method_verified')); } catch (CardException $e) { return back()->with('error', $e->getMessage()); } diff --git a/resources/views/email/gateways/ach-verification-notification.blade.php b/resources/views/email/gateways/ach-verification-notification.blade.php index 1c49dddc0ef9..765173d62e43 100644 --- a/resources/views/email/gateways/ach-verification-notification.blade.php +++ b/resources/views/email/gateways/ach-verification-notification.blade.php @@ -2,5 +2,7 @@

{{ ctrans('texts.ach_verification_notification_label') }}

{{ ctrans('texts.ach_verification_notification') }}

+ + {{ ctrans('texts.complete_verification') }}
@endcomponent