#tarunmv30
1 messages · Page 1 of 1 (latest)
HI there, so you want to save a payment method from platform to a connected account?
Lets just say Mcdonalds is the restaurant im building an app for to make it easier to understand
Im building them an online food ordering app where customers can order food online, and I take 10% of the transaction and send the rest to the connected account
Ive been able to implement this successfully
the part thats tripping me up is I want users who decided to buy something from the mcdonalds app to be able to save their payment details so it makes it convenient to place orders
IM getting an error saying the customer cant be found and I think its because the customer is being saved to my platform account but im making the request from the connect account?
I can share my code and the error
Are you creating direct charges or destination charges?
i believe im using destination charges
Hi! Can you share the request ID (req_xxx)? Here's how you can find it: https://support.stripe.com/questions/finding-the-id-for-an-api-request
Find help and support for Stripe. Our support center provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
req_QC6kjae9M7rVoD
const items = req.body;
const { total, fee } = calculateOrderAmount(items);
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 my code to create the payment intent
It looks like you are doing a direct charge, not destination charge.
yes my fault i just followed the documentation it is a direct charge
Because you are making an API request on a connected account, Stripe will looks for the customer connected account, not platform, and err if the customer is not found,
interesting
So you should create a customer in the connected account, and attach a payment method to the customer in connected account as well
How can I create a customer object in the connect account?
exports.createStripeCustomer = functions.auth.user().onCreate(async (user) => {
try {
const customer = await stripe.customers.create({
email: user.email,
name: user.displayName,
metadata: {
firebaseUid: user.uid
}
});
await admin.auth().updateUser(user.uid, {
displayName: user.displayName,
emailVerified: user.emailVerified,
photoURL: user.photoURL,
disabled: user.disabled,
customClaims: {
stripeCustomerId: customer.id
}
});
console.log(`Stripe customer ${customer.id} created for user ${user.uid}`);
} catch (error) {
console.error(`Error creating Stripe customer for user ${user.uid}:`, error);
}
});```
I have this code too which creates a customer object everytime a user is made in my firestore database. Would you reccomend trying to make the customer at this point or directly in the create-payment-intent endpoint?
You should specify a stripe_account in the request.
By specifying a stripe_account, you are telling Stripe that you want to make an API call on behalf of a connected account. You can refer to this doc to learn more about making API request for connected account (https://stripe.com/docs/connect/authentication)
let me try be right back
thanks by the way!
So i'm now able to make the purchase however let me ask you this
what would the logic need to look like to be able to find the customer object associated with the user in the connected account so that their payment details can be saved for future payments? @thin harness