Stripe - 不更新数据库中的用户信息
Stripe - not updating User's information in database
我正在使用条纹进行我的第一个项目。我有一个订阅产品并且我有基本的条带功能,但我需要将我的用户在数据库中的记录更新为 "subscribed" 以便我可以在以后的开发中将其用作验证。我在网上看过几个教程,这些教程显示向您的模型添加一个名为 subscribed 或类似内容的列,并在条带客户创建过程中更新它。我已经开始工作了,只是它没有更新我的用户模型(在本例中为供应商)。这是我的条带进程控制器:
class ChargesController < ApplicationController
before_filter :authenticate_supplier!
def new
end
def create
# Amount in cents
token = params[:stripeToken]
customer = Stripe::Customer.create(
:source => token, # obtained from Stripe.js
:plan => "Free_month_annual",
:email => current_supplier.email,
#:coupon => "coupon_ID"
)
current_supplier.subscribed = true
#current_supplier.stripe_id = token
redirect_to orders_path
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to charges_path
end
end
如您所见,有两件事被注释掉了 - 优惠券,我打算稍后处理,以及 stripe_id
更新,因为我 运行 因为已经使用了token
一次(不能使用两次)。我更新了我的供应商模型,数据库中有一个适当的列,参数已更新为允许 supplier.subscribed
。我相信这对很多人来说是一个快速的答案,但我需要帮助来发现我的问题。
编辑:
subscribed 是一个布尔字段 - fyi
您似乎忘记保存 current_supplier
记录。
解决方案应该是添加如下内容:
current_supplier.subscribed = true
#current_supplier.stripe_id = token
current_supplier.save!
redirect_to orders_path
我正在使用条纹进行我的第一个项目。我有一个订阅产品并且我有基本的条带功能,但我需要将我的用户在数据库中的记录更新为 "subscribed" 以便我可以在以后的开发中将其用作验证。我在网上看过几个教程,这些教程显示向您的模型添加一个名为 subscribed 或类似内容的列,并在条带客户创建过程中更新它。我已经开始工作了,只是它没有更新我的用户模型(在本例中为供应商)。这是我的条带进程控制器:
class ChargesController < ApplicationController
before_filter :authenticate_supplier!
def new
end
def create
# Amount in cents
token = params[:stripeToken]
customer = Stripe::Customer.create(
:source => token, # obtained from Stripe.js
:plan => "Free_month_annual",
:email => current_supplier.email,
#:coupon => "coupon_ID"
)
current_supplier.subscribed = true
#current_supplier.stripe_id = token
redirect_to orders_path
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to charges_path
end
end
如您所见,有两件事被注释掉了 - 优惠券,我打算稍后处理,以及 stripe_id
更新,因为我 运行 因为已经使用了token
一次(不能使用两次)。我更新了我的供应商模型,数据库中有一个适当的列,参数已更新为允许 supplier.subscribed
。我相信这对很多人来说是一个快速的答案,但我需要帮助来发现我的问题。
编辑: subscribed 是一个布尔字段 - fyi
您似乎忘记保存 current_supplier
记录。
解决方案应该是添加如下内容:
current_supplier.subscribed = true
#current_supplier.stripe_id = token
current_supplier.save!
redirect_to orders_path