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
paymentelement.Using the
fieldsparam won't help - you have two values:autoandnever. There is noalwaysvalue.autowill only conditionally show the field.Concretely, the
paymentelement 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
paymentelement withnever), or use anaddresselement in conjunction with yourpaymentelement:https://stripe.com/docs/elements/address-element