【问题标题】:Stripe Session Getting Customer NameStripe 会话获取客户名称
【发布时间】:2020-12-22 02:28:17
【问题描述】:

我还想检索付款人的姓名。如何从条带会话中获取名称值?我试过这个:

const sessions = await stripe.checkout.sessions.list({
    limit: 1,
  });
console.log(sessions.data[0].customer)
const customer = await stripe.customers.retrieve(sessions.data[0].customer);
console.log(customer)

这让我收到了电子邮件,但名字是null

【问题讨论】:

    标签: stripe-payments


    【解决方案1】:

    更新:通过 Checkout 创建的客户有一个 null 名称,因为它没有被收集/设置。结帐页面上的“卡上姓名”字段是付款方式的持卡人姓名,而不是客户姓名(请参阅https://stripe.com/docs/api/payment_methods/object#payment_method_object-billing_details-name)。如果您希望通过 Checkout 创建的客户没有 null 名称,则必须在会话完成后更新客户。

    Stripe 有一个仪表板设置 (https://dashboard.stripe.com/settings/emails),您可以启用该设置自动将收据发送给客户,以便在实时模式下成功完成付款。在测试模式下完成的付款不会自动发送电子邮件,但您可以通过仪表板手动触发。您可以在此处阅读有关发送收据的更多信息:https://stripe.com/docs/receipts#automatically-send-receipts-when-payments-are-successful

    如果您想获取客户的电子邮件并自己发送收据,这会有点复杂。

    1. 通过 webhook 端点 (https://stripe.com/docs/payments/checkout/fulfill-orders#handle-the-checkoutsessioncompleted-event) 侦听 checkout_session.completed,等待结帐会话完成。
    2. checkout_session.completed 事件附带的 Checkout Session 对象中获取客户 ID。
    3. 使用上一步中的客户 ID,检索客户对象 (https://stripe.com/docs/api/customers/retrieve) 并获取客户的电子邮件。

    【讨论】:

    猜你喜欢
    • 2022-08-02
    • 2011-05-17
    • 2020-12-22
    • 1970-01-01
    • 2014-07-24
    • 1970-01-01
    • 2020-11-30
    • 2015-09-23
    • 1970-01-01
    相关资源
    最近更新 更多