#james_67481
1 messages · Page 1 of 1 (latest)
Hi there!
hi
Can you share the customer ID (cus_xxx) you are using in your request?
cus_OVGS2e7vSQASO4
{
"stripe_user_id" : "acct_1Nhud0CjGTmRljNw",
"stripe_customer_id" : "cus_OVGS2e7vSQASO4",
"amount" : 200,
"currency" : "gbp"
}
That customer doesn't have any payment method saved: https://dashboard.stripe.com/test/customers/cus_OVGS2e7vSQASO4
So it's expected that the API call returns an empty list
this is how I setup the intent exports.createSetupIntents = async (req, res) => {
try {
const { stripe_user_id } = req.body
const customer = await stripe.customers.create({
stripeAccount: stripe_user_id
})
const ephemeralKey = await stripe.ephemeralKeys.create(
{ customer: customer.id },
{ apiVersion: '2020-08-27', stripeAccount: stripe_user_id }
)
const setupIntent = await stripe.setupIntents.create(
{
customer: customer.id,
automatic_payment_methods: {
enabled: true
}
},
{
stripeAccount: stripe_user_id
}
)
res.json({
setupIntent: setupIntent.client_secret,
ephemeralKey: ephemeralKey.secret,
stripeCustomerId: customer.id,
publishable_key: process.env.STRIPE_PUBLISHABLE_KEY
})
} catch (err) {
console.log(err)
}
}
work fine
Yes I can see that you created a SetupIntent: https://dashboard.stripe.com/test/logs/req_e2ga5yrgRYBcdK
But then the next step is to collect a payment method on the frontend and confirm the SetupIntent.
Yes, react native is the front end. useEffect(() => {
const initializePaymentSheet = async () => {
try {
const { setupIntent, ephemeralKey, stripeCustomerId, publishable_key } =
await fetchPaymentSheetParams(params);
const { error } = await initPaymentSheet({
merchantDisplayName: "Jerur, Inc.",
customerId: stripeCustomerId,
customerEphemeralKeySecret: ephemeralKey,
setupIntentClientSecret: setupIntent,
});
if (!error) {
setPublishableKey(publishable_key)
setPaymentSheetStatus(true)
params.stripeCustomerId = stripeCustomerId
} else {
console.log(error.message);
}
} catch (error) {
console.log(error.message);
}
};
getOne("STRIPE_CUSTOMER").then((customer) => {
if (customer) {
setCustomerId(customer)
} else {
initializePaymentSheet();
}
})
}, [params]);
const openPaymentSheet = useCallback(async () => {
const {error} = await presentPaymentSheet();
if (!error) {
} else {
console.log(error)
}
}, [presentPaymentSheet]);
worked fine,
and payment details saved
I'm not sure why you are showing me all your code.
You created this SetupIntent for the customer you shared earlier: seti_1NiFvPCjGTmRljNwBveIifIU
But then you never did anything with that SetupIntent, so the customer doesn't have any payment method saved.
I just follow this steps, after creating the intent, the next step, I though is for the payment sheet to save the customer payment details for the future.
the next step, I though is for the payment sheet to save the customer payment details for the future.
Correct! But for the SetupIntent you shared you didn't do this step.
seti_1NiFvPCjGTmRljNwBveIifIU has status: "requires_payment_method"
is a frontend step. React native
useEffect(() => {
const initializePaymentSheet = async () => {
try {
const { setupIntent, ephemeralKey, stripeCustomerId, publishable_key } =
await fetchPaymentSheetParams(params);
const { error } = await initPaymentSheet({
merchantDisplayName: "Jerur, Inc.",
customerId: stripeCustomerId,
customerEphemeralKeySecret: ephemeralKey,
setupIntentClientSecret: setupIntent,
});
if (!error) {
setPublishableKey(publishable_key)
setPaymentSheetStatus(true)
params.stripeCustomerId = stripeCustomerId
} else {
console.log(error.message);
}
} catch (error) {
console.log(error.message);
}
};
getOne("STRIPE_CUSTOMER").then((customer) => {
if (customer) {
setCustomerId(customer)
} else {
initializePaymentSheet();
}
})
}, [params]);
const openPaymentSheet = useCallback(async () => {
const {error} = await presentPaymentSheet();
if (!error) {
} else {
console.log(error)
}
}, [presentPaymentSheet]);
here is the react native side of the code.
Ok, what step I am missing pls
Did the payment sheet opened? Did you see any error message? What exactly happened?
no, the payment open fine and the green button label was setup. Aftering my payment details, it give and ok and close when any error on the console
const openPaymentSheet = useCallback(async () => {
const {error} = await presentPaymentSheet();
if (!error) {
} else {
console.log(error)
}
}, [presentPaymentSheet]);
no error message came from this line console.log(error)
*sorry without any error
Can you try again and share with me the new SetupIntent ID (seti_xxx)?
ok
done, this the setIntent id seti_1NiGaoCjGTmRljNwkr6Hbdmf
full object {
id: 'seti_1NiGaoCjGTmRljNwkr6Hbdmf',
object: 'setup_intent',
application: 'ca_OGfMWcHsxZJgf2IrxdpidiiwBTlUBlSo',
automatic_payment_methods: { allow_redirects: 'always', enabled: true },
cancellation_reason: null,
client_secret: 'seti_1NiGaoCjGTmRljNwkr6Hbdmf_secret_OVH9hkoyM54xFcbeNyvOCS9qy4frZKq',
created: 1692795326,
customer: 'cus_OVH9qWlIowRRN6',
description: null,
flow_directions: null,
last_setup_error: null,
latest_attempt: null,
livemode: false,
mandate: null,
metadata: {},
next_action: null,
on_behalf_of: null,
payment_method: null,
payment_method_options: {
card: {
mandate_options: null,
network: null,
request_three_d_secure: 'automatic'
}
},
payment_method_types: [ 'card' ],
single_use_mandate: null,
status: 'requires_payment_method',
usage: 'off_session'
}
This time it worked, I see status: "succeeded" on the SetupIntent
And the custom does have a payment methhod set
So looks like eveything wored as expected?
Let me try and charge the customer, I have not done that.
yes, it works. So what was the issue, is it from my end, I have not change my code
Glad that the issue is resolved!