diff --git a/app/PaymentDrivers/Square/CreditCard.php b/app/PaymentDrivers/Square/CreditCard.php index 1075b0a292ad..f95428c04ebb 100644 --- a/app/PaymentDrivers/Square/CreditCard.php +++ b/app/PaymentDrivers/Square/CreditCard.php @@ -21,6 +21,7 @@ use App\Models\Invoice; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; +use App\PaymentDrivers\Common\LivewireMethodInterface; use App\PaymentDrivers\Common\MethodInterface; use App\PaymentDrivers\SquarePaymentDriver; use App\Utils\Traits\MakesHash; @@ -29,7 +30,7 @@ use Illuminate\Http\Request; use Illuminate\View\View; use Square\Http\ApiResponse; -class CreditCard implements MethodInterface +class CreditCard implements MethodInterface, LivewireMethodInterface { use MakesHash; @@ -64,10 +65,7 @@ class CreditCard implements MethodInterface public function paymentView($data) { - $data['gateway'] = $this->square_driver; - $data['amount'] = $this->square_driver->payment_hash->data->amount_with_fee; - $data['currencyCode'] = $this->square_driver->client->getCurrencyCode(); - $data['square_contact'] = $this->buildClientObject(); + $data = $this->paymentData($data); return render('gateways.square.credit_card.pay', $data); } @@ -238,5 +236,24 @@ class CreditCard implements MethodInterface return false; } + /** + * @inheritDoc + */ + public function livewirePaymentView(array $data): string + { + return 'gateways.square.credit_card.pay_livewire'; + } + + /** + * @inheritDoc + */ + public function paymentData(array $data): array + { + $data['gateway'] = $this->square_driver; + $data['amount'] = $this->square_driver->payment_hash->data->amount_with_fee; + $data['currencyCode'] = $this->square_driver->client->getCurrencyCode(); + $data['square_contact'] = $this->buildClientObject(); + return $data; + } } diff --git a/resources/js/clients/payments/square-credit-card.js b/resources/js/clients/payments/square-credit-card.js index 4242eae5d651..358a672fdddb 100644 --- a/resources/js/clients/payments/square-credit-card.js +++ b/resources/js/clients/payments/square-credit-card.js @@ -8,6 +8,8 @@ * @license https://www.elastic.co/licensing/elastic-license */ +import { wait, instant } from '../wait'; + class SquareCreditCard { constructor() { this.appId = document.querySelector('meta[name=square-appId]').content; @@ -180,4 +182,9 @@ class SquareCreditCard { } } -new SquareCreditCard().handle(); +function boot() { + new SquareCreditCard().handle(); +} + +instant() ? boot() : wait('#square-credit-card-payment').then(() => boot()); + diff --git a/resources/views/portal/ninja2020/gateways/square/credit_card/pay.blade.php b/resources/views/portal/ninja2020/gateways/square/credit_card/pay.blade.php index f4841afd7295..a5512001bec7 100644 --- a/resources/views/portal/ninja2020/gateways/square/credit_card/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/square/credit_card/pay.blade.php @@ -7,6 +7,8 @@ + + + +
+ @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.includes.save_card') + + @component('portal.ninja2020.components.general.card-element-single') +
+
+ @endcomponent + + @include('portal.ninja2020.gateways.includes.pay_now') + + +@assets + @if ($gateway->company_gateway->getConfigField('testMode')) + + @else + + @endif + + @vite('resources/js/clients/payments/square-credit-card.js') +@endassets