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') -