【问题标题】:Stripe - How to get billing address information in Checkout.SessionStripe - 如何在 Checkout.Session 中获取账单地址信息
【发布时间】:2021-08-18 13:26:53
【问题描述】:

我正在尝试通过 Webhook 调用从 Stripe Checkout 获取帐单地址。

我想要实现的是从黄色矩形中的表单中获取信息。

这是我的结帐配置:

var options = new SessionCreateOptions()
                {
                    CustomerEmail = user.Email,
                    BillingAddressCollection = "required",
                    ShippingAddressCollection = new SessionShippingAddressCollectionOptions
                    {
                        AllowedCountries = new List<string>
                        {
                          "FR",
                        },
                    },
                    PaymentMethodTypes = new List<string>() {
                       result.Payment.Type
                    },
                    LineItems = new List<SessionLineItemOptions>{
                        new SessionLineItemOptions
                          {
                            PriceData = new SessionLineItemPriceDataOptions
                            {
                              UnitAmountDecimal = result.Payment.Amount * 100,
                              Currency = result.Payment.Currency,
                              ProductData = new SessionLineItemPriceDataProductDataOptions
                              {
                                Name = _stringLocalizer.GetString("StripeProductLabel"),
                              },
                            },
                            Quantity = 1,
                        },
                    },
                    Mode = result.Payment.Mode,
                    SuccessUrl = $"{request.Scheme}://{request.Host}" + "/payment/complete",
                    CancelUrl = $"{request.Scheme}://{request.Host}" + "/payment/cancel",
                    Metadata = new Dictionary<string, string>()
                    {
                        { Constants.StripeMetaDataOrderId, result.Id }
                    }
                };

当我在完成的事件中收到会话对象时:session = stripeEvent.Data.Object as Stripe.Checkout.Session;

我无法获取信息,因为 paymentIntent 对象为空(信息来自:Retrieve Billing Address from Stripe checkout session?)。

这是 Sripe 的一项重要功能,因为该应用程序是一个 B2B 应用程序,可帮助专业人士为其 B2C 业务创建订单。它将避免从 Stripe API 中退出的东西制作自定义代码 :)

提前致谢

【问题讨论】:

    标签: c# .net-core stripe-payments


    【解决方案1】:

    您链接到的答案是从payment_intent 上的payment_method 获取此信息的正确方法。我不确定您的 payment_intent 值如何/为什么不会被填充,因为我的测试表明它会在创建会话时被初始化,即使我从未重定向到它。

    您确定要创建mode=payment 会话吗?我在您共享的代码中看到了这一点,但是如果您实际上是在使用 setupsubscription 模式,情况会有所改变。

    【讨论】:

    • 是的,我处于付款模式(它来自域逻辑,这就是为什么这里不明确)。在与职能团队一起查看后,我们决定在我们的系统中制作账单信息,但感谢确认我的配置似乎是正确的 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-13
    • 2013-05-04
    • 1970-01-01
    • 1970-01-01
    • 2022-06-12
    • 2013-10-29
    相关资源
    最近更新 更多