Reputation: 176
Hi I am trying to implement stripe connect where the platform takes an application fee but the connected user gets majority of charge.
Following this as my guide https://stripe.com/docs/connect/shared-customers
I have this as my code. The user is saved w/ default credit card source in another view.
Parse.Cloud.define("chargeCard", function(req, res){
stripe.tokens.create({
customer: req.params.customer,
}, {
stripe_account: req.params.stripeAccount,
}).then((token) => {
console.log("successfully created token");
stripe.charges.create({
amount: req.params.amount,
currency: req.params.currency,
source: token.id,
application_fee: req.params.fee,
}, {
stripe_account: req.params.stripeAccount,
}).then((charge) => {
console.log("successfully charged card");
res.success(charge);
}).catch((error) => {
console.log(error);
res.error(error.message);
});
}).catch((error) => {
console.log(error);
res.error(error.message);
});
});
But receive the error:
"You provided a customer without specifying a source. The default source of the customer is a source and cannot be shared from existing customer".
Im not able to specify its default source in the create token body. any help?
Upvotes: 1
Views: 296
Reputation: 176
This issue was with the users source. Although the user had a credit card source it is not "shareable" (as the error kinda states) , you need to create a shared source when using stripe-connect.
https://stripe.com/docs/sources/connect#creating-direct-charges
You want to use this instead of the above tokens.create for direct charges in stripe-connect.
stripe.sources.create({
customer: "cus_AFGbOSiITuJVDs",
usage: "reusable",
original_source: "src_19YP2AAHEMiOZZp1Di4rt1K6",
}, {
stripe_account: "{CONNECTED_STRIPE_ACCOUNT_ID}",
}).then(function(token) {
// asynchronously called
});
FYI: I do not save or attach this new source, kept the primary one and the regenerate a new token for each purchase since my application is 1 to many sellers.
Upvotes: 0