4

I've had this problem before when trying to make a charge on a live card/customer when in dev mode. I've never made an ACH charge with stripe before and I'm in dev mode for sure. https://stripe.com/docs/ach#integrating-plaid

js

var linkHandler = Plaid.create({
env: 'tartan',
clientName: 'Stripe / Plaid Test',
key: '[Plaid key]',
product: 'auth',
selectAccount: true,
onSuccess: function(public_token, metadata) {
 // Token & Account ID - I use this for subsequent cURL requuest
 console.log('public_token: ' + public_token);
 console.log('account ID: ' + metadata.account_id);
 },
});

// Trigger the Link UI
 document.getElementById('linkButton').onclick = function() {
 linkHandler.open();
};

Response is valid. I use the public_token and account ID from above:

    $data = array(
            'client_id' => 'MY_CLIENT_ID',
            'secret' => 'MY_SECRET',
            'public_token' => 'MY_PUBLIC_TOKEN_FROM_ABOVE',
            'account_id' => 'MY_ACCOUNT_ID_FROM_ABOVE'
     );


    $string = http_build_query($data);

    //initialize session
    $ch=curl_init("https://tartan.plaid.com/exchange_token");

    //set options
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    //execute session
    $keys = curl_exec($ch);
    $keys = json_decode($keys);
    //close session
    curl_close($ch);

This also results in a valid response object:

{
 access_token: 'MY_ACCESS_TOKEN',
 account_id: 'MY_ACCOUNT_ID',
 stripe_bank_account_token: 'MY_STRIPE_BANK_ACCOUNT'
}

This is where I'm mixed up I suppose. The docs say: The response will contain a verified Stripe bank account token ID. You can attach this token to a Stripe Customer object, or create a charge directly on it.

However when I create a charge on the bank account token like this:

    \Stripe\Stripe::setApiKey("sk_test_MY_TEST_KEY");

    $charge = \Stripe\Charge::create(array(
      "amount" => 2100,
      "currency" => "usd",
      "source" => $keys->stripe_bank_account_token, //(btok_MY_TOKEN_FROM_ABOVE)
      "description" => "my description"
    ));

    var_dump( $charge );

Error I get is: Fatal error: Uncaught exception 'Stripe\Error\InvalidRequest' with message 'No such token: btoken_MY_BANK_TOKEN; a similar object exists in live mode, but a test mode key was used to make this request.'

Justin W Hall
  • 371
  • 1
  • 5
  • 21

1 Answers1

1

That means you created a live bank account token.

If you want to test your integration, you need to generate the Plaid token with the following credentials:

  • Username: test_plaid
  • Password: test_good
  • Code: 1234

This will return a test bank account token that you can use in an API request sent with your Stripe test secret API key (sk_test_...).

If you want to process a live charge, then you need to use real credentials in Plaid link to get a real bank account token back, then use the bank account token in an API request sent with your Stripe live secret API key (sk_live_...).

Ywain
  • 16,854
  • 4
  • 51
  • 67
  • Thank you. Just to be clear, this would be something like: https://jsfiddle.net/u2L1cgw6/1/ – Justin W Hall Nov 08 '16 at 17:13
  • @Ywain can you please answer to my this question https://stackoverflow.com/questions/58096180/how-to-implement-stripe-ach-with-plaid-in-php – Sudhir Sep 27 '19 at 10:01