0

My PHP application is using Stripe. People sell their products on my platform and I'm getting my fee from it. I already have a link that makes it possible for users to connect their Stripe accounts to my platform. I get authentication code and then I use it to get access token. The response is as follows (replaced long random strings with abcd):

{
  "token_type": "bearer",
  "stripe_publishable_key": "pk_test_abcd",
  "scope": "read_write",
  "livemode": false,
  "stripe_user_id": "acct_abcd",
  "refresh_token": "rt_abcd",
  "access_token": "sk_test_abcd"
}

Then, I'm trying to create a test charge for a connected account:

$charge = Stripe\Charge::create([
    'amount'   => 1000,
    'currency' => 'usd',
    'source'   => 'sk_test_abcd',
], ['stripe_account' => 'acct_abcd']);

But I'm getting the following error:

No such token: sk_test_abcd

What am I doing wrong?

Robo Robok
  • 21,132
  • 17
  • 68
  • 126

1 Answers1

0

When creating a charge, the source parameter should be set to a card token ID. In your example, you're using the destination account's API key, which is a different concept altogether. You need to use either the source parameter with a card token returned by Checkout or Stripe.js, or the customer parameter with the ID of a customer object that you created previously.

As a side note, you don't need to worry about the API keys you get in the response in the last step of the Connect OAuth flow. The only field of interest is the stripe_user_id field containing the account's ID. You should save this ID in your database, so you can then use it with the Stripe-Account header to issue API requests on behalf of this account.

Ywain
  • 16,854
  • 4
  • 51
  • 67
  • Are you sure it must be a card's token? Stripe's OAuth documentation is not very clear about it: https://stripe.com/docs/connect/payments-fees - how can I send money to a person without knowing their cards? I just want to send money to their Stripe account. – Robo Robok Mar 17 '16 at 12:40
  • Stripe cannot be used as a money transmission service or as an e-wallet. The purpose of Stripe Connect is to allow platforms to accept charges on behalf of other accounts. So you can't just send money from your Stripe account to another account -- you would need to create a charge from an actual card, and that charge would have to be for a good or service provided by the connected account's owner. – Ywain Mar 17 '16 at 16:05
  • @Ywain can i send the money to my stripe connected accounts if not can you please suggest an alternative way for that using stripe. – Muhammad Usama Mashkoor Jul 31 '16 at 16:32