Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using Stripe Checkout to process orders on my site and then save the order once its complete using the webhook Checkout.Session.Complete . It works all well and good but I would like to store the last 4 digits used to process the order. If I send a receipt using Stripe it lists that info so I know its possible, I just prefer to store it and send my own receipt to customize and assist customers if an order is off. The checkout session object doesnt list the last 4 digits for some reason so whats the best way to get that info based on what the session object returns???

question from:https://stackoverflow.com/questions/65672083/get-last-4-digits-of-card-stripe-checkout

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
426 views
Welcome To Ask or Share your Answers For Others

1 Answer

The answer will depend on the type of Checkout Session you are working with.

If you are working with Checkout Sessions where mode:payment, then you should expand payment_intent.payment_method when you retrieve the Session. Then, you can check payment_intent.payment_method.card.last4 to get the last 4 digits.

If you are working with Checkout Sessions where mode:subscription, then you should expand subscription.default_payment_method when you retrieve the Session. Then, you can check subscription.default_payment_method.card.last4.

If you're not already familiar with expansion, you can read more about it here (https://stripe.com/docs/expand).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...