【发布时间】:2015-09-15 23:38:32
【问题描述】:
我的 Ruby on Rails 应用程序中有两个订阅计划。创建订阅后,我使用条带 webhook 向客户发送电子邮件。在电子邮件中,我想存储有关订阅(和计划)详细信息的数据,例如当 trial_end 和计划名称或价格时。
def webhook
stripe_event = Stripe::Event.retrieve(params[:id]) #retrieving Event ID
if stripe_event.type == "customer.subscription.created" #checks if retrieved Event type subscription is created
stripe_customer_token = stripe_event.data.object.customer # Get Customer ID
customer = Stripe::Customer.retrieve(stripe_customer_token) #here I'm able to retrieve Customer data e.g. customer.email
subscription = customer.subscriptions.first.id #according to documentation I need to retrieve Subscription by supplying its ID. I can retrieve Subscription, but don't understand how to retrieve its data, like: subscription.trial_end
UserMailer.customer_subscription_created(customer.email).deliver #this works well
UserMailer.customer_subscription_created(subscription.trial_end).deliver #this does not work
end
end
我已检索到我的客户的订阅。当我检索客户时,我可以访问我的客户数据,例如:customer.email 我以为我在检索订阅时可以做同样的事情:subscription.trial_end,但这给了我一个错误。如何访问订阅数据?
除了当我更改订阅计划时,我会这样做并且它有效:
def change_user_plan(customer_id, subscription_id)
customer = Stripe::Customer.retrieve("#{customer_id}")
subscription = customer.subscriptions.retrieve("#{subscription_id}")
subscription.plan = 2
subscription.save
end
这里是指向 retrieve Subscription 的 Stripe API 的链接
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 stripe-payments