Show or hide post code in Stripe elements based on company settings

This commit is contained in:
Benjamin Beganović 2021-08-09 14:05:39 +02:00
parent dd2d490db3
commit 4e6477d441
3 changed files with 8 additions and 4 deletions

View File

@ -195,8 +195,9 @@ class StripePaymentDriver extends BaseDriver
$fields[] = ['name' => 'client_country_id', 'label' => ctrans('texts.country'), 'type' => 'text', 'validation' => 'required'];
}
if($this->company_gateway->require_postal_code)
if($this->company_gateway->require_postal_code) {
$fields[] = ['name' => 'client_postal_code', 'label' => ctrans('texts.postal_code'), 'type' => 'text', 'validation' => 'required'];
}
if ($this->company_gateway->require_shipping_address) {
$fields[] = ['name' => 'client_shipping_address_line_1', 'label' => ctrans('texts.shipping_address1'), 'type' => 'text', 'validation' => 'required'];

View File

@ -37,6 +37,7 @@ class StripeCreditCard {
createElement() {
this.cardElement = this.elements.create('card', {
hidePostalCode: document.querySelector('meta[name=stripe-require-postal-code]')?.content === "0",
value: {
postalCode: document.querySelector('meta[name=client-postal-code]').content,
}

View File

@ -2,14 +2,16 @@
@section('gateway_head')
@if($gateway->company_gateway->getConfigField('account_id'))
<meta name="stripe-account-id" content="{{ $gateway->company_gateway->getConfigField('account_id') }}">
<meta name="stripe-publishable-key" content="{{ config('ninja.ninja_stripe_publishable_key') }}">
<meta name="stripe-account-id" content="{{ $gateway->company_gateway->getConfigField('account_id') }}">
<meta name="stripe-publishable-key" content="{{ config('ninja.ninja_stripe_publishable_key') }}">
@else
<meta name="stripe-publishable-key" content="{{ $gateway->getPublishableKey() }}">
<meta name="stripe-publishable-key" content="{{ $gateway->getPublishableKey() }}">
@endif
<meta name="stripe-secret" content="{{ $intent->client_secret }}">
<meta name="only-authorization" content="">
<meta name="client-postal-code" content="{{ $client->postal_code ?? '' }}">
<meta name="stripe-require-postal-code" content="{{ $gateway->company_gateway->require_postal_code }}">
@endsection
@section('gateway_content')