7

I am trying to setup the following with Stripe:

  • A master account
  • Multiple sub-accounts (i.e. connected to the Master account via Stripe Connect app)
  • Enable payments to be made to a sub-account, with a percentage fee taken by the Master account per transaction.

I have created a Master account, and a sub account. I have connected the sub account to the Master account via Stripe Connect. I received and stored an access_token and a refresh_token at the end of the Stripe Connect process.

When payments are made, one payment can cover multiple items. I have the following code (PHP) to process the payment:

Stripe_Charge::create(array(
    "amount" => $amt,
    "currency" => "EUR",
    "source" => $stripeCardToken,
    "description" => $description),
    "application_fee_percent" => 0.5
),
    $stripeAccessToken
);

This is placed in a loop, for every item being paid for. It is also in a try / catch block with multiple Stripe exception catches. However, this method fails without any error being thrown.

Is this the correct class method to use? Is the 'source' field for the credit card token? Is there a way of tracking amounts paid against multiple items without using a loop? Is the $stripeAccessToken the sub-account's access_token returned from the Connect process, or the refresh_token? Or is it the Master Account Publishable / Secret key? Or something else? Can I use this format for the $stripeAccessToken, or do I have to instead use Stripe::setApiKey($stripeAccessToken) before the loop?

Both Master and sub-account are currently using the Test environment and a fake card, but I would like to test live transactions also.

Eamonn
  • 1,338
  • 2
  • 21
  • 53

1 Answers1

2

The first issue here is that you are trying to reuse a card token but those are one-time use so once you create a charge with a card token you can't create a new one.

If you want to charge your customer and split the payments between multiple sellers, you would need to use shared customers. This is the flow you would need to follow in your case:

  • Create a card token for your customer's card details with your publishable API key
  • Create a customer in your stripe account with your secret key.
  • For each of your sellers, you need to create a token for the customer that you then use to create a charge in your sellers accounts. You would have to create separate charges here for each seller but you don't have to ask your customer for his card details multiple times.

In case I misunderstood and all items would come from the same seller you wouldn't need to do all this and you'd need to follow this flow:

  • Create a card token for your customer's card details with their publishable API key that you got during the Connect flow.
  • Create a customer in their stripe account with their access_token that you got during the Connect flow, passed as the second parameter to the API call.
  • Create a charge for the total amount of the items the customer bought passing the customer id you got at the previous step and the access_token as a second parameter again.
koopajah
  • 23,792
  • 9
  • 78
  • 104
  • Thanks for that koopajah. The latter xample is what I was looking for. A follow-on question: Is there a way of putting through a single transaction that covers multiple items and have each item noted in the transaction description (other than just creating a really long string)? – Eamonn Mar 19 '15 at 16:36
  • The only solution I can think of is to create invoice items for each item and then create an invoice to bundle everything together – koopajah Mar 19 '15 at 20:52
  • Just to be clear you're saying if you had sold a widget for $10 with $9 going to two separate associates of yours, you'd need say charge the customer twice, say $5 going to assoc. Foo and a separate charge of $4 to assoc. Bar. – MCB Feb 29 '16 at 20:48
  • @MCB: Correct: https://support.stripe.com/questions/can-a-charge-s-funds-be-split-among-different-connected-accounts has details about this – koopajah Mar 01 '16 at 00:06