From 6ad2cba624f04c11f93826020263add9ff93b460 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 14:43:03 +0100 Subject: [PATCH] Further changes --- app/PaymentDrivers/Stripe/BACS.php | 23 ++++++-- public/js/clients/payments/stripe-bacs.js | 57 ++++++++++++++++++- resources/js/clients/payments/stripe-bacs.js | 15 +---- .../gateways/stripe/bacs/authorize.blade.php | 12 +--- 4 files changed, 75 insertions(+), 32 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index ca7edbcbe3c5..f315850d43fc 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -36,9 +36,24 @@ class BACS 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) @@ -47,10 +62,6 @@ class BACS $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); $this->storePaymentMethod($stripe_method, $request->payment_method_id, $customer); diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index 22d576f971e7..6a89d1e000bc 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -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 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()})(); \ No newline at end of file +/** + * 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(); diff --git a/resources/js/clients/payments/stripe-bacs.js b/resources/js/clients/payments/stripe-bacs.js index 3aab9174a0bb..6a89d1e000bc 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -40,20 +40,7 @@ class ProcessBACS { document.getElementById('pay-now').disabled = true; document.querySelector('#pay-now > svg').classList.remove('hidden'); document.querySelector('#pay-now > span').classList.add('hidden'); - - 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, - } - ); + location.href=document.querySelector('meta[name=stripe-redirect-url]').content; }); }; } diff --git a/resources/views/portal/ninja2020/gateways/stripe/bacs/authorize.blade.php b/resources/views/portal/ninja2020/gateways/stripe/bacs/authorize.blade.php index 7a0052785397..18a6d0591764 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/authorize.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/authorize.blade.php @@ -8,9 +8,7 @@ @else @endif - - - + @endsection @@ -25,12 +23,6 @@ - @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']) {{ ctrans('texts.add_payment_method') }} @endcomponent @@ -38,5 +30,5 @@ @section('gateway_footer') - + @endsection