如何使用条带结帐在 rails 中实施多个计划
How to implement multiple plan in rails with stripe checkout
我正尝试在带条带的 rails 应用程序上实施多计划订阅。
我的订阅控制器
def new
session = Stripe::Checkout::Session.create(
payment_method_types: ['card'],
client_reference_id: current_user.id,
customer_email: current_user.email,
subscription_data: {
items: [{
plan: 'beginner'
}]
},
success_url: 'http://localhost:3000/',
cancel_url: 'http://localhost:3000/'
)
@session_id = session.id
end
我的路线
....
resources :subscriptions, only: :new
....
我的订阅按钮就像
<%= link_to 'Subscribe to Beginner', new_subscription_path, %>
<%= link_to 'Subscribe to Pro', #TODO, %>
通过此设置,我可以毫无问题地订阅新手计划。
我的问题是如何在此设置中添加专业计划。路线会是什么样子?
我在我的条纹仪表板中创建了所有计划。
我已经查看了文档,但我不清楚。
我看到你可以像这样在 link 中传递参数
<%= link_to "subscribe", some_path(:params[:value]) %>
我怎样才能达到那种URL?
毕竟,我想在用户模型上有一个方法来检查用户是订阅了 beginner 还是 pro
谢谢
您似乎在询问“查询参数”。
您可以将参数添加到 URL
<%= link_to 'Subscribe to Beginner', new_subscription_path(plan: :beginner), %>
<%= link_to 'Subscribe to Pro', new_subscription_path(plan: :pro), %>
new_subscription_path(plan: :beginner)
将计算为 subscription/new?plan=beginner
然后您可以通过参数在模型中访问它。
def new
plan_type = params[:plan]
session = Stripe::Checkout::Session.create(
payment_method_types: ['card'],
client_reference_id: current_user.id,
customer_email: current_user.email,
subscription_data: {
items: [{
plan: plan_type
}]
},
success_url: 'http://localhost:3000/',
cancel_url: 'http://localhost:3000/'
)
@session_id = session.id
end
我正尝试在带条带的 rails 应用程序上实施多计划订阅。
我的订阅控制器
def new
session = Stripe::Checkout::Session.create(
payment_method_types: ['card'],
client_reference_id: current_user.id,
customer_email: current_user.email,
subscription_data: {
items: [{
plan: 'beginner'
}]
},
success_url: 'http://localhost:3000/',
cancel_url: 'http://localhost:3000/'
)
@session_id = session.id
end
我的路线
....
resources :subscriptions, only: :new
....
我的订阅按钮就像
<%= link_to 'Subscribe to Beginner', new_subscription_path, %>
<%= link_to 'Subscribe to Pro', #TODO, %>
通过此设置,我可以毫无问题地订阅新手计划。
我的问题是如何在此设置中添加专业计划。路线会是什么样子?
我在我的条纹仪表板中创建了所有计划。 我已经查看了文档,但我不清楚。
我看到你可以像这样在 link 中传递参数
<%= link_to "subscribe", some_path(:params[:value]) %>
我怎样才能达到那种URL?
毕竟,我想在用户模型上有一个方法来检查用户是订阅了 beginner 还是 pro
谢谢
您似乎在询问“查询参数”。
您可以将参数添加到 URL
<%= link_to 'Subscribe to Beginner', new_subscription_path(plan: :beginner), %>
<%= link_to 'Subscribe to Pro', new_subscription_path(plan: :pro), %>
new_subscription_path(plan: :beginner)
将计算为 subscription/new?plan=beginner
然后您可以通过参数在模型中访问它。
def new
plan_type = params[:plan]
session = Stripe::Checkout::Session.create(
payment_method_types: ['card'],
client_reference_id: current_user.id,
customer_email: current_user.email,
subscription_data: {
items: [{
plan: plan_type
}]
},
success_url: 'http://localhost:3000/',
cancel_url: 'http://localhost:3000/'
)
@session_id = session.id
end