diff --git a/app/Http/Controllers/ClientPortal/PaymentController.php b/app/Http/Controllers/ClientPortal/PaymentController.php index 3307eb7d2eb7..61a08aea9c3e 100644 --- a/app/Http/Controllers/ClientPortal/PaymentController.php +++ b/app/Http/Controllers/ClientPortal/PaymentController.php @@ -12,21 +12,24 @@ namespace App\Http\Controllers\ClientPortal; -use App\Factory\PaymentFactory; -use App\Http\Controllers\Controller; -use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; -use App\Models\CompanyGateway; use App\Models\Invoice; use App\Models\Payment; +use Illuminate\View\View; +use App\Models\GatewayType; use App\Models\PaymentHash; +use App\Models\PaymentType; +use Illuminate\Http\Request; +use App\Models\CompanyGateway; +use App\Factory\PaymentFactory; +use App\Utils\Traits\MakesHash; +use App\Utils\Traits\MakesDates; +use App\Http\Controllers\Controller; +use Illuminate\Http\RedirectResponse; +use Illuminate\Contracts\View\Factory; +use App\PaymentDrivers\Stripe\BankTransfer; use App\Services\ClientPortal\InstantPayment; use App\Services\Subscription\SubscriptionService; -use App\Utils\Traits\MakesDates; -use App\Utils\Traits\MakesHash; -use Illuminate\Contracts\View\Factory; -use Illuminate\Http\RedirectResponse; -use Illuminate\Http\Request; -use Illuminate\View\View; +use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; /** * Class PaymentController. @@ -56,9 +59,35 @@ class PaymentController extends Controller public function show(Request $request, Payment $payment) { $payment->load('invoices'); + $bank_details = false; + $payment_intent = false; + $data = false; + $gateway = false; + if($payment->gateway_type_id == GatewayType::DIRECT_DEBIT && $payment->type_id == PaymentType::DIRECT_DEBIT){ + + if (method_exists($payment->company_gateway->driver($payment->client), 'getPaymentIntent')) { + $stripe = $payment->company_gateway->driver($payment->client); + $payment_intent = $stripe->getPaymentIntent($payment->transaction_reference); + + $bt = new BankTransfer($stripe); + + match($payment->currency->code){ + 'MXN' => $data = $bt->formatDataforMx($payment_intent), + 'EUR' => $data = $bt->formatDataforEur($payment_intent), + 'JPY' => $data = $bt->formatDataforJp($payment_intent), + 'GBP' => $data = $bt->formatDataforUk($payment_intent), + }; + + $gateway = $stripe; + } + } + + return $this->render('payments.show', [ 'payment' => $payment, + 'bank_details' => $payment_intent ? $data : false, + 'currency' => strtolower($payment->currency->code), ]); } diff --git a/app/PaymentDrivers/Stripe/BankTransfer.php b/app/PaymentDrivers/Stripe/BankTransfer.php index 64fb1545e100..4e99dacbe00d 100644 --- a/app/PaymentDrivers/Stripe/BankTransfer.php +++ b/app/PaymentDrivers/Stripe/BankTransfer.php @@ -121,20 +121,23 @@ class BankTransfer ); if (in_array($pi->status, ['succeeded', 'processing'])) { - return $this->processSuccesfulRedirect($pi); + $payment = $this->processSuccesfulRedirect($pi); + redirect()->route('client.payments.show', ['payment' => $this->stripe->encodePrimaryKey($payment->id)]); } /* Create a pending payment */ if($pi->status == 'requires_action' && $pi->next_action->type == 'display_bank_transfer_instructions') { -nlog($pi); + match($pi->next_action->display_bank_transfer_instructions->currency){ - 'mxn' => $data = $this->formatDataforMx($pi), - 'gbp' => $data = $this->formatDataforUk($pi), - 'eur' => $data = $this->formatDataforEur($pi), - 'jpy' => $data = $this->formatDataforJp($pi), + 'mxn' => $data['bank_details'] = $this->formatDataforMx($pi), + 'gbp' => $data['bank_details'] = $this->formatDataforUk($pi), + 'eur' => $data['bank_details'] = $this->formatDataforEur($pi), + 'jpy' => $data['bank_details'] = $this->formatDataforJp($pi), }; - return render('gateways.stripe.bank_transfer.bank_details', $data); + $payment = $this->processSuccesfulRedirect($pi); + + return render('gateways.stripe.bank_transfer.bank_details_container', $data); // $data = [ // 'payment_method' => $pi->payment_method, @@ -166,7 +169,7 @@ nlog($pi); } - private function formatDataForUk(PaymentIntent $pi): array + public function formatDataForUk(PaymentIntent $pi): array { return [ @@ -183,7 +186,7 @@ nlog($pi); } - private function formatDataforMx(PaymentIntent $pi): array + public function formatDataforMx(PaymentIntent $pi): array { return [ @@ -202,7 +205,7 @@ nlog($pi); } - private function formatDataforEur(PaymentIntent $pi): array + public function formatDataforEur(PaymentIntent $pi): array { return [ @@ -225,7 +228,7 @@ nlog($pi); * @param PaymentIntent $pi * @return array */ - private function formatDataforJp(PaymentIntent $pi): array + public function formatDataforJp(PaymentIntent $pi): array { return [ @@ -261,7 +264,7 @@ nlog($pi); ]; - $payment = $this->stripe->createPayment($data, $payment_intent->status == 'processing' ? Payment::STATUS_PENDING : Payment::STATUS_COMPLETED); + $payment = $this->stripe->createPayment($data, $payment_intent->status == 'succeeded' ? Payment::STATUS_COMPLETED : Payment::STATUS_PENDING); SystemLogger::dispatch( ['response' => $this->stripe->payment_hash->data, 'data' => $data], @@ -272,9 +275,9 @@ nlog($pi); $this->stripe->client->company, ); - return redirect()->route('client.payments.show', ['payment' => $this->stripe->encodePrimaryKey($payment->id)]); + return $payment; } - + public function processUnsuccesfulRedirect() { $server_response = $this->stripe->payment_hash->data; diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 0f31bc45a5e7..9f331d5bfee2 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -438,6 +438,17 @@ class StripePaymentDriver extends BaseDriver return PaymentIntent::create($data, array_merge($meta, ['idempotency_key' => uniqid("st", true)])); } + public function getPaymentIntent($payment_intent_id): ?PaymentIntent + { + $this->init(); + + return PaymentIntent::retrieve( + $payment_intent_id, + $this->stripe_connect_auth + ); + + } + /** * Returns a setup intent that allows the user * to enter card details without initiating a transaction. diff --git a/resources/views/portal/ninja2020/gateways/stripe/bank_transfer/bank_details.blade.php b/resources/views/portal/ninja2020/gateways/stripe/bank_transfer/bank_details.blade.php index 6fed75af7ba7..82d1d4a2fd96 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bank_transfer/bank_details.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bank_transfer/bank_details.blade.php @@ -1,199 +1,203 @@ -@extends('portal.ninja2020.layout.payments', ['gateway_title' => 'Bank Transfer', 'card_title' => $description ]) -@section('gateway_content') -
-
+
+
+

+ {{ ctrans('texts.bank_transfer') }} +

+
+
+
- @if($currency == 'gbp') + @if($bank_details['currency'] == 'gbp') -
- {{ ctrans('texts.sort') }} -
-
- {{ $sort_code }} -
- -
- {{ ctrans('texts.account_number') }} -
-
- {{ $account_number }} -
+
+ {{ ctrans('texts.sort') }} +
+
+ {{ $bank_details['sort_code'] }} +
+ +
+ {{ ctrans('texts.account_number') }} +
+
+ {{ $bank_details['account_number'] }} +
-
- {{ ctrans('texts.account_name') }} -
-
- {{ $account_holder_name }} -
+
+ {{ ctrans('texts.account_name') }} +
+
+ {{ $bank_details['account_holder_name'] }} +
- -
- {{ ctrans('texts.reference') }} -
-
- {{ $reference }} -
+ +
+ {{ ctrans('texts.reference') }} +
+
+ {{ $bank_details['reference'] }} +
-
- {{ ctrans('texts.balance_due') }} -
-
- {{ $amount }} -
+
+ {{ ctrans('texts.balance_due') }} +
+
+ {{ $bank_details['amount'] }} +
-
-
-
- {{ ctrans('texts.stripe_direct_debit_details') }} -
- - @elseif($currency == 'mxn') - -
- Clabe +
+
+
+ {{ ctrans('texts.stripe_direct_debit_details') }} +
+ + @elseif($bank_details['currency'] == 'mxn') + +
+ Clabe +
+
+ {{ $bank_details['sort_code'] }} +
+ +
+ {{ ctrans('texts.account_number') }} +
+
+ {{ $bank_details['account_number'] }} +
+ +
+ {{ ctrans('texts.account_name') }} +
+
+ {{ $bank_details['account_holder_name'] }} +
+ + +
+ {{ ctrans('texts.reference') }} +
+
+ {{ $bank_details['reference'] }} +
+ + +
+ {{ ctrans('texts.balance_due') }} +
+
+ {{ $bank_details['amount'] }} +
+ +
+
+
+ {{ ctrans('texts.stripe_direct_debit_details') }} +
+ + @elseif($bank_details['currency'] == 'jpy') + +
+ {{ ctrans('texts.account_number') }} +
+
+ {{ $bank_details['account_number'] }} +
+ +
+ {{ ctrans('texts.account_name') }} +
+
+ {{ $bank_details['account_holder_name'] }} +
+ +
+ {{ ctrans('texts.account_type') }} +
+
+ {{ $bank_details['account_type'] }} +
+ +
+ {{ ctrans('texts.bank_name') }} +
+
+ {{ $bank_details['bank_name'] }} +
+ +
+ {{ ctrans('texts.bank_code') }} +
+
+ {{ $bank_details['bank_code'] }} +
+ +
+ {{ ctrans('texts.branch_name') }} +
+
+ {{ $bank_details['branch_name'] }} +
+ +
+ {{ ctrans('texts.branch_code') }} +
+
+ {{ $bank_details['branch_code'] }} +
+ +
+ {{ ctrans('texts.reference') }} +
+
+ {{ $bank_details['reference'] }} +
+ + +
+ {{ ctrans('texts.balance_due') }} +
+
+ {{ $bank_details['amount'] }} +
+ +
+
+
+ {{ ctrans('texts.stripe_direct_debit_details') }} +
+ + @elseif($bank_details['currency'] == 'eur') + +
+ {{ ctrans('texts.account_name') }}
- {{ $sort_code }} + {{ $bank_details['account_holder_name'] }}
{{ ctrans('texts.account_number') }}
- {{ $account_number }} -
- -
- {{ ctrans('texts.account_name') }} -
-
- {{ $account_holder_name }} -
- - -
- {{ ctrans('texts.reference') }} -
-
- {{ $reference }} -
- - -
- {{ ctrans('texts.balance_due') }} -
-
- {{ $amount }} -
- -
-
-
- {{ ctrans('texts.stripe_direct_debit_details') }} -
- - @elseif($currency == 'jpy') - -
- {{ ctrans('texts.account_number') }} -
-
- {{ $account_number }} -
- -
- {{ ctrans('texts.account_name') }} -
-
- {{ $account_holder_name }} -
- -
- {{ ctrans('texts.account_type') }} -
-
- {{ $account_type }} -
- -
- {{ ctrans('texts.bank_name') }} -
-
- {{ $bank_name }} -
- -
- {{ ctrans('texts.bank_code') }} -
-
- {{ $bank_code }} -
- -
- {{ ctrans('texts.branch_name') }} -
-
- {{ $branch_name }} -
- -
- {{ ctrans('texts.branch_code') }} -
-
- {{ $branch_code }} -
- -
- {{ ctrans('texts.reference') }} -
-
- {{ $reference }} -
- - -
- {{ ctrans('texts.balance_due') }} -
-
- {{ $amount }} -
- -
-
-
- {{ ctrans('texts.stripe_direct_debit_details') }} -
- - @elseif($currency == 'eur') - -
- {{ ctrans('texts.account_name') }} -
-
- {{ $account_holder_name }} -
- -
- {{ ctrans('texts.account_number') }} -
-
- {{ $account_number }} + {{ $bank_details['account_number'] }}
{{ ctrans('texts.bic') }}
- {{ $sort_code }} + {{ $bank_details['sort_code'] }}
{{ ctrans('texts.reference') }}
- {{ $reference }} + {{ $bank_details['reference'] }}
@@ -201,7 +205,7 @@ {{ ctrans('texts.balance_due') }}
- {{ $amount }} + {{ $bank_details['amount'] }}
@@ -210,12 +214,8 @@ {{ ctrans('texts.stripe_direct_debit_details') }} - @endif - +
- @endsection - -@push('footer') -@endpush \ No newline at end of file +
\ No newline at end of file diff --git a/resources/views/portal/ninja2020/gateways/stripe/bank_transfer/bank_details_container.blade.php b/resources/views/portal/ninja2020/gateways/stripe/bank_transfer/bank_details_container.blade.php new file mode 100644 index 000000000000..81d9337bf59c --- /dev/null +++ b/resources/views/portal/ninja2020/gateways/stripe/bank_transfer/bank_details_container.blade.php @@ -0,0 +1,5 @@ +@extends('portal.ninja2020.layout.app') + +@section('meta_title', ctrans('texts.bank_transfer')) + +@include('portal.ninja2020.gateways.stripe.bank_transfer.bank_details') \ No newline at end of file diff --git a/resources/views/portal/ninja2020/payments/show.blade.php b/resources/views/portal/ninja2020/payments/show.blade.php index 11e42598a526..546f55a89dee 100644 --- a/resources/views/portal/ninja2020/payments/show.blade.php +++ b/resources/views/portal/ninja2020/payments/show.blade.php @@ -122,6 +122,12 @@ @endforeach
+ +
+ @if($bank_details) + @include('portal.ninja2020.gateways.stripe.bank_transfer.bank_details') + @endif + @endsection