I am trying to integrate Stripe payments into my project, but it seems that Stripe's payment element doesn't show the postal code field. Is there a way to display that field?
Here is my code
<script src="https://js.stripe.com/v3/"></script>
<script>
const stripe = Stripe('PUBLIC_KEY');
const elements = stripe.elements({
clientSecret: clientSecret,
theme: 'stripe',
});
const element = elements.create("payment");
element.mount('#card-stripe');
</script>
There is no way to 'force-display' fields with the payment
element.
Using the fields
param won't help - you have two values: auto
and never
. There is no always
value. auto
will only conditionally show the field.
Concretely, the payment
element will show the postal code field only if the card BIN matches a card that requires postal code collection - e.g. US or GB cards. You can also witness this by changing the country field on the element.
If you want to always display and collect a postal code, your options are to create the postal code element yourself (in which case you would omit it from the payment
element with never
), or use an address
element in conjunction with your payment
element:
https://stripe.com/docs/elements/address-element