1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

bank transfer

This commit is contained in:
David Bomba 2023-02-27 15:32:37 +11:00
parent 3288a7633e
commit 275041b903
6 changed files with 253 additions and 199 deletions

View File

@ -12,21 +12,24 @@
namespace App\Http\Controllers\ClientPortal; 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\Invoice;
use App\Models\Payment; use App\Models\Payment;
use Illuminate\View\View;
use App\Models\GatewayType;
use App\Models\PaymentHash; 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\ClientPortal\InstantPayment;
use App\Services\Subscription\SubscriptionService; use App\Services\Subscription\SubscriptionService;
use App\Utils\Traits\MakesDates; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Utils\Traits\MakesHash;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
/** /**
* Class PaymentController. * Class PaymentController.
@ -56,9 +59,35 @@ class PaymentController extends Controller
public function show(Request $request, Payment $payment) public function show(Request $request, Payment $payment)
{ {
$payment->load('invoices'); $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', [ return $this->render('payments.show', [
'payment' => $payment, 'payment' => $payment,
'bank_details' => $payment_intent ? $data : false,
'currency' => strtolower($payment->currency->code),
]); ]);
} }

View File

@ -121,20 +121,23 @@ class BankTransfer
); );
if (in_array($pi->status, ['succeeded', 'processing'])) { 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 */ /* Create a pending payment */
if($pi->status == 'requires_action' && $pi->next_action->type == 'display_bank_transfer_instructions') { if($pi->status == 'requires_action' && $pi->next_action->type == 'display_bank_transfer_instructions') {
nlog($pi);
match($pi->next_action->display_bank_transfer_instructions->currency){ match($pi->next_action->display_bank_transfer_instructions->currency){
'mxn' => $data = $this->formatDataforMx($pi), 'mxn' => $data['bank_details'] = $this->formatDataforMx($pi),
'gbp' => $data = $this->formatDataforUk($pi), 'gbp' => $data['bank_details'] = $this->formatDataforUk($pi),
'eur' => $data = $this->formatDataforEur($pi), 'eur' => $data['bank_details'] = $this->formatDataforEur($pi),
'jpy' => $data = $this->formatDataforJp($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 = [ // $data = [
// 'payment_method' => $pi->payment_method, // 'payment_method' => $pi->payment_method,
@ -166,7 +169,7 @@ nlog($pi);
} }
private function formatDataForUk(PaymentIntent $pi): array public function formatDataForUk(PaymentIntent $pi): array
{ {
return [ return [
@ -183,7 +186,7 @@ nlog($pi);
} }
private function formatDataforMx(PaymentIntent $pi): array public function formatDataforMx(PaymentIntent $pi): array
{ {
return [ return [
@ -202,7 +205,7 @@ nlog($pi);
} }
private function formatDataforEur(PaymentIntent $pi): array public function formatDataforEur(PaymentIntent $pi): array
{ {
return [ return [
@ -225,7 +228,7 @@ nlog($pi);
* @param PaymentIntent $pi * @param PaymentIntent $pi
* @return array * @return array
*/ */
private function formatDataforJp(PaymentIntent $pi): array public function formatDataforJp(PaymentIntent $pi): array
{ {
return [ 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( SystemLogger::dispatch(
['response' => $this->stripe->payment_hash->data, 'data' => $data], ['response' => $this->stripe->payment_hash->data, 'data' => $data],
@ -272,7 +275,7 @@ nlog($pi);
$this->stripe->client->company, $this->stripe->client->company,
); );
return redirect()->route('client.payments.show', ['payment' => $this->stripe->encodePrimaryKey($payment->id)]); return $payment;
} }
public function processUnsuccesfulRedirect() public function processUnsuccesfulRedirect()

View File

@ -438,6 +438,17 @@ class StripePaymentDriver extends BaseDriver
return PaymentIntent::create($data, array_merge($meta, ['idempotency_key' => uniqid("st", true)])); 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 * Returns a setup intent that allows the user
* to enter card details without initiating a transaction. * to enter card details without initiating a transaction.

View File

@ -1,199 +1,203 @@
@extends('portal.ninja2020.layout.payments', ['gateway_title' => 'Bank Transfer', 'card_title' => $description ])
@section('gateway_content') <div class="mt-4 overflow-hidden bg-white shadow sm:rounded-lg">
<div class="container mx-auto"> <div class="px-4 py-5 border-b border-gray-200 sm:px-6">
<div class="px-4 py-5 bg-white sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"> <h3 class="text-lg font-medium leading-6 text-gray-900">
{{ ctrans('texts.bank_transfer') }}
</h3>
</div>
<div class="container mx-auto">
<div class="px-4 py-5 bg-white sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
@if($currency == 'gbp') @if($bank_details['currency'] == 'gbp')
<dt class="text-sm font-medium leading-5 text-gray-500"> <dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.sort') }} {{ ctrans('texts.sort') }}
</dt> </dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2"> <dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $sort_code }} {{ $bank_details['sort_code'] }}
</dd> </dd>
<dt class="text-sm font-medium leading-5 text-gray-500"> <dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.account_number') }} {{ ctrans('texts.account_number') }}
</dt> </dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2"> <dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $account_number }} {{ $bank_details['account_number'] }}
</dd> </dd>
<dt class="text-sm font-medium leading-5 text-gray-500"> <dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.account_name') }} {{ ctrans('texts.account_name') }}
</dt> </dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2"> <dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $account_holder_name }} {{ $bank_details['account_holder_name'] }}
</dd> </dd>
<dt class="text-sm font-medium leading-5 text-gray-500"> <dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.reference') }} {{ ctrans('texts.reference') }}
</dt> </dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2"> <dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $reference }} {{ $bank_details['reference'] }}
</dd> </dd>
<dt class="text-sm font-medium leading-5 text-gray-500"> <dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.balance_due') }} {{ ctrans('texts.balance_due') }}
</dt> </dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2"> <dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $amount }} {{ $bank_details['amount'] }}
</dd> </dd>
<dt class="text-sm font-medium leading-5 text-gray-500"> <dt class="text-sm font-medium leading-5 text-gray-500">
</dt> </dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2"> <dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ ctrans('texts.stripe_direct_debit_details') }} {{ ctrans('texts.stripe_direct_debit_details') }}
</dd> </dd>
@elseif($currency == 'mxn') @elseif($bank_details['currency'] == 'mxn')
<dt class="text-sm font-medium leading-5 text-gray-500"> <dt class="text-sm font-medium leading-5 text-gray-500">
Clabe Clabe
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $bank_details['sort_code'] }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.account_number') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $bank_details['account_number'] }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.account_name') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $bank_details['account_holder_name'] }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.reference') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $bank_details['reference'] }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.balance_due') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $bank_details['amount'] }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ ctrans('texts.stripe_direct_debit_details') }}
</dd>
@elseif($bank_details['currency'] == 'jpy')
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.account_number') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $bank_details['account_number'] }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.account_name') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $bank_details['account_holder_name'] }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.account_type') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $bank_details['account_type'] }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.bank_name') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $bank_details['bank_name'] }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.bank_code') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $bank_details['bank_code'] }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.branch_name') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $bank_details['branch_name'] }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.branch_code') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $bank_details['branch_code'] }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.reference') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $bank_details['reference'] }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.balance_due') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $bank_details['amount'] }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ ctrans('texts.stripe_direct_debit_details') }}
</dd>
@elseif($bank_details['currency'] == 'eur')
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.account_name') }}
</dt> </dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2"> <dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $sort_code }} {{ $bank_details['account_holder_name'] }}
</dd> </dd>
<dt class="text-sm font-medium leading-5 text-gray-500"> <dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.account_number') }} {{ ctrans('texts.account_number') }}
</dt> </dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2"> <dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $account_number }} {{ $bank_details['account_number'] }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.account_name') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $account_holder_name }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.reference') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $reference }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.balance_due') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $amount }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ ctrans('texts.stripe_direct_debit_details') }}
</dd>
@elseif($currency == 'jpy')
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.account_number') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $account_number }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.account_name') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $account_holder_name }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.account_type') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $account_type }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.bank_name') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $bank_name }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.bank_code') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $bank_code }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.branch_name') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $branch_name }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.branch_code') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $branch_code }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.reference') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $reference }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.balance_due') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $amount }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ ctrans('texts.stripe_direct_debit_details') }}
</dd>
@elseif($currency == 'eur')
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.account_name') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $account_holder_name }}
</dd>
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.account_number') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $account_number }}
</dd> </dd>
<dt class="text-sm font-medium leading-5 text-gray-500"> <dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.bic') }} {{ ctrans('texts.bic') }}
</dt> </dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2"> <dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $sort_code }} {{ $bank_details['sort_code'] }}
</dd> </dd>
<dt class="text-sm font-medium leading-5 text-gray-500"> <dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.reference') }} {{ ctrans('texts.reference') }}
</dt> </dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2"> <dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $reference }} {{ $bank_details['reference'] }}
</dd> </dd>
@ -201,7 +205,7 @@
{{ ctrans('texts.balance_due') }} {{ ctrans('texts.balance_due') }}
</dt> </dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2"> <dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $amount }} {{ $bank_details['amount'] }}
</dd> </dd>
<dt class="text-sm font-medium leading-5 text-gray-500"> <dt class="text-sm font-medium leading-5 text-gray-500">
@ -210,12 +214,8 @@
{{ ctrans('texts.stripe_direct_debit_details') }} {{ ctrans('texts.stripe_direct_debit_details') }}
</dd> </dd>
@endif @endif
</div> </div>
</div> </div>
@endsection </div>
@push('footer')
@endpush

View File

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

View File

@ -122,6 +122,12 @@
@endforeach @endforeach
</dl> </dl>
</div> </div>
<!-- if this is a stripe bank transfer - show the required details here: -->
</div> </div>
@if($bank_details)
@include('portal.ninja2020.gateways.stripe.bank_transfer.bank_details')
@endif
</div> </div>
@endsection @endsection