stripe-payments - 如何仅通过一个请求检索 Stripe 订阅和信用卡?
问题描述
在 Stripe 版本 2020-03-02 中,我能够一次性检索 asubscription
及其关联credit_card
,如下所示:
stripe_subscription = Stripe::Subscription.retrieve({:id => stripe_subscription_id, :expand => [:customer]})
stripe_customer = stripe_subscription.customer
stripe_credit_card = stripe_customer.sources.data.first
在 2020-08-27 版本中,这似乎不再可能,因为 Stripe 无法sources
识别customer
.
那么如何仅通过一个请求检索订阅及其信用卡呢?
解决方案
由于默认情况下不包含sources
on Customer
,因此您必须在展开相关属性时显式包含它。您的代码如下所示:
stripe_subscription = Stripe::Subscription.retrieve({
id: stripe_subscription_id,
expand: ['customer.sources'],
})
stripe_customer = stripe_subscription.customer
stripe_credit_card = stripe_customer.sources.data.first
扩展功能非常强大,可以像我们上面那样扩展多个单独的属性或链扩展。我建议阅读Stripe 提供的详细文档。
推荐阅读
- html - 如何在ionic 3中显示json描述各自的id
- sql-server - 如何在sql中更改列存储索引
- android - 为什么 Kotlin 在从资源中设置 Glide 错误可绘制时提示创建扩展函数?
- oracle - Oracle SQL - 无法看到创建的表
- c# - 我在使用 Office365 的 oauth2 身份验证对用户进行身份验证时遇到问题
- html - 使用 XSLT 将带有名称和内容的元标记添加到我的 html 页面
- computer-vision - 图像转换:将直线转换为圆弧
- java - 读取spss文件java
- r - 使用 ggplot2 创建渐变色条
- reactjs - 从 redux-form 覆盖初始值