#jovan_paymentelement-country
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1226991794923901029
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
@ocean thistle The country is saved on the PaymentMethod the same way after you call confirmPayment()
jovan_paymentelement-country
Which object or method should I use here? to get the value of the country input?
Sorry I don't really get the ask, this is just a picture of a raw JS object.
Can you share your real code where you call confirmPayment() instead?
function handleCardPayment(){
const { error: submitError } = await elements.submit();
if (submitError) {
handleError(submitError);
return;
}
const fields = {
country: 'I WANT TO PUT COUNTRY VALUE HERE',
}
//Fetching Client Secret in Server
const { clientSecret, status, message, link } = await fetchClientSecret(fields);
if (status == 'error') {
handleError({'message' : message});
return;
}
// Confirm the PaymentIntent using the details collected by the Payment Element
const setupIntent = await stripe.confirmSetup({
elements,
clientSecret,
redirect: 'if_required'
});
}
this one
As you can see, I want to put the country value on fields object.
yeah you can't you will only know the country after confirmSetup() completes
Oh then why you can do this on payment request button:
const fullName = ev.paymentMethod.billing_details.name;
where there's a paymentMethod object
Are they different?
yes they are completely different integration paths.
In your flow you get a SetupIntent seti_123 back and that will have payment_method: 'pm_123' and then on your server you can retrieve that object and look at the billing_details on it. Not possible in JS client-side
Okay, this is my current form. Is it really not possible to get the country value here?
It is, after confirmSetup(). Impossible before.
Okay, I'll give it a try
Another question, I just wanted to confirm if I implemented it correctly. Is this code will automatically charge the card after 30 days trial ended?
// Create a subscription with 30 days trial
$subscription = $this->stripe->subscriptions->create([
'customer' => $customer->id,
'items' => [
[
'price' => $_ENV['STARTER_PLAN'],
'quantity' => $fields['client_allowed_members']
]
],
'trial_period_days' => 30,
'payment_behavior' => 'default_incomplete',
'payment_settings' => [
'save_default_payment_method' => 'on_subscription',
'payment_method_types' => ['card'],
],
'expand' => ['pending_setup_intent'],
// 'metadata' => $metadata
]);
I tried to simulate it but I think it's working well?
yep as long as you collect card details for that trial it will automatically charge as expected which you seem to have done!
Thanks for the confirmation!
I'll try getting the value of country now after confirmSetup()
Thanks I got it.
Is there any reason why country cannot be fetched before confirmSetup?
๐ There's no change event that would return this information so you need to wait until a customer submits the country value
Is it for security purposes?
No, not for security purposes
If you're interested in retrieving address details from the customer as they're providing them, you may want to look into using the Address Element: https://docs.stripe.com/elements/address-element/collect-addresses