Skip to content

Instantly share code, notes, and snippets.

@ehongyu
Last active March 27, 2017 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehongyu/8f270ece88fffdd99d586e45b2907dee to your computer and use it in GitHub Desktop.
Save ehongyu/8f270ece88fffdd99d586e45b2907dee to your computer and use it in GitHub Desktop.
<?php
// include stripe PHP lib path here
// set up API key
\Stripe\Stripe::setApiKey("your API key here");
$managed_account = \Stripe\Account::create([
'managed' => true,
'email' => 'test@tradesy.com'
]);
// create a debit card recipient
$token = \Stripe\Token::create([
'card' =>[
'name' => 'John Doe',
'number' => '4000056655665556',
'exp_month' => '01',
'exp_year' => '2020',
'cvc' => '123',
'address_line1' => '1207 2nd St',
'address_line2' => '2rd Floor',
'address_state' => 'CA',
'address_city' => 'Santa Monica',
'address_zip' => 90401,
// 'currency' => 'usd'
]
]);
$recipient = \Stripe\Recipient::create([
"name" => 'John Doe',
"type" => "individual",
'card' => $token->id
]);
// re-tokenize the debit card recipient
$token = \Stripe\Token::create(
[
'recipient' => $recipient->id,
'card' => $recipient->cards->data[0]->id
],
[
'stripe_account' => $managed_account->id
]
);
// link the debit card to the managed account
$managed_account->external_accounts->create([
'external_account' => $token->id
]);
$managed_account->save();
@ehongyu
Copy link
Author

ehongyu commented Mar 27, 2017

The above code gives error:

Stripe\Error\InvalidRequest: You must provide a card that has the 'currency' field set when adding a card to a Stripe account.

@ehongyu
Copy link
Author

ehongyu commented Mar 27, 2017

I have tried to assign the currency to the card like this after line 26, but it didn't help:

        $recipient->cards->data[0]->currency = 'usd';
        $recipient->save();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment