From 7151a66bdfb6ee30cbc5b271625a6499b775a242 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 9 Oct 2021 11:38:57 +1100 Subject: [PATCH] Fixes for SEAP --- app/PaymentDrivers/Stripe/SEPA.php | 29 +++++++++++++++++ public/js/clients/payments/stripe-sepa.js | 2 +- public/mix-manifest.json | 2 +- resources/js/clients/payments/stripe-sepa.js | 31 +++++++++++++++++-- .../gateways/stripe/sepa/pay.blade.php | 2 +- .../gateways/stripe/sepa/sepa_debit.blade.php | 1 + 6 files changed, 61 insertions(+), 6 deletions(-) diff --git a/app/PaymentDrivers/Stripe/SEPA.php b/app/PaymentDrivers/Stripe/SEPA.php index 62c41f2224..7f36e42474 100644 --- a/app/PaymentDrivers/Stripe/SEPA.php +++ b/app/PaymentDrivers/Stripe/SEPA.php @@ -72,6 +72,10 @@ class SEPA $this->stripe->payment_hash->save(); if (property_exists($gateway_response, 'status') && $gateway_response->status == 'processing') { + + $this->stripe->init(); + $this->storePaymentMethod($gateway_response); + return $this->processSuccessfulPayment($gateway_response->id); } @@ -132,4 +136,29 @@ class SEPA throw new PaymentFailed('Failed to process the payment.', 500); } + + + private function storePaymentMethod($intent) + { + try { + + $method = $this->stripe->getStripePaymentMethod($intent->payment_method); + + $payment_meta = new \stdClass; + $payment_meta->brand = (string) \sprintf('%s (%s)', $method->sepa_debit->bank_code, ctrans('texts.sepa')); + $payment_meta->last4 = (string) $method->sepa_debit->last4; + $payment_meta->state = 'authorized'; + $payment_meta->type = GatewayType::SEPA; + + $data = [ + 'payment_meta' => $payment_meta, + 'token' => $intent->payment_method, + 'payment_method_id' => GatewayType::SEPA, + ]; + + $this->stripe->storeGatewayToken($data, ['gateway_customer_reference' => $method->customer]); + } catch (\Exception $e) { + return $this->stripe->processInternallyFailedPayment($this->stripe, $e); + } + } } diff --git a/public/js/clients/payments/stripe-sepa.js b/public/js/clients/payments/stripe-sepa.js index a541a26a50..ba48020c06 100644 --- a/public/js/clients/payments/stripe-sepa.js +++ b/public/js/clients/payments/stripe-sepa.js @@ -1,2 +1,2 @@ /*! For license information please see stripe-sepa.js.LICENSE.txt */ -!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/",n(n.s=28)}({28:function(e,t,n){e.exports=n("guV3")},guV3:function(e,t){var n,r,o,a;function i(e,t){for(var n=0;n svg").classList.remove("hidden"),document.querySelector("#pay-now > span").classList.add("hidden"),r.stripe.confirmSepaDebitPayment(document.querySelector("meta[name=pi-client-secret").content,{payment_method:{sepa_debit:r.iban,billing_details:{name:document.getElementById("sepa-name").value,email:document.getElementById("sepa-email-address").value}}}).then((function(e){return e.error?r.handleFailure(e.error.message):r.handleSuccess(e)}))}))})),this.key=t,this.errors=document.getElementById("errors"),this.stripeConnect=n}var t,n,r;return t=e,(n=[{key:"handleSuccess",value:function(e){document.querySelector('input[name="gateway_response"]').value=JSON.stringify(e.paymentIntent),document.getElementById("server-response").submit()}},{key:"handleFailure",value:function(e){var t=document.getElementById("errors");t.textContent="",t.textContent=e,t.hidden=!1,this.payNowButton.disabled=!1,this.payNowButton.querySelector("svg").classList.add("hidden"),this.payNowButton.querySelector("span").classList.remove("hidden")}}])&&i(t.prototype,n),r&&i(t,r),e}(),c=null!==(n=null===(r=document.querySelector('meta[name="stripe-publishable-key"]'))||void 0===r?void 0:r.content)&&void 0!==n?n:"",s=null!==(o=null===(a=document.querySelector('meta[name="stripe-account-id"]'))||void 0===a?void 0:a.content)&&void 0!==o?o:"";new l(c,s).setupStripe().handle()}}); \ No newline at end of file +!function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/",n(n.s=28)}({28:function(e,t,n){e.exports=n("guV3")},guV3:function(e,t){var n,o,r,a;function i(e,t){for(var n=0;n svg").classList.remove("hidden"),document.querySelector("#pay-now > span").classList.add("hidden"),void o.stripe.confirmSepaDebitPayment(document.querySelector("meta[name=pi-client-secret").content,{payment_method:{sepa_debit:o.iban,billing_details:{name:document.getElementById("sepa-name").value,email:document.getElementById("sepa-email-address").value}}}).then((function(e){return e.error?o.handleFailure(e.error.message):o.handleSuccess(e)}))):(t.textContent="Accept Terms",t.hidden=!1,void console.log("Terms"))}))})),this.key=t,this.errors=document.getElementById("errors"),this.stripeConnect=n}var t,n,o;return t=e,(n=[{key:"handleSuccess",value:function(e){document.querySelector('input[name="gateway_response"]').value=JSON.stringify(e.paymentIntent),document.getElementById("server-response").submit()}},{key:"handleFailure",value:function(e){var t=document.getElementById("errors");t.textContent="",t.textContent=e,t.hidden=!1,document.getElementById("pay-now").disabled=!1,document.querySelector("#pay-now > svg").classList.add("hidden"),document.querySelector("#pay-now > span").classList.remove("hidden")}}])&&i(t.prototype,n),o&&i(t,o),e}(),c=null!==(n=null===(o=document.querySelector('meta[name="stripe-publishable-key"]'))||void 0===o?void 0:o.content)&&void 0!==n?n:"",d=null!==(r=null===(a=document.querySelector('meta[name="stripe-account-id"]'))||void 0===a?void 0:a.content)&&void 0!==r?r:"";new l(c,d).setupStripe().handle()}}); \ No newline at end of file diff --git a/public/mix-manifest.json b/public/mix-manifest.json index c100c403d8..5d5f62e8a7 100755 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -20,7 +20,7 @@ "/js/clients/payments/stripe-ach.js": "/js/clients/payments/stripe-ach.js?id=81c2623fc1e5769b51c7", "/js/clients/payments/stripe-alipay.js": "/js/clients/payments/stripe-alipay.js?id=665ddf663500767f1a17", "/js/clients/payments/stripe-credit-card.js": "/js/clients/payments/stripe-credit-card.js?id=a30464874dee84678344", - "/js/clients/payments/stripe-sepa.js": "/js/clients/payments/stripe-sepa.js?id=156cf4a3a2ae71625a0f", + "/js/clients/payments/stripe-sepa.js": "/js/clients/payments/stripe-sepa.js?id=e7dc964c85085314b12c", "/js/clients/payments/stripe-sofort.js": "/js/clients/payments/stripe-sofort.js?id=231571942310348aa616", "/js/clients/payments/wepay-credit-card.js": "/js/clients/payments/wepay-credit-card.js?id=f51400e03c5fdb6cdabe", "/js/clients/quotes/action-selectors.js": "/js/clients/quotes/action-selectors.js?id=1b8f9325aa6e8595e7fa", diff --git a/resources/js/clients/payments/stripe-sepa.js b/resources/js/clients/payments/stripe-sepa.js index ecc03d48a1..8c62df2d7c 100644 --- a/resources/js/clients/payments/stripe-sepa.js +++ b/resources/js/clients/payments/stripe-sepa.js @@ -58,6 +58,31 @@ class ProcessSEPA { handle = () => { document.getElementById('pay-now').addEventListener('click', (e) => { + + let errors = document.getElementById('errors'); + + if (document.getElementById('sepa-name').value === "") { + document.getElementById('sepa-name').focus(); + errors.textContent = "Name required."; + errors.hidden = false; + return; + } + + if (document.getElementById('sepa-email-address').value === "") { + document.getElementById('sepa-email-address').focus(); + errors.textContent = "Email required."; + errors.hidden = false; + return ; + } + + + if (!document.getElementById('sepa-mandate-acceptance').checked) { + errors.textContent = "Accept Terms"; + errors.hidden = false; + console.log("Terms"); + return ; + } + document.getElementById('pay-now').disabled = true; document.querySelector('#pay-now > svg').classList.remove('hidden'); document.querySelector('#pay-now > span').classList.add('hidden'); @@ -98,9 +123,9 @@ class ProcessSEPA { errors.textContent = message; errors.hidden = false; - this.payNowButton.disabled = false; - this.payNowButton.querySelector('svg').classList.add('hidden'); - this.payNowButton.querySelector('span').classList.remove('hidden'); + document.getElementById('pay-now').disabled = false; + document.querySelector('#pay-now > svg').classList.add('hidden'); + document.querySelector('#pay-now > span').classList.remove('hidden'); } } diff --git a/resources/views/portal/ninja2020/gateways/stripe/sepa/pay.blade.php b/resources/views/portal/ninja2020/gateways/stripe/sepa/pay.blade.php index e5969b2141..dd8ff6b605 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/sepa/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/sepa/pay.blade.php @@ -19,7 +19,7 @@ @endcomponent @include('portal.ninja2020.gateways.stripe.sepa.sepa_debit') - + @include('portal.ninja2020.gateways.includes.save_card') @include('portal.ninja2020.gateways.includes.pay_now') @endsection diff --git a/resources/views/portal/ninja2020/gateways/stripe/sepa/sepa_debit.blade.php b/resources/views/portal/ninja2020/gateways/stripe/sepa/sepa_debit.blade.php index 4f2be62eed..7cbab29d9b 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/sepa/sepa_debit.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/sepa/sepa_debit.blade.php @@ -7,6 +7,7 @@ +