【发布时间】:2014-11-19 16:46:22
【问题描述】:
我正在开发一个应用程序,该应用程序允许会员升级为高级会员(在使用 Stripe 付款后)以访问其他功能。我仅在生产中以测试模式使用 Stripe,因此我正在寻找一种在 Heroku 控制台中创建高级用户的方法。会是这样吗?:
user = User.find_by(name:’existing user name’)
user.update_attribute(‘premium’).save
我的 schema.rb 文件中有 t.boolean "premium"。
我是编程新手,所以如果您需要任何其他文件信息,请告诉我。谢谢!
编辑更新:这是我的收费控制器代码:
class ChargesController < ApplicationController
def new
@stripe_btn_data = {
key: "#{ Rails.configuration.stripe[:publishable_key] }",
description: 'Premium Membership',
amount: 1_299
}
end
def create
@amount = params[:amount]
customer = Stripe::Customer.create(
email: current_user.email,
card: params[:stripeToken]
)
charge = Stripe::Charge.create(
customer: customer.id,
amount: @amount,
description: 'Premium Membership',
currency: 'usd'
)
current_user.update_attribute(:premium, true)
redirect_to wikis_path, flash: { notice: "Congratulations, #{current_user.email}, on becoming a premium member!"}
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to new_charge_path
end
end
【问题讨论】:
标签: ruby-on-rails heroku stripe-payments