4

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).

WJA
  • 6,676
  • 16
  • 85
  • 152
  • For the ones interested, here is the solution (source code): https://www.noodl.io/market/product/P201512041604740/stripe-payments-kit-server-side-api-to-process-all-payments-with-a-live-example-in-ionic – WJA Jun 27 '17 at 06:51
  • This question is still relevant for me in 2020. – Jaap Weijland Oct 07 '20 at 13:38

3 Answers3

5

In case anybody is still having this issue, looks like Stripe now has a transfer_group property that can be placed on a PaymentIntent. This transfer_group is some string you come up with and can attach it to multiple transfers.

Read more about it here: https://stripe.com/docs/connect/charges-transfers

You can see that in the example, there are multiple transfers happening for the same PaymentIntent.

caseyli
  • 479
  • 5
  • 9
  • According to the documentation you provided, this solution is only available for these regions: Australia, Europe, Japan, Malaysia, New Zealand, Singapore, and the U.S. So if you live in another country I think there should be a workaround. – Manuel Duarte Nov 22 '20 at 18:04
1

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

Matthew Arkin
  • 4,460
  • 2
  • 27
  • 28
  • Ok so lets say you have 4 accounts. You would then first generate the stripeToken in the normal way. Then take this token, create 4 customer accounts and then save this token in their accounts. Then you follow up by creating 1 charge token using Shared Customers which you can use to create the charge? – WJA Feb 25 '16 at 01:56
  • you don't need to create customers in the connected account (though there could be reasons to). You need 4 tokens from the shared customers code (1 token per connected account) – Matthew Arkin Feb 25 '16 at 02:23
  • Tried that and have one final question: http://stackoverflow.com/q/36520164/4262057 – WJA Apr 09 '16 at 17:52
0

Take a look at transfer group:

// Set your secret key. Remember to switch to your live secret key in 

production.
// See your keys here: https://dashboard.stripe.com/apikeys
const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc');

// Create a PaymentIntent:
const paymentIntent = await stripe.paymentIntents.create({
  amount: 10000,
  currency: 'usd',
  payment_method_types: ['card'],
  transfer_group: '{ORDER10}',
});

// Create a Transfer to the connected account (later):
const transfer = await stripe.transfers.create({
  amount: 7000,
  currency: 'usd',
  destination: '{{CONNECTED_STRIPE_ACCOUNT_ID}}',
  transfer_group: '{ORDER10}',
});

// Create a second Transfer to another connected account (later):
const secondTransfer = await stripe.transfers.create({
  amount: 2000,
  currency: 'usd',
  destination: '{{OTHER_CONNECTED_STRIPE_ACCOUNT_ID}}',
  transfer_group: '{ORDER10}',
});

reference: https://stripe.com/docs/connect/charges-transfers

habib
  • 1,454
  • 17
  • 31