Reputation: 631
For compliance reasons I am generating tokens on the client side and sending those details to stripe. I want to display the last four digits and the type of card on my confirmation page
I am creating a customer
// Create a Customer:
$customer = \Stripe\Customer::create([
'source' => $token,
'email' => $current_user->user_email,
]);
than adding them to a subscription
//create the subscription for the customer
$subscription = \Stripe\Subscription::create(array(
'customer' => $customer->id,
"items" => array(
array(
"plan" => "dpc-standard",
),
)
));
The subscription returns https://stripe.com/docs/api#subscription_object a ton of data including the invoice_id that is generated for the subscription but doesn't return any CC details
Upvotes: 0
Views: 1490
Reputation: 25602
When you create a Customer and pass the source
parameter set to a token id, it will save that card on the new customer. The value returned by this call is a Customer object with the sources
property which will contain the new card you just saved.
You can access the last 4 digits easily using:
$last4 = $customer->sources->data[0]->last4;
Upvotes: 1