#sushbhat
1 messages · Page 1 of 1 (latest)
Where's the code that sets defaultValues on the Payment Element?
this.stripeService
.confirmPayment({
elements: this.paymentElement.elements,
confirmParams: {
payment_method_data: {
billing_details: {
name: this.checkoutForm.get('name').value,
email: this.checkoutForm.get('email').value,
address: {
line1: this.checkoutForm.get('address').value,
postal_code: this.checkoutForm.get('zipcode').value,
city: this.checkoutForm.get('city').value,
country: 'US'
},
},
},
},
redirect: 'if_required',
})
country is set to 'US' but it still shows india
You're not setting a default value for the Element there, you're just passing billing details on confirmation
They're 2 separate concepts
ok, any idea where to set it? Also, what exactly does this above code do? It simply hardcodes to US irrespective of what user selectes is it?
No, the fields selected in the Element will override those values: https://stripe.com/docs/js/payment_intents/confirm_payment#confirm_payment_intent-options-confirmParams-payment_method_data-billing_details
ok, is it possible to prefill and freeze it?
It's not, no
how about just prefill?
I'm not sure how the defaultValues parameter on the Payment Element maps to that ngx-stripe lib
Trying to figure it out from their docs
ok
Looks like you can pass options to the StripePaymentElement component: https://github.com/richnologies/ngx-stripe/blob/main/projects/ngx-stripe/src/lib/components/payment-element.component.ts#L104
Which is where you'd pass defaultValues: https://stripe.com/docs/js/elements_object/create_payment_element#payment_element_create-options
Maybe like this:
<ngx-stripe-payment
[appearance]="appearance"
[clientSecret]="elementsOptions?.clientSecret"
[options]="options"
></ngx-stripe-payment>
Where options is:
options: StripePaymentElementOptions = {
defaultValues: {
billingDetails: {
address: {
country: 'IN'
}
}
}
};
You can try, but depending on the BIN of the card we will likely request a country
ok