gpt4 book ai didi

ruby-on-rails - Stripe,取消订阅 Ruby on Rails

转载 作者:太空宇宙 更新时间:2023-11-03 16:26:33 24 4
gpt4 key购买 nike

我正在尝试取消已创建的订阅。我确实传递了正确的客户 ID 和计划 ID。然而我的终端出现错误

Stripe::InvalidRequestError (Customer cus_xxxxxxxxxxx does not have a subscription with ID Golden)

这是我的 Controller 方法。

def create
sub_plan = params[:plan_id]
subscription_plan_id = SubscriptionPlan.where(plan_id:sub_plan).first.id
token = params[:stripeToken]
email = current_user.email
customer = Stripe::Customer.create(
:card => token,
:plan => sub_plan,
:email => email
)
Subscription.create(subscription_plan_id:subscription_plan_id,user_id:current_user.id,stripe_customer_token:customer[:id])
redirect_to '/membership'
end

def destroy
p "---------------------------"
subscription_plan_id = SubscriptionPlan.where(plan_id:params[:plan_id]).first.id
customer_id = Subscription.where(subscription_plan_id:subscription_plan_id,user_id:current_user.id).first.stripe_customer_token
customer = Stripe::Customer.retrieve(customer_id)
customer.subscriptions.retrieve(params[:plan_id]).delete()
Subscription.where(subscription_plan_id:subscription_plan_id,user_id:current_user.id).first.destroy
end

在我的创建方法中,用户创建了一个成功的订阅,它也出现在我的 stripe 帐户上..但是在试图销毁它时会发生此错误。有什么不对的吗。请帮助。提前致谢

最佳答案

无法使用计划 ID 检索 strip 订阅。

要检索订阅:首先您需要一个客户:

customer = Stripe::Customer.retrieve("cus_xxxxxxxxxx")

对于客户,您可以检索他的所有订阅:

subscriptions = customer.subscriptions.data

或具有检索方法和订阅的 stripe_id 的特定订阅(文档引用:https://stripe.com/docs/api/ruby#retrieve_subscription):

subscription = customer.subscriptions.retrieve("sub_xxxxxxxxxx")

希望对你有帮助

关于ruby-on-rails - Stripe,取消订阅 Ruby on Rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23866252/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com