#tarunmv30
1 messages · Page 1 of 1 (latest)
IM trying to retrieve a customer to save their payment details for future payments
the customer ID is the cus_NhJH.... string right?
Hi, what does your request to save the Payment Method look like?
Yes, the customer is would start wit cus_
this is my server side function for creating the payment intent
const items = req.body;
const { total, fee } = calculateOrderAmount(items);
//retrieves the customer based on the user ID
const customer = await stripe.customers.retrieve(
'cus_NhJHZYH5HcMDja'
);
// Generate an ephemeral key for the customer
const ephemeralKey = await stripe.ephemeralKeys.create(
{ customer: customer.id },
{ apiVersion: '2020-08-27', stripeAccount: 'acct_1MsyJPCWAlRghLO7' }
);
// Create a PaymentIntent with the order amount and currency
const paymentIntent = await stripe.paymentIntents.create({
amount: total,
currency: 'usd',
application_fee_amount: fee,
customer: customer.id,
setup_future_usage: 'off_session',
automatic_payment_methods: {
enabled: true,
},
}, {
stripeAccount: 'acct_1MsyJPCWAlRghLO7',
});
// Return the necessary information to the client
res.send({
customer: customer.id,
ephemeralKey: ephemeralKey.secret,
paymentIntent: paymentIntent.client_secret,
publishableKey: 'pk_test_51MSCbfJMYkCh6QmLjYSQLK5gPtmLvaUMn0KrXsbFVnqVROCRere3kLrAQnKOT2Uepb5fRqv34vjgNAArl8wzPwWd00OoOZlDFj' // replace with your own publishable key
});
});```
I think you want to look at this guide, https://stripe.com/docs/payments/save-during-payment?platform=web#create-the-paymentintent
You'd need to specify: setup_future_usage: : https://stripe.com/docs/api/payment_intents/create#create_payment_intent-setup_future_usage to save the payment method during a payment.
Let me see what im doing wrong just a moment
const items = req.body;
const { total, fee } = calculateOrderAmount(items);
//retrieves the customer based on the user ID
const customer = await stripe.customers.retrieve(
'cus_NhJHZYH5HcMDja'
);
// Generate an ephemeral key for the customer
const ephemeralKey = await stripe.ephemeralKeys.create(
{ customer: customer.id },
{ apiVersion: '2020-08-27', stripeAccount: 'acct_1MsyJPCWAlRghLO7' }
);
// Create a PaymentIntent with the order amount and currency
const paymentIntent = await stripe.paymentIntents.create({
amount: total,
currency: 'usd',
application_fee_amount: fee,
customer: customer.id,
setup_future_usage: 'on_session',
automatic_payment_methods: {
enabled: true,
},
}, {
stripeAccount: 'acct_1MsyJPCWAlRghLO7',
});
// Return the necessary information to the client
res.send({
customer: customer.id,
ephemeralKey: ephemeralKey.secret,
paymentIntent: paymentIntent.client_secret,
publishableKey: 'pk_test_51MSCbfJMYkCh6QmLjYSQLK5gPtmLvaUMn0KrXsbFVnqVROCRere3kLrAQnKOT2Uepb5fRqv34vjgNAArl8wzPwWd00OoOZlDFj' // replace with your own publishable key
});
});```
this is the code
the error im getting is that a user with that ID does not exist even though i sent you the picture of the user daniel with that ID
Error: No such customer: 'cus_NhJHZYH5HcMDja'
THis the user im testing with
Can you share the request id for this error please
That is because the customer, cus_NhJHZYH5HcMDja is created, https://dashboard.stripe.com/test/logs/req_0PLwqLf52VE7ik on your account ending in QmL. Meanwhile, this request is being made on the connected account ending in LO7.
If you make the same request directly on your account, QmL it should work.
How would I do that im confused
and thank you for your help by the way!
const customerId = 'cus_NhJHZYH5HcMDja';
const accountId = 'acct_1MsyJPCWAlRghLO7';
const customer = await stripe.customers.retrieve(customerId, {
stripeAccount: accountId
});
is this fix sort of what youre talking about?
You use the API key from your QmL account, and make that request
There is an example code here: https://stripe.com/docs/api/customers/retrieve
youre talking about the publishable key right?
Also I think im getting confused because im trying to save the customers payment detail, but im using multi party payments. Is it possible to save card details while using connect to facilitate online orders for a restaurant
You should use the secret key: https://stripe.com/docs/api/customers/retrieve
Yes, you can use the Stripe Account header: https://stripe.com/docs/connect/authentication to make these calls. I recommend that you read through this document and start fresh from creating the customer with the account header.
Can you try that please?
yes thank you