When calling retrieveExternalAccount from the API I'd like a response of whether or not the stripe connected account is a card or bank_account and then list the last 4 digits of account or card accordingly.

https://stripe.com/docs/api/external_account_cards/retrieve


require_once 'stripe-php-master/init.php';
//$stripe = new \Stripe\StripeClient($STRIPE_API_KEY);

$stripe = new \Stripe\StripeClient(
    $STRIPE_API_KEY
);
$link = $stripe->accounts->retrieve(
    $STRIPE_DEST,
    []
);

$linkaccount = $stripe->accounts->retrieveExternalAccount(
    $STRIPE_DEST,
    []
);

if ($link->transfers_enabled == FALSE){
echo '<script>top.location.href = "https://www.website.net/oa-drive.php"</script>';
exit();
}

if ($linkaccount->object == "bank_account"){
$accounttype = 'account ending in '.$linkaccount->last4.'';
} else {
$accounttype .= 'card ending in '.$linkaccount->last4.'';
}

    Okay, so what does it do now? Do you have all errors turned on and display_errors set while testing it?

      It's saying retrieveExternalAccount is returning empty. I just tried passing the ID as in API examples they're passing account id and card or bank id.

      
      $linkaccount = $stripe->accounts->retrieveExternalAccount(
         $STRIPE_DEST,
         $linkaccount->id,
         []
      );
      
      

      Does this line have the correct syntax?

      
      if ($linkaccount->object == "bank_account"){
      
      

        The syntax is obviously correct, or you'd have a syntax error and nothing would even run, but

        $linkaccount = $stripe->accounts->retrieveExternalAccount(
           $STRIPE_DEST,
           $linkaccount->id,
           []
        );

        The whole point of that line is to create $linkaccount, so $linkaccount->id won't even exist yet. If you don't already have the account number how do you know which account you want to look up?

          10 months later
          Write a Reply...