Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
420 views
in Technique[技术] by (71.8m points)

Get last 4 digits of card Stripe Checkout

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

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

1 Reply

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...