Eamonn Eamonn - 3 years ago 124
PHP Question

Transactions via Stripe Connect

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

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:

"amount" => $amt,
"currency" => "EUR",
"source" => $stripeCardToken,
"description" => $description),
"application_fee_percent" => 0.5

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

Answer Source

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.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download