Philipp Mochine
Philipp Mochine

Reputation: 4705

Stripe-Api: How to get the "PaymentMethod" (ID) from the Customer Object?

Before the Strong Customer Authentication (SCA), I could get the sources collection from the Customer Object with $customer->sources['data']

Now I'm trying to migrate to SCA, but cannot figure out how I can get my "paymentMethod" via the customer object without saving it to the database.

Here is the documentation again: https://stripe.com/docs/payments/cards/saving-cards#save-payment-method-without-payment

But to make it short, I save the "paymentMethod" like this:

// This creates a new Customer and attaches the PaymentMethod in one API call.
\Stripe\Customer::create([
  'payment_method' => $intent->payment_method,
]);

However, the Payment-Method-ID is not publically reachable with the customer object.

Is it possible to get it somehow?

Upvotes: 1

Views: 3717

Answers (1)

karllekko
karllekko

Reputation: 7268

PaymentMethods are not embedded on the Customer object itself and don't appear in $customer->sources. Instead, you can for example list them using the API [0] or retrieve directly given an ID(that you might also save in your database associated with the customer ID along with your user information).

$customer = \Stripe\Customer::create([
  'payment_method' => $intent->payment_method,
]);

$cards = \Stripe\PaymentMethod::all([
  "customer" => $customer->id, "type" => "card"
]);

/*
OR
*/

$card = \Stripe\PaymentMethod::retrieve($intent->payment_method);

[0] - https://stripe.com/docs/api/payment_methods/list

Upvotes: 1

Related Questions