Stripe - 如何在 Checkout.Session 中获取账单地址信息
Stripe - How to get billing address information in Checkout.Session
我正在尝试通过 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 :)
中存在的内容制作自定义代码
提前致谢
您链接到的答案是从 payment_intent
上的 payment_method
获取此信息的正确方法。我不确定 how/why 你的 payment_intent
值不会被填充,因为我的测试表明它在创建会话时被初始化,即使我从未重定向到它。
您确定要创建 mode=payment
会话吗?我在你分享的代码中看到了这一点,但如果你真的在做 setup
或 subscription
模式,事情会有所改变。
我正在尝试通过 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 :)
中存在的内容制作自定义代码提前致谢
您链接到的答案是从 payment_intent
上的 payment_method
获取此信息的正确方法。我不确定 how/why 你的 payment_intent
值不会被填充,因为我的测试表明它在创建会话时被初始化,即使我从未重定向到它。
您确定要创建 mode=payment
会话吗?我在你分享的代码中看到了这一点,但如果你真的在做 setup
或 subscription
模式,事情会有所改变。