diff --git a/app/PaymentDrivers/BasePaymentDriver.php b/app/PaymentDrivers/BasePaymentDriver.php index 2e6390c96e57..b77e087a786c 100644 --- a/app/PaymentDrivers/BasePaymentDriver.php +++ b/app/PaymentDrivers/BasePaymentDriver.php @@ -44,7 +44,7 @@ use Omnipay\Omnipay; class BasePaymentDriver { use SystemLogTrait; - + /* The company gateway instance*/ protected $company_gateway; @@ -56,7 +56,7 @@ class BasePaymentDriver /* Gateway capabilities */ protected $refundable = false; - + /* Token billing */ protected $token_billing = false; @@ -194,7 +194,7 @@ class BasePaymentDriver public function processPaymentView(array $data) { } - + public function processPaymentResponse($request) { } @@ -251,7 +251,7 @@ class BasePaymentDriver /* $this->purchaseResponse = (array)$response->getData();*/ } - + public function completePurchase($data) { $this->gateway(); @@ -269,14 +269,14 @@ class BasePaymentDriver $payment->status_id = Payment::STATUS_COMPLETED; $payment->currency_id = $this->client->getSetting('currency_id'); $payment->date = Carbon::now(); - + return $payment; } - + public function attachInvoices(Payment $payment, $hashed_ids) : Payment { - $invoices = Invoice::whereIn('id', $this->transformKeys(explode(",", $hashed_ids))) + $invoices = Invoice::whereIn('id', $this->transformKeys($hashed_ids)) ->whereClientId($this->client->id) ->get(); diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index aa760fce9f5a..058ed0b49ac6 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -264,7 +264,7 @@ class StripePaymentDriver extends BasePaymentDriver $gateway_type_id = $request->input('payment_method_id'); $hashed_ids = $request->input('hashed_ids'); - $invoices = Invoice::whereIn('id', $this->transformKeys(explode(",", $hashed_ids))) + $invoices = Invoice::whereIn('id', $this->transformKeys($hashed_ids)) ->whereClientId($this->client->id) ->get(); /** diff --git a/public/js/clients/payments/process.js b/public/js/clients/payments/process.js new file mode 100644 index 000000000000..780c3c642649 --- /dev/null +++ b/public/js/clients/payments/process.js @@ -0,0 +1,2 @@ +/*! For license information please see process.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=6)}({6:function(e,t,n){e.exports=n("OXGg")},OXGg:function(e,t){function n(e,t){for(var n=0;n { + if (result.error) { + return this.handleFailure(result.error.message); + } + + return this.handleSuccess(result); + }); + } + + completePaymentWithoutToken() { + let payNowButton = document.getElementById("pay-now"); + let cardHolderName = document.getElementById("cardholder-name"); + + this.stripe + .handleCardPayment(payNowButton.dataset.secret, this.cardElement, { + payment_method_data: { + billing_details: { name: cardHolderName.value } + } + }) + .then(result => { + if (result.error) { + return this.handleFailure(result.error.message); + } + + return this.handleSuccess(result); + }); + } + + handleSuccess(result) { + document.querySelector( + 'input[name="gateway_response"]' + ).value = JSON.stringify(result.paymentIntent); + + let tokenBillingCheckbox = document.querySelector( + 'input[name="token-billing-checkbox"]' + ); + + if (tokenBillingCheckbox) { + document.querySelector('input[name="store_card"]').value = + tokenBillingCheckbox.checked; + } + + document.getElementById("server-response").submit(); + } + + handleFailure(message) { + let errors = document.getElementById("errors"); + + errors.textContent = ""; + errors.textContent = message; + errors.hidden = false; + } + + handle() { + this.setupStripe(); + + if (this.usingToken) { + document + .getElementById("pay-now-with-token") + .addEventListener("click", () => { + return this.completePaymentUsingToken(); + }); + } + + if (!this.usingToken) { + this.createElement().mountCardElement(); + + document.getElementById("pay-now").addEventListener("click", () => { + return this.completePaymentWithoutToken(); + }); + } + } +} + +const publishableKey = document.querySelector( + 'meta[name="stripe-publishable-key"]' +).content; + +const usingToken = document.querySelector('meta[name="using-token"]').content; + +new ProcessStripePayment(publishableKey, usingToken).handle(); diff --git a/resources/views/portal/ninja2020/gateways/stripe/add_credit_card.blade.php b/resources/views/portal/ninja2020/gateways/stripe/add_credit_card.blade.php index e6dda2e0ec20..592065c79f74 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/add_credit_card.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/add_credit_card.blade.php @@ -44,7 +44,7 @@ {{ ctrans('texts.credit_card') }}
-
+
diff --git a/resources/views/portal/ninja2020/gateways/stripe/credit_card.blade.php b/resources/views/portal/ninja2020/gateways/stripe/credit_card.blade.php new file mode 100644 index 000000000000..dbed364d4b72 --- /dev/null +++ b/resources/views/portal/ninja2020/gateways/stripe/credit_card.blade.php @@ -0,0 +1,106 @@ +@extends('portal.ninja2020.layout.app') +@section('meta_title', ctrans('texts.pay_now')) + +@push('head') + + +@endpush + +@section('header') + Insert breadcrumbs.. +@endsection + +@section('body') +
+ @csrf + + + @foreach($invoices as $invoice) + + @endforeach + + +
+
+
+
+ +
+
+

+ {{ ctrans('texts.pay_now') }} +

+

+ {{ ctrans('texts.complete_your_payment') }} +

+
+
+
+ @if($token) +
+
+ {{ ctrans('texts.credit_card') }} +
+
+ {{ strtoupper($token->meta->brand) }} - **** {{ $token->meta->last4 }} +
+
+
+ +
+ @else +
+
+ {{ ctrans('texts.name') }} +
+
+ +
+
+
+
+ {{ ctrans('texts.credit_card') }} +
+
+
+
+
+
+
+ {{ ctrans('texts.token_billing_checkbox') }} +
+
+ +
+
+
+ +
+ @endif +
+
+
+
+
+
+@endsection + +@push('footer') + + +@endpush diff --git a/webpack.mix.js b/webpack.mix.js index 1101da75c348..407f284dcddf 100644 --- a/webpack.mix.js +++ b/webpack.mix.js @@ -23,6 +23,10 @@ mix.js("resources/js/app.js", "public/js") .js( "resources/js/clients/quotes/approve.js", "public/js/clients/quotes/approve.js" + ) + .js( + "resources/js/clients/payments/process.js", + "public/js/clients/payments/process.js" ); mix.sass("resources/sass/app.scss", "public/css")