#BilalSaeedAlam
1 messages · Page 1 of 1 (latest)
Hi there i need some help i am using CARD element for future payments and i just want to confirm one thing, here in the form at the top there is email address, from where card element is getting this address?
yes
then this is either passed with customer or customer_email params when the Checkout Session was created
Okay lemme check then
Hi there
I ma using both customer and customer_email in the object but still didn't update that email?
const session = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
mode: "setup",
customer: customerId,
customer_email: customer_email,
success_url: ${process.env.APP_URL}/dashboard/user/account?session_id={CHECKOUT_SESSION_ID},
cancel_url: ${process.env.APP_URL}/dashboard/user/account?session=failed,
});
??
??
still didn't update that email?
could you elaborate on that? what did you expect to happen, where did you look and what did you see instead?
Yes
I am passing email to backend, where i check if there is customer then get customer id from stripe and if there is no customer then create it.
And then i am setting up checkout session, in this object first i was passing customer to customer id whcich i am getting above and still i am not getting updated email then i am passing customer_email to to email which i am getting from frontend.
Here are the steps and code:
1- Frontend Email
2- Getting customer id
let customerId = "";
// If customer is not register at stripe account
if (merchant.stripe_customer_id !== "") {
// Compare new fields with data in database and update info on stripe as needed
if (merchant.stripe_customer_email !== stripe_customer_email) {
// Update customer on stripe using same customer id
const customer = await stripe.customers.update(
merchant.stripe_customer_id,
{
email: stripe_customer_email,
}
);
// Update customer info into database
if (customer) {
await updateUserObjectService(merchant._id, {
stripe_customer_email: stripe_customer_email,
});
}
}
customerId = merchant.stripe_customer_id;
} else {
// Create new customer on stripe
const customer = await stripe.customers.create({
email: stripe_customer_email,
});
customerId = customer.id;
// Update customer info to database
await updateUserObjectService(merchant._id, {
stripe_customer_id: customer.id,
stripe_customer_email: stripe_customer_email,
});
}
3- Setting up session
const session = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
mode: "setup",
customer: customerId,
customer_email: customer_email,
success_url: ${process.env.APP_URL}/dashboard/user/account?session_id={CHECKOUT_SESSION_ID},
cancel_url: ${process.env.APP_URL}/dashboard/user/account?session=failed,
});
Now which email i am passing from frontend that should be the customer stripe email ehich i am updating in step 2. But on the checkout page i am getting anyother email.
So where this email is coming from
So where this email is coming from
it would be the
https://stripe.com/docs/api/checkout/sessions/create?lang=node#create_checkout_session-customer
If the Customer already has a valid email set, the email will be prefilled and not editable in Checkout.er.
But if customer want to update its email, like we are doing and we are updating stripe customer object as well with that email and then start session object so why that email is not showing?
It means customer email is not updated?
they can't update it using Checkout that way
the email will be prefilled and not editable
Okay but we can update it with customer object?
yep, you can