#mauriver21
1 messages ยท Page 1 of 1 (latest)
Hi there, are you using the Prebuilt checkout page or the Custom payment flow?
It's a custom payment flow, I'm working with the CardElement only
OK. You can use CardElement with SetupIntent.
This is the doc that tells how to use CardElement https://stripe.com/docs/payments/card-element?client=react, you should replace PaymentIntent with SetupIntent, and call stripe.confirmCardSetup instead of stripe.confirmCardPayment
Thxs, I think this give me a clue of how to solve it. One last question, the confirmCardPayment associates the payment method to the customer object?
If you set the PaymentIntent's setup_future_suage and cutomer. Then the payment_method will be attached to the customer
Thxs for the guidance, I will take a look. This was very helpful
@viscid hazel your solution didn't work ๐ , the card element expects a payment intent key, but I need to work with a setup intent key
can you share with me your code?
Client side code:
const handleClick = async () => {
if (!stripe || !elements) return;
try {
setProcessing(true);
const { id, setupIntentClientSecret } = await lessonCreate({
name: orderName,
email: orderEmail,
});
setCustomerId(id);
const { error, rest } = await stripe.confirmCardPayment(
setupIntentClientSecret,
{
payment_method: {
card: elements.getElement(CardElement),
},
}
);
console.log(rest);
if (error) {
setError(error);
return;
}
setSucceeded(true);
} catch (error) {
switch (error.name) {
case "CustomerExists":
setError(error.message);
setExistingCustomer({
customerId: error.data.id,
email: error.data.email,
});
break;
default:
console.error(error);
}
} finally {
setProcessing(false);
}
};
Server side code:
app.post('/lessons', async (req, res) => {
try {
const { email } = req.body;
const foundCustomers = await stripe.customers.list({
email,
});
const [foundCustomer] = foundCustomers.data;
if (Boolean(foundCustomer)) {
throw newError('CustomerExists', 409, {
message: 'This customer already exists',
data: { id: foundCustomer.id, email: foundCustomer.email },
});
}
const customer = await stripe.customers.create({
...req.body,
});
const setupIntent = await stripe.setupIntents.create({
customer: customer.id,
payment_method_types: ['card'],
});
res.send({
...customer,
setupIntentClientSecret: setupIntent.client_secret,
});
} catch (error) {
handleError(res, error);
}
});
stripe.confirmCardPayment( ->. it should be stripe.confirmCardSetup() as I explained earlier.
You mentioned earlier confirmCardPayments
There are lots of gaps in the docs for setup intents.
Yes, what I mean, as a feedback, the docs about setup intents is very hidden and has many gaps, specifically for custom flows.
I've just used confirmCardSetup and worked as expected ๐
That's great and thanks a lot for your feedback
Also I'd suggest to use PaymentElement so that your customer have more payment method options
Related to attaching the payment method to the customer obj, you mentionend to use "setup_future_usage" however this is for payment intents. For setup intents may I use stripe.retrieveSetupIntent(clientSecret) ?
The purpose of SetupIntent is to setup a payment_method for a customer, so there's no setup_future_usage param in SetupIntent and you don't need to specify one
but using stripe.confirmCardSetup, visualizing the dashboard, the customer still doesn't show an associated payment method
give me your setupIntent ID
seti_1MRRRMG7PaZ8mE7W1VYw76n6
Here payment method appears empty
But clicking inside, it appears
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
May be is a bug in the dashboard?
you can view the payment method here
No, the payment methods are shown in the customer details page, not list page.
so which is the purpose of this payment method column?
Checking the overview, It's working as expected, it got me confused the list view of the dashboard with this empty column ๐ .
Can you share with me the URL?
Oh I see, that payment method column shows the default payment method attached to the customer
This customer doesn't have a default payment method, and that's why it shows empty
That's good to know ๐
I agree the UI should be less confusing, thanks for your feedback!