Search code examples
node.jsstripe-paymentsstripe-connect

Stripe Connect with Multiple Destination Account Ids


We can create payments and charge an application_fee with Stripe connect in NodeJS as follows:

// Get the credit card details submitted by the form
var token = request.body.stripeToken;

// Create the charge on Stripe's servers - this will charge the user's card
stripe.charges.create(
  {
    amount: 1000, // amount in cents
    currency: "eur",
    source: token,
    description: "Example charge",
    application_fee: 123 // amount in cents
  },
  {stripe_account: CONNECTED_STRIPE_ACCOUNT_ID},
  function(err, charge) {
    // check for `err`
    // do something with `charge`
  }
);

The source can be obtained using the Stripe native checkout handler.

However, if I have a marketplace and I want to perform a checkout of multiple items that have different authors, how would I then proceed?

The problem is that I would need to create multiple charges from one source. But then the system will think that there is an error as the total amount (used when retrieving the stripeToken source) does not match the individual amounts (of the individual items).


Solution

  • A single charge can not be split between multiple accounts.

    1) You'd need to save the token to a customer in the platform account. 2) Create a new token per account you want to create the charge in using "Shared Customers"

    // Create a Token from the existing customer on the platform's account
    stripe.tokens.create(
      { customer: CUSTOMER_ID, card: CARD_ID },
      { stripe_account: CONNECTED_STRIPE_ACCOUNT_ID }, // id of the connected account
      function(err, token) {
        // callback
      }
    

    3) Using the new token create a charge with the code you have in your question