4
votes

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

1
It looks like the end of your question is missing. What happens when you try to use the bank account token returned by Plaid? Does the API return an error message?Ywain
Ya, sorry. Updated.Justin W Hall

1 Answers

1
votes

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