0
votes

I know that asking this here could be throwing a stone in the dark because I found 2 other similar questions but none had any answers to it.

Any way, I hope someone has already found the solution for this and can shed a light on it.

Let me explain the scenario first as it might help with finding a solution:

I am creating stripe custom connect accounts like this:

$acct = \Stripe\Account::create(array(
    "country" => "US",
    "type" => "custom",
    "email" => "[email protected]"
));

Then I add Bank Accounts to them like so:

$account->external_accounts->create(
array(
        'external_account' => array(
            "object" => "bank_account",
            "country" => "US",
            "currency" => "usd",
            "account_holder_name" => 'Jane Austen',
            "account_holder_type" => 'individual',
            "routing_number" => "111000025",
            "account_number" => "000123456789"
        )
));

This all works fine so far....

Now, what I need to do is to be able to transfer Money/Payments from the connected custom accounts into their Bank accounts.

For that purpose, I will need to add a Credit Card to that connetced account so that card details can be used for making payments into the Bank Accounts.

So I went ahead and tried this:

$account->external_accounts->create(
array(
        'external_account' => array(
            "object" => "card",
            "exp_month" => 8,
            "exp_year" => 2018,
            "number" => "4012888888881881",
            "currency" => "usd",
            "cvc" => "123"
        )
));

And that did NOT work and gave me this error:

Requests made on behalf of a connected account must use card tokens from Stripe.js, but card details were directly provided.

So I changed my strategy and tried this:

$result = \Stripe\Token::create(
                    array(
                        "card" => array(
                        "name" => "Some Name",
                        "exp_month" => 8,
                        "exp_year" => 2018,
                        "number" => "4012888888881881",
                        "currency" => "usd",
                        "cvc" => "123"
                        )
                    ));



$token = $result['id'];


$account->external_accounts->create(
array(
        'external_account' => array(
            "object" => "card",
            "source" => "".$token.""
        )
));

However, this gave me the same error message!!!

This is very frustrating because if you look at their own API documentation, you will clearly see that they say:

source required

Either a token, like the ones returned by Stripe.js, or a dictionary containing a user's credit card details (with the options shown below). Stripe will automatically validate the card. 

This can be seen here:

https://stripe.com/docs/api#create_card

Could someone please advice on this issue?

I cannot use stripe.js in my project so I will need to use the API.

Any help would be greatly appreciated.

Thanks in advance.

First Edit:

Here is a strange one.. I generated a Stripe card token from here:

https://codepen.io/fmartingr/pen/pGfhy

Note that the above codepen uses the stripe.js to generate the tokens....

and tried to use the token from there in my PHP code like so:

$account->external_accounts->create(
array(
        'external_account' => array(
            "object" => "card",
            "source" => "tok_1AqPXeDQzcw33c71uncYBFdm"
        )
));

but this gives me the exact same error:

Requests made on behalf of a connected account must use card tokens from Stripe.js, but card details were directly provided.
1
How are you creating the token your sending as the source in the second attempt? Does the token get returned from stripe successfully? - Birdy
@Birdy, my first attempt was using the $result = \Stripe\Token::create(...). I have included the code in my question. Also, I have edited my question with another way of trying it (using stripe.js) generated token and used that token directly in the source but that gave me the same error message. - David Hope
@Birdy, yes, I get the token successfully. - David Hope
I can simply echo $token; on my page and I see the token on my page. - David Hope

1 Answers

0
votes

Please use this it will add your external account

$result = \Stripe\Token::create(
                array(
                    "card" => array(
                    "name" => "Some Name",
                    "exp_month" => 8,
                    "exp_year" => 2018,
                    "number" => "4012888888881881",
                    "currency" => "usd",
                    "cvc" => "123"
                    )
                ));



$token = $result['id'];

$account->external_accounts->create(
   array(
      'external_account' => "".$token.""
));