订阅后条纹收费,从订阅中获取元数据 [英] Stripe charge after subscription, get metadata from subscription

查看:30
本文介绍了订阅后条纹收费,从订阅中获取元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建订阅时,我设置了一些元数据来标识我在数据库中的订单.当我收到 webhook charge.succeeded 时,订阅的元数据不会在此事件中传递,我无法识别与此付款相关的订单.如何发送与订阅相关的每个 webhook 的元数据.

When I'm creating a subscription, I set some metadata to identify my order on the database. When I receive the webhook charge.succeeded, the metadata from subscription, is not passed in this event and I can't identify the order related to this payment. How can I send the metadata on every webhook related to subscription.

推荐答案

订阅的元数据存在于订阅而不是 Charge 对象上.费用与特定发票(如果有)相关联,而发票本身又与订阅(如果有)相关联.

The subscription's metadata live on the Subscription not the Charge object. A charge is associated with a specific invoice (if any) which itself is associated with a Subscription (if any).

根本不可能在订阅上设置元数据以查看它被移植到相应的费用.

It is simply not possible to set metadata on a subscription to see it ported over to the corresponding charge.

相反,您可以使用 API 来检索费用并使用 扩展功能,还可以一次性获取关联的发票和订阅.

Instead, you would use the API to retrieve the Charge and use the Expand feature to also fetch the associated invoice and subscription in one go.

在 PHP 中它看起来像这样:

In PHP it would look like this:

$charge = \Stripe\Charge::retrieve(
  array(
    "id" => "ch_1CP95G2eZvKYlo2C4pcS2pxm",
    "expand" => array("invoice.subscription")
  )
);

然后您可以直接在代码中访问订阅的元数据.

You can then access the subscription's metadata in your code directly.

这篇关于订阅后条纹收费,从订阅中获取元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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