refactor for ach payments

This commit is contained in:
David Bomba 2022-05-18 09:39:54 +10:00
parent 8e3ccc83ad
commit c4231f702d
3 changed files with 138 additions and 1 deletions

View File

@ -143,7 +143,21 @@ class ACH
$data['customer'] = $this->stripe->findOrCreateCustomer();
$data['amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency());
return render('gateways.stripe.ach.pay', $data);
$intent =
$this->stripe->createPaymentIntent([
'amount' => $data['amount'],
'currency' => $data['currency'],
'setup_future_usage' => 'off_session',
'customer' => $data['customer']->id,
'payment_method_types' => ['us_bank_account'],
]
);
$data['client_secret'] = $intent->client_secret;
return render('gateways.stripe.ach.pay_instant_verification', $data);
// return render('gateways.stripe.ach.pay', $data);
}
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)

View File

@ -0,0 +1,66 @@
@extends('portal.ninja2020.layout.payments', ['gateway_title' => 'ACH', 'card_title' => 'ACH'])
@section('gateway_content')
@if(count($tokens) > 0)
<div class="alert alert-failure mb-4" hidden id="errors"></div>
@include('portal.ninja2020.gateways.includes.payment_details')
<form action="{{ route('client.payments.response') }}" method="post" id="server-response">
@csrf
<input type="hidden" name="company_gateway_id" value="{{ $gateway->getCompanyGatewayId() }}">
<input type="hidden" name="payment_method_id" value="{{ $payment_method_id }}">
<input type="hidden" name="source" value="">
<input type="hidden" name="amount" value="{{ $amount }}">
<input type="hidden" name="currency" value="{{ $currency }}">
<input type="hidden" name="customer" value="{{ $customer->id }}">
<input type="hidden" name="payment_hash" value="{{ $payment_hash }}">
<input type="hidden" name="client_secret" value="{{ $client_secret }}">
</form>
@component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.pay_with')])
@if(count($tokens) > 0)
@foreach($tokens as $token)
<label class="mr-4">
<input
type="radio"
data-token="{{ $token->hashed_id }}"
name="payment-type"
class="form-radio cursor-pointer toggle-payment-with-token"/>
<span class="ml-1 cursor-pointer">{{ ctrans('texts.bank_transfer') }} (*{{ $token->meta->last4 }})</span>
</label>
@endforeach
@endisset
@endcomponent
@else
@component('portal.ninja2020.components.general.card-element-single', ['title' => 'ACH', 'show_title' => false])
<span>{{ ctrans('texts.bank_account_not_linked') }}</span>
<a class="button button-link text-primary"
href="{{ route('client.payment_methods.index') }}">{{ ctrans('texts.add_payment_method') }}</a>
@endcomponent
@endif
@include('portal.ninja2020.gateways.includes.pay_now')
@endsection
@push('footer')
<script>
Array
.from(document.getElementsByClassName('toggle-payment-with-token'))
.forEach((element) => element.addEventListener('click', (element) => {
document.querySelector('input[name=source]').value = element.target.dataset.token;
}));
document.getElementById('pay-now').addEventListener('click', function () {
let payNowButton = document.getElementById('pay-now');
payNowButton.disabled = true;
payNowButton.querySelector('svg').classList.remove('hidden');
payNowButton.querySelector('span').classList.add('hidden');
document.getElementById('server-response').submit();
});
</script>
@endpush

View File

@ -0,0 +1,57 @@
<button id="link-button">Link Account</button>
<script src="https://cdn.plaid.com/link/v2/stable/link-initialize.js"></script>
<script type="text/javascript">
(async function() {
const configs = {
// Pass the link_token generated in step 2.
token: '{{ $link_token }}',
onLoad: function() {
// The Link module finished loading.
},
onSuccess: function(public_token, metadata) {
// The onSuccess function is called when the user has
// successfully authenticated and selected an account to
// use.
//
// When called, you will send the public_token
// and the selected account ID, metadata.accounts,
// to your backend app server.
//
// sendDataToBackendServer({
// public_token: public_token,
// account_id: metadata.accounts[0].id
// });
console.log('Public Token: ' + public_token);
switch (metadata.accounts.length) {
case 0:
// Select Account is disabled: https://dashboard.plaid.com/link/account-select
break;
case 1:
console.log('Customer-selected account ID: ' + metadata.accounts[0].id);
break;
default:
// Multiple Accounts is enabled: https://dashboard.plaid.com/link/account-select
}
},
onExit: async function(err, metadata) {
// The user exited the Link flow.
if (err != null) {
// The user encountered a Plaid API error
// prior to exiting.
}
// metadata contains information about the institution
// that the user selected and the most recent
// API request IDs.
// Storing this information can be helpful for support.
},
};
var linkHandler = Plaid.create(configs);
document.getElementById('link-button').onclick = function() {
linkHandler.open();
};
})();
</script>