From e2bc018c977b910c16b4d1168e231d482da599e4 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 11:02:49 +0100 Subject: [PATCH 01/88] Add base classes --- app/Models/Gateway.php | 1 + app/Models/GatewayType.php | 4 ++ app/Models/PaymentType.php | 1 + app/PaymentDrivers/StripePaymentDriver.php | 9 +++++ .../2022_16_12_54687_add_stripe_bacs.php | 39 +++++++++++++++++++ 5 files changed, 54 insertions(+) create mode 100644 database/migrations/2022_16_12_54687_add_stripe_bacs.php diff --git a/app/Models/Gateway.php b/app/Models/Gateway.php index 24d53a510c2e..7a41c48f1fc2 100644 --- a/app/Models/Gateway.php +++ b/app/Models/Gateway.php @@ -149,6 +149,7 @@ class Gateway extends StaticModel GatewayType::EPS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], GatewayType::BANCONTACT => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], GatewayType::BECS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], + GatewayType::BACS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], GatewayType::IDEAL => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], GatewayType::ACSS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], GatewayType::FPX => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']], diff --git a/app/Models/GatewayType.php b/app/Models/GatewayType.php index cc4d0a998fe7..8b0edb053249 100644 --- a/app/Models/GatewayType.php +++ b/app/Models/GatewayType.php @@ -61,6 +61,8 @@ class GatewayType extends StaticModel const KLARNA = 23; + const BACS = 24; + public function gateway() { return $this->belongsTo(Gateway::class); @@ -108,6 +110,8 @@ class GatewayType extends StaticModel return ctrans('texts.eps'); case self::BECS: return ctrans('texts.becs'); + case self::BACS: + return ctrans('texts.bacs'); case self::ACSS: return ctrans('texts.acss'); case self::DIRECT_DEBIT: diff --git a/app/Models/PaymentType.php b/app/Models/PaymentType.php index 5459a83774a8..f718203ec9fb 100644 --- a/app/Models/PaymentType.php +++ b/app/Models/PaymentType.php @@ -57,6 +57,7 @@ class PaymentType extends StaticModel const FPX = 46; const KLARNA = 47; const Interac_E_Transfer = 48; + const BACS = 49; public static function parseCardType($cardName) { diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index c6a4f9fdbcc9..699865183e22 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -239,6 +239,13 @@ class StripePaymentDriver extends BaseDriver && in_array($this->client->country->iso_3166_3, ['CAN', 'USA'])) { $types[] = GatewayType::ACSS; } + if ($this->client + && $this->client->currency() + && in_array($this->client->currency()->code, ['GDB']) + && isset($this->client->country) + && in_array($this->client->country->iso_3166_3, ['GBR'])) { + $types[] = GatewayType::BACS; + } if ($this->client && $this->client->currency() && in_array($this->client->currency()->code, ['EUR', 'DKK', 'GBP', 'NOK', 'SEK', 'AUD', 'NZD', 'CAD', 'PLN', 'CHF']) @@ -302,6 +309,8 @@ class StripePaymentDriver extends BaseDriver return 'gateways.stripe.bancontact'; case GatewayType::BECS: return 'gateways.stripe.becs'; + case GatewayType::BACS: + return 'gateways.stripe.bacs'; case GatewayType::ACSS: return 'gateways.stripe.acss'; case GatewayType::FPX: diff --git a/database/migrations/2022_16_12_54687_add_stripe_bacs.php b/database/migrations/2022_16_12_54687_add_stripe_bacs.php new file mode 100644 index 000000000000..a454e483e29b --- /dev/null +++ b/database/migrations/2022_16_12_54687_add_stripe_bacs.php @@ -0,0 +1,39 @@ +id = 49; + $type->name = 'BACS'; + $type->gateway_type_id = GatewayType::BACS; + $type->save(); + } + + $gt = GatewayType::find(24); + + if(!$gt) + { + $type = new GatewayType(); + $type->id = 24; + $type->alias = 'bacs'; + $type->name = 'BACS'; + $type->save(); + } + } +}; From a48e08cbefbaa1752ff39a15a78191561db535d4 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 11:09:37 +0100 Subject: [PATCH 02/88] Scafold inital classes --- app/PaymentDrivers/Stripe/BACS.php | 213 ++++++++++++++++++ .../gateways/stripe/bacs/authorize.blade.php | 42 ++++ .../gateways/stripe/bacs/pay.blade.php | 97 ++++++++ 3 files changed, 352 insertions(+) create mode 100644 app/PaymentDrivers/Stripe/BACS.php create mode 100644 resources/views/portal/ninja2020/gateways/stripe/bacs/authorize.blade.php create mode 100644 resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php new file mode 100644 index 000000000000..ca7edbcbe3c5 --- /dev/null +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -0,0 +1,213 @@ +stripe = $stripe; + } + + public function authorizeView(array $data) + { + $intent['intent'] = $this->stripe->getSetupIntent(); + + return render('gateways.stripe.bacs.authorize', array_merge($data, $intent)); + } + + public function authorizeResponse($request) + { + $this->stripe->init(); + + $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); + + return redirect()->route('client.payment_methods.index'); + } + + public function paymentView(array $data) + { + + // $description = $this->stripe->decodeUnicodeString(ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number')) . " for client {$this->stripe->client->present()->name()}"; + $invoice_numbers = collect($data['invoices'])->pluck('invoice_number')->implode(','); + $description = ctrans('texts.stripe_payment_text', ['invoicenumber' => $invoice_numbers, 'amount' => Number::formatMoney($data['total']['amount_with_fee'], $this->stripe->client), 'client' => $this->stripe->client->present()->name()]); + + $payment_intent_data = [ + 'amount' => $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()), + 'currency' => $this->stripe->client->getCurrencyCode(), + 'customer' => $this->stripe->findOrCreateCustomer(), + 'description' => $description, + 'metadata' => [ + 'payment_hash' => $this->stripe->payment_hash->hash, + 'gateway_type_id' => GatewayType::BACS, + ], + 'setup_future_usage' => 'off_session', + ]; + + $data['intent'] = $this->stripe->createPaymentIntent($payment_intent_data); + $data['gateway'] = $this->stripe; + + return render('gateways.stripe.bacs.pay', $data); + } + public function paymentResponse(PaymentResponseRequest $request) + { + $this->stripe->init(); + + $state = [ + 'server_response' => json_decode($request->gateway_response), + 'payment_hash' => $request->payment_hash, + ]; + + $state = array_merge($state, $request->all()); + $state['store_card'] = boolval($state['store_card']); + + if ($request->has('token') && ! is_null($request->token)) { + $state['store_card'] = false; + } + + $state['payment_intent'] = PaymentIntent::retrieve($state['server_response']->id, array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st",true)])); + $state['customer'] = $state['payment_intent']->customer; + + $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, $state); + $this->stripe->payment_hash->save(); + + $server_response = $this->stripe->payment_hash->data->server_response; + + if ($server_response->status == 'succeeded') { + $this->stripe->logSuccessfulGatewayResponse(['response' => json_decode($request->gateway_response), 'data' => $this->stripe->payment_hash], SystemLog::TYPE_STRIPE); + + return $this->processSuccessfulPayment(); + } + + return $this->processUnsuccessfulPayment($server_response); + } + + public function processSuccessfulPayment() + { + UpdateCustomer::dispatch($this->stripe->company_gateway->company->company_key, $this->stripe->company_gateway->id, $this->stripe->client->id); + + $stripe_method = $this->stripe->getStripePaymentMethod($this->stripe->payment_hash->data->server_response->payment_method); + + $data = [ + 'payment_method' => $this->stripe->payment_hash->data->server_response->payment_method, + 'payment_type' => PaymentType::parseCardType(strtolower($stripe_method->card->brand)) ?: PaymentType::CREDIT_CARD_OTHER, + 'amount' => $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->server_response->amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()), + 'transaction_reference' => isset($this->stripe->payment_hash->data->payment_intent->latest_charge) ? $this->stripe->payment_hash->data->payment_intent->latest_charge : optional($this->stripe->payment_hash->data->payment_intent->charges->data[0])->id, + 'gateway_type_id' => GatewayType::CREDIT_CARD, + ]; + + $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['amount' => $data['amount']]); + $this->stripe->payment_hash->save(); + + if ($this->stripe->payment_hash->data->store_card) { + $customer = new \stdClass; + $customer->id = $this->stripe->payment_hash->data->customer; + + $this->stripe->attach($this->stripe->payment_hash->data->server_response->payment_method, $customer); + + $stripe_method = $this->stripe->getStripePaymentMethod($this->stripe->payment_hash->data->server_response->payment_method); + + $this->storePaymentMethod($stripe_method, $this->stripe->payment_hash->data->payment_method_id, $customer); + } + + $payment = $this->stripe->createPayment($data, Payment::STATUS_COMPLETED); + + SystemLogger::dispatch( + ['response' => $this->stripe->payment_hash->data->server_response, 'data' => $data], + SystemLog::CATEGORY_GATEWAY_RESPONSE, + SystemLog::EVENT_GATEWAY_SUCCESS, + SystemLog::TYPE_STRIPE, + $this->stripe->client, + $this->stripe->client->company, + ); + + //If the user has come from a subscription double check here if we need to redirect. + //08-08-2022 + if($payment->invoices()->whereHas('subscription')->exists()){ + $subscription = $payment->invoices()->first()->subscription; + + if($subscription && array_key_exists('return_url', $subscription->webhook_configuration) && strlen($subscription->webhook_configuration['return_url']) >=1) + return redirect($subscription->webhook_configuration['return_url']); + + } + //08-08-2022 + + return redirect()->route('client.payments.show', ['payment' => $this->stripe->encodePrimaryKey($payment->id)]); + } + + public function processUnsuccessfulPayment($server_response) + { + $this->stripe->sendFailureMail($server_response->cancellation_reason); + + $message = [ + 'server_response' => $server_response, + 'data' => $this->stripe->payment_hash->data, + ]; + + SystemLogger::dispatch( + $message, + SystemLog::CATEGORY_GATEWAY_RESPONSE, + SystemLog::EVENT_GATEWAY_FAILURE, + SystemLog::TYPE_STRIPE, + $this->stripe->client, + $this->stripe->client->company, + ); + + throw new PaymentFailed('Failed to process the payment.', 500); + } + + private function storePaymentMethod(PaymentMethod $method, $payment_method_id, $customer) + { + try { + $payment_meta = new \stdClass; + $payment_meta->exp_month = (string) $method->card->exp_month; + $payment_meta->exp_year = (string) $method->card->exp_year; + $payment_meta->brand = (string) $method->card->brand; + $payment_meta->last4 = (string) $method->card->last4; + $payment_meta->type = GatewayType::BACS; + + $data = [ + 'payment_meta' => $payment_meta, + 'token' => $method->id, + 'payment_method_id' => $payment_method_id, + ]; + + $this->stripe->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]); + } catch (\Exception $e) { + return $this->stripe->processInternallyFailedPayment($this->stripe, $e); + } + } +} diff --git a/resources/views/portal/ninja2020/gateways/stripe/bacs/authorize.blade.php b/resources/views/portal/ninja2020/gateways/stripe/bacs/authorize.blade.php new file mode 100644 index 000000000000..7a0052785397 --- /dev/null +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/authorize.blade.php @@ -0,0 +1,42 @@ +@extends('portal.ninja2020.layout.payments', ['gateway_title' => 'BACS', 'card_title' => 'BACS']) + +@section('gateway_head') + + @if($gateway->getConfigField('account_id')) + + + @else + + @endif + + + + +@endsection + +@section('gateway_content') +
+ @csrf + + + + +
+ + + + @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 +@endsection + +@section('gateway_footer') + + +@endsection diff --git a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php new file mode 100644 index 000000000000..a20313b7899d --- /dev/null +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -0,0 +1,97 @@ +@extends('portal.ninja2020.layout.payments', ['gateway_title' => 'Credit card', 'card_title' => 'Credit card']) + +@php + $gateway_instance = $gateway instanceof \App\Models\CompanyGateway ? $gateway : $gateway->company_gateway; + $token_billing_string = 'true'; + + if($gateway_instance->token_billing == 'off' || $gateway_instance->token_billing == 'optin'){ + $token_billing_string = 'false'; + } + + +@endphp + +@section('gateway_head') + @if($gateway->company_gateway->getConfigField('account_id')) + + + @else + + @endif + + + + + +@endsection + +@section('gateway_content') +
+ @csrf + + + + + + + + +
+ + + + @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.payment_type')]) + {{ ctrans('texts.credit_card') }} + @endcomponent + + @include('portal.ninja2020.gateways.includes.payment_details') + + @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.pay_with')]) + + + @endcomponent + + @include('portal.ninja2020.gateways.stripe.includes.card_widget') + @include('portal.ninja2020.gateways.includes.pay_now') + +@endsection + +@section('gateway_footer') + + + + +@endsection From 347b2d0b4af26c48acefe67b5e81db94b82e2393 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 11:23:06 +0100 Subject: [PATCH 03/88] Add language file --- lang/en/texts.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lang/en/texts.php b/lang/en/texts.php index e64bc61fabeb..6a8100db5ca1 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -4298,6 +4298,7 @@ $LANG = array( 'klarna' => 'Klarna', 'eps' => 'EPS', 'becs' => 'BECS Direct Debit', + 'bacs' => 'BACS Direct Debit', 'becs_mandate' => 'By providing your bank account details, you agree to this Direct Debit Request and the Direct Debit Request service agreement, and authorise Stripe Payments Australia Pty Ltd ACN 160 180 343 Direct Debit User ID number 507156 (“Stripe”) to debit your account through the Bulk Electronic Clearing System (BECS) on behalf of :company (the “Merchant”) for any amounts separately communicated to you by the Merchant. You certify that you are either an account holder or an authorised signatory on the account listed above.', 'you_need_to_accept_the_terms_before_proceeding' => 'You need to accept the terms before proceeding.', 'direct_debit' => 'Direct Debit', @@ -4906,7 +4907,7 @@ $LANG = array( 'backup_restore' => 'Backup | Restore', 'export_company' => 'Create company backup', 'backup' => 'Backup', - + ); return $LANG; From 034ed039e028990de6b122c483edb8d7e3676d8b Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 11:25:23 +0100 Subject: [PATCH 04/88] Minor fixes --- app/PaymentDrivers/StripePaymentDriver.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 699865183e22..f0958519b7fe 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -29,6 +29,7 @@ use App\PaymentDrivers\Stripe\ACH; use App\PaymentDrivers\Stripe\ACSS; use App\PaymentDrivers\Stripe\Alipay; use App\PaymentDrivers\Stripe\ApplePay; +use App\PaymentDrivers\Stripe\BACS; use App\PaymentDrivers\Stripe\Bancontact; use App\PaymentDrivers\Stripe\BECS; use App\PaymentDrivers\Stripe\BrowserPay; @@ -100,6 +101,7 @@ class StripePaymentDriver extends BaseDriver GatewayType::ACSS => ACSS::class, GatewayType::FPX => FPX::class, GatewayType::KLARNA => Klarna::class, + GatewayType::BACS => BACS::class, ]; const SYSTEM_LOG_TYPE = SystemLog::TYPE_STRIPE; @@ -241,7 +243,7 @@ class StripePaymentDriver extends BaseDriver } if ($this->client && $this->client->currency() - && in_array($this->client->currency()->code, ['GDB']) + && in_array($this->client->currency()->code, ['GBP']) && isset($this->client->country) && in_array($this->client->country->iso_3166_3, ['GBR'])) { $types[] = GatewayType::BACS; From 380cff056a400df12f9791263955b3cd4249211a Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 11:27:32 +0100 Subject: [PATCH 05/88] Minor fixes --- app/Models/Gateway.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Models/Gateway.php b/app/Models/Gateway.php index 7a41c48f1fc2..fc963fcc7f8b 100644 --- a/app/Models/Gateway.php +++ b/app/Models/Gateway.php @@ -113,6 +113,7 @@ class Gateway extends StaticModel GatewayType::EPS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']], GatewayType::BANCONTACT => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']], GatewayType::BECS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']], + GatewayType::BACS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']], GatewayType::IDEAL => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']], GatewayType::ACSS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']], GatewayType::KLARNA => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], From 974f4b2ca3fd32cf45de00951ecaa30f7de65616 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 11:34:00 +0100 Subject: [PATCH 06/88] Add BACS to payment methods --- .../components/livewire/payment-methods-table.blade.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/resources/views/portal/ninja2020/components/livewire/payment-methods-table.blade.php b/resources/views/portal/ninja2020/components/livewire/payment-methods-table.blade.php index 0a7ff18fea53..2405338a500e 100644 --- a/resources/views/portal/ninja2020/components/livewire/payment-methods-table.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/payment-methods-table.blade.php @@ -9,7 +9,7 @@ -
+
Add BACS @if($client->getCreditCardGateway() || $client->getBankTransferGateway()) @@ -25,6 +25,11 @@ {{ ctrans('texts.bank_account') }} @endif + @if($client->getBACSGateway()) + + {{ ctrans('texts.bacs') }} + + @endif
@endif From b88dc785d7ab52c0373d4f7d8580508069eb94b7 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 11:35:35 +0100 Subject: [PATCH 07/88] Add BACS to livewire --- app/Models/Client.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/Models/Client.php b/app/Models/Client.php index 7b09fa68f80e..a63a47281aa8 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -458,6 +458,29 @@ class Client extends BaseModel implements HasLocalePreference return null; } + public function getBACSGateway() :?CompanyGateway + { + $pms = $this->service()->getPaymentMethods(-1); + + foreach ($pms as $pm) { + if ($pm['gateway_type_id'] == GatewayType::BACS) { + $cg = CompanyGateway::find($pm['company_gateway_id']); + + if ($cg && ! property_exists($cg->fees_and_limits, GatewayType::BACS)) { + $fees_and_limits = $cg->fees_and_limits; + $fees_and_limits->{GatewayType::BACS} = new FeesAndLimits; + $cg->fees_and_limits = $fees_and_limits; + $cg->save(); + } + + if ($cg && $cg->fees_and_limits->{GatewayType::BACS}->is_enabled) { + return $cg; + } + } + } + + return null; + } //todo refactor this - it is only searching for existing tokens public function getBankTransferGateway() :?CompanyGateway From 148190727c831cae781a3eb8fe2c28d3b405a64b Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 11:41:08 +0100 Subject: [PATCH 08/88] Remove typo --- .../components/livewire/payment-methods-table.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/portal/ninja2020/components/livewire/payment-methods-table.blade.php b/resources/views/portal/ninja2020/components/livewire/payment-methods-table.blade.php index 2405338a500e..9d77a7c3a26b 100644 --- a/resources/views/portal/ninja2020/components/livewire/payment-methods-table.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/payment-methods-table.blade.php @@ -9,7 +9,7 @@ -
Add BACS +
@if($client->getCreditCardGateway() || $client->getBankTransferGateway()) From b3dd3aaaa11279a61739ed3e123f609d2b8b79d4 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 12:05:10 +0100 Subject: [PATCH 09/88] Added BACS to payment controller --- .../ClientPortal/PaymentMethodController.php | 4 +- public/js/clients/payments/stripe-bacs.js | 2 + .../payments/stripe-bacs.js.LICENSE.txt | 9 ++ resources/js/clients/payments/stripe-bacs.js | 68 ++++++++++++++ .../gateways/stripe/bacs/pay.blade.php | 90 +++---------------- webpack.mix.js | 4 + 6 files changed, 98 insertions(+), 79 deletions(-) create mode 100644 public/js/clients/payments/stripe-bacs.js create mode 100644 public/js/clients/payments/stripe-bacs.js.LICENSE.txt create mode 100644 resources/js/clients/payments/stripe-bacs.js diff --git a/app/Http/Controllers/ClientPortal/PaymentMethodController.php b/app/Http/Controllers/ClientPortal/PaymentMethodController.php index 4dbf694c3b17..97b9a0d3d889 100644 --- a/app/Http/Controllers/ClientPortal/PaymentMethodController.php +++ b/app/Http/Controllers/ClientPortal/PaymentMethodController.php @@ -57,7 +57,6 @@ class PaymentMethodController extends Controller $data['gateway'] = $gateway; $data['client'] = auth()->user()->client; - return $gateway ->driver(auth()->user()->client) ->setPaymentMethod($request->query('method')) @@ -148,6 +147,9 @@ class PaymentMethodController extends Controller if (request()->query('method') == GatewayType::CREDIT_CARD) { return auth()->user()->client->getCreditCardGateway(); } + if (request()->query('method') == GatewayType::BACS) { + return auth()->user()->client->getBACSGateway(); + } if (in_array(request()->query('method'), [GatewayType::BANK_TRANSFER, GatewayType::DIRECT_DEBIT, GatewayType::SEPA])) { return auth()->user()->client->getBankTransferGateway(); diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js new file mode 100644 index 000000000000..22d576f971e7 --- /dev/null +++ b/public/js/clients/payments/stripe-bacs.js @@ -0,0 +1,2 @@ +/*! 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 diff --git a/public/js/clients/payments/stripe-bacs.js.LICENSE.txt b/public/js/clients/payments/stripe-bacs.js.LICENSE.txt new file mode 100644 index 000000000000..97e5374d6e40 --- /dev/null +++ b/public/js/clients/payments/stripe-bacs.js.LICENSE.txt @@ -0,0 +1,9 @@ +/** + * 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 + */ diff --git a/resources/js/clients/payments/stripe-bacs.js b/resources/js/clients/payments/stripe-bacs.js new file mode 100644 index 000000000000..3aab9174a0bb --- /dev/null +++ b/resources/js/clients/payments/stripe-bacs.js @@ -0,0 +1,68 @@ +/** + * 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'); + + 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, + } + ); + }); + }; +} + +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/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php index a20313b7899d..74046f442d82 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -1,97 +1,31 @@ -@extends('portal.ninja2020.layout.payments', ['gateway_title' => 'Credit card', 'card_title' => 'Credit card']) - -@php - $gateway_instance = $gateway instanceof \App\Models\CompanyGateway ? $gateway : $gateway->company_gateway; - $token_billing_string = 'true'; - - if($gateway_instance->token_billing == 'off' || $gateway_instance->token_billing == 'optin'){ - $token_billing_string = 'false'; - } - - -@endphp +@extends('portal.ninja2020.layout.payments', ['gateway_title' => 'BACS', 'card_title' => 'BACS']) @section('gateway_head') @if($gateway->company_gateway->getConfigField('account_id')) @else - + @endif - - - - - + + + + + @endsection @section('gateway_content') -
- @csrf - - - - - - - - -
- - @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.payment_type')]) - {{ ctrans('texts.credit_card') }} - @endcomponent - @include('portal.ninja2020.gateways.includes.payment_details') - @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.pay_with')]) -
    - @if(count($tokens) > 0) - @foreach($tokens as $token) -
  • - -
  • - @endforeach - @endisset - -
  • - -
  • -
- + @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.payment_type')]) + {{ ctrans('texts.bacs') }} ({{ ctrans('texts.bank_transfer') }}) @endcomponent - - @include('portal.ninja2020.gateways.stripe.includes.card_widget') @include('portal.ninja2020.gateways.includes.pay_now') - @endsection -@section('gateway_footer') - - +@push('footer') - -@endsection + +@endpush diff --git a/webpack.mix.js b/webpack.mix.js index df0604426709..4706ea5bda62 100644 --- a/webpack.mix.js +++ b/webpack.mix.js @@ -26,6 +26,10 @@ mix.js("resources/js/app.js", "public/js") "resources/js/clients/payments/stripe-klarna.js", "public/js/clients/payments/stripe-klarna.js" ) + .js( + "resources/js/clients/payments/stripe-bacs.js", + "public/js/clients/payments/stripe-bacs.js" + ) .js( "resources/js/clients/invoices/action-selectors.js", "public/js/clients/invoices/action-selectors.js" From 6ad2cba624f04c11f93826020263add9ff93b460 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 14:43:03 +0100 Subject: [PATCH 10/88] 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 From d4a99ad64a3662301b60f6139661498e6ccc53ab Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 14:48:33 +0100 Subject: [PATCH 11/88] Minor fixes --- app/PaymentDrivers/Stripe/BACS.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index f315850d43fc..433acbf431b2 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -21,6 +21,7 @@ use App\Models\PaymentType; use App\Models\SystemLog; use App\PaymentDrivers\StripePaymentDriver; use App\PaymentDrivers\Stripe\Jobs\UpdateCustomer; +use Stripe\Checkout\Session; use Stripe\PaymentIntent; use Stripe\PaymentMethod; use App\Utils\Number; @@ -37,7 +38,7 @@ class BACS public function authorizeView(array $data) { $customer = $this->stripe->findOrCreateCustomer(); - $session = $this->stripe->Checkout->Session::create([ + $session = Session::create([ 'payment_method_types' => ['bacs_debit'], 'mode' => 'setup', 'customer' => $customer->id, From f9434c8cc10b55c89a552e3cabd82f2ea77c7982 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 14:52:45 +0100 Subject: [PATCH 12/88] Minor fixes --- app/PaymentDrivers/Stripe/BACS.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 433acbf431b2..b51fe4e75357 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -52,7 +52,6 @@ class BACS { 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, ]); } @@ -61,6 +60,8 @@ class BACS { $this->stripe->init(); + $customer = $this->stripe->findOrCreateCustomer(); + $stripe_response = json_decode($request->input('gateway_response')); $stripe_method = $this->stripe->getStripePaymentMethod($stripe_response->payment_method); From cb593be1deeced7b2ad49bbf750eab086272cc1b Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 14:55:13 +0100 Subject: [PATCH 13/88] Minor fixes --- app/PaymentDrivers/Stripe/BACS.php | 4 ++-- .../portal/ninja2020/gateways/stripe/bacs/authorize.blade.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index b51fe4e75357..bc2494ab2b98 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -38,7 +38,7 @@ class BACS public function authorizeView(array $data) { $customer = $this->stripe->findOrCreateCustomer(); - $session = Session::create([ + $data['session'] = Session::create([ 'payment_method_types' => ['bacs_debit'], 'mode' => 'setup', 'customer' => $customer->id, @@ -46,7 +46,7 @@ class BACS 'cancel_url' => 'https://example.com/cancel', ]); - return render('gateways.stripe.bacs.authorize', array_merge($data, $session)); + return render('gateways.stripe.bacs.authorize', $data); } private function buildReturnUrl(): string { 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 18a6d0591764..3c2c7d460102 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/authorize.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/authorize.blade.php @@ -8,7 +8,7 @@ @else @endif - + @endsection From b16b46204ab3d9938d07016d6dbad615211c34f1 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 14:57:49 +0100 Subject: [PATCH 14/88] Fixes --- .../portal/ninja2020/gateways/stripe/bacs/authorize.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3c2c7d460102..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,7 +8,7 @@ @else @endif - + @endsection From 1a37049ff8399671ee9a829888981b9ae60ffa70 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 15:00:54 +0100 Subject: [PATCH 15/88] Fixes for JS --- public/js/clients/payments/stripe-bacs.js | 8 ++++---- resources/js/clients/payments/stripe-bacs.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index 6a89d1e000bc..55d1402334e6 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -18,10 +18,10 @@ class ProcessBACS { setupStripe = () => { if (this.stripeConnect){ - // this.stripe.stripeAccount = this.stripeConnect; + // this.stripe.stripeAccount = this.stripeConnect; - this.stripe = Stripe(this.key, { - stripeAccount: this.stripeConnect, + this.stripe = Stripe(this.key, { + stripeAccount: this.stripeConnect, }); } @@ -40,7 +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'); - location.href=document.querySelector('meta[name=stripe-redirect-url]').content; + location.href=document.querySelector('meta[name=stripe-redirect-url').content; }); }; } diff --git a/resources/js/clients/payments/stripe-bacs.js b/resources/js/clients/payments/stripe-bacs.js index 6a89d1e000bc..35139e2f6c99 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -40,7 +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'); - location.href=document.querySelector('meta[name=stripe-redirect-url]').content; + location.href=document.querySelector('meta[name=stripe-redirect-url').content; }); }; } From bd77acf70502d5c0190ef98a20ac696e86752ba6 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 15:03:24 +0100 Subject: [PATCH 16/88] Fixes for JS --- public/js/clients/payments/stripe-bacs.js | 8 ++++---- resources/js/clients/payments/stripe-bacs.js | 14 +++++++------- .../gateways/stripe/bacs/authorize.blade.php | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index 55d1402334e6..b0295b03f98a 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -34,12 +34,12 @@ class ProcessBACS { }; handle = () => { - document.getElementById('pay-now').addEventListener('click', (e) => { + document.getElementById('authorize-bacs').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'); + 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; }); }; diff --git a/resources/js/clients/payments/stripe-bacs.js b/resources/js/clients/payments/stripe-bacs.js index 35139e2f6c99..b0295b03f98a 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -18,10 +18,10 @@ class ProcessBACS { setupStripe = () => { if (this.stripeConnect){ - // this.stripe.stripeAccount = this.stripeConnect; + // this.stripe.stripeAccount = this.stripeConnect; - this.stripe = Stripe(this.key, { - stripeAccount: this.stripeConnect, + this.stripe = Stripe(this.key, { + stripeAccount: this.stripeConnect, }); } @@ -34,12 +34,12 @@ class ProcessBACS { }; handle = () => { - document.getElementById('pay-now').addEventListener('click', (e) => { + document.getElementById('authorize-bacs').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'); + 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; }); }; 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 18a6d0591764..7eb969d268b2 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/authorize.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/authorize.blade.php @@ -23,7 +23,7 @@ - @component('portal.ninja2020.gateways.includes.pay_now', ['id' => 'authorize-card']) + @component('portal.ninja2020.gateways.includes.pay_now', ['id' => 'authorize-bacs']) {{ ctrans('texts.add_payment_method') }} @endcomponent @endsection From 10cc02c14d61e2c1ae6f3060524c0dace0e9495f Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 15:19:00 +0100 Subject: [PATCH 17/88] Fix route --- .../Controllers/ClientPortal/PaymentMethodController.php | 1 + app/PaymentDrivers/Stripe/BACS.php | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ClientPortal/PaymentMethodController.php b/app/Http/Controllers/ClientPortal/PaymentMethodController.php index 97b9a0d3d889..403fec5f848b 100644 --- a/app/Http/Controllers/ClientPortal/PaymentMethodController.php +++ b/app/Http/Controllers/ClientPortal/PaymentMethodController.php @@ -15,6 +15,7 @@ namespace App\Http\Controllers\ClientPortal; use App\Events\Payment\Methods\MethodDeleted; use App\Http\Controllers\Controller; use App\Http\Requests\ClientPortal\PaymentMethod\CreatePaymentMethodRequest; +use App\Http\Requests\ClientPortal\PaymentMethod\VerifyPaymentMethodRequest; use App\Http\Requests\Request; use App\Models\ClientGatewayToken; use App\Models\GatewayType; diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index bc2494ab2b98..20060830d50e 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -29,6 +29,7 @@ use App\Utils\Number; class BACS { public $stripe; + public $session; public function __construct(StripePaymentDriver $stripe) { @@ -45,14 +46,16 @@ class BACS 'success_url' => $this->buildReturnUrl(), 'cancel_url' => 'https://example.com/cancel', ]); + $session = $data['session']; return render('gateways.stripe.bacs.authorize', $data); } private function buildReturnUrl(): string { - return route('client.payments.response', [ + return route('client.payments.store', [ 'company_gateway_id' => $this->stripe->company_gateway->id, 'payment_method_id' => GatewayType::BACS, + 'session_id' => "{CHECKOUT_SESSION_ID}", ]); } From 0eb88c5f5a26b83416b3e04093d4995d6fc5f89f Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 15:21:56 +0100 Subject: [PATCH 18/88] Fix route --- app/PaymentDrivers/Stripe/BACS.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 20060830d50e..aec5e68bc2bf 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -52,7 +52,7 @@ class BACS } private function buildReturnUrl(): string { - return route('client.payments.store', [ + return route('client.payment_methods.store', [ 'company_gateway_id' => $this->stripe->company_gateway->id, 'payment_method_id' => GatewayType::BACS, 'session_id' => "{CHECKOUT_SESSION_ID}", From c56d41ad2ad671fa763570774449402d3fe30eab Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 15:44:43 +0100 Subject: [PATCH 19/88] Fixes for Session-ID --- app/PaymentDrivers/Stripe/BACS.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index aec5e68bc2bf..0cb01bf6d698 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -43,7 +43,7 @@ class BACS 'payment_method_types' => ['bacs_debit'], 'mode' => 'setup', 'customer' => $customer->id, - 'success_url' => $this->buildReturnUrl(), + 'success_url' => str_replace("%7B", "{", str_replace("%7D", "}", $this->buildReturnUrl())), 'cancel_url' => 'https://example.com/cancel', ]); $session = $data['session']; From c323060139fba9f33327c760c92b35f05ad8b652 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 16:37:02 +0100 Subject: [PATCH 20/88] Fixes for Session-ID --- app/PaymentDrivers/Stripe/BACS.php | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 0cb01bf6d698..9f013b9793d6 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -29,7 +29,6 @@ use App\Utils\Number; class BACS { public $stripe; - public $session; public function __construct(StripePaymentDriver $stripe) { @@ -44,17 +43,14 @@ class BACS 'mode' => 'setup', 'customer' => $customer->id, 'success_url' => str_replace("%7B", "{", str_replace("%7D", "}", $this->buildReturnUrl())), - 'cancel_url' => 'https://example.com/cancel', + 'cancel_url' => route('client.payment_methods.index'), ]); - $session = $data['session']; - return render('gateways.stripe.bacs.authorize', $data); } private function buildReturnUrl(): string { - return route('client.payment_methods.store', [ - 'company_gateway_id' => $this->stripe->company_gateway->id, - 'payment_method_id' => GatewayType::BACS, + return route('client.payments.confirm', [ + 'method' => GatewayType::BACS, 'session_id' => "{CHECKOUT_SESSION_ID}", ]); } @@ -62,14 +58,14 @@ class BACS public function authorizeResponse($request) { $this->stripe->init(); - - $customer = $this->stripe->findOrCreateCustomer(); + file_put_contents("/home/blumagin/domains/blumagine.de/invoiceninja/log2.txt", $request); + $this->stripe->setupIntents->retrieve('seti_1EzVO3HssDVaQm2PJjXHmLlM', []); $stripe_response = json_decode($request->input('gateway_response')); $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, $this->stripe->findOrCreateCustomer()); return redirect()->route('client.payment_methods.index'); } @@ -209,10 +205,9 @@ class BACS { try { $payment_meta = new \stdClass; - $payment_meta->exp_month = (string) $method->card->exp_month; - $payment_meta->exp_year = (string) $method->card->exp_year; - $payment_meta->brand = (string) $method->card->brand; - $payment_meta->last4 = (string) $method->card->last4; + $payment_meta->brand = (string) ""; + $payment_meta->last4 = (string) ""; + $payment_meta->state = 'authorized'; $payment_meta->type = GatewayType::BACS; $data = [ From 2b18bf2b4b9d7aa47278f633e0e2b64ae3e2d547 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 16:54:07 +0100 Subject: [PATCH 21/88] Save BACS --- app/PaymentDrivers/Stripe/BACS.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 9f013b9793d6..dd6ba037518c 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -58,14 +58,11 @@ class BACS public function authorizeResponse($request) { $this->stripe->init(); - file_put_contents("/home/blumagin/domains/blumagine.de/invoiceninja/log2.txt", $request); - $this->stripe->setupIntents->retrieve('seti_1EzVO3HssDVaQm2PJjXHmLlM', []); - - $stripe_response = json_decode($request->input('gateway_response')); - - $stripe_method = $this->stripe->getStripePaymentMethod($stripe_response->payment_method); - - $this->storePaymentMethod($stripe_method, $request->payment_method_id, $this->stripe->findOrCreateCustomer()); + if ($request->session_id){ + $session = $this->stripe->stripe->checkout->sessions->retrieve($request->session_id, ['expand' => ['setup_intent']]); + } + file_put_contents("/home/blumagin/domains/blumagine.de/invoiceninja/log2.txt", $session); + $this->storePaymentMethod($session->setup_intent->payment_method, 1, $this->stripe->findOrCreateCustomer()); return redirect()->route('client.payment_methods.index'); } @@ -212,7 +209,7 @@ class BACS $data = [ 'payment_meta' => $payment_meta, - 'token' => $method->id, + 'token' => $method, 'payment_method_id' => $payment_method_id, ]; From 597610ed4c36c29b400f0e5ef01009906c84a17e Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 16:55:42 +0100 Subject: [PATCH 22/88] Minor fixes --- app/PaymentDrivers/Stripe/BACS.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index dd6ba037518c..b7d908697447 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -49,7 +49,7 @@ class BACS } private function buildReturnUrl(): string { - return route('client.payments.confirm', [ + return route('client.payment_methods.confirm', [ 'method' => GatewayType::BACS, 'session_id' => "{CHECKOUT_SESSION_ID}", ]); From 3ed29c8e77953044240180441b400e095368ccc9 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 16:56:38 +0100 Subject: [PATCH 23/88] Minor fixes --- app/PaymentDrivers/Stripe/BACS.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index b7d908697447..3a5346e6f61f 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -198,7 +198,7 @@ class BACS throw new PaymentFailed('Failed to process the payment.', 500); } - private function storePaymentMethod(PaymentMethod $method, $payment_method_id, $customer) + private function storePaymentMethod($method, $payment_method_id, $customer) { try { $payment_meta = new \stdClass; From 98a938235f8cd0d155a3059f59f68a4a3f752d61 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 16:58:27 +0100 Subject: [PATCH 24/88] Minor fixes --- app/PaymentDrivers/Stripe/BACS.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 3a5346e6f61f..4b37c4d7f2c7 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -62,7 +62,7 @@ class BACS $session = $this->stripe->stripe->checkout->sessions->retrieve($request->session_id, ['expand' => ['setup_intent']]); } file_put_contents("/home/blumagin/domains/blumagine.de/invoiceninja/log2.txt", $session); - $this->storePaymentMethod($session->setup_intent->payment_method, 1, $this->stripe->findOrCreateCustomer()); + $this->storePaymentMethod($session, 1, $this->stripe->findOrCreateCustomer()); return redirect()->route('client.payment_methods.index'); } @@ -209,8 +209,8 @@ class BACS $data = [ 'payment_meta' => $payment_meta, - 'token' => $method, - 'payment_method_id' => $payment_method_id, + 'token' => $method->setup_intent->payment_method, + 'payment_method_id' => GatewayType::BACS, ]; $this->stripe->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]); From b0e6c620493fcc9ed97cfbd54b8e20727745f3a6 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 16 Dec 2022 17:18:20 +0100 Subject: [PATCH 25/88] Remove debbuging code --- app/PaymentDrivers/Stripe/BACS.php | 5 +- public/js/clients/payments/stripe-bacs.js | 57 +---------------------- 2 files changed, 4 insertions(+), 58 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 4b37c4d7f2c7..9dc28ab281d2 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -61,8 +61,7 @@ class BACS if ($request->session_id){ $session = $this->stripe->stripe->checkout->sessions->retrieve($request->session_id, ['expand' => ['setup_intent']]); } - file_put_contents("/home/blumagin/domains/blumagine.de/invoiceninja/log2.txt", $session); - $this->storePaymentMethod($session, 1, $this->stripe->findOrCreateCustomer()); + $this->storePaymentMethod($session, $this->stripe->findOrCreateCustomer()); return redirect()->route('client.payment_methods.index'); } @@ -198,7 +197,7 @@ class BACS throw new PaymentFailed('Failed to process the payment.', 500); } - private function storePaymentMethod($method, $payment_method_id, $customer) + private function storePaymentMethod($method, $customer) { try { $payment_meta = new \stdClass; diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index b0295b03f98a..a4537ee2ab78 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -1,55 +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; - } - - 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('authorize-bacs').addEventListener('click', (e) => { - let errors = document.getElementById('errors'); - - 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; - }); - }; -} - -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(); +/*! For license information please see stripe-bacs.js.LICENSE.txt */ +(()=>{var e,t,n,r;function i(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}))})),this.key=t,this.errors=document.getElementById("errors"),this.stripeConnect=n}));new a(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 From 04d13f78bd88ec35465aa3b2f5029ee1f07c174b Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 05:59:27 +0100 Subject: [PATCH 26/88] Scaffold inital payment view --- .../gateways/stripe/bacs/pay.blade.php | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) 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 74046f442d82..e9d798d11540 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -7,25 +7,46 @@ @else @endif - - - + @endsection @section('gateway_content') +
+ @csrf + + + + + + +
+ @include('portal.ninja2020.gateways.includes.payment_details') @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.payment_type')]) - {{ ctrans('texts.bacs') }} ({{ ctrans('texts.bank_transfer') }}) + {{ ctrans('texts.sepa') }} ({{ ctrans('texts.bank_transfer') }}) + @endcomponent + + @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.pay_with')]) + @if (count($tokens) > 0) + @foreach ($tokens as $token) + + @endforeach + @endisset + @endcomponent @include('portal.ninja2020.gateways.includes.pay_now') @endsection @push('footer') - + @endpush From 1459a52892f9481d634024fe0685f788efcf1ec6 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 06:02:50 +0100 Subject: [PATCH 27/88] Further fixes --- .../views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php | 3 --- 1 file changed, 3 deletions(-) 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 e9d798d11540..267b9593341c 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -7,9 +7,6 @@ @else @endif - - - @endsection @section('gateway_content') From 067dac5ac9b3a04e28244ce946dd58728fcab104 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 06:04:46 +0100 Subject: [PATCH 28/88] Adapt texts --- .../views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 267b9593341c..4f8b81ee2388 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -25,7 +25,7 @@ @include('portal.ninja2020.gateways.includes.payment_details') @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.payment_type')]) - {{ ctrans('texts.sepa') }} ({{ ctrans('texts.bank_transfer') }}) + {{ ctrans('texts.bacs') }} ({{ ctrans('texts.bank_transfer') }}) @endcomponent @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.pay_with')]) From bbeef5fd50766bedfaac91e2066f7c8364576d0e Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 06:19:52 +0100 Subject: [PATCH 29/88] Added payment view for BACS --- app/PaymentDrivers/Stripe/BACS.php | 1 - public/js/clients/payments/stripe-bacs.js | 66 ++++++++++++++++++- resources/js/clients/payments/stripe-bacs.js | 25 ++++--- .../gateways/stripe/bacs/authorize.blade.php | 1 + .../gateways/stripe/bacs/pay.blade.php | 1 + 5 files changed, 83 insertions(+), 11 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 9dc28ab281d2..ab57def73b28 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -100,7 +100,6 @@ class BACS ]; $state = array_merge($state, $request->all()); - $state['store_card'] = boolval($state['store_card']); if ($request->has('token') && ! is_null($request->token)) { $state['store_card'] = false; diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index a4537ee2ab78..be0a7bcd8616 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -1,2 +1,64 @@ -/*! For license information please see stripe-bacs.js.LICENSE.txt */ -(()=>{var e,t,n,r;function i(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}))})),this.key=t,this.errors=document.getElementById("errors"),this.stripeConnect=n}));new a(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 = () => { + 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{ + 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'); + } + }; +} + +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(); diff --git a/resources/js/clients/payments/stripe-bacs.js b/resources/js/clients/payments/stripe-bacs.js index b0295b03f98a..be0a7bcd8616 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -34,14 +34,21 @@ class ProcessBACS { }; handle = () => { - document.getElementById('authorize-bacs').addEventListener('click', (e) => { - let errors = document.getElementById('errors'); - - 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; - }); + 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{ + 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'); + } }; } @@ -51,5 +58,7 @@ const publishableKey = document.querySelector( 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(); 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 7eb969d268b2..f088cadd1315 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/authorize.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/authorize.blade.php @@ -9,6 +9,7 @@ @endif + @endsection 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 4f8b81ee2388..faba871e55bf 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -7,6 +7,7 @@ @else @endif + @endsection @section('gateway_content') From 7db95405e525668c0b303115ab4e0cb0cde0dee3 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 06:22:57 +0100 Subject: [PATCH 30/88] Minor changes --- app/PaymentDrivers/Stripe/BACS.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index ab57def73b28..5830cadac8c3 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -78,6 +78,7 @@ class BACS 'currency' => $this->stripe->client->getCurrencyCode(), 'customer' => $this->stripe->findOrCreateCustomer(), 'description' => $description, + 'payment_method_types' => ['bacs_debit'], 'metadata' => [ 'payment_hash' => $this->stripe->payment_hash->hash, 'gateway_type_id' => GatewayType::BACS, From 6b163f1d3fd4412186f28acbaef86465623212bb Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 06:26:52 +0100 Subject: [PATCH 31/88] Minor fix --- .../views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 faba871e55bf..f6d726906155 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -46,5 +46,5 @@ @push('footer') - + @endpush From 360282dce4ffedb4a2ae0c81a333b37ddc968a96 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 06:29:21 +0100 Subject: [PATCH 32/88] Minor fix --- app/PaymentDrivers/Stripe/BACS.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 5830cadac8c3..fe4d50b78268 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -83,7 +83,7 @@ class BACS 'payment_hash' => $this->stripe->payment_hash->hash, 'gateway_type_id' => GatewayType::BACS, ], - 'setup_future_usage' => 'off_session', + 'confirm' => true, ]; $data['intent'] = $this->stripe->createPaymentIntent($payment_intent_data); From 01fbebb42e4e484426fb0912bbd9c229ee3648ce Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 06:39:16 +0100 Subject: [PATCH 33/88] First generartion of final js --- app/PaymentDrivers/Stripe/BACS.php | 1 - public/js/clients/payments/stripe-bacs.js | 11 +++++++++++ resources/js/clients/payments/stripe-bacs.js | 11 +++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index fe4d50b78268..d0db624d82cb 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -83,7 +83,6 @@ class BACS 'payment_hash' => $this->stripe->payment_hash->hash, 'gateway_type_id' => GatewayType::BACS, ], - 'confirm' => true, ]; $data['intent'] = $this->stripe->createPaymentIntent($payment_intent_data); diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index be0a7bcd8616..b0731fe19cea 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -48,6 +48,17 @@ 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=pi-client-secret').content, + {} + ).then((result) => { + if (result.error) { + return this.handleFailure(result.error.message); + } + + return this.handleSuccess(result); + }); } }; } diff --git a/resources/js/clients/payments/stripe-bacs.js b/resources/js/clients/payments/stripe-bacs.js index be0a7bcd8616..b0731fe19cea 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -48,6 +48,17 @@ 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=pi-client-secret').content, + {} + ).then((result) => { + if (result.error) { + return this.handleFailure(result.error.message); + } + + return this.handleSuccess(result); + }); } }; } From fdafa049043945496d7f87ae6a6fb47ddfcdb20e Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 06:47:43 +0100 Subject: [PATCH 34/88] Fixes --- public/js/clients/payments/stripe-bacs.js | 31 +++++++++++--------- resources/js/clients/payments/stripe-bacs.js | 31 +++++++++++--------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index b0731fe19cea..5dade9c73027 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -42,22 +42,25 @@ class ProcessBACS { location.href=document.querySelector('meta[name=stripe-redirect-url').content; });} else{ - 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'); + 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=pi-client-secret').content, - {} - ).then((result) => { - if (result.error) { - return this.handleFailure(result.error.message); - } + this.stripe.confirmBecsDebitPayment( + document.querySelector('meta[name=pi-client-secret') + .content, + {} + ).then((result) => { + if (result.error) { + return this.handleFailure(result.error.message); + } - return this.handleSuccess(result); + return this.handleSuccess(result); + }); }); } }; diff --git a/resources/js/clients/payments/stripe-bacs.js b/resources/js/clients/payments/stripe-bacs.js index b0731fe19cea..5dade9c73027 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -42,22 +42,25 @@ class ProcessBACS { location.href=document.querySelector('meta[name=stripe-redirect-url').content; });} else{ - 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'); + 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=pi-client-secret').content, - {} - ).then((result) => { - if (result.error) { - return this.handleFailure(result.error.message); - } + this.stripe.confirmBecsDebitPayment( + document.querySelector('meta[name=pi-client-secret') + .content, + {} + ).then((result) => { + if (result.error) { + return this.handleFailure(result.error.message); + } - return this.handleSuccess(result); + return this.handleSuccess(result); + }); }); } }; From 2cf9db7b2bffc09cc2242cef0e04f59c79bb553a Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 06:58:45 +0100 Subject: [PATCH 35/88] Fixes --- app/PaymentDrivers/Stripe/BACS.php | 8 +++++--- public/js/clients/payments/stripe-bacs.js | 2 +- resources/js/clients/payments/stripe-bacs.js | 2 +- .../portal/ninja2020/gateways/stripe/bacs/pay.blade.php | 1 + 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index d0db624d82cb..d859b3354eda 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -58,11 +58,13 @@ class BACS public function authorizeResponse($request) { $this->stripe->init(); - if ($request->session_id){ + if ($request->session_id) { $session = $this->stripe->stripe->checkout->sessions->retrieve($request->session_id, ['expand' => ['setup_intent']]); - } - $this->storePaymentMethod($session, $this->stripe->findOrCreateCustomer()); + $customer = $this->stripe->findOrCreateCustomer(); + $this->stripe->attach($session->setup_intent->payment_method, $customer); + $this->storePaymentMethod($session, $customer); + } return redirect()->route('client.payment_methods.index'); } diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index 5dade9c73027..0c43cd308ffc 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -51,7 +51,7 @@ class ProcessBACS { this.payNowButton.querySelector('span').classList.add('hidden'); this.stripe.confirmBecsDebitPayment( - document.querySelector('meta[name=pi-client-secret') + document.querySelector('meta[name=stripe-secret') .content, {} ).then((result) => { diff --git a/resources/js/clients/payments/stripe-bacs.js b/resources/js/clients/payments/stripe-bacs.js index 5dade9c73027..0c43cd308ffc 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -51,7 +51,7 @@ class ProcessBACS { this.payNowButton.querySelector('span').classList.add('hidden'); this.stripe.confirmBecsDebitPayment( - document.querySelector('meta[name=pi-client-secret') + document.querySelector('meta[name=stripe-secret') .content, {} ).then((result) => { 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 f6d726906155..84d96b14523c 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -8,6 +8,7 @@ @endif + @endsection @section('gateway_content') From 5dc9edab359fd5c8e0773177de8a4aa3d0b5ee94 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 07:05:19 +0100 Subject: [PATCH 36/88] Fixes --- public/js/clients/payments/stripe-bacs.js | 1 + resources/js/clients/payments/stripe-bacs.js | 1 + 2 files changed, 2 insertions(+) diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index 0c43cd308ffc..6e213a70a7a6 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -13,6 +13,7 @@ class ProcessBACS { this.key = key; this.errors = document.getElementById('errors'); this.stripeConnect = stripeConnect; + this.onlyAuthorization = onlyAuthorization; } setupStripe = () => { diff --git a/resources/js/clients/payments/stripe-bacs.js b/resources/js/clients/payments/stripe-bacs.js index 0c43cd308ffc..6e213a70a7a6 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -13,6 +13,7 @@ class ProcessBACS { this.key = key; this.errors = document.getElementById('errors'); this.stripeConnect = stripeConnect; + this.onlyAuthorization = onlyAuthorization; } setupStripe = () => { From e1fa873d1f384e9c92ed042fa57f42b4702e4c53 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 07:11:02 +0100 Subject: [PATCH 37/88] Fixes --- app/PaymentDrivers/Stripe/BACS.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index d859b3354eda..2d857ce065e6 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -62,8 +62,8 @@ class BACS $session = $this->stripe->stripe->checkout->sessions->retrieve($request->session_id, ['expand' => ['setup_intent']]); $customer = $this->stripe->findOrCreateCustomer(); - $this->stripe->attach($session->setup_intent->payment_method, $customer); - $this->storePaymentMethod($session, $customer); + $payment_method = $this->stripe->attach($session->setup_intent->payment_method, $customer); + $this->storePaymentMethod($payment_method, $customer); } return redirect()->route('client.payment_methods.index'); } @@ -202,14 +202,14 @@ class BACS { try { $payment_meta = new \stdClass; - $payment_meta->brand = (string) ""; - $payment_meta->last4 = (string) ""; + $payment_meta->brand = (string) $method->bacs_debit->sort_code; + $payment_meta->last4 = (string) $method->bacs_debit->last4; $payment_meta->state = 'authorized'; $payment_meta->type = GatewayType::BACS; $data = [ 'payment_meta' => $payment_meta, - 'token' => $method->setup_intent->payment_method, + 'token' => $method->id, 'payment_method_id' => GatewayType::BACS, ]; From 9f38380d61393766749cac92a5ba1f4a28a17c14 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 07:16:20 +0100 Subject: [PATCH 38/88] Fixes --- app/PaymentDrivers/Stripe/BACS.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 2d857ce065e6..acb724990cf2 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -62,7 +62,8 @@ class BACS $session = $this->stripe->stripe->checkout->sessions->retrieve($request->session_id, ['expand' => ['setup_intent']]); $customer = $this->stripe->findOrCreateCustomer(); - $payment_method = $this->stripe->attach($session->setup_intent->payment_method, $customer); + $this->stripe->attach($session->setup_intent->payment_method, $customer); + $payment_method = $this->stripe->getStripePaymentMethod($session->setup_intent->payment_method); $this->storePaymentMethod($payment_method, $customer); } return redirect()->route('client.payment_methods.index'); From ea1a373a9bfc18dc8b49e4a999f0367e9a4a8acb Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 07:36:13 +0100 Subject: [PATCH 39/88] Fixes for tokenbillling --- app/PaymentDrivers/Stripe/Charge.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/PaymentDrivers/Stripe/Charge.php b/app/PaymentDrivers/Stripe/Charge.php index ee09ba95fb57..78a0200102f2 100644 --- a/app/PaymentDrivers/Stripe/Charge.php +++ b/app/PaymentDrivers/Stripe/Charge.php @@ -89,6 +89,9 @@ class Charge if ($cgt->gateway_type_id == GatewayType::SEPA) { $data['payment_method_types'] = ['sepa_debit']; } + if ($cgt->gateway_type_id == GatewayType::BACS) { + $data['payment_method_types'] = ['bacs_debit']; + } /* Should improve token billing with client not present */ if (!auth()->guard('contact')->check()) { @@ -158,7 +161,7 @@ class Charge $status = Payment::STATUS_COMPLETED; } - + if(!in_array($response?->status, ['succeeded', 'processing'])){ $this->stripe->processInternallyFailedPayment($this->stripe, new \Exception('Auto billing failed.',400)); } From f2fd4aec37884f8f688ad09e166a0cf380b3a05a Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 12:40:51 +0100 Subject: [PATCH 40/88] More fixes for autobilling --- app/PaymentDrivers/Stripe/Charge.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/PaymentDrivers/Stripe/Charge.php b/app/PaymentDrivers/Stripe/Charge.php index 78a0200102f2..a5b9bf6a0211 100644 --- a/app/PaymentDrivers/Stripe/Charge.php +++ b/app/PaymentDrivers/Stripe/Charge.php @@ -148,7 +148,11 @@ class Charge if ($cgt->gateway_type_id == GatewayType::SEPA) { $payment_method_type = PaymentType::SEPA; $status = Payment::STATUS_PENDING; - } else { + } elseif ($cgt->gateway_type_id == GatewayType::BACS){ + $payment_method_type = PaymentType::SEPA; + $status = Payment::STATUS_PENDING; + } + else { if(isset($response->latest_charge)) { $charge = \Stripe\Charge::retrieve($response->latest_charge, $this->stripe->stripe_connect_auth); @@ -209,6 +213,8 @@ class Charge break; case PaymentType::SEPA: return PaymentType::SEPA; + case PaymentType::BACS: + return PaymentType::BACS; default: return PaymentType::CREDIT_CARD_OTHER; break; From 331d4f71730d75b8bf0199ef4a22b87f1fe594d5 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 12:43:08 +0100 Subject: [PATCH 41/88] More fixes for autobilling --- app/PaymentDrivers/Stripe/Charge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/PaymentDrivers/Stripe/Charge.php b/app/PaymentDrivers/Stripe/Charge.php index a5b9bf6a0211..99e838cd617f 100644 --- a/app/PaymentDrivers/Stripe/Charge.php +++ b/app/PaymentDrivers/Stripe/Charge.php @@ -149,7 +149,7 @@ class Charge $payment_method_type = PaymentType::SEPA; $status = Payment::STATUS_PENDING; } elseif ($cgt->gateway_type_id == GatewayType::BACS){ - $payment_method_type = PaymentType::SEPA; + $payment_method_type = PaymentType::BACS; $status = Payment::STATUS_PENDING; } else { From d67fc2d4931a081c6f885f39c4f8245dc4701b9f Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 12:53:54 +0100 Subject: [PATCH 42/88] Add new webhhoks for BACS --- app/PaymentDrivers/Stripe/Jobs/StripeWebhook.php | 3 +++ app/PaymentDrivers/StripePaymentDriver.php | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/app/PaymentDrivers/Stripe/Jobs/StripeWebhook.php b/app/PaymentDrivers/Stripe/Jobs/StripeWebhook.php index bd7acab7a276..f573e26005c7 100644 --- a/app/PaymentDrivers/Stripe/Jobs/StripeWebhook.php +++ b/app/PaymentDrivers/Stripe/Jobs/StripeWebhook.php @@ -49,6 +49,9 @@ class StripeWebhook implements ShouldQueue 'charge.failed', 'payment_intent.succeeded', 'payment_intent.payment_failed', + 'mandate.updated', + 'checkout.session.completed', + 'payment_method.automatically_updated' ]; public function __construct(string $company_key, int $company_gateway_id) diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index f0958519b7fe..d60b26eb5dc0 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -714,6 +714,13 @@ class StripePaymentDriver extends BaseDriver } } } + } elseif ($request->type === "payment_method.automatically_updated"){ + return response()->json([], 200); + } elseif ($request->type === "checkout.session.completed"){ + return response()->json([], 200); + } elseif ($request->type === "mandate.updated"){ + + return response()->json([], 200); } return response()->json([], 200); From f897df733a60166a773461faac9b874904f74629 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 14:22:03 +0100 Subject: [PATCH 43/88] 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 acb724990cf2..c817ec5b87a8 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 6e213a70a7a6..b5d0188c0582 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 6e213a70a7a6..96950c0885aa 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 84d96b14523c..becd88c713df 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') From 9fe832ab22263b9a6fe22b5fd2b7501f731438e8 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 14:42:04 +0100 Subject: [PATCH 44/88] Redirect after payment --- app/PaymentDrivers/Stripe/BACS.php | 9 - public/js/clients/payments/stripe-becs.js | 157 +----------------- .../gateways/stripe/bacs/pay.blade.php | 3 +- 3 files changed, 3 insertions(+), 166 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index c817ec5b87a8..6df45f473d77 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -68,14 +68,6 @@ 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) { @@ -97,7 +89,6 @@ 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); } diff --git a/public/js/clients/payments/stripe-becs.js b/public/js/clients/payments/stripe-becs.js index abdae988297b..33252ede49c0 100644 --- a/public/js/clients/payments/stripe-becs.js +++ b/public/js/clients/payments/stripe-becs.js @@ -1,155 +1,2 @@ -/******/ (() => { // webpackBootstrap -var __webpack_exports__ = {}; -/*!******************************************************!*\ - !*** ./resources/js/clients/payments/stripe-becs.js ***! - \******************************************************/ -var _document$querySelect, _document$querySelect2, _document$querySelect3, _document$querySelect4; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } - -function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } - -/** - * 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 - */ -var ProcessBECS = /*#__PURE__*/function () { - function ProcessBECS(key, stripeConnect) { - var _this = this; - - _classCallCheck(this, ProcessBECS); - - _defineProperty(this, "setupStripe", function () { - if (_this.stripeConnect) { - // this.stripe.stripeAccount = this.stripeConnect; - _this.stripe = Stripe(_this.key, { - stripeAccount: _this.stripeConnect - }); - } else { - _this.stripe = Stripe(_this.key); - } - - var elements = _this.stripe.elements(); - - var style = { - base: { - color: '#32325d', - fontSize: '16px', - '::placeholder': { - color: '#aab7c4' - }, - ':-webkit-autofill': { - color: '#32325d' - } - }, - invalid: { - color: '#fa755a', - iconColor: '#fa755a', - ':-webkit-autofill': { - color: '#fa755a' - } - } - }; - var options = { - style: style, - disabled: false, - hideIcon: false, - iconStyle: "default" // or "solid" - - }; - _this.auBankAccount = elements.create("auBankAccount", options); - - _this.auBankAccount.mount("#becs-iban"); - - return _this; - }); - - _defineProperty(this, "handle", function () { - document.getElementById('pay-now').addEventListener('click', function (e) { - var errors = document.getElementById('errors'); - - if (document.getElementById('becs-name').value === "") { - document.getElementById('becs-name').focus(); - errors.textContent = document.querySelector('meta[name=translation-name-required]').content; - errors.hidden = false; - return; - } - - if (document.getElementById('becs-email-address').value === "") { - document.getElementById('becs-email-address').focus(); - errors.textContent = document.querySelector('meta[name=translation-email-required]').content; - errors.hidden = false; - return; - } - - if (!document.getElementById('becs-mandate-acceptance').checked) { - document.getElementById('becs-mandate-acceptance').focus(); - errors.textContent = document.querySelector('meta[name=translation-terms-required]').content; - 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'); - - _this.stripe.confirmAuBecsDebitPayment(document.querySelector('meta[name=pi-client-secret').content, { - payment_method: { - au_becs_debit: _this.auBankAccount, - billing_details: { - name: document.getElementById("becs-name").value, - email: document.getElementById("becs-email-address").value - } - } - }).then(function (result) { - if (result.error) { - return _this.handleFailure(result.error.message); - } - - return _this.handleSuccess(result); - }); - }); - }); - - this.key = key; - this.errors = document.getElementById('errors'); - this.stripeConnect = stripeConnect; - } - - _createClass(ProcessBECS, [{ - key: "handleSuccess", - value: function handleSuccess(result) { - document.querySelector('input[name="gateway_response"]').value = JSON.stringify(result.paymentIntent); - document.getElementById('server-response').submit(); - } - }, { - key: "handleFailure", - value: function handleFailure(message) { - var errors = document.getElementById('errors'); - errors.textContent = ''; - errors.textContent = message; - errors.hidden = false; - document.getElementById('pay-now').disabled = false; - document.querySelector('#pay-now > svg').classList.add('hidden'); - document.querySelector('#pay-now > span').classList.remove('hidden'); - } - }]); - - return ProcessBECS; -}(); - -var publishableKey = (_document$querySelect = (_document$querySelect2 = document.querySelector('meta[name="stripe-publishable-key"]')) === null || _document$querySelect2 === void 0 ? void 0 : _document$querySelect2.content) !== null && _document$querySelect !== void 0 ? _document$querySelect : ''; -var stripeConnect = (_document$querySelect3 = (_document$querySelect4 = document.querySelector('meta[name="stripe-account-id"]')) === null || _document$querySelect4 === void 0 ? void 0 : _document$querySelect4.content) !== null && _document$querySelect3 !== void 0 ? _document$querySelect3 : ''; -new ProcessBECS(publishableKey, stripeConnect).setupStripe().handle(); -/******/ })() -; \ No newline at end of file +/*! For license information please see stripe-becs.js.LICENSE.txt */ +(()=>{var e,t,n,o;function a(e,t){for(var n=0;n svg").classList.remove("hidden"),document.querySelector("#pay-now > span").classList.add("hidden"),void o.stripe.confirmAuBecsDebitPayment(document.querySelector("meta[name=pi-client-secret").content,{payment_method:{au_becs_debit:o.auBankAccount,billing_details:{name:document.getElementById("becs-name").value,email:document.getElementById("becs-email-address").value}}}).then((function(e){return e.error?o.handleFailure(e.error.message):o.handleSuccess(e)}))):(document.getElementById("becs-mandate-acceptance").focus(),t.textContent=document.querySelector("meta[name=translation-terms-required]").content,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")}}])&&a(t.prototype,n),o&&a(t,o),Object.defineProperty(t,"prototype",{writable:!1}),e}();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===(o=document.querySelector('meta[name="stripe-account-id"]'))||void 0===o?void 0:o.content)&&void 0!==n?n:"").setupStripe().handle()})(); \ No newline at end of file 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 becd88c713df..d494228c6ce2 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -8,8 +8,7 @@ @endif - - + @endsection @section('gateway_content') From 9a39035650f288458b0233a59de3b081d6e1aaef Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 14:42:58 +0100 Subject: [PATCH 45/88] Redirect after payment --- public/js/clients/payments/stripe-bacs.js | 2 +- resources/js/clients/payments/stripe-bacs.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index b5d0188c0582..5352d53e4139 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -1,2 +1,2 @@ /*! 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 +(()=>{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){document.querySelector("input[name=token]").value;var t=document.getElementById("pay-now");o.payNowButton=t,o.payNowButton.disabled=!0,o.payNowButton.querySelector("svg").classList.remove("hidden"),o.payNowButton.querySelector("span").classList.add("hidden"),stripe.confirmBacsDebitPayment(document.querySelector("meta[name=pi-client-secret").content)}))})),this.key=t,this.errors=document.getElementById("errors"),this.stripeConnect=n,this.onlyAuthorization=m})),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:"",m=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 96950c0885aa..2f930c6c6ae4 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -50,7 +50,9 @@ class ProcessBACS { this.payNowButton.disabled = true; this.payNowButton.querySelector('svg').classList.remove('hidden'); this.payNowButton.querySelector('span').classList.add('hidden'); - location.href=document.querySelector('meta[name=redirect-url').content + "&payment_id=" + token; + stripe.confirmBacsDebitPayment( + document.querySelector('meta[name=pi-client-secret').content, + ); }); } }; From ad3a6b2f267947cae5e472f6dcc4219eaf8f7296 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 14:44:41 +0100 Subject: [PATCH 46/88] Fixes --- .../views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d494228c6ce2..b0aa482d5e63 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -8,7 +8,7 @@ @endif - + @endsection @section('gateway_content') From d50bfa9226da33dfba86e73d11fde94644f248d5 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 14:46:25 +0100 Subject: [PATCH 47/88] Fixes for js --- public/js/clients/payments/stripe-bacs.js | 2 +- resources/js/clients/payments/stripe-bacs.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index 5352d53e4139..31c8136a7df0 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -1,2 +1,2 @@ /*! 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){document.querySelector("input[name=token]").value;var t=document.getElementById("pay-now");o.payNowButton=t,o.payNowButton.disabled=!0,o.payNowButton.querySelector("svg").classList.remove("hidden"),o.payNowButton.querySelector("span").classList.add("hidden"),stripe.confirmBacsDebitPayment(document.querySelector("meta[name=pi-client-secret").content)}))})),this.key=t,this.errors=document.getElementById("errors"),this.stripeConnect=n,this.onlyAuthorization=m})),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:"",m=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 +(()=>{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){document.querySelector("input[name=token]").value;var t=document.getElementById("pay-now");o.payNowButton=t,o.payNowButton.disabled=!0,o.payNowButton.querySelector("svg").classList.remove("hidden"),o.payNowButton.querySelector("span").classList.add("hidden"),o.stripe.confirmBacsDebitPayment(document.querySelector("meta[name=pi-client-secret").content)}))})),this.key=t,this.errors=document.getElementById("errors"),this.stripeConnect=n,this.onlyAuthorization=m})),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:"",m=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 2f930c6c6ae4..9e26aa613033 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -50,7 +50,7 @@ class ProcessBACS { this.payNowButton.disabled = true; this.payNowButton.querySelector('svg').classList.remove('hidden'); this.payNowButton.querySelector('span').classList.add('hidden'); - stripe.confirmBacsDebitPayment( + this.stripe.confirmBacsDebitPayment( document.querySelector('meta[name=pi-client-secret').content, ); }); From bc53a46fac0e60ab6b0179f9df8daa06a72f4ae9 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 14:52:21 +0100 Subject: [PATCH 48/88] Fixes for js --- public/js/clients/payments/stripe-bacs.js | 2 +- resources/js/clients/payments/stripe-bacs.js | 29 +++++++++++++++++-- resources/js/clients/payments/stripe-sepa.js | 18 +++++++++++- .../gateways/stripe/bacs/pay.blade.php | 2 -- 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index 31c8136a7df0..aa816738d10f 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -1,2 +1,2 @@ /*! 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){document.querySelector("input[name=token]").value;var t=document.getElementById("pay-now");o.payNowButton=t,o.payNowButton.disabled=!0,o.payNowButton.querySelector("svg").classList.remove("hidden"),o.payNowButton.querySelector("span").classList.add("hidden"),o.stripe.confirmBacsDebitPayment(document.querySelector("meta[name=pi-client-secret").content)}))})),this.key=t,this.errors=document.getElementById("errors"),this.stripeConnect=n,this.onlyAuthorization=m})),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:"",m=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 +(()=>{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"),o.stripe.confirmBacsDebitPayment(document.querySelector("meta[name=pi-client-secret").content,{payment_method:t}).then((function(e){return e.error?o.handleFailure(e.error.message):o.handleSuccess(e)}))}))})),this.key=t,this.errors=document.getElementById("errors"),this.stripeConnect=n,this.onlyAuthorization=s}var t,n,o;return t=e,(n=[{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")}},{key:"handleSuccess",value:function(e){document.querySelector('input[name="gateway_response"]').value=JSON.stringify(e.paymentIntent),document.getElementById("server-response").submit()}}])&&a(t.prototype,n),o&&a(t,o),Object.defineProperty(t,"prototype",{writable:!1}),e}(),d=null!==(e=null===(t=document.querySelector('meta[name="stripe-publishable-key"]'))||void 0===t?void 0:t.content)&&void 0!==e?e:"",l=null!==(n=null===(o=document.querySelector('meta[name="stripe-account-id"]'))||void 0===o?void 0:o.content)&&void 0!==n?n:"",s=null!==(r=null===(i=document.querySelector('meta[name="only-authorization"]'))||void 0===i?void 0:i.content)&&void 0!==r?r:"";new c(d,l).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 9e26aa613033..2b55c8f1fbbd 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -51,11 +51,36 @@ class ProcessBACS { this.payNowButton.querySelector('svg').classList.remove('hidden'); this.payNowButton.querySelector('span').classList.add('hidden'); this.stripe.confirmBacsDebitPayment( - document.querySelector('meta[name=pi-client-secret').content, - ); + document.querySelector('meta[name=pi-client-secret').content, { + payment_method: token}).then((result) => { + if (result.error) { + return this.handleFailure(result.error.message); + } + + return this.handleSuccess(result); + }); }); } }; + + handleFailure(message) { + let errors = document.getElementById('errors'); + + errors.textContent = ''; + errors.textContent = message; + errors.hidden = false; + + document.getElementById('pay-now').disabled = false; + document.querySelector('#pay-now > svg').classList.add('hidden'); + document.querySelector('#pay-now > span').classList.remove('hidden'); + } + handleSuccess(result) { + document.querySelector( + 'input[name="gateway_response"]' + ).value = JSON.stringify(result.paymentIntent); + + document.getElementById('server-response').submit(); + } } const publishableKey = document.querySelector( diff --git a/resources/js/clients/payments/stripe-sepa.js b/resources/js/clients/payments/stripe-sepa.js index 8e9a74536187..cafcf8e7cc9c 100644 --- a/resources/js/clients/payments/stripe-sepa.js +++ b/resources/js/clients/payments/stripe-sepa.js @@ -5,7 +5,7 @@ * * @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com) * - * @license https://www.elastic.co/licensing/elastic-license + * @license https://www.elastic.co/licensing/elastic-license */ class ProcessSEPA { @@ -215,6 +215,22 @@ class ProcessSEPA { document.querySelector('#pay-now > svg').classList.add('hidden'); document.querySelector('#pay-now > span').classList.remove('hidden'); } + handleSuccess(result) { + document.querySelector( + 'input[name="gateway_response"]' + ).value = JSON.stringify(result.paymentIntent); + + let tokenBillingCheckbox = document.querySelector( + 'input[name="token-billing-checkbox"]:checked' + ); + + if (tokenBillingCheckbox) { + document.querySelector('input[name="store_card"]').value = + tokenBillingCheckbox.value; + } + + document.getElementById('server-response').submit(); + } } const publishableKey = 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 b0aa482d5e63..7116a6a183aa 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -18,8 +18,6 @@ - - From 33764a482835a71916e89478718c14be7a9f60d7 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 14:59:20 +0100 Subject: [PATCH 49/88] Fixes for js --- public/js/clients/payments/stripe-bacs.js | 97 +++++++++++++++++++- resources/js/clients/payments/stripe-bacs.js | 4 +- 2 files changed, 97 insertions(+), 4 deletions(-) diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index aa816738d10f..47660dcf7a1f 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -1,2 +1,95 @@ -/*! 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"),o.stripe.confirmBacsDebitPayment(document.querySelector("meta[name=pi-client-secret").content,{payment_method:t}).then((function(e){return e.error?o.handleFailure(e.error.message):o.handleSuccess(e)}))}))})),this.key=t,this.errors=document.getElementById("errors"),this.stripeConnect=n,this.onlyAuthorization=s}var t,n,o;return t=e,(n=[{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")}},{key:"handleSuccess",value:function(e){document.querySelector('input[name="gateway_response"]').value=JSON.stringify(e.paymentIntent),document.getElementById("server-response").submit()}}])&&a(t.prototype,n),o&&a(t,o),Object.defineProperty(t,"prototype",{writable:!1}),e}(),d=null!==(e=null===(t=document.querySelector('meta[name="stripe-publishable-key"]'))||void 0===t?void 0:t.content)&&void 0!==e?e:"",l=null!==(n=null===(o=document.querySelector('meta[name="stripe-account-id"]'))||void 0===o?void 0:o.content)&&void 0!==n?n:"",s=null!==(r=null===(i=document.querySelector('meta[name="only-authorization"]'))||void 0===i?void 0:i.content)&&void 0!==r?r:"";new c(d,l).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; + 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.confirmBacsDebitPayment( + document.querySelector('meta[name=pi-client-secret]').content, { + payment_method: token}).then((result) => { + if (result.error) { + return this.handleFailure(result.error.message); + } + + return this.handleSuccess(result); + }); + }); + } + }; + + handleFailure(message) { + let errors = document.getElementById('errors'); + + errors.textContent = ''; + errors.textContent = message; + errors.hidden = false; + + document.getElementById('pay-now').disabled = false; + document.querySelector('#pay-now > svg').classList.add('hidden'); + document.querySelector('#pay-now > span').classList.remove('hidden'); + } + handleSuccess(result) { + document.querySelector( + 'input[name="gateway_response"]' + ).value = JSON.stringify(result.paymentIntent); + + document.getElementById('server-response').submit(); + } +} + +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(); diff --git a/resources/js/clients/payments/stripe-bacs.js b/resources/js/clients/payments/stripe-bacs.js index 2b55c8f1fbbd..8ae872676311 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -40,7 +40,7 @@ class ProcessBACS { 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; + location.href=document.querySelector('meta[name=stripe-redirect-url]').content; });} else{ document.getElementById('pay-now').addEventListener('click', (e) => { @@ -51,7 +51,7 @@ class ProcessBACS { this.payNowButton.querySelector('svg').classList.remove('hidden'); this.payNowButton.querySelector('span').classList.add('hidden'); this.stripe.confirmBacsDebitPayment( - document.querySelector('meta[name=pi-client-secret').content, { + document.querySelector('meta[name=pi-client-secret]').content, { payment_method: token}).then((result) => { if (result.error) { return this.handleFailure(result.error.message); From aab55a93466730ca9375af806261439ef7993347 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 15:04:06 +0100 Subject: [PATCH 50/88] Fixes for js --- public/js/clients/payments/stripe-bacs.js | 21 ++++++++++++-------- resources/js/clients/payments/stripe-bacs.js | 21 ++++++++++++-------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index 47660dcf7a1f..0cc7a1b12e6e 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -50,15 +50,20 @@ class ProcessBACS { this.payNowButton.disabled = true; this.payNowButton.querySelector('svg').classList.remove('hidden'); this.payNowButton.querySelector('span').classList.add('hidden'); - this.stripe.confirmBacsDebitPayment( - document.querySelector('meta[name=pi-client-secret]').content, { - payment_method: token}).then((result) => { - if (result.error) { - return this.handleFailure(result.error.message); - } + this.stripe + .confirmBacsDebitPayment( + document.querySelector('meta[name=pi-client-secret') + .content, { + payment_method: document.querySelector('input[name=token]').value + } + ) + .then((result) => { + if (result.error) { + return this.handleFailure(result.error.message); + } - return this.handleSuccess(result); - }); + return this.handleSuccess(result); + }); }); } }; diff --git a/resources/js/clients/payments/stripe-bacs.js b/resources/js/clients/payments/stripe-bacs.js index 8ae872676311..0cc7a1b12e6e 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -50,15 +50,20 @@ class ProcessBACS { this.payNowButton.disabled = true; this.payNowButton.querySelector('svg').classList.remove('hidden'); this.payNowButton.querySelector('span').classList.add('hidden'); - this.stripe.confirmBacsDebitPayment( - document.querySelector('meta[name=pi-client-secret]').content, { - payment_method: token}).then((result) => { - if (result.error) { - return this.handleFailure(result.error.message); - } + this.stripe + .confirmBacsDebitPayment( + document.querySelector('meta[name=pi-client-secret') + .content, { + payment_method: document.querySelector('input[name=token]').value + } + ) + .then((result) => { + if (result.error) { + return this.handleFailure(result.error.message); + } - return this.handleSuccess(result); - }); + return this.handleSuccess(result); + }); }); } }; From efa148e74239378110be5ac1d374373f8ef9e59a Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 15:05:13 +0100 Subject: [PATCH 51/88] Fixes for js --- public/js/clients/payments/stripe-bacs.js | 1 - resources/js/clients/payments/stripe-bacs.js | 1 - 2 files changed, 2 deletions(-) diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index 0cc7a1b12e6e..db5dd01cd2fb 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -44,7 +44,6 @@ class ProcessBACS { });} 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; diff --git a/resources/js/clients/payments/stripe-bacs.js b/resources/js/clients/payments/stripe-bacs.js index 0cc7a1b12e6e..db5dd01cd2fb 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -44,7 +44,6 @@ class ProcessBACS { });} 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; From 4592fbcc4b4b0a699cb7d8d80027b7e72782d65f Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 15:08:37 +0100 Subject: [PATCH 52/88] Fixes for js --- public/js/clients/payments/stripe-bacs.js | 15 +++++++++++++++ resources/js/clients/payments/stripe-bacs.js | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index db5dd01cd2fb..136764b9c04c 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -35,6 +35,7 @@ class ProcessBACS { }; handle = () => { + if (this.onlyAuthorization) { document.getElementById('authorize-bacs').addEventListener('click', (e) => { document.getElementById('authorize-bacs').disabled = true; @@ -43,6 +44,20 @@ class ProcessBACS { location.href=document.querySelector('meta[name=stripe-redirect-url]').content; });} else{ + + Array.from( + document.getElementsByClassName('toggle-payment-with-token') + ).forEach((element) => + element.addEventListener('click', (element) => { + document + .getElementById('stripe--payment-container') + .classList.add('hidden'); + document.getElementById('save-card--container').style.display = + 'none'; + document.querySelector('input[name=token]').value = + element.target.dataset.token; + }) + ); document.getElementById('pay-now').addEventListener('click', (e) => { let payNowButton = document.getElementById('pay-now'); this.payNowButton = payNowButton; diff --git a/resources/js/clients/payments/stripe-bacs.js b/resources/js/clients/payments/stripe-bacs.js index db5dd01cd2fb..136764b9c04c 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -35,6 +35,7 @@ class ProcessBACS { }; handle = () => { + if (this.onlyAuthorization) { document.getElementById('authorize-bacs').addEventListener('click', (e) => { document.getElementById('authorize-bacs').disabled = true; @@ -43,6 +44,20 @@ class ProcessBACS { location.href=document.querySelector('meta[name=stripe-redirect-url]').content; });} else{ + + Array.from( + document.getElementsByClassName('toggle-payment-with-token') + ).forEach((element) => + element.addEventListener('click', (element) => { + document + .getElementById('stripe--payment-container') + .classList.add('hidden'); + document.getElementById('save-card--container').style.display = + 'none'; + document.querySelector('input[name=token]').value = + element.target.dataset.token; + }) + ); document.getElementById('pay-now').addEventListener('click', (e) => { let payNowButton = document.getElementById('pay-now'); this.payNowButton = payNowButton; From 87fcdfd90bfa039248dff1070ebea7a3e3cf8bd2 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sat, 17 Dec 2022 15:11:36 +0100 Subject: [PATCH 53/88] Fixes for js --- public/js/clients/payments/stripe-bacs.js | 116 +----------------- resources/js/clients/payments/stripe-bacs.js | 5 - .../gateways/stripe/bacs/pay.blade.php | 1 + 3 files changed, 3 insertions(+), 119 deletions(-) diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index 136764b9c04c..61f18bbe5898 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -1,114 +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{ - - Array.from( - document.getElementsByClassName('toggle-payment-with-token') - ).forEach((element) => - element.addEventListener('click', (element) => { - document - .getElementById('stripe--payment-container') - .classList.add('hidden'); - document.getElementById('save-card--container').style.display = - 'none'; - document.querySelector('input[name=token]').value = - element.target.dataset.token; - }) - ); - document.getElementById('pay-now').addEventListener('click', (e) => { - 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 - .confirmBacsDebitPayment( - document.querySelector('meta[name=pi-client-secret') - .content, { - payment_method: document.querySelector('input[name=token]').value - } - ) - .then((result) => { - if (result.error) { - return this.handleFailure(result.error.message); - } - - return this.handleSuccess(result); - }); - }); - } - }; - - handleFailure(message) { - let errors = document.getElementById('errors'); - - errors.textContent = ''; - errors.textContent = message; - errors.hidden = false; - - document.getElementById('pay-now').disabled = false; - document.querySelector('#pay-now > svg').classList.add('hidden'); - document.querySelector('#pay-now > span').classList.remove('hidden'); - } - handleSuccess(result) { - document.querySelector( - 'input[name="gateway_response"]' - ).value = JSON.stringify(result.paymentIntent); - - document.getElementById('server-response').submit(); - } -} - -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,a;function i(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})):(Array.from(document.getElementsByClassName("toggle-payment-with-token")).forEach((function(e){return e.addEventListener("click",(function(e){document.querySelector("input[name=token]").value=e.target.dataset.token}))})),document.getElementById("pay-now").addEventListener("click",(function(e){var t=document.getElementById("pay-now");o.payNowButton=t,o.payNowButton.disabled=!0,o.payNowButton.querySelector("svg").classList.remove("hidden"),o.payNowButton.querySelector("span").classList.add("hidden"),o.stripe.confirmBacsDebitPayment(document.querySelector("meta[name=pi-client-secret").content,{payment_method:document.querySelector("input[name=token]").value}).then((function(e){return e.error?o.handleFailure(e.error.message):o.handleSuccess(e)}))})))})),this.key=t,this.errors=document.getElementById("errors"),this.stripeConnect=n,this.onlyAuthorization=s}var t,n,o;return t=e,(n=[{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")}},{key:"handleSuccess",value:function(e){document.querySelector('input[name="gateway_response"]').value=JSON.stringify(e.paymentIntent),document.getElementById("server-response").submit()}}])&&i(t.prototype,n),o&&i(t,o),Object.defineProperty(t,"prototype",{writable:!1}),e}(),l=null!==(e=null===(t=document.querySelector('meta[name="stripe-publishable-key"]'))||void 0===t?void 0:t.content)&&void 0!==e?e:"",d=null!==(n=null===(o=document.querySelector('meta[name="stripe-account-id"]'))||void 0===o?void 0:o.content)&&void 0!==n?n:"",s=null!==(r=null===(a=document.querySelector('meta[name="only-authorization"]'))||void 0===a?void 0:a.content)&&void 0!==r?r:"";new c(l,d).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 136764b9c04c..b538a49995bb 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -49,11 +49,6 @@ class ProcessBACS { document.getElementsByClassName('toggle-payment-with-token') ).forEach((element) => element.addEventListener('click', (element) => { - document - .getElementById('stripe--payment-container') - .classList.add('hidden'); - document.getElementById('save-card--container').style.display = - 'none'; document.querySelector('input[name=token]').value = element.target.dataset.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 7116a6a183aa..5b66c6684da2 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -18,6 +18,7 @@ + From 1aa854d4b5389fbf712a2467ce2e67fe9001e584 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Thu, 22 Dec 2022 11:06:00 +0100 Subject: [PATCH 54/88] More fixes --- app/PaymentDrivers/Stripe/BACS.php | 5 +-- resources/js/clients/payments/stripe-bacs.js | 31 ++----------------- .../gateways/stripe/bacs/pay.blade.php | 2 -- 3 files changed, 6 insertions(+), 32 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 6df45f473d77..e7e265e52764 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -85,9 +85,9 @@ class BACS 'payment_hash' => $this->stripe->payment_hash->hash, 'gateway_type_id' => GatewayType::BACS, ], + 'confirm' => true, ]; - - $data['intent'] = $this->stripe->createPaymentIntent($payment_intent_data); + $data['intent'] = $payment_intent_data; $data['gateway'] = $this->stripe; return render('gateways.stripe.bacs.pay', $data); @@ -96,6 +96,7 @@ class BACS { $this->stripe->init(); nlog($request); + $state = [ 'server_response' => json_decode($request->gateway_response), 'payment_hash' => $request->payment_hash, diff --git a/resources/js/clients/payments/stripe-bacs.js b/resources/js/clients/payments/stripe-bacs.js index b538a49995bb..3fe9120a3356 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -59,39 +59,14 @@ class ProcessBACS { this.payNowButton.disabled = true; this.payNowButton.querySelector('svg').classList.remove('hidden'); this.payNowButton.querySelector('span').classList.add('hidden'); - this.stripe - .confirmBacsDebitPayment( - document.querySelector('meta[name=pi-client-secret') - .content, { - payment_method: document.querySelector('input[name=token]').value - } - ) - .then((result) => { - if (result.error) { - return this.handleFailure(result.error.message); - } - - return this.handleSuccess(result); - }); + this.handleResult(); }); } }; - - handleFailure(message) { - let errors = document.getElementById('errors'); - - errors.textContent = ''; - errors.textContent = message; - errors.hidden = false; - - document.getElementById('pay-now').disabled = false; - document.querySelector('#pay-now > svg').classList.add('hidden'); - document.querySelector('#pay-now > span').classList.remove('hidden'); - } - handleSuccess(result) { + handleResult() { document.querySelector( 'input[name="gateway_response"]' - ).value = JSON.stringify(result.paymentIntent); + ).value = ocument.querySelector('input[name=token]').value; document.getElementById('server-response').submit(); } 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 5b66c6684da2..a18d42b210c9 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -14,9 +14,7 @@ @section('gateway_content')
@csrf - -
From 848ada87908862618078a31448ff3ccec99d3187 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Thu, 22 Dec 2022 11:09:42 +0100 Subject: [PATCH 55/88] More fixes --- public/js/clients/payments/stripe-bacs.js | 86 ++++++++++++++++++- .../gateways/stripe/bacs/pay.blade.php | 1 - 2 files changed, 84 insertions(+), 3 deletions(-) diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index 61f18bbe5898..3fe9120a3356 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -1,2 +1,84 @@ -/*! For license information please see stripe-bacs.js.LICENSE.txt */ -(()=>{var e,t,n,o,r,a;function i(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})):(Array.from(document.getElementsByClassName("toggle-payment-with-token")).forEach((function(e){return e.addEventListener("click",(function(e){document.querySelector("input[name=token]").value=e.target.dataset.token}))})),document.getElementById("pay-now").addEventListener("click",(function(e){var t=document.getElementById("pay-now");o.payNowButton=t,o.payNowButton.disabled=!0,o.payNowButton.querySelector("svg").classList.remove("hidden"),o.payNowButton.querySelector("span").classList.add("hidden"),o.stripe.confirmBacsDebitPayment(document.querySelector("meta[name=pi-client-secret").content,{payment_method:document.querySelector("input[name=token]").value}).then((function(e){return e.error?o.handleFailure(e.error.message):o.handleSuccess(e)}))})))})),this.key=t,this.errors=document.getElementById("errors"),this.stripeConnect=n,this.onlyAuthorization=s}var t,n,o;return t=e,(n=[{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")}},{key:"handleSuccess",value:function(e){document.querySelector('input[name="gateway_response"]').value=JSON.stringify(e.paymentIntent),document.getElementById("server-response").submit()}}])&&i(t.prototype,n),o&&i(t,o),Object.defineProperty(t,"prototype",{writable:!1}),e}(),l=null!==(e=null===(t=document.querySelector('meta[name="stripe-publishable-key"]'))||void 0===t?void 0:t.content)&&void 0!==e?e:"",d=null!==(n=null===(o=document.querySelector('meta[name="stripe-account-id"]'))||void 0===o?void 0:o.content)&&void 0!==n?n:"",s=null!==(r=null===(a=document.querySelector('meta[name="only-authorization"]'))||void 0===a?void 0:a.content)&&void 0!==r?r:"";new c(l,d).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; + 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{ + + Array.from( + document.getElementsByClassName('toggle-payment-with-token') + ).forEach((element) => + element.addEventListener('click', (element) => { + document.querySelector('input[name=token]').value = + element.target.dataset.token; + }) + ); + document.getElementById('pay-now').addEventListener('click', (e) => { + 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.handleResult(); + }); + } + }; + handleResult() { + document.querySelector( + 'input[name="gateway_response"]' + ).value = ocument.querySelector('input[name=token]').value; + + document.getElementById('server-response').submit(); + } +} + +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(); 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 a18d42b210c9..af6f50866f2b 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -8,7 +8,6 @@ @endif - @endsection @section('gateway_content') From 5a54a368ba7fbf74d5e10cf41006f5e122ac3c17 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Thu, 22 Dec 2022 11:18:02 +0100 Subject: [PATCH 56/88] More fixes --- public/js/clients/payments/stripe-bacs.js | 9 +-------- resources/js/clients/payments/stripe-bacs.js | 9 +-------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index 3fe9120a3356..9b553e6e7721 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -59,17 +59,10 @@ class ProcessBACS { this.payNowButton.disabled = true; this.payNowButton.querySelector('svg').classList.remove('hidden'); this.payNowButton.querySelector('span').classList.add('hidden'); - this.handleResult(); + document.getElementById('server-response').submit(); }); } }; - handleResult() { - document.querySelector( - 'input[name="gateway_response"]' - ).value = ocument.querySelector('input[name=token]').value; - - document.getElementById('server-response').submit(); - } } const publishableKey = document.querySelector( diff --git a/resources/js/clients/payments/stripe-bacs.js b/resources/js/clients/payments/stripe-bacs.js index 3fe9120a3356..9b553e6e7721 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -59,17 +59,10 @@ class ProcessBACS { this.payNowButton.disabled = true; this.payNowButton.querySelector('svg').classList.remove('hidden'); this.payNowButton.querySelector('span').classList.add('hidden'); - this.handleResult(); + document.getElementById('server-response').submit(); }); } }; - handleResult() { - document.querySelector( - 'input[name="gateway_response"]' - ).value = ocument.querySelector('input[name=token]').value; - - document.getElementById('server-response').submit(); - } } const publishableKey = document.querySelector( From 2b7893aad9d7212cf3860075de6c502f8cf599f4 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Thu, 22 Dec 2022 11:34:17 +0100 Subject: [PATCH 57/88] More fixes --- app/PaymentDrivers/Stripe/BACS.php | 31 +++++++++---------- .../gateways/stripe/bacs/pay.blade.php | 2 +- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index e7e265e52764..3eeb3e2bba6b 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -70,13 +70,19 @@ class BACS } public function paymentView(array $data) { + $data['gateway'] = $this->stripe; + $data['amount'] = $data['total']['amount_with_fee']; - // $description = $this->stripe->decodeUnicodeString(ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number')) . " for client {$this->stripe->client->present()->name()}"; - $invoice_numbers = collect($data['invoices'])->pluck('invoice_number')->implode(','); - $description = ctrans('texts.stripe_payment_text', ['invoicenumber' => $invoice_numbers, 'amount' => Number::formatMoney($data['total']['amount_with_fee'], $this->stripe->client), 'client' => $this->stripe->client->present()->name()]); - + return render('gateways.stripe.bacs.pay', $data); + } + public function paymentResponse(PaymentResponseRequest $request) + { + $this->stripe->init(); + nlog($request); + $invoice_numbers = collect($this->stripe->payment_hash->invoices())->pluck('invoice_number')->implode(','); + $description = ctrans('texts.stripe_payment_text', ['invoicenumber' => $invoice_numbers, 'amount' => Number::formatMoney($request->amount, $this->stripe->client), 'client' => $this->stripe->client->present()->name()]); $payment_intent_data = [ - 'amount' => $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency()), + 'amount' => $this->stripe->convertToStripeAmount($request->amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()), 'currency' => $this->stripe->client->getCurrencyCode(), 'customer' => $this->stripe->findOrCreateCustomer(), 'description' => $description, @@ -85,21 +91,12 @@ class BACS 'payment_hash' => $this->stripe->payment_hash->hash, 'gateway_type_id' => GatewayType::BACS, ], + 'payment_method' => $request->token, 'confirm' => true, ]; - $data['intent'] = $payment_intent_data; - $data['gateway'] = $this->stripe; - - return render('gateways.stripe.bacs.pay', $data); - } - public function paymentResponse(PaymentResponseRequest $request) - { - $this->stripe->init(); - nlog($request); - + $this->stripe->createPaymentIntent($payment_intent_data); $state = [ - 'server_response' => json_decode($request->gateway_response), - 'payment_hash' => $request->payment_hash, + 'payment_hash' => $this->stripe->payment_hash->hash, ]; $state = array_merge($state, $request->all()); 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 af6f50866f2b..d0f9b7388da4 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -14,8 +14,8 @@
@csrf - +
From f87d84ee1eeb87f72a01296abe5277871bc85a34 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Thu, 22 Dec 2022 11:38:32 +0100 Subject: [PATCH 58/88] More fixes --- app/PaymentDrivers/Stripe/BACS.php | 4 ++-- .../views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 3eeb3e2bba6b..b34731a767ea 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -72,13 +72,13 @@ class BACS { $data['gateway'] = $this->stripe; $data['amount'] = $data['total']['amount_with_fee']; + $data['payment_hash'] = $this->stripe->payment_hash->hash; return render('gateways.stripe.bacs.pay', $data); } public function paymentResponse(PaymentResponseRequest $request) { $this->stripe->init(); - nlog($request); $invoice_numbers = collect($this->stripe->payment_hash->invoices())->pluck('invoice_number')->implode(','); $description = ctrans('texts.stripe_payment_text', ['invoicenumber' => $invoice_numbers, 'amount' => Number::formatMoney($request->amount, $this->stripe->client), 'client' => $this->stripe->client->present()->name()]); $payment_intent_data = [ @@ -96,7 +96,7 @@ class BACS ]; $this->stripe->createPaymentIntent($payment_intent_data); $state = [ - 'payment_hash' => $this->stripe->payment_hash->hash, + 'payment_hash' => $request->payment_hash, ]; $state = array_merge($state, $request->all()); 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 d0f9b7388da4..7a963a046a81 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -15,6 +15,7 @@ @csrf + From 2ca27f7602212319d5a666117fb8571f6d31533d Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 14:50:33 +0100 Subject: [PATCH 59/88] Debugging --- app/PaymentDrivers/Stripe/BACS.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index b34731a767ea..808e40cef0df 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -77,8 +77,10 @@ class BACS return render('gateways.stripe.bacs.pay', $data); } public function paymentResponse(PaymentResponseRequest $request) + { $this->stripe->init(); + nlog($request); $invoice_numbers = collect($this->stripe->payment_hash->invoices())->pluck('invoice_number')->implode(','); $description = ctrans('texts.stripe_payment_text', ['invoicenumber' => $invoice_numbers, 'amount' => Number::formatMoney($request->amount, $this->stripe->client), 'client' => $this->stripe->client->present()->name()]); $payment_intent_data = [ From 07d9149ec372a24143b4e2cd00a8aa4c0df21bae Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 14:58:38 +0100 Subject: [PATCH 60/88] Fixes --- app/PaymentDrivers/Stripe/BACS.php | 19 +++---------------- .../gateways/stripe/bacs/pay.blade.php | 1 + 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 808e40cef0df..990a0401b3a9 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -128,31 +128,18 @@ class BACS { UpdateCustomer::dispatch($this->stripe->company_gateway->company->company_key, $this->stripe->company_gateway->id, $this->stripe->client->id); - $stripe_method = $this->stripe->getStripePaymentMethod($this->stripe->payment_hash->data->server_response->payment_method); - $data = [ 'payment_method' => $this->stripe->payment_hash->data->server_response->payment_method, - 'payment_type' => PaymentType::parseCardType(strtolower($stripe_method->card->brand)) ?: PaymentType::CREDIT_CARD_OTHER, + 'payment_type' => PaymentType::BACS, 'amount' => $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->server_response->amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()), 'transaction_reference' => isset($this->stripe->payment_hash->data->payment_intent->latest_charge) ? $this->stripe->payment_hash->data->payment_intent->latest_charge : optional($this->stripe->payment_hash->data->payment_intent->charges->data[0])->id, - 'gateway_type_id' => GatewayType::CREDIT_CARD, + 'gateway_type_id' => GatewayType::BACS, ]; $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['amount' => $data['amount']]); $this->stripe->payment_hash->save(); - if ($this->stripe->payment_hash->data->store_card) { - $customer = new \stdClass; - $customer->id = $this->stripe->payment_hash->data->customer; - - $this->stripe->attach($this->stripe->payment_hash->data->server_response->payment_method, $customer); - - $stripe_method = $this->stripe->getStripePaymentMethod($this->stripe->payment_hash->data->server_response->payment_method); - - $this->storePaymentMethod($stripe_method, $this->stripe->payment_hash->data->payment_method_id, $customer); - } - - $payment = $this->stripe->createPayment($data, Payment::STATUS_COMPLETED); + $payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING); SystemLogger::dispatch( ['response' => $this->stripe->payment_hash->data->server_response, 'data' => $data], 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 7a963a046a81..1a7f09531136 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -14,6 +14,7 @@
@csrf + From 8df7457c6a96b041a44a58164e92fb8604f00420 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 15:00:35 +0100 Subject: [PATCH 61/88] Fixes --- app/PaymentDrivers/Stripe/BACS.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 990a0401b3a9..cc8b51aa84a6 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -96,18 +96,13 @@ class BACS 'payment_method' => $request->token, 'confirm' => true, ]; - $this->stripe->createPaymentIntent($payment_intent_data); + $state['payment_intent'] = $this->stripe->createPaymentIntent($payment_intent_data); $state = [ 'payment_hash' => $request->payment_hash, ]; $state = array_merge($state, $request->all()); - if ($request->has('token') && ! is_null($request->token)) { - $state['store_card'] = false; - } - - $state['payment_intent'] = PaymentIntent::retrieve($state['server_response']->id, array_merge($this->stripe->stripe_connect_auth, ['idempotency_key' => uniqid("st",true)])); $state['customer'] = $state['payment_intent']->customer; $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, $state); From ea205553781908294fde7fe41e3fbcba2727a8ad Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 15:07:06 +0100 Subject: [PATCH 62/88] Fixes --- app/PaymentDrivers/Stripe/BACS.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index cc8b51aa84a6..6aec78e41b0d 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -96,11 +96,10 @@ class BACS 'payment_method' => $request->token, 'confirm' => true, ]; - $state['payment_intent'] = $this->stripe->createPaymentIntent($payment_intent_data); $state = [ 'payment_hash' => $request->payment_hash, + 'payment_intent' => $this->stripe->createPaymentIntent($payment_intent_data), ]; - $state = array_merge($state, $request->all()); $state['customer'] = $state['payment_intent']->customer; From 1639df18adafae5d21233561e3d52839bfadf344 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 15:11:47 +0100 Subject: [PATCH 63/88] Fixes --- app/PaymentDrivers/Stripe/BACS.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 6aec78e41b0d..7aaa3e9fbd84 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -80,7 +80,6 @@ class BACS { $this->stripe->init(); - nlog($request); $invoice_numbers = collect($this->stripe->payment_hash->invoices())->pluck('invoice_number')->implode(','); $description = ctrans('texts.stripe_payment_text', ['invoicenumber' => $invoice_numbers, 'amount' => Number::formatMoney($request->amount, $this->stripe->client), 'client' => $this->stripe->client->present()->name()]); $payment_intent_data = [ @@ -107,15 +106,13 @@ class BACS $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, $state); $this->stripe->payment_hash->save(); - $server_response = $this->stripe->payment_hash->data->server_response; - - if ($server_response->status == 'succeeded') { - $this->stripe->logSuccessfulGatewayResponse(['response' => json_decode($request->gateway_response), 'data' => $this->stripe->payment_hash], SystemLog::TYPE_STRIPE); + if ($state['payment_intent']->status == 'succeeded') { + $this->stripe->logSuccessfulGatewayResponse(['response' => $state['payment_intent'], 'data' => $this->stripe->payment_hash], SystemLog::TYPE_STRIPE); return $this->processSuccessfulPayment(); } - return $this->processUnsuccessfulPayment($server_response); + return $this->processUnsuccessfulPayment(""); } public function processSuccessfulPayment() From b679e4e349372b4106f98c4c50922738637568eb Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 15:15:45 +0100 Subject: [PATCH 64/88] Fixes --- app/PaymentDrivers/Stripe/BACS.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 7aaa3e9fbd84..c13122be6cfe 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -106,7 +106,7 @@ class BACS $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, $state); $this->stripe->payment_hash->save(); - if ($state['payment_intent']->status == 'succeeded') { + if ($state['payment_intent']->status == 'processing') { $this->stripe->logSuccessfulGatewayResponse(['response' => $state['payment_intent'], 'data' => $this->stripe->payment_hash], SystemLog::TYPE_STRIPE); return $this->processSuccessfulPayment(); @@ -157,7 +157,7 @@ class BACS public function processUnsuccessfulPayment($server_response) { - $this->stripe->sendFailureMail($server_response->cancellation_reason); + $this->stripe->sendFailureMail($server_response); $message = [ 'server_response' => $server_response, From fda44f1552b641ea4e9da7d1e7db8e1d973092dd Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 15:22:18 +0100 Subject: [PATCH 65/88] More fixes --- app/PaymentDrivers/Stripe/BACS.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index c13122be6cfe..6797c37cbb8a 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -109,31 +109,31 @@ class BACS if ($state['payment_intent']->status == 'processing') { $this->stripe->logSuccessfulGatewayResponse(['response' => $state['payment_intent'], 'data' => $this->stripe->payment_hash], SystemLog::TYPE_STRIPE); - return $this->processSuccessfulPayment(); + return $this->processSuccessfulPayment($state['payment_intent']); } return $this->processUnsuccessfulPayment(""); } - public function processSuccessfulPayment() + public function processSuccessfulPayment($payment_id) { UpdateCustomer::dispatch($this->stripe->company_gateway->company->company_key, $this->stripe->company_gateway->id, $this->stripe->client->id); $data = [ - 'payment_method' => $this->stripe->payment_hash->data->server_response->payment_method, + 'payment_method' => $payment_id['id'], 'payment_type' => PaymentType::BACS, 'amount' => $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->server_response->amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()), - 'transaction_reference' => isset($this->stripe->payment_hash->data->payment_intent->latest_charge) ? $this->stripe->payment_hash->data->payment_intent->latest_charge : optional($this->stripe->payment_hash->data->payment_intent->charges->data[0])->id, + 'transaction_reference' => $payment_id['id'], 'gateway_type_id' => GatewayType::BACS, ]; - $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['amount' => $data['amount']]); + $this->stripe->payment_hash->data = array_merge((array) $payment_id, ['amount' => $data['amount']]); $this->stripe->payment_hash->save(); $payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING); SystemLogger::dispatch( - ['response' => $this->stripe->payment_hash->data->server_response, 'data' => $data], + ['response' => $payment_id, 'data' => $data], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, From 398281a691c17fc020ca49038d287507dfd6ebe3 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 15:24:47 +0100 Subject: [PATCH 66/88] More fixes --- app/PaymentDrivers/Stripe/BACS.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 6797c37cbb8a..3a4470dbc13f 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -122,7 +122,7 @@ class BACS $data = [ 'payment_method' => $payment_id['id'], 'payment_type' => PaymentType::BACS, - 'amount' => $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->server_response->amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()), + 'amount' => $this->stripe->convertFromStripeAmount($payment_id->amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()), 'transaction_reference' => $payment_id['id'], 'gateway_type_id' => GatewayType::BACS, ]; From ba5d8e4b8993018134e0e9638c2edeb01b45b77c Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 15:27:50 +0100 Subject: [PATCH 67/88] More fixes --- app/PaymentDrivers/Stripe/BACS.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 3a4470dbc13f..5f605a449efa 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -141,16 +141,6 @@ class BACS $this->stripe->client->company, ); - //If the user has come from a subscription double check here if we need to redirect. - //08-08-2022 - if($payment->invoices()->whereHas('subscription')->exists()){ - $subscription = $payment->invoices()->first()->subscription; - - if($subscription && array_key_exists('return_url', $subscription->webhook_configuration) && strlen($subscription->webhook_configuration['return_url']) >=1) - return redirect($subscription->webhook_configuration['return_url']); - - } - //08-08-2022 return redirect()->route('client.payments.show', ['payment' => $this->stripe->encodePrimaryKey($payment->id)]); } From c157f25f4a4ea2ee34977eb791050dc7c61570af Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 15:27:50 +0100 Subject: [PATCH 68/88] More fixes --- app/PaymentDrivers/Stripe/BACS.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 3a4470dbc13f..a70fd0c48c38 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -127,7 +127,7 @@ class BACS 'gateway_type_id' => GatewayType::BACS, ]; - $this->stripe->payment_hash->data = array_merge((array) $payment_id, ['amount' => $data['amount']]); + $this->stripe->payment_hash->data = array_merge((array) $payment_id, ['amount' => $data['amount'], 'invoices' => collect($this->stripe->payment_hash->invoices())]); $this->stripe->payment_hash->save(); $payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING); @@ -141,16 +141,6 @@ class BACS $this->stripe->client->company, ); - //If the user has come from a subscription double check here if we need to redirect. - //08-08-2022 - if($payment->invoices()->whereHas('subscription')->exists()){ - $subscription = $payment->invoices()->first()->subscription; - - if($subscription && array_key_exists('return_url', $subscription->webhook_configuration) && strlen($subscription->webhook_configuration['return_url']) >=1) - return redirect($subscription->webhook_configuration['return_url']); - - } - //08-08-2022 return redirect()->route('client.payments.show', ['payment' => $this->stripe->encodePrimaryKey($payment->id)]); } From 315f4e10957c6fd1d1b872bd47b0db1290c09d0a Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 15:37:26 +0100 Subject: [PATCH 69/88] More fixes --- app/PaymentDrivers/Stripe/BACS.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index a70fd0c48c38..03f0c4d7f7d0 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -125,9 +125,10 @@ class BACS 'amount' => $this->stripe->convertFromStripeAmount($payment_id->amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()), 'transaction_reference' => $payment_id['id'], 'gateway_type_id' => GatewayType::BACS, + 'invoices' => collect($this->stripe->payment_hash->invoices()), ]; - $this->stripe->payment_hash->data = array_merge((array) $payment_id, ['amount' => $data['amount'], 'invoices' => collect($this->stripe->payment_hash->invoices())]); + $this->stripe->payment_hash->data = array_merge((array) $payment_id, $data); $this->stripe->payment_hash->save(); $payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING); From cd2d1d690dde7586dbd2260590e8a75914e374d8 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 15:40:28 +0100 Subject: [PATCH 70/88] More fixes --- app/PaymentDrivers/Stripe/BACS.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 03f0c4d7f7d0..aa3b4be79031 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -96,7 +96,7 @@ class BACS 'confirm' => true, ]; $state = [ - 'payment_hash' => $request->payment_hash, + 'payment_hash' => $this->stripe->payment_hash->hash, 'payment_intent' => $this->stripe->createPaymentIntent($payment_intent_data), ]; $state = array_merge($state, $request->all()); From 4720df823633f6b99d0e5994098baa4982809772 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 16:04:43 +0100 Subject: [PATCH 71/88] More fixes --- app/PaymentDrivers/Stripe/BACS.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index aa3b4be79031..85dd8e86c4f2 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -125,12 +125,8 @@ class BACS 'amount' => $this->stripe->convertFromStripeAmount($payment_id->amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()), 'transaction_reference' => $payment_id['id'], 'gateway_type_id' => GatewayType::BACS, - 'invoices' => collect($this->stripe->payment_hash->invoices()), ]; - $this->stripe->payment_hash->data = array_merge((array) $payment_id, $data); - $this->stripe->payment_hash->save(); - $payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING); SystemLogger::dispatch( From d5397a2954201ab98763d7f603b9dd9c5e0e55d8 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 16:08:15 +0100 Subject: [PATCH 72/88] Added language string --- lang/en/texts.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lang/en/texts.php b/lang/en/texts.php index 6a8100db5ca1..4cf4b88ab8cd 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -4299,6 +4299,7 @@ $LANG = array( 'eps' => 'EPS', 'becs' => 'BECS Direct Debit', 'bacs' => 'BACS Direct Debit', + 'payment_type_BACS' => 'BACS Direct Debit', 'becs_mandate' => 'By providing your bank account details, you agree to this Direct Debit Request and the Direct Debit Request service agreement, and authorise Stripe Payments Australia Pty Ltd ACN 160 180 343 Direct Debit User ID number 507156 (“Stripe”) to debit your account through the Bulk Electronic Clearing System (BECS) on behalf of :company (the “Merchant”) for any amounts separately communicated to you by the Merchant. You certify that you are either an account holder or an authorised signatory on the account listed above.', 'you_need_to_accept_the_terms_before_proceeding' => 'You need to accept the terms before proceeding.', 'direct_debit' => 'Direct Debit', From f14131b494fa904a89c2db425454deb358c8ffa5 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 19:19:14 +0100 Subject: [PATCH 73/88] Added webhooks and changed default BACS state to unauthorzied --- app/PaymentDrivers/Stripe/BACS.php | 2 +- .../Stripe/Jobs/PaymentIntentWebhook.php | 17 ++++--- app/PaymentDrivers/StripePaymentDriver.php | 46 ++++++++++++++++++- 3 files changed, 55 insertions(+), 10 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 85dd8e86c4f2..3515d2d20f8b 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -169,7 +169,7 @@ class BACS $payment_meta = new \stdClass; $payment_meta->brand = (string) $method->bacs_debit->sort_code; $payment_meta->last4 = (string) $method->bacs_debit->last4; - $payment_meta->state = 'authorized'; + $payment_meta->state = 'unauthorized'; $payment_meta->type = GatewayType::BACS; $data = [ diff --git a/app/PaymentDrivers/Stripe/Jobs/PaymentIntentWebhook.php b/app/PaymentDrivers/Stripe/Jobs/PaymentIntentWebhook.php index e6971ae79a67..4876dadd3ad6 100644 --- a/app/PaymentDrivers/Stripe/Jobs/PaymentIntentWebhook.php +++ b/app/PaymentDrivers/Stripe/Jobs/PaymentIntentWebhook.php @@ -97,7 +97,7 @@ class PaymentIntentWebhook implements ShouldQueue if(isset($this->stripe_request['object']['charges']) && optional($this->stripe_request['object']['charges']['data'][0])['id']) $charge_id = $this->stripe_request['object']['charges']['data'][0]['id']; // API VERSION 2018 - elseif (isset($this->stripe_request['object']['latest_charge'])) + elseif (isset($this->stripe_request['object']['latest_charge'])) $charge_id = $this->stripe_request['object']['latest_charge']; // API VERSION 2022-11-15 @@ -126,7 +126,7 @@ class PaymentIntentWebhook implements ShouldQueue //return early if($payment && $payment->status_id == Payment::STATUS_COMPLETED){ - nlog(" payment found and status correct - returning "); + nlog(" payment found and status correct - returning "); return; } elseif($payment){ @@ -196,6 +196,9 @@ class PaymentIntentWebhook implements ShouldQueue $this->updateAchPayment($payment_hash, $client, $meta); } + elseif(isset($pi['payment_method_types']) && in_array('bacs_debit', $pi['payment_method_types'])){ + return; + } } @@ -216,7 +219,7 @@ class PaymentIntentWebhook implements ShouldQueue 'transaction_reference' => $meta['transaction_reference'], 'gateway_type_id' => GatewayType::BANK_TRANSFER, ]; - + $payment = $driver->createPayment($data, Payment::STATUS_COMPLETED); SystemLogger::dispatch( @@ -265,7 +268,7 @@ class PaymentIntentWebhook implements ShouldQueue } $driver->storeGatewayToken($data, $additional_data); - + } catch(\Exception $e){ nlog("failed to import payment methods"); @@ -291,7 +294,7 @@ class PaymentIntentWebhook implements ShouldQueue // 'transaction_reference' => $meta['transaction_reference'], // 'gateway_type_id' => GatewayType::CREDIT_CARD, // ]; - + // $payment = $driver->createPayment($data, Payment::STATUS_COMPLETED); // SystemLogger::dispatch( @@ -324,7 +327,7 @@ class PaymentIntentWebhook implements ShouldQueue 'transaction_reference' => $meta['transaction_reference'], 'gateway_type_id' => GatewayType::CREDIT_CARD, ]; - + $payment = $driver->createPayment($data, Payment::STATUS_COMPLETED); SystemLogger::dispatch( @@ -338,4 +341,4 @@ class PaymentIntentWebhook implements ShouldQueue } -} \ No newline at end of file +} diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index d60b26eb5dc0..d58948f00ddc 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -715,11 +715,53 @@ class StripePaymentDriver extends BaseDriver } } } elseif ($request->type === "payment_method.automatically_updated"){ + // Will notify customer on updated information return response()->json([], 200); } elseif ($request->type === "checkout.session.completed"){ - return response()->json([], 200); - } elseif ($request->type === "mandate.updated"){ + // Store payment token for Stripe BACS + try { + $setup_intent = $this->stripe->stripe->setupIntents->retrieve($request->data->setup_inent, []); + $customer = $this->stripe->findOrCreateCustomer(); + $this->stripe->attach($setup_intent->payment_method, $customer); + $payment_method = $this->stripe->getStripePaymentMethod($setup_intent->payment_method); + $payment_meta = new \stdClass; + $payment_meta->brand = (string) $payment_method->bacs_debit->sort_code; + $payment_meta->last4 = (string) $payment_method->bacs_debit->last4; + $payment_meta->state = 'unauthorized'; + $payment_meta->type = GatewayType::BACS; + $data = [ + 'payment_meta' => $payment_meta, + 'token' => $payment_method->id, + 'payment_method_id' => GatewayType::BACS, + ]; + $this->stripe->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]); + return response()->json([], 200); + } catch (\Exception $e) { + return $this->stripe->processInternallyFailedPayment($this->stripe, $e); + } + } elseif ($request->type === "mandate.updated"){ + // Check if payment method BACS is still valid + if ($request->data->status === "active"){ + // Check if payment method exists + $clientgateway = ClientGatewayToken::query() + ->where('token', $request->data->payment_method) + ->first(); + if ($clientgateway){ + $clientgateway->state = "authorized"; + $clientgateway->save(); + } + } + elseif ($request->data->status === "inactive"){ + // Deactivate payment method + $clientgateway = ClientGatewayToken::query() + ->where('token', $request->data->payment_method) + ->first(); + $clientgateway->delete(); + } + elseif ($request->data->status === "pending"){ + // Do nothing + } return response()->json([], 200); } From 0fe89ecf96b0a799afaff5f54cd9dbe4a3c7f57d Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 20:09:48 +0100 Subject: [PATCH 74/88] Fixes for webhook --- app/PaymentDrivers/StripePaymentDriver.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 35c0afdf6286..0c6dcf326ba9 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -641,7 +641,7 @@ class StripePaymentDriver extends BaseDriver { // if($request->type === 'payment_intent.requires_action') // nlog($request->all()); - + if($request->type === 'customer.source.updated') { $ach = new ACH($this); $ach->updateBankAccount($request->all()); @@ -730,7 +730,6 @@ class StripePaymentDriver extends BaseDriver return response()->json([], 200); } elseif ($request->type === "checkout.session.completed"){ // Store payment token for Stripe BACS - try { $setup_intent = $this->stripe->stripe->setupIntents->retrieve($request->data->setup_inent, []); $customer = $this->stripe->findOrCreateCustomer(); $this->stripe->attach($setup_intent->payment_method, $customer); @@ -748,12 +747,9 @@ class StripePaymentDriver extends BaseDriver ]; $this->stripe->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]); return response()->json([], 200); - } catch (\Exception $e) { - return $this->stripe->processInternallyFailedPayment($this->stripe, $e); - } } elseif ($request->type === "mandate.updated"){ // Check if payment method BACS is still valid - if ($request->data->status === "active"){ + if ($request->data['status'] === "active"){ // Check if payment method exists $clientgateway = ClientGatewayToken::query() ->where('token', $request->data->payment_method) @@ -763,14 +759,14 @@ class StripePaymentDriver extends BaseDriver $clientgateway->save(); } } - elseif ($request->data->status === "inactive"){ + elseif ($request->data['status'] === "inactive"){ // Deactivate payment method $clientgateway = ClientGatewayToken::query() ->where('token', $request->data->payment_method) ->first(); $clientgateway->delete(); } - elseif ($request->data->status === "pending"){ + elseif ($request->data['status'] === "pending"){ // Do nothing } return response()->json([], 200); From dd1634a8078631fb0a553d0d0d6021da8b2ce528 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 20:12:40 +0100 Subject: [PATCH 75/88] Fixes for webhook --- app/PaymentDrivers/StripePaymentDriver.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 0c6dcf326ba9..eaaa11f14972 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -749,7 +749,7 @@ class StripePaymentDriver extends BaseDriver return response()->json([], 200); } elseif ($request->type === "mandate.updated"){ // Check if payment method BACS is still valid - if ($request->data['status'] === "active"){ + if ($request->data['object']['status'] === "active"){ // Check if payment method exists $clientgateway = ClientGatewayToken::query() ->where('token', $request->data->payment_method) @@ -759,14 +759,14 @@ class StripePaymentDriver extends BaseDriver $clientgateway->save(); } } - elseif ($request->data['status'] === "inactive"){ + elseif ($request->data['object']['status'] === "inactive"){ // Deactivate payment method $clientgateway = ClientGatewayToken::query() ->where('token', $request->data->payment_method) ->first(); $clientgateway->delete(); } - elseif ($request->data['status'] === "pending"){ + elseif ($request->data['object']['status'] === "pending"){ // Do nothing } return response()->json([], 200); From b6197b5ed7645a29757f637c1a42b1a7f887959a Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 20:13:59 +0100 Subject: [PATCH 76/88] Fixes for webhook --- app/PaymentDrivers/StripePaymentDriver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index eaaa11f14972..e98049fc61c6 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -752,7 +752,7 @@ class StripePaymentDriver extends BaseDriver if ($request->data['object']['status'] === "active"){ // Check if payment method exists $clientgateway = ClientGatewayToken::query() - ->where('token', $request->data->payment_method) + ->where('token', $request->data['object']['payment_method']) ->first(); if ($clientgateway){ $clientgateway->state = "authorized"; @@ -762,7 +762,7 @@ class StripePaymentDriver extends BaseDriver elseif ($request->data['object']['status'] === "inactive"){ // Deactivate payment method $clientgateway = ClientGatewayToken::query() - ->where('token', $request->data->payment_method) + ->where('token', $request->data['object']['payment_method']) ->first(); $clientgateway->delete(); } From 95f2e47abf5914b215ac2d73817fed063deb351d Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 20:48:14 +0100 Subject: [PATCH 77/88] Fixes for webhook --- app/PaymentDrivers/StripePaymentDriver.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index e98049fc61c6..5438e0e6c68c 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -730,7 +730,7 @@ class StripePaymentDriver extends BaseDriver return response()->json([], 200); } elseif ($request->type === "checkout.session.completed"){ // Store payment token for Stripe BACS - $setup_intent = $this->stripe->stripe->setupIntents->retrieve($request->data->setup_inent, []); + $setup_intent = $this->stripe->stripe->setupIntents->retrieve($request->data['setup_intent'], []); $customer = $this->stripe->findOrCreateCustomer(); $this->stripe->attach($setup_intent->payment_method, $customer); $payment_method = $this->stripe->getStripePaymentMethod($setup_intent->payment_method); @@ -751,13 +751,15 @@ class StripePaymentDriver extends BaseDriver // Check if payment method BACS is still valid if ($request->data['object']['status'] === "active"){ // Check if payment method exists + $payment_method = (string) $request->data['object']['payment_method']; $clientgateway = ClientGatewayToken::query() - ->where('token', $request->data['object']['payment_method']) + ->where('token', $payment_method) ->first(); if ($clientgateway){ - $clientgateway->state = "authorized"; - $clientgateway->save(); - } + $clientgateway->meta->state = 'authorized'; + $clientgateway->update(); + }; + return response()->json([], 200); } elseif ($request->data['object']['status'] === "inactive"){ // Deactivate payment method @@ -765,11 +767,11 @@ class StripePaymentDriver extends BaseDriver ->where('token', $request->data['object']['payment_method']) ->first(); $clientgateway->delete(); + return response()->json([], 200); } elseif ($request->data['object']['status'] === "pending"){ - // Do nothing + return response()->json([], 200); } - return response()->json([], 200); } return response()->json([], 200); From 1580a93a6e57c85ef25a606e75a7d95cdc88ddf1 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 21:21:04 +0100 Subject: [PATCH 78/88] Fixes for webhook --- app/PaymentDrivers/StripePaymentDriver.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 5438e0e6c68c..169e6cb14e3f 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -18,6 +18,7 @@ use App\Factory\PaymentFactory; use App\Http\Requests\Payments\PaymentWebhookRequest; use App\Http\Requests\Request; use App\Jobs\Util\SystemLogger; +use App\Models\Client; use App\Models\ClientGatewayToken; use App\Models\Country; use App\Models\GatewayType; @@ -730,10 +731,12 @@ class StripePaymentDriver extends BaseDriver return response()->json([], 200); } elseif ($request->type === "checkout.session.completed"){ // Store payment token for Stripe BACS - $setup_intent = $this->stripe->stripe->setupIntents->retrieve($request->data['setup_intent'], []); - $customer = $this->stripe->findOrCreateCustomer(); - $this->stripe->attach($setup_intent->payment_method, $customer); - $payment_method = $this->stripe->getStripePaymentMethod($setup_intent->payment_method); + $this->init(); + $setup_intent = $this->stripe->setupIntents->retrieve($request->data['object']['setup_intent'], []); + $this->client = Client::where('id', ClientGatewayToken::where('gateway_customer_reference', $request->data['object']['customer'])->first()->client_id)->first(); + $customer = $this->findOrCreateCustomer(); + $this->attach($setup_intent->payment_method, $customer); + $payment_method = $this->getStripePaymentMethod($setup_intent->payment_method); $payment_meta = new \stdClass; $payment_meta->brand = (string) $payment_method->bacs_debit->sort_code; $payment_meta->last4 = (string) $payment_method->bacs_debit->last4; @@ -745,7 +748,7 @@ class StripePaymentDriver extends BaseDriver 'token' => $payment_method->id, 'payment_method_id' => GatewayType::BACS, ]; - $this->stripe->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]); + $this->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]); return response()->json([], 200); } elseif ($request->type === "mandate.updated"){ // Check if payment method BACS is still valid From 133c49595fcbdbc8b3d1ecda9d9c09a5323ff506 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 21:46:23 +0100 Subject: [PATCH 79/88] Fixes for webhook --- app/PaymentDrivers/StripePaymentDriver.php | 27 +++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 169e6cb14e3f..4067fbff22e5 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -737,18 +737,23 @@ class StripePaymentDriver extends BaseDriver $customer = $this->findOrCreateCustomer(); $this->attach($setup_intent->payment_method, $customer); $payment_method = $this->getStripePaymentMethod($setup_intent->payment_method); - $payment_meta = new \stdClass; - $payment_meta->brand = (string) $payment_method->bacs_debit->sort_code; - $payment_meta->last4 = (string) $payment_method->bacs_debit->last4; - $payment_meta->state = 'unauthorized'; - $payment_meta->type = GatewayType::BACS; + $clientgateway = ClientGatewayToken::query() + ->where('token', $payment_method) + ->first(); + if (!$clientgateway){ + $payment_meta = new \stdClass; + $payment_meta->brand = (string) $payment_method->bacs_debit->sort_code; + $payment_meta->last4 = (string) $payment_method->bacs_debit->last4; + $payment_meta->state = 'unauthorized'; + $payment_meta->type = GatewayType::BACS; - $data = [ - 'payment_meta' => $payment_meta, - 'token' => $payment_method->id, - 'payment_method_id' => GatewayType::BACS, - ]; - $this->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]); + $data = [ + 'payment_meta' => $payment_meta, + 'token' => $payment_method->id, + 'payment_method_id' => GatewayType::BACS, + ]; + $this->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]); + } return response()->json([], 200); } elseif ($request->type === "mandate.updated"){ // Check if payment method BACS is still valid From 7dbb9bd60a181a32d80b2a81c4cb3b924fa8d69b Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 20 Jan 2023 08:16:26 +0100 Subject: [PATCH 80/88] Archive payment token, instead of deleting it. --- app/PaymentDrivers/StripePaymentDriver.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 4067fbff22e5..171e467a97d4 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -51,6 +51,7 @@ use App\PaymentDrivers\Stripe\SOFORT; use App\PaymentDrivers\Stripe\UpdatePaymentMethods; use App\PaymentDrivers\Stripe\Utilities; use App\PaymentDrivers\Stripe\iDeal; +use App\Repositories\ClientGatewayTokenRepository; use App\Utils\Traits\MakesHash; use Exception; use Google\Service\ServiceConsumerManagement\CustomError; @@ -769,12 +770,14 @@ class StripePaymentDriver extends BaseDriver }; return response()->json([], 200); } - elseif ($request->data['object']['status'] === "inactive"){ - // Deactivate payment method - $clientgateway = ClientGatewayToken::query() - ->where('token', $request->data['object']['payment_method']) - ->first(); - $clientgateway->delete(); + elseif ($request->data['object']['status'] === "inactive" && $request->data['object']['payment_method']){ + // Delete payment method + // $clientgateway = ClientGatewayToken::query() + // ->where('token', $request->data['object']['payment_method']) + // ->first(); + // $clientgateway->delete(); + + (new ClientGatewayTokenRepository)->archive($request->data['object']['payment_method']); return response()->json([], 200); } elseif ($request->data['object']['status'] === "pending"){ From 1b50175c34caf418345b660307fdb4e20a790a61 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 20 Jan 2023 08:22:24 +0100 Subject: [PATCH 81/88] Show error message on no payment method --- .../views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php | 2 ++ 1 file changed, 2 insertions(+) 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 1a7f09531136..46b28ab3e31b 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -37,6 +37,8 @@ **** {{ $token->meta?->last4 }} @endforeach + @else + @endisset @endcomponent From 198ef6b19101c3578a89b6c2817a9309e0ed95a0 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 20 Jan 2023 08:49:36 +0100 Subject: [PATCH 82/88] Correct error message in formular --- public/js/clients/payments/stripe-bacs.js | 30 ++++++++++++------- resources/js/clients/payments/stripe-bacs.js | 28 ++++++++++------- .../gateways/stripe/bacs/pay.blade.php | 2 -- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index 9b553e6e7721..095e99ff9579 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -33,6 +33,7 @@ class ProcessBACS { return this; }; + payment_data; handle = () => { @@ -44,15 +45,6 @@ class ProcessBACS { location.href=document.querySelector('meta[name=stripe-redirect-url]').content; });} else{ - - Array.from( - document.getElementsByClassName('toggle-payment-with-token') - ).forEach((element) => - element.addEventListener('click', (element) => { - document.querySelector('input[name=token]').value = - element.target.dataset.token; - }) - ); document.getElementById('pay-now').addEventListener('click', (e) => { let payNowButton = document.getElementById('pay-now'); this.payNowButton = payNowButton; @@ -61,8 +53,24 @@ class ProcessBACS { this.payNowButton.querySelector('span').classList.add('hidden'); document.getElementById('server-response').submit(); }); - } - }; + + this.payment_data = Array.from(document.getElementsByClassName('toggle-payment-with-token')); + if (this.payment_data.length() > 0){ + this.payment_data.forEach((element) => + element.addEventListener('click', (element) => { + document.querySelector('input[name=token]').value = + element.target.dataset.token; + }) + );} + else{ + this.errors.textContent = "Please add a payment method first, before trying to pay the invoice."; + this.payNowButton.disabled = false; + this.payNowButton.querySelector('span').classList.remove('hidden'); + this.payNowButton.querySelector('svg').classList.add('hidden'); + }} + + + } } const publishableKey = document.querySelector( diff --git a/resources/js/clients/payments/stripe-bacs.js b/resources/js/clients/payments/stripe-bacs.js index 9b553e6e7721..ce08e0d03b87 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -33,6 +33,7 @@ class ProcessBACS { return this; }; + payment_data; handle = () => { @@ -44,15 +45,6 @@ class ProcessBACS { location.href=document.querySelector('meta[name=stripe-redirect-url]').content; });} else{ - - Array.from( - document.getElementsByClassName('toggle-payment-with-token') - ).forEach((element) => - element.addEventListener('click', (element) => { - document.querySelector('input[name=token]').value = - element.target.dataset.token; - }) - ); document.getElementById('pay-now').addEventListener('click', (e) => { let payNowButton = document.getElementById('pay-now'); this.payNowButton = payNowButton; @@ -61,8 +53,24 @@ class ProcessBACS { this.payNowButton.querySelector('span').classList.add('hidden'); document.getElementById('server-response').submit(); }); + + this.payment_data = Array.from(document.getElementsByClassName('toggle-payment-with-token')); + if (this.payment_data.length() > 0){ + this.payment_data.forEach((element) => + element.addEventListener('click', (element) => { + document.querySelector('input[name=token]').value = + element.target.dataset.token; + }) + );} + else{ + this.errors.textContent = "Please add a payment method first, before trying to pay the invoice."; + this.payNowButton.disabled = false; + this.payNowButton.querySelector('span').classList.remove('hidden'); + this.payNowButton.querySelector('svg').classList.add('hidden'); + }} + + } - }; } const publishableKey = document.querySelector( 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 46b28ab3e31b..1a7f09531136 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -37,8 +37,6 @@ **** {{ $token->meta?->last4 }} @endforeach - @else - @endisset @endcomponent From 3629caad34f2e3dd2097f95a38fa14b716a865d3 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 20 Jan 2023 08:55:35 +0100 Subject: [PATCH 83/88] Fixes for js --- public/js/clients/payments/stripe-bacs.js | 6 +++--- resources/js/clients/payments/stripe-bacs.js | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index 095e99ff9579..f0ea7c92750a 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -45,9 +45,8 @@ class ProcessBACS { location.href=document.querySelector('meta[name=stripe-redirect-url]').content; });} else{ + this.payNowButton = document.getElementById('pay-now'); document.getElementById('pay-now').addEventListener('click', (e) => { - 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'); @@ -55,7 +54,7 @@ class ProcessBACS { }); this.payment_data = Array.from(document.getElementsByClassName('toggle-payment-with-token')); - if (this.payment_data.length() > 0){ + if (this.payment_data.length > 0){ this.payment_data.forEach((element) => element.addEventListener('click', (element) => { document.querySelector('input[name=token]').value = @@ -64,6 +63,7 @@ class ProcessBACS { );} else{ this.errors.textContent = "Please add a payment method first, before trying to pay the invoice."; + this.errors.hidden = false; this.payNowButton.disabled = false; this.payNowButton.querySelector('span').classList.remove('hidden'); this.payNowButton.querySelector('svg').classList.add('hidden'); diff --git a/resources/js/clients/payments/stripe-bacs.js b/resources/js/clients/payments/stripe-bacs.js index ce08e0d03b87..f0ea7c92750a 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -45,9 +45,8 @@ class ProcessBACS { location.href=document.querySelector('meta[name=stripe-redirect-url]').content; });} else{ + this.payNowButton = document.getElementById('pay-now'); document.getElementById('pay-now').addEventListener('click', (e) => { - 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'); @@ -55,7 +54,7 @@ class ProcessBACS { }); this.payment_data = Array.from(document.getElementsByClassName('toggle-payment-with-token')); - if (this.payment_data.length() > 0){ + if (this.payment_data.length > 0){ this.payment_data.forEach((element) => element.addEventListener('click', (element) => { document.querySelector('input[name=token]').value = @@ -64,13 +63,14 @@ class ProcessBACS { );} else{ this.errors.textContent = "Please add a payment method first, before trying to pay the invoice."; + this.errors.hidden = false; this.payNowButton.disabled = false; this.payNowButton.querySelector('span').classList.remove('hidden'); this.payNowButton.querySelector('svg').classList.add('hidden'); }} - } + } } const publishableKey = document.querySelector( From 8cb650dd60baef5fd5a8906194fc1aef8d1c597c Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 20 Jan 2023 09:01:37 +0100 Subject: [PATCH 84/88] Add translation for error message --- lang/en/texts.php | 3 ++- public/js/clients/payments/stripe-bacs.js | 6 ++++-- resources/js/clients/payments/stripe-bacs.js | 6 ++++-- .../portal/ninja2020/gateways/stripe/bacs/pay.blade.php | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lang/en/texts.php b/lang/en/texts.php index ac74fe95f352..d6272c281d5c 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -4300,6 +4300,7 @@ $LANG = array( 'becs' => 'BECS Direct Debit', 'bacs' => 'BACS Direct Debit', 'payment_type_BACS' => 'BACS Direct Debit', + 'missing_payment_method' => 'Please add a payment method first, before trying to pay.', 'becs_mandate' => 'By providing your bank account details, you agree to this Direct Debit Request and the Direct Debit Request service agreement, and authorise Stripe Payments Australia Pty Ltd ACN 160 180 343 Direct Debit User ID number 507156 (“Stripe”) to debit your account through the Bulk Electronic Clearing System (BECS) on behalf of :company (the “Merchant”) for any amounts separately communicated to you by the Merchant. You certify that you are either an account holder or an authorised signatory on the account listed above.', 'you_need_to_accept_the_terms_before_proceeding' => 'You need to accept the terms before proceeding.', 'direct_debit' => 'Direct Debit', @@ -4909,7 +4910,7 @@ $LANG = array( 'export_company' => 'Create company backup', 'backup' => 'Backup', 'notification_purchase_order_created_body' => 'The following purchase_order :purchase_order was created for vendor :vendor for :amount.', - 'notification_purchase_order_created_subject' => 'Purchase Order :purchase_order was created for :vendor', + 'notification_purchase_order_created_subject' => 'Purchase Order :purchase_order was created for :vendor', 'notification_purchase_order_sent_subject' => 'Purchase Order :purchase_order was sent to :vendor', 'notification_purchase_order_sent' => 'The following vendor :vendor was emailed Purchase Order :purchase_order for :amount.', 'subscription_blocked' => 'This product is a restricted item, please contact the vendor for further information.', diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index f0ea7c92750a..a67c9057c588 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -62,9 +62,11 @@ class ProcessBACS { }) );} else{ - this.errors.textContent = "Please add a payment method first, before trying to pay the invoice."; + this.errors.textContent = document.querySelector( + 'meta[name=translation-payment-method-required]' + ).content; this.errors.hidden = false; - this.payNowButton.disabled = false; + this.payNowButton.disabled = true; this.payNowButton.querySelector('span').classList.remove('hidden'); this.payNowButton.querySelector('svg').classList.add('hidden'); }} diff --git a/resources/js/clients/payments/stripe-bacs.js b/resources/js/clients/payments/stripe-bacs.js index f0ea7c92750a..a67c9057c588 100644 --- a/resources/js/clients/payments/stripe-bacs.js +++ b/resources/js/clients/payments/stripe-bacs.js @@ -62,9 +62,11 @@ class ProcessBACS { }) );} else{ - this.errors.textContent = "Please add a payment method first, before trying to pay the invoice."; + this.errors.textContent = document.querySelector( + 'meta[name=translation-payment-method-required]' + ).content; this.errors.hidden = false; - this.payNowButton.disabled = false; + this.payNowButton.disabled = true; this.payNowButton.querySelector('span').classList.remove('hidden'); this.payNowButton.querySelector('svg').classList.add('hidden'); }} 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 1a7f09531136..895d09fdae92 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/pay.blade.php @@ -8,6 +8,7 @@ @endif + @endsection @section('gateway_content') From 0414b6e62287bc6bc3c1a1597e45d0f91c447d7e Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Fri, 20 Jan 2023 09:20:30 +0100 Subject: [PATCH 85/88] Fix for adding a payment method twice --- app/PaymentDrivers/Stripe/BACS.php | 9 ++++-- app/PaymentDrivers/StripePaymentDriver.php | 32 ++++++++++------------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 3515d2d20f8b..76013ac71073 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -15,6 +15,7 @@ namespace App\PaymentDrivers\Stripe; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Jobs\Util\SystemLogger; +use App\Models\ClientGatewayToken; use App\Models\GatewayType; use App\Models\Payment; use App\Models\PaymentType; @@ -177,8 +178,12 @@ class BACS 'token' => $method->id, 'payment_method_id' => GatewayType::BACS, ]; - - $this->stripe->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]); + $clientgateway = ClientGatewayToken::query() + ->where('token', $method->id) + ->first(); + if (!$clientgateway){ + $this->stripe->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]); + } } catch (\Exception $e) { return $this->stripe->processInternallyFailedPayment($this->stripe, $e); } diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 171e467a97d4..ac2f7e925543 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -738,21 +738,21 @@ class StripePaymentDriver extends BaseDriver $customer = $this->findOrCreateCustomer(); $this->attach($setup_intent->payment_method, $customer); $payment_method = $this->getStripePaymentMethod($setup_intent->payment_method); + $payment_meta = new \stdClass; + $payment_meta->brand = (string) $payment_method->bacs_debit->sort_code; + $payment_meta->last4 = (string) $payment_method->bacs_debit->last4; + $payment_meta->state = 'unauthorized'; + $payment_meta->type = GatewayType::BACS; + + $data = [ + 'payment_meta' => $payment_meta, + 'token' => $payment_method->id, + 'payment_method_id' => GatewayType::BACS, + ]; $clientgateway = ClientGatewayToken::query() ->where('token', $payment_method) ->first(); if (!$clientgateway){ - $payment_meta = new \stdClass; - $payment_meta->brand = (string) $payment_method->bacs_debit->sort_code; - $payment_meta->last4 = (string) $payment_method->bacs_debit->last4; - $payment_meta->state = 'unauthorized'; - $payment_meta->type = GatewayType::BACS; - - $data = [ - 'payment_meta' => $payment_meta, - 'token' => $payment_method->id, - 'payment_method_id' => GatewayType::BACS, - ]; $this->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]); } return response()->json([], 200); @@ -772,12 +772,10 @@ class StripePaymentDriver extends BaseDriver } elseif ($request->data['object']['status'] === "inactive" && $request->data['object']['payment_method']){ // Delete payment method - // $clientgateway = ClientGatewayToken::query() - // ->where('token', $request->data['object']['payment_method']) - // ->first(); - // $clientgateway->delete(); - - (new ClientGatewayTokenRepository)->archive($request->data['object']['payment_method']); + $clientgateway = ClientGatewayToken::query() + ->where('token', $request->data['object']['payment_method']) + ->first(); + $clientgateway->delete(); return response()->json([], 200); } elseif ($request->data['object']['status'] === "pending"){ From 0c11e1a932a4db22dacbaa760888115fb4d1cc0d Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 23 Jan 2023 08:29:35 +0100 Subject: [PATCH 86/88] Add compiled js and allow BACS only for Great Britian --- app/PaymentDrivers/StripePaymentDriver.php | 1 + public/js/clients/payments/stripe-bacs.js | 89 +-------------------- public/mix-manifest.json | 91 +++++++++++----------- 3 files changed, 49 insertions(+), 132 deletions(-) diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index ac2f7e925543..e38ab4bb3b5a 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -248,6 +248,7 @@ class StripePaymentDriver extends BaseDriver && $this->client->currency() && in_array($this->client->currency()->code, ['GBP']) && isset($this->client->country) + && in_array($this->client->company->country()->getID(), ['826']) && in_array($this->client->country->iso_3166_3, ['GBR'])) { $types[] = GatewayType::BACS; } diff --git a/public/js/clients/payments/stripe-bacs.js b/public/js/clients/payments/stripe-bacs.js index a67c9057c588..91b29fd0c177 100644 --- a/public/js/clients/payments/stripe-bacs.js +++ b/public/js/clients/payments/stripe-bacs.js @@ -1,87 +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; - }; - payment_data; - - 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{ - this.payNowButton = document.getElementById('pay-now'); - document.getElementById('pay-now').addEventListener('click', (e) => { - this.payNowButton.disabled = true; - this.payNowButton.querySelector('svg').classList.remove('hidden'); - this.payNowButton.querySelector('span').classList.add('hidden'); - document.getElementById('server-response').submit(); - }); - - this.payment_data = Array.from(document.getElementsByClassName('toggle-payment-with-token')); - if (this.payment_data.length > 0){ - this.payment_data.forEach((element) => - element.addEventListener('click', (element) => { - document.querySelector('input[name=token]').value = - element.target.dataset.token; - }) - );} - else{ - this.errors.textContent = document.querySelector( - 'meta[name=translation-payment-method-required]' - ).content; - this.errors.hidden = false; - this.payNowButton.disabled = true; - this.payNowButton.querySelector('span').classList.remove('hidden'); - this.payNowButton.querySelector('svg').classList.add('hidden'); - }} - - - } -} - -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,a;function i(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})):(o.payNowButton=document.getElementById("pay-now"),document.getElementById("pay-now").addEventListener("click",(function(e){o.payNowButton.disabled=!0,o.payNowButton.querySelector("svg").classList.remove("hidden"),o.payNowButton.querySelector("span").classList.add("hidden"),document.getElementById("server-response").submit()})),o.payment_data=Array.from(document.getElementsByClassName("toggle-payment-with-token")),o.payment_data.length>0?o.payment_data.forEach((function(e){return e.addEventListener("click",(function(e){document.querySelector("input[name=token]").value=e.target.dataset.token}))})):(o.errors.textContent=document.querySelector("meta[name=translation-payment-method-required]").content,o.errors.hidden=!1,o.payNowButton.disabled=!0,o.payNowButton.querySelector("span").classList.remove("hidden"),o.payNowButton.querySelector("svg").classList.add("hidden")))})),this.key=t,this.errors=document.getElementById("errors"),this.stripeConnect=n,this.onlyAuthorization=m})),s=null!==(e=null===(t=document.querySelector('meta[name="stripe-publishable-key"]'))||void 0===t?void 0:t.content)&&void 0!==e?e:"",l=null!==(n=null===(o=document.querySelector('meta[name="stripe-account-id"]'))||void 0===o?void 0:o.content)&&void 0!==n?n:"",m=null!==(r=null===(a=document.querySelector('meta[name="only-authorization"]'))||void 0===a?void 0:a.content)&&void 0!==r?r:"";new d(s,l).setupStripe().handle()})(); \ No newline at end of file diff --git a/public/mix-manifest.json b/public/mix-manifest.json index 312446a4580f..b61363a2ca1b 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -1,49 +1,50 @@ { - "/js/app.js": "/js/app.js?id=7b6124b74168ccb1cc7da22f7a2bc9ed", - "/js/clients/payment_methods/authorize-authorize-card.js": "/js/clients/payment_methods/authorize-authorize-card.js?id=b6723e0b8ea33f1f50617fa5f289a9d3", - "/js/clients/payments/authorize-credit-card-payment.js": "/js/clients/payments/authorize-credit-card-payment.js?id=faf4828cc6b3b73b69c53d3046661884", - "/js/clients/payments/forte-credit-card-payment.js": "/js/clients/payments/forte-credit-card-payment.js?id=f42dd0caddb3603e71db061924c4b172", - "/js/clients/payments/forte-ach-payment.js": "/js/clients/payments/forte-ach-payment.js?id=b8173c7c0dee76bf9ae6312a963ae0e4", - "/js/clients/payments/stripe-ach.js": "/js/clients/payments/stripe-ach.js?id=207f218c44553470287f35f33a7eb154", - "/js/clients/payments/stripe-klarna.js": "/js/clients/payments/stripe-klarna.js?id=7268f9282c6bb3b04d19d11a7b0c1681", - "/js/clients/invoices/action-selectors.js": "/js/clients/invoices/action-selectors.js?id=404b7ee18e420de0e73f5402b7e39122", - "/js/clients/purchase_orders/action-selectors.js": "/js/clients/purchase_orders/action-selectors.js?id=2f0c4e3bab30a98e33ac768255113174", - "/js/clients/purchase_orders/accept.js": "/js/clients/purchase_orders/accept.js?id=9bb483a89a887f753e49c0b635d6276a", - "/js/clients/invoices/payment.js": "/js/clients/invoices/payment.js?id=752e2bb6390f1a422e31868cf2a2bf67", - "/js/clients/payments/stripe-sofort.js": "/js/clients/payments/stripe-sofort.js?id=4fc5dec1bc4fc21b9e32b1b490c3e7ae", - "/js/clients/payments/stripe-alipay.js": "/js/clients/payments/stripe-alipay.js?id=018ecad3a1bcc1ecc47f76754a573ff2", - "/js/clients/payments/checkout-credit-card.js": "/js/clients/payments/checkout-credit-card.js?id=7cb96275b3eb4901054564c654fb60e3", - "/js/clients/quotes/action-selectors.js": "/js/clients/quotes/action-selectors.js?id=3a4c5cfac7dd4c9218be55945c3c8e85", - "/js/clients/quotes/approve.js": "/js/clients/quotes/approve.js?id=1e58e219878ce3f3ee4d313346ad5f68", - "/js/clients/payments/stripe-credit-card.js": "/js/clients/payments/stripe-credit-card.js?id=6e7c8ab039a239727317ae8622de10db", - "/js/setup/setup.js": "/js/setup/setup.js?id=8cab3339ef48418e1fb2e7a9259d51ca", - "/js/clients/payments/card-js.min.js": "/js/clients/payments/card-js.min.js?id=cf50b5ba1fcd1d184bf0c10d710672c8", - "/js/clients/shared/pdf.js": "/js/clients/shared/pdf.js?id=682de6347049b32c9488f39c78a68ace", - "/js/clients/shared/multiple-downloads.js": "/js/clients/shared/multiple-downloads.js?id=d3c404bb646f1aeaf2382a8c57ab8e1a", - "/js/clients/linkify-urls.js": "/js/clients/linkify-urls.js?id=e1c0599d6f7dc163b549a6df0b3490b4", - "/js/clients/payments/braintree-credit-card.js": "/js/clients/payments/braintree-credit-card.js?id=8b036822abaa4ceb379008fc14208dc2", - "/js/clients/payments/braintree-paypal.js": "/js/clients/payments/braintree-paypal.js?id=de0b1d0c6da7ff509bef3aee8d09e7f8", - "/js/clients/payments/wepay-credit-card.js": "/js/clients/payments/wepay-credit-card.js?id=92ef8632637d335cd0e4bc29a05b7df8", - "/js/clients/payment_methods/wepay-bank-account.js": "/js/clients/payment_methods/wepay-bank-account.js?id=af85b3f6d53c55b5d0e3a80ef58ce0de", - "/js/clients/payments/paytrace-credit-card.js": "/js/clients/payments/paytrace-credit-card.js?id=3869bc6d80acc83f81d9afe8efaae728", - "/js/clients/payments/mollie-credit-card.js": "/js/clients/payments/mollie-credit-card.js?id=7cd5a1d95d33ada211ce185ad6e4bb33", - "/js/clients/payments/eway-credit-card.js": "/js/clients/payments/eway-credit-card.js?id=27274d334aed0824ce4654fa22132f7f", - "/js/clients/payment_methods/braintree-ach.js": "/js/clients/payment_methods/braintree-ach.js?id=f85ebb6a77002afd350086d1274b6af5", - "/js/clients/payments/square-credit-card.js": "/js/clients/payments/square-credit-card.js?id=238e7001420a22b001856193689a1e70", - "/js/clients/statements/view.js": "/js/clients/statements/view.js?id=13e043123f1e58409394458a70461d63", - "/js/clients/payments/razorpay-aio.js": "/js/clients/payments/razorpay-aio.js?id=494f58d2fd8984792833ba7d3055de08", - "/js/clients/payments/stripe-sepa.js": "/js/clients/payments/stripe-sepa.js?id=77d4e397d193196e482af80737bff64a", - "/js/clients/payment_methods/authorize-checkout-card.js": "/js/clients/payment_methods/authorize-checkout-card.js?id=659c4287fb8ef1c458071c206c4d965d", - "/js/clients/payments/stripe-giropay.js": "/js/clients/payments/stripe-giropay.js?id=852a9abf5f3a29f5d7d2f989cbeab374", - "/js/clients/payments/stripe-acss.js": "/js/clients/payments/stripe-acss.js?id=447c587a5eeb0c1de3091c8358db7ad7", - "/js/clients/payments/stripe-bancontact.js": "/js/clients/payments/stripe-bancontact.js?id=f694d3f9f01e4550cb5a3eb6cb43c12d", - "/js/clients/payments/stripe-becs.js": "/js/clients/payments/stripe-becs.js?id=97ea3555a8504662eda5fce9c9115e5a", - "/js/clients/payments/stripe-eps.js": "/js/clients/payments/stripe-eps.js?id=749cba1332a29baa444b37cee2ade2d7", - "/js/clients/payments/stripe-ideal.js": "/js/clients/payments/stripe-ideal.js?id=34cf4ee3f189427fb69d0df8f5a4b766", - "/js/clients/payments/stripe-przelewy24.js": "/js/clients/payments/stripe-przelewy24.js?id=448b197a1d94b4408e130b5b8b1c2e53", - "/js/clients/payments/stripe-browserpay.js": "/js/clients/payments/stripe-browserpay.js?id=7015e43eb5f9f9f2f45f54b41b5780a0", - "/js/clients/payments/stripe-fpx.js": "/js/clients/payments/stripe-fpx.js?id=243c2929386b10c6a0c49ca3bcabfb2d", - "/css/app.css": "/css/app.css?id=0cb847167b91d8db2ca50d30e0d691ae", + "/js/app.js": "/js/app.js?id=19300612c6880925e8043b61e8d49632", + "/js/clients/payment_methods/authorize-authorize-card.js": "/js/clients/payment_methods/authorize-authorize-card.js?id=9fb77e87fe0f85a367050e08f79ec9df", + "/js/clients/payments/authorize-credit-card-payment.js": "/js/clients/payments/authorize-credit-card-payment.js?id=803182f668c39d631ca5c55437876da4", + "/js/clients/payments/forte-credit-card-payment.js": "/js/clients/payments/forte-credit-card-payment.js?id=6e9f466c5504d3753f9b4ffc6f947095", + "/js/clients/payments/forte-ach-payment.js": "/js/clients/payments/forte-ach-payment.js?id=1d10fcc52a1f15858e5da216f1df45ec", + "/js/clients/payments/stripe-ach.js": "/js/clients/payments/stripe-ach.js?id=7bed15f51bca764378d9a3aa605b8664", + "/js/clients/payments/stripe-klarna.js": "/js/clients/payments/stripe-klarna.js?id=5770e0d82d3843c68903744530f5ae73", + "/js/clients/payments/stripe-bacs.js": "/js/clients/payments/stripe-bacs.js?id=5739aad61ac7bbb20f2149d203849ff7", + "/js/clients/invoices/action-selectors.js": "/js/clients/invoices/action-selectors.js?id=d4f86ddee4e8a1d6e9719010aa0fe62b", + "/js/clients/purchase_orders/action-selectors.js": "/js/clients/purchase_orders/action-selectors.js?id=160b8161599fc2429b449b0970d3ba6c", + "/js/clients/purchase_orders/accept.js": "/js/clients/purchase_orders/accept.js?id=ddd4aa4069ea79411eeec367b7d5986d", + "/js/clients/invoices/payment.js": "/js/clients/invoices/payment.js?id=28221de8f1cb37f845ba4ec59bcd8867", + "/js/clients/payments/stripe-sofort.js": "/js/clients/payments/stripe-sofort.js?id=1c5493a4c53a5b862d07ee1818179ea9", + "/js/clients/payments/stripe-alipay.js": "/js/clients/payments/stripe-alipay.js?id=0274ab4f8d2b411f2a2fe5142301e7af", + "/js/clients/payments/checkout-credit-card.js": "/js/clients/payments/checkout-credit-card.js?id=4bd34a0b160f6f29b3096d870ac4d308", + "/js/clients/quotes/action-selectors.js": "/js/clients/quotes/action-selectors.js?id=6fb63bae43d077b5061f4dadfe8dffc8", + "/js/clients/quotes/approve.js": "/js/clients/quotes/approve.js?id=cdc76607aaf0b47a5a4e554e4177713d", + "/js/clients/payments/stripe-credit-card.js": "/js/clients/payments/stripe-credit-card.js?id=809de47258a681f0ffebe787dd6a9a93", + "/js/setup/setup.js": "/js/setup/setup.js?id=27560b012f166f8b9417ced2188aab70", + "/js/clients/payments/card-js.min.js": "/js/clients/payments/card-js.min.js?id=8ce33c3deae058ad314fb8357e5be63b", + "/js/clients/shared/pdf.js": "/js/clients/shared/pdf.js?id=be5307abc990bb44f2f92628103b1d98", + "/js/clients/shared/multiple-downloads.js": "/js/clients/shared/multiple-downloads.js?id=c2caa29f753ad1f3a12ca45acddacd72", + "/js/clients/linkify-urls.js": "/js/clients/linkify-urls.js?id=2b2fe55f926789abc52f19111006e1ec", + "/js/clients/payments/braintree-credit-card.js": "/js/clients/payments/braintree-credit-card.js?id=8e3b1c4c78c976ff0c43cb739c26b1f3", + "/js/clients/payments/braintree-paypal.js": "/js/clients/payments/braintree-paypal.js?id=5764a8d406c1eda848d073f10d178626", + "/js/clients/payments/wepay-credit-card.js": "/js/clients/payments/wepay-credit-card.js?id=dbba20d70fbebb326ddbc46115af9771", + "/js/clients/payment_methods/wepay-bank-account.js": "/js/clients/payment_methods/wepay-bank-account.js?id=b8706d7de6127f184ad19b2a810880be", + "/js/clients/payments/paytrace-credit-card.js": "/js/clients/payments/paytrace-credit-card.js?id=e0b1231a7bf6252672836222285c0f52", + "/js/clients/payments/mollie-credit-card.js": "/js/clients/payments/mollie-credit-card.js?id=bbab588ed009a93345bec520cbe66869", + "/js/clients/payments/eway-credit-card.js": "/js/clients/payments/eway-credit-card.js?id=31d068e55757636f34834bc2494250df", + "/js/clients/payment_methods/braintree-ach.js": "/js/clients/payment_methods/braintree-ach.js?id=6d8c7fd66d911b20cdc4248e33db1b3a", + "/js/clients/payments/square-credit-card.js": "/js/clients/payments/square-credit-card.js?id=b180fd6378d3723d3e9133e0b1943ac6", + "/js/clients/statements/view.js": "/js/clients/statements/view.js?id=7971b212e8a849fe36bfe915f81023bd", + "/js/clients/payments/razorpay-aio.js": "/js/clients/payments/razorpay-aio.js?id=c36ab5621413ef1de7c864bc8eb7439e", + "/js/clients/payments/stripe-sepa.js": "/js/clients/payments/stripe-sepa.js?id=0e3a5b2c1c8af491d577da6e84d2c219", + "/js/clients/payment_methods/authorize-checkout-card.js": "/js/clients/payment_methods/authorize-checkout-card.js?id=e43f862d70d8710761f0856e528ec3d1", + "/js/clients/payments/stripe-giropay.js": "/js/clients/payments/stripe-giropay.js?id=72ad4ad19297f211c2e6d0fa1fa1f76d", + "/js/clients/payments/stripe-acss.js": "/js/clients/payments/stripe-acss.js?id=90b1805b1ca0264474b38054a2664c5b", + "/js/clients/payments/stripe-bancontact.js": "/js/clients/payments/stripe-bancontact.js?id=03e5d7ee187e76b0b7c16bfa91804a8a", + "/js/clients/payments/stripe-becs.js": "/js/clients/payments/stripe-becs.js?id=de2bd0ef2859e19e4f98ea9d6d11cb54", + "/js/clients/payments/stripe-eps.js": "/js/clients/payments/stripe-eps.js?id=213d9ad34a79144a0d3345cb6a262e95", + "/js/clients/payments/stripe-ideal.js": "/js/clients/payments/stripe-ideal.js?id=0a6b434e3849db26c35a143e0347e914", + "/js/clients/payments/stripe-przelewy24.js": "/js/clients/payments/stripe-przelewy24.js?id=3d53d2f7d0291d9f92cf7414dd2d351c", + "/js/clients/payments/stripe-browserpay.js": "/js/clients/payments/stripe-browserpay.js?id=db71055862995fd6ae21becfc587a3de", + "/js/clients/payments/stripe-fpx.js": "/js/clients/payments/stripe-fpx.js?id=914a6846ad1e5584635e7430fef76875", + "/css/app.css": "/css/app.css?id=e4a77372c1d7aa003b6f548a9fddfd5b", "/css/card-js.min.css": "/css/card-js.min.css?id=62afeb675235451543ada60afcedcb7c", "/vendor/clipboard.min.js": "/vendor/clipboard.min.js?id=15f52a1ee547f2bdd46e56747332ca2d" } From 9c672e9bb1c39c360a04e66242294eb3f75faa8e Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 30 Jan 2023 08:46:39 +0100 Subject: [PATCH 87/88] Minor fixes --- app/PaymentDrivers/Stripe/BACS.php | 12 ++++++------ app/PaymentDrivers/StripePaymentDriver.php | 2 +- .../gateways/stripe/bacs/authorize.blade.php | 4 +++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/PaymentDrivers/Stripe/BACS.php b/app/PaymentDrivers/Stripe/BACS.php index 76013ac71073..e772bd6e13f9 100644 --- a/app/PaymentDrivers/Stripe/BACS.php +++ b/app/PaymentDrivers/Stripe/BACS.php @@ -113,25 +113,25 @@ class BACS return $this->processSuccessfulPayment($state['payment_intent']); } - return $this->processUnsuccessfulPayment(""); + return $this->processUnsuccessfulPayment("An unknown error occured."); } - public function processSuccessfulPayment($payment_id) + public function processSuccessfulPayment($payment_intent) { UpdateCustomer::dispatch($this->stripe->company_gateway->company->company_key, $this->stripe->company_gateway->id, $this->stripe->client->id); $data = [ - 'payment_method' => $payment_id['id'], + 'payment_method' => $payment_intent['id'], 'payment_type' => PaymentType::BACS, - 'amount' => $this->stripe->convertFromStripeAmount($payment_id->amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()), - 'transaction_reference' => $payment_id['id'], + 'amount' => $this->stripe->convertFromStripeAmount($payment_intent->amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()), + 'transaction_reference' => $payment_intent['id'], 'gateway_type_id' => GatewayType::BACS, ]; $payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING); SystemLogger::dispatch( - ['response' => $payment_id, 'data' => $data], + ['response' => $payment_intent, 'data' => $data], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index e38ab4bb3b5a..4e670da4e66e 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -263,7 +263,7 @@ class StripePaymentDriver extends BaseDriver && $this->client->currency() && in_array($this->client->currency()->code, ['EUR', 'DKK', 'GBP', 'NOK', 'SEK', 'AUD', 'NZD', 'CAD', 'PLN', 'CHF', 'USD']) && isset($this->client->country) - && in_array($this->client->company->country()->getID(), ['840']) + && in_array($this->client->company->country()->id, ['840']) && in_array($this->client->country->iso_3166_3, ['AUT','BEL','DNK','FIN','FRA','DEU','IRL','ITA','NLD','NOR','ESP','SWE','GBR','USA'])) { $types[] = GatewayType::KLARNA; } 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 f088cadd1315..9b278815f070 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/authorize.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/authorize.blade.php @@ -23,7 +23,9 @@ - + @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.method')]) + {{ ctrans('texts.bacs') }} + @endcomponent @component('portal.ninja2020.gateways.includes.pay_now', ['id' => 'authorize-bacs']) {{ ctrans('texts.add_payment_method') }} @endcomponent From e0271b7b6a6ffc56b17a22b17db8d07a41cee7b3 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 30 Jan 2023 08:56:59 +0100 Subject: [PATCH 88/88] Minor fixes --- app/PaymentDrivers/StripePaymentDriver.php | 41 ++++++++++--------- .../gateways/stripe/bacs/authorize.blade.php | 1 + 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 4e670da4e66e..758dd9688a94 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -735,26 +735,29 @@ class StripePaymentDriver extends BaseDriver // Store payment token for Stripe BACS $this->init(); $setup_intent = $this->stripe->setupIntents->retrieve($request->data['object']['setup_intent'], []); - $this->client = Client::where('id', ClientGatewayToken::where('gateway_customer_reference', $request->data['object']['customer'])->first()->client_id)->first(); - $customer = $this->findOrCreateCustomer(); - $this->attach($setup_intent->payment_method, $customer); - $payment_method = $this->getStripePaymentMethod($setup_intent->payment_method); - $payment_meta = new \stdClass; - $payment_meta->brand = (string) $payment_method->bacs_debit->sort_code; - $payment_meta->last4 = (string) $payment_method->bacs_debit->last4; - $payment_meta->state = 'unauthorized'; - $payment_meta->type = GatewayType::BACS; + $clientpayment_token = ClientGatewayToken::where('gateway_customer_reference', $request->data['object']['customer'])->first(); + if ($clientpayment_token){ + $this->client = Client::where('id', $clientpayment_token->client_id)->first(); + $customer = $this->findOrCreateCustomer(); + $this->attach($setup_intent->payment_method, $customer); + $payment_method = $this->getStripePaymentMethod($setup_intent->payment_method); + $payment_meta = new \stdClass; + $payment_meta->brand = (string) $payment_method->bacs_debit->sort_code; + $payment_meta->last4 = (string) $payment_method->bacs_debit->last4; + $payment_meta->state = 'unauthorized'; + $payment_meta->type = GatewayType::BACS; - $data = [ - 'payment_meta' => $payment_meta, - 'token' => $payment_method->id, - 'payment_method_id' => GatewayType::BACS, - ]; - $clientgateway = ClientGatewayToken::query() - ->where('token', $payment_method) - ->first(); - if (!$clientgateway){ - $this->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]); + $data = [ + 'payment_meta' => $payment_meta, + 'token' => $payment_method->id, + 'payment_method_id' => GatewayType::BACS, + ]; + $clientgateway = ClientGatewayToken::query() + ->where('token', $payment_method) + ->first(); + if (!$clientgateway){ + $this->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]); + } } return response()->json([], 200); } elseif ($request->type === "mandate.updated"){ 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 9b278815f070..a18484125868 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/bacs/authorize.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/bacs/authorize.blade.php @@ -26,6 +26,7 @@ @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.method')]) {{ ctrans('texts.bacs') }} @endcomponent + @component('portal.ninja2020.gateways.includes.pay_now', ['id' => 'authorize-bacs']) {{ ctrans('texts.add_payment_method') }} @endcomponent