Further changes

This commit is contained in:
Lars Kusch 2022-12-16 14:43:03 +01:00
parent b3dd3aaaa1
commit 6ad2cba624
4 changed files with 75 additions and 32 deletions

View File

@ -36,9 +36,24 @@ class BACS
public function authorizeView(array $data) public function authorizeView(array $data)
{ {
$intent['intent'] = $this->stripe->getSetupIntent(); $customer = $this->stripe->findOrCreateCustomer();
$session = $this->stripe->Checkout->Session::create([
'payment_method_types' => ['bacs_debit'],
'mode' => 'setup',
'customer' => $customer->id,
'success_url' => $this->buildReturnUrl(),
'cancel_url' => 'https://example.com/cancel',
]);
return render('gateways.stripe.bacs.authorize', array_merge($data, $intent)); return render('gateways.stripe.bacs.authorize', array_merge($data, $session));
}
private function buildReturnUrl(): string
{
return route('client.payments.response', [
'company_gateway_id' => $this->stripe->company_gateway->id,
'payment_hash' => $this->stripe->payment_hash->hash,
'payment_method_id' => GatewayType::BACS,
]);
} }
public function authorizeResponse($request) public function authorizeResponse($request)
@ -47,10 +62,6 @@ class BACS
$stripe_response = json_decode($request->input('gateway_response')); $stripe_response = json_decode($request->input('gateway_response'));
$customer = $this->stripe->findOrCreateCustomer();
$this->stripe->attach($stripe_response->payment_method, $customer);
$stripe_method = $this->stripe->getStripePaymentMethod($stripe_response->payment_method); $stripe_method = $this->stripe->getStripePaymentMethod($stripe_response->payment_method);
$this->storePaymentMethod($stripe_method, $request->payment_method_id, $customer); $this->storePaymentMethod($stripe_method, $request->payment_method_id, $customer);

View File

@ -1,2 +1,55 @@
/*! For license information please see stripe-bacs.js.LICENSE.txt */ /**
(()=>{var e,t,n,r;function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var c=i((function e(t,n){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),a(this,"setupStripe",(function(){return r.stripeConnect?r.stripe=Stripe(r.key,{stripeAccount:r.stripeConnect}):r.stripe=Stripe(r.key),r})),a(this,"handle",(function(){document.getElementById("pay-now").addEventListener("click",(function(e){document.getElementById("errors");document.getElementById("pay-now").disabled=!0,document.querySelector("#pay-now > svg").classList.remove("hidden"),document.querySelector("#pay-now > span").classList.add("hidden"),r.stripe.confirmGiropayPayment(document.querySelector("meta[name=pi-client-secret").content,{payment_method:{billing_details:{name:document.getElementById("giropay-name").value}},return_url:document.querySelector('meta[name="return-url"]').content})}))})),this.key=t,this.errors=document.getElementById("errors"),this.stripeConnect=n}));new c(null!==(e=null===(t=document.querySelector('meta[name="stripe-publishable-key"]'))||void 0===t?void 0:t.content)&&void 0!==e?e:"",null!==(n=null===(r=document.querySelector('meta[name="stripe-account-id"]'))||void 0===r?void 0:r.content)&&void 0!==n?n:"").setupStripe().handle()})(); * Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
class ProcessBACS {
constructor(key, stripeConnect) {
this.key = key;
this.errors = document.getElementById('errors');
this.stripeConnect = stripeConnect;
}
setupStripe = () => {
if (this.stripeConnect){
// this.stripe.stripeAccount = this.stripeConnect;
this.stripe = Stripe(this.key, {
stripeAccount: this.stripeConnect,
});
}
else {
this.stripe = Stripe(this.key);
}
return this;
};
handle = () => {
document.getElementById('pay-now').addEventListener('click', (e) => {
let errors = document.getElementById('errors');
document.getElementById('pay-now').disabled = true;
document.querySelector('#pay-now > svg').classList.remove('hidden');
document.querySelector('#pay-now > span').classList.add('hidden');
location.href=document.querySelector('meta[name=stripe-redirect-url]').content;
});
};
}
const publishableKey = document.querySelector(
'meta[name="stripe-publishable-key"]'
)?.content ?? '';
const stripeConnect =
document.querySelector('meta[name="stripe-account-id"]')?.content ?? '';
new ProcessBACS(publishableKey, stripeConnect).setupStripe().handle();

View File

@ -40,20 +40,7 @@ class ProcessBACS {
document.getElementById('pay-now').disabled = true; document.getElementById('pay-now').disabled = true;
document.querySelector('#pay-now > svg').classList.remove('hidden'); document.querySelector('#pay-now > svg').classList.remove('hidden');
document.querySelector('#pay-now > span').classList.add('hidden'); document.querySelector('#pay-now > span').classList.add('hidden');
location.href=document.querySelector('meta[name=stripe-redirect-url]').content;
this.stripe.confirmGiropayPayment(
document.querySelector('meta[name=pi-client-secret').content,
{
payment_method: {
billing_details: {
name: document.getElementById("giropay-name").value,
},
},
return_url: document.querySelector(
'meta[name="return-url"]'
).content,
}
);
}); });
}; };
} }

View File

@ -8,9 +8,7 @@
@else @else
<meta name="stripe-publishable-key" content="{{ $gateway->getPublishableKey() }}"> <meta name="stripe-publishable-key" content="{{ $gateway->getPublishableKey() }}">
@endif @endif
<meta name="stripe-secret" content="{{ $intent->client_secret }}"> <meta name="stripe-redirect-url" content="{{ $session->url }}">
<meta name="only-authorization" content="true">
<meta name="stripe-token" content="">
@endsection @endsection
@ -25,12 +23,6 @@
<div class="alert alert-failure mb-4" hidden id="errors"></div> <div class="alert alert-failure mb-4" hidden id="errors"></div>
@component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.method')])
{{ ctrans('texts.credit_card') }}
@endcomponent
@include('portal.ninja2020.gateways.stripe.includes.card_widget', ['show_save_method' => false])
@component('portal.ninja2020.gateways.includes.pay_now', ['id' => 'authorize-card']) @component('portal.ninja2020.gateways.includes.pay_now', ['id' => 'authorize-card'])
{{ ctrans('texts.add_payment_method') }} {{ ctrans('texts.add_payment_method') }}
@endcomponent @endcomponent
@ -38,5 +30,5 @@
@section('gateway_footer') @section('gateway_footer')
<script src="https://js.stripe.com/v3/"></script> <script src="https://js.stripe.com/v3/"></script>
<script src="{{ asset('js/clients/payments/stripe-credit-card.js') }}"></script> <script src="{{ asset('js/clients/payments/stripe-bacs.js') }}"></script>
@endsection @endsection