0

So I have spent the last two days looking around on stackoverflow and also the stripe API and I can't seem to find out how to get the banking ID when I add a new bank account for a worker. The account gets added to stripe, but it never seems to return me a bank id token, the ba_****.

Here is my code to add the bank account:

First method I tried:

 $bank_account_token = mysqli_real_escape_string($link, $_POST['token']);

 $account = \Stripe\Account::retrieve($worker_token);
$account->external_accounts->create(["external_account" => 
$bank_account_token]);
$bank_id = $account->external_account->id;

This is the second method I tried:

$account = \Stripe\Account::retrieve($worker_token);
  $account->external_accounts->create(array(
    "external_account" => array(
    "object" => "bank_account",
    "account_number" => $account_number,
    "routing_number" => $routing_number,
    "country" => "US",
    "currency" => "USD",)
  ));
$bank_id = $account->external_account->id;

I have also tried these various other methods to try and capture the bank id after it has been input into stripe and none of them return an id.

$bank_id = $account->bank_account->id;
$bank_id = $account->bank_account->external_account->id;
$bank_id = $account->external_accounts->bank_account->id;

This is the response that stripe says I should get when I add a new bank account:

com.stripe.model.BankAccount JSON: {
"id": "ba_1DVFGuC7941OKJKEoBwDlmHc",
"object": "bank_account",
"account_holder_name": null,
"account_holder_type": null,
"bank_name": "STRIPE TEST BANK",
"country": "US",
"currency": "usd",
"fingerprint": "bGA06pJMr6Vwreh6",
"last4": "6789",
"metadata": {
},
"routing_number": "110000000",
"status": "new",
"account": "acct_1BS4bBC7941OKJKE"
}
2
  • How is this related to Android ? A Web API can consume by any platform so android tag is irrelevant. Commented Nov 11, 2018 at 10:40
  • @ADM I am getting the tokens from Android stripe api and passing to the web api, so wasn't sure if it is related to that or not, or figured someone else who was doing the same thing might have an answer. Commented Nov 11, 2018 at 10:44

1 Answer 1

1

Okay so after further digging and reaching out to stripe (waiting on their email replies) I have figured out that their documentation is outdated in some sections. The correct response is:

 "external_accounts": {
"object": "list",
"data": [
  {
    "id": "ba_1DVFGuC7941OKJKEoBwDlmHc",
    "object": "bank_account",
    "account": "acct_2BS4cCb7841ONDLK",
    "account_holder_name": null,
    "account_holder_type": null,
    "bank_name": "STRIPE TEST BANK",
    "country": "US",
    "currency": "usd",
    "default_for_currency": true,
    "fingerprint": "bGA06pJMr6Vwreh6",
    "last4": "6789",
    "metadata": {
    },
    "routing_number": "110000000",
    "status": "new"
  }
],

So to pull the first element (which is the id) I needed to pull it for an array:

  $account = \Stripe\Account::retrieve($worker_token);
  $account->external_accounts->create(["external_account" => $bank_account_token]);
  $bank_id = $account->external_accounts->data[0]->id;

Not the answer you're looking for? Browse other questions tagged or ask your own question.