0

I'm trying to connect through stripe object and derive the destination account, and then try and retrieve the customer object id, and eventually the available payment methods with the attached last 4 digits of either the bank account or card associated with the customer id.

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

  $link = $stripe->accounts->retrieve(
  $STRIPE_DEST
  []
   );

 $paymentMethods = $stripe->paymentMethods->all([
 'customer' => $customer,
  'type' => 'card',
 ]);

 $last4 = $paymentMethods->sources->data[0]->last4;

1 Answers1

0

For stripe, you may use retrieveSource

$stripe->customers->retrieveSource

So in PHP it is like

$stripe = new \Stripe\StripeClient(
  'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
);
$stripe->customers->retrieveSource(
  'cus_8eqdcH07DUqA5s',
  'card_1LsEJ12eZvKYlo2C4AdGdib2',
  []
);

The response will be like

{
  "id": "card_1LsEJ12eZvKYlo2C4AdGdib2",
  "object": "card",
  "address_city": null,
  "address_country": null,
  "address_line1": null,
  "address_line1_check": null,
  "address_line2": null,
  "address_state": null,
  "address_zip": null,
  "address_zip_check": null,
  "brand": "Visa",
  "country": "US",
  "customer": "cus_8eqdcH07DUqA5s",
  "cvc_check": "pass",
  "dynamic_last4": null,
  "exp_month": 8,
  "exp_year": 2023,
  "fingerprint": "Xt5EWLLDS7FJjR1c",
  "funding": "credit",
  "last4": "4242",
  "metadata": {},
  "name": null,
  "redaction": null,
  "tokenization_method": null
}

So you parse it and the "last4" data item should be what you want

If you need further details, please refer to the official documentation: https://stripe.com/docs/api/cards/retrieve

Further/other reference

Getting Last4 Digits of Card using Customer Object - Stripe API with PHP

Ken Lee
  • 6,985
  • 3
  • 10
  • 29
  • Is there anyway to receive the card last4 by just using the account id, instead of the customer id? – Justin Crawfish Oct 14 '22 at 11:47
  • please check "further/other reference" link in my answer and see whether it can provide the necessary information for you. Thanks – Ken Lee Oct 15 '22 at 00:46