Stripe 订阅 webhook 缺少元数据和 client_reference_id [英] Stripe subscription webhooks missing metadata and client_reference_id

查看:34
本文介绍了Stripe 订阅 webhook 缺少元数据和 client_reference_id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将条带网络钩子链接到客户时遇到问题,因为我通常使用 client_reference_id 或元数据字段,但是订阅网络钩子似乎没有这些字段.例如,事件 checkout.session.completed 确实包含 client_reference_id,而 invoice.paid 不包含.

I'm having issues linking stripe webhooks to customers, since I generally use the client_reference_id or metadata field, however subscription webhooks seem to not have these fields. For example the event checkout.session.completed does contain the client_reference_id, whereas invoice.paid does not.

用于生成付款的 NodeJS 代码:

        const session = await stripe.checkout.sessions.create({
            payment_method_types: ['card'],
            line_items: [
            {
                price_data: {
                    currency: 'usd',
                    product_data: {
                        name: `Premium license`,
                    },
                    unit_amount: 600,
                    recurring: {
                        interval: "month",
                        interval_count: 1
                    },
                },
                quantity: 1
            }],
            subscription_data: {
                trial_period_days: 1,
            },
            metadata: { 'userId': userId },
            client_reference_id: userId,
            mode: 'subscription',
            customer_email: customerEmail,
            success_url: `...`,
            cancel_url: `...`,
        });

推荐答案

client_reference_id 是 Stripe 中 Checkout Session 对象的属性,但不是任何其他 Stripe 对象的属性.

The client_reference_id is a property of Checkout Session objects in Stripe, but not any other Stripe objects.

订阅事件(如customer.subscription.created)描述订阅对象,发票事件(如invoice.paid)描述发票,两者都不是结账会话,所以该属性丢失了.

Subscription events (like customer.subscription.created) describe Subscription objects, and Invoice events (like invoice.paid) describe Invoices, neither of which are Checkout Sessions, so the property is missing.

通常,所有这些链接在一起的方式是使用 Stripe 中的 Customer 对象 (cus_123),该对象应该出现在 customer 中提到的所有事件中财产.如果您不指定现有的客户对象,Checkout 将为您创建客户对象一个.

Typically the way all of this is linked together is with the Customer object (cus_123) in Stripe, which should be present on all of the events mentioned in the customer property. Checkout will create the Customer object for you if you don't specify an existing one.

这篇关于Stripe 订阅 webhook 缺少元数据和 client_reference_id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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