From f897df733a60166a773461faac9b874904f74629 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 14:22:03 +0100 Subject: [PATCH] Redirect after payment --- app/PaymentDrivers/Stripe/BACS.php | 14 +++- public/js/clients/payments/stripe-bacs.js | 81 +------------------ resources/js/clients/payments/stripe-bacs.js | 13 +-- .../gateways/stripe/bacs/pay.blade.php | 1 + 4 files changed, 15 insertions(+), 94 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index acb724990c..c817ec5b87 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -42,12 +42,12 @@ class BACS 'payment_method_types' => ['bacs_debit'], 'mode' => 'setup', 'customer' => $customer->id, - 'success_url' => str_replace("%7B", "{", str_replace("%7D", "}", $this->buildReturnUrl())), + 'success_url' => str_replace("%7B", "{", str_replace("%7D", "}", $this->buildAuthorizeUrl())), 'cancel_url' => route('client.payment_methods.index'), ]); return render('gateways.stripe.bacs.authorize', $data); } - private function buildReturnUrl(): string + private function buildAuthorizeUrl(): string { return route('client.payment_methods.confirm', [ 'method' => GatewayType::BACS, @@ -68,6 +68,13 @@ class BACS } return redirect()->route('client.payment_methods.index'); } + private function buildPaymentUrl(): string + { + return route('client.payments.response', [ + 'method' => GatewayType::BACS, + 'session_id' => "{CHECKOUT_SESSION_ID}", + ]); + } public function paymentView(array $data) { @@ -90,13 +97,14 @@ class BACS $data['intent'] = $this->stripe->createPaymentIntent($payment_intent_data); $data['gateway'] = $this->stripe; + $data['payment_url'] = $this->buildPaymentUrl(); return render('gateways.stripe.bacs.pay', $data); } public function paymentResponse(PaymentResponseRequest $request) { $this->stripe->init(); - + nlog($request); $state = [ 'server_response' => json_decode($request->gateway_response), 'payment_hash' => $request->payment_hash, diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index 6e213a70a7..b5d0188c05 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -1,79 +1,2 @@ -/** - * 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; - this.onlyAuthorization = onlyAuthorization; - } - - 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 = () => { - if (this.onlyAuthorization) { - document.getElementById('authorize-bacs').addEventListener('click', (e) => { - document.getElementById('authorize-bacs').disabled = true; - document.querySelector('#authorize-bacs > svg').classList.remove('hidden'); - document.querySelector('#authorize-bacs > span').classList.add('hidden'); - location.href=document.querySelector('meta[name=stripe-redirect-url').content; - });} - else{ - document.getElementById('pay-now').addEventListener('click', (e) => { - let token = document.querySelector('input[name=token]').value; - let payNowButton = document.getElementById('pay-now'); - this.payNowButton = payNowButton; - this.payNowButton.disabled = true; - this.payNowButton.querySelector('svg').classList.remove('hidden'); - this.payNowButton.querySelector('span').classList.add('hidden'); - - this.stripe.confirmBecsDebitPayment( - document.querySelector('meta[name=stripe-secret') - .content, - {} - ).then((result) => { - if (result.error) { - return this.handleFailure(result.error.message); - } - - return this.handleSuccess(result); - }); - }); - } - }; -} - -const publishableKey = document.querySelector( - 'meta[name="stripe-publishable-key"]' -)?.content ?? ''; - -const stripeConnect = - document.querySelector('meta[name="stripe-account-id"]')?.content ?? ''; -const onlyAuthorization = - document.querySelector('meta[name="only-authorization"]')?.content ?? ''; - -new ProcessBACS(publishableKey, stripeConnect).setupStripe().handle(); +/*! For license information please see stripe-bacs.js.LICENSE.txt */ +(()=>{var e,t,n,o,r,i;function a(e,t){for(var n=0;n svg").classList.remove("hidden"),document.querySelector("#authorize-bacs > span").classList.add("hidden"),location.href=document.querySelector("meta[name=stripe-redirect-url").content})):document.getElementById("pay-now").addEventListener("click",(function(e){var t=document.querySelector("input[name=token]").value,n=document.getElementById("pay-now");o.payNowButton=n,o.payNowButton.disabled=!0,o.payNowButton.querySelector("svg").classList.remove("hidden"),o.payNowButton.querySelector("span").classList.add("hidden"),location.href=document.querySelector("meta[name=redirect-url").content+"&payment_id="+t}))})),this.key=t,this.errors=document.getElementById("errors"),this.stripeConnect=n,this.onlyAuthorization=y})),d=null!==(e=null===(t=document.querySelector('meta[name="stripe-publishable-key"]'))||void 0===t?void 0:t.content)&&void 0!==e?e:"",s=null!==(n=null===(o=document.querySelector('meta[name="stripe-account-id"]'))||void 0===o?void 0:o.content)&&void 0!==n?n:"",y=null!==(r=null===(i=document.querySelector('meta[name="only-authorization"]'))||void 0===i?void 0:i.content)&&void 0!==r?r:"";new l(d,s).setupStripe().handle()})(); \ No newline at end of file diff --git a/resources/js/clients/payments/stripe-bacs.js b/resources/js/clients/payments/stripe-bacs.js index 6e213a70a7..96950c0885 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -50,18 +50,7 @@ class ProcessBACS { this.payNowButton.disabled = true; this.payNowButton.querySelector('svg').classList.remove('hidden'); this.payNowButton.querySelector('span').classList.add('hidden'); - - this.stripe.confirmBecsDebitPayment( - document.querySelector('meta[name=stripe-secret') - .content, - {} - ).then((result) => { - if (result.error) { - return this.handleFailure(result.error.message); - } - - return this.handleSuccess(result); - }); + location.href=document.querySelector('meta[name=redirect-url').content + "&payment_id=" + token; }); } }; diff --git a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php index 84d96b1452..becd88c713 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -9,6 +9,7 @@ @endif + @endsection @section('gateway_content')