Ruby on rails Rails-条带订阅(设置时间段)
我在我的rails应用程序上运行得很好,还有两个附加问题来总结一些功能 是否有一种方法可以创建仅6个月或任何给定时间的订阅,以便在所述时间段后不向客户收费? 如果用户完全取消了他们的计划,我需要删除他们的订阅。我肯定这将包括dependent::destroy,但我不确定放在哪里。谢谢 订阅\u controller.rbRuby on rails Rails-条带订阅(设置时间段),ruby-on-rails,ruby-on-rails-4,stripe-payments,Ruby On Rails,Ruby On Rails 4,Stripe Payments,我在我的rails应用程序上运行得很好,还有两个附加问题来总结一些功能 是否有一种方法可以创建仅6个月或任何给定时间的订阅,以便在所述时间段后不向客户收费? 如果用户完全取消了他们的计划,我需要删除他们的订阅。我肯定这将包括dependent::destroy,但我不确定放在哪里。谢谢 订阅\u controller.rb def create token = params[:stripeToken] customer = Stripe::Customer.create(
def create
token = params[:stripeToken]
customer = Stripe::Customer.create(
:email => current_user.email,
:card => token,
plan: params[:id]
)
current_user.subscribed = true
current_user.stripe_id = customer.id
current_user.stripe_subscription_id = customer.subscriptions['data'][0].id
current_user.plan_name = customer.subscriptions['data'][0].plan.name
current_user.interval = customer.subscriptions['data'][0].plan.interval
current_user.amount = customer.subscriptions['data'][0].plan.amount
current_user.status = customer.subscriptions['data'][0].status
current_user.stripe_plan_id = customer.subscriptions['data'][0].plan.id
current_user.save
end
def destroy
customer = Stripe::Customer.retrieve(current_user.stripe_id)
free_plan = Stripe::Plan.retrieve('1')
if current_user.stripe_id = customer.id
customer.subscriptions.retrieve(current_user.stripe_subscription_id).delete
current_user.update_attributes(stripe_plan_id: free_plan.id , plan_name: free_plan.name, amount: free_plan.amount , status: "Inactive" )
current_user.save
flash[:notice] = "Your plan has been downgraded to #{current_user.plan_name}"
redirect_to edit_user_registration_path
else
customer.subscriptions.retrieve(current_user.stripe_subscription_id).delete
current_user.update_attributes(stripe_subscription_id: customer.subscriptions['data'][0].id)
flash[:notice] = "Blah"
redirect_to edit_user_registration_path
end
end
订阅模式
class Subscription < ActiveRecord::Base
belongs_to :user
end
对于问题1,您可以创建一个进程,该进程可由计划程序触发,然后检查给定订阅是否超过6个月,并将帐户移动到另一个订阅 对于问题2,请查看。 您不想删除或销毁,因为您丢失了用于记帐的历史记录
您想将订阅更新为取消状态wow!看起来棒极了,我来试一试!谢谢希望你的活动很有趣!
has_many :subscriptions, dependent: :destroy