从 Stripe 结帐会话中检索帐单地址? [英] Retrieve Billing Address from Stripe checkout session?

查看:65
本文介绍了从 Stripe 结帐会话中检索帐单地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在像这样在 Node 中创建一个结帐会话.https://stripe.com/docs/api/checkout/sessions/create

我已将 billing_address_collection 参数设置为 required,现在想知道是否可以检索从 checkout.completed 收集的帐单地址触发的网络钩子.

我没有找到从结帐会话中检索帐单地址的好方法.

有没有办法做到这一点?或者我应该在将用户发送到结账会话之前收集这些信息?

解决方案

账单地址可以通过 Checkout 收集.但它不会存在于 CheckoutSession 对象上,而是存在于 PaymentMethod 对象上.

当您收到 checkout.session.completed 事件时,它有一个带有 PaymentIntent 对象 ID 的 payment_intent 字段.PaymentIntent 对象又具有您需要的 PaymentMethod.所以你需要从 CheckoutSession -> PaymentIntent -> PaymentMethod 去获取账单明细.

如何执行此操作:在您的 webhook 事件处理程序中,检索 [0] PaymentIntent 和 expand PaymentMethod(通过传递 expand: ['payment_method']).

PaymentMethod 在 billing_details 哈希 [2]

下有账单明细

[0] https://stripe.com/docs/api/payment_intents/retrieve

[1]https://stripe.com/docs/api/expanding_objects>

[2] https://stripe.com/docs/api/payment_methods/object#payment_method_object-billing_details

I am creating a checkout session in Node like so. https://stripe.com/docs/api/checkout/sessions/create

I've set the billing_address_collection parameter to required and am now wondering if I can retrieve the billing address collected from the checkout.completed webhook that is triggered.

I'm not finding a good way to retrieve the billing address from a checkout session.

Is there a way to do this? Or should I just gather this information before sending the user to a checkout session?

解决方案

Billing address can be collected via Checkout. It won't live on the CheckoutSession object though but instead on the PaymentMethod object.

When you get the checkout.session.completed event, it has a payment_intent field with the PaymentIntent object ID. The PaymentIntent object in turn has the PaymentMethod that you need. So you need to go from CheckoutSession -> PaymentIntent -> PaymentMethod to get the billing details.

How to do this: In your webhook event handler, retrieve [0] the PaymentIntent and expand the PaymentMethod (by passing expand: ['payment_method']).

The PaymentMethod has the billing details under the billing_details hash [2]

[0] https://stripe.com/docs/api/payment_intents/retrieve

[1]https://stripe.com/docs/api/expanding_objects

[2] https://stripe.com/docs/api/payment_methods/object#payment_method_object-billing_details

这篇关于从 Stripe 结帐会话中检索帐单地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆