Stripe 创建后获取订阅 ID

Posted

技术标签:

【中文标题】Stripe 创建后获取订阅 ID【英文标题】:Stripe Get Subscription ID after Creation 【发布时间】:2017-08-28 07:10:26 【问题描述】:

我正在使用 Stripe gem 为测试 web 应用创建订阅模型。我可以手动输入订阅 ID 来创建订阅并删除它,但我想将订阅保存到我的数据库中,所以我不必这样做。这是我目前所拥有的:

 customer = Stripe::Customer.create(
    card: token,
    email: current_user.email
    )

 Stripe::Subscription.create(
    customer: customer.id,
    plan: 000
    )

 current_user.stripe_id = customer.id
 current_user.stripe_subscription_id = subscription.id

我收到一条错误消息,指出没有订阅 ID。如何获取订阅 ID?我需要它,以便在请求时取消订阅。我厌倦了浏览 API,但它没有明确说明如何检索订阅 API。

【问题讨论】:

【参考方案1】:

Doh...我忘记分配订阅了。我将第一行从:

Stripe::Subscription.create()

到:

subscription = Stripe::Subscription.create()

现在它可以工作了。

【讨论】:

以上是关于Stripe 创建后获取订阅 ID的主要内容,如果未能解决你的问题,请参考以下文章