我Stripe
和Rails
设置了Devise
。它工作得很漂亮,但有三个错误。
首先,我想实施两个不同的计划。一旦他们使用Pay With Stripe
按钮选择它,Stripe
就可以让客户支付他们每月选择的计划。
第二个问题:当我进入/charges/new
路径时,它的工作效果非常好,并显示了计划。但是,当我转到/charges
路径时,它会给我This customer has no attached payment source
的错误。
第三个问题:用户应该从/users/new
转到/charges/new
。这不会发生。
我如何解决所有这些错误?
这是我的charges_controller.rb
:
class ChargesController < ApplicationController
before_filter :authenticate_user!
def new
end
def update
end
def create
token = params[:stripeToken]
customer = Stripe::Customer.create(
source: token,
plan: 2020,
email: current_user.email,
)
current_user.subscribed = true
current_user.stripeid = customer.id
current_user.save
redirect_to profile_path
end
end
这是我的routes.rb
文件:
Rails.application.routes.draw do
devise_for :users, controllers: {registrations: "registrations"}, path_names: { sign_in: "login", sign_out: "logout", registration: "signup", sign_up: "cmon_lemme_in_guys" }
resources :things
resources :charges, only: [:new, :create]
get "charges", to: "charges#create"
authenticated :user do
root "things#profile"
get "profile", to: "things#profile"
end
root "index#welcome"
get "license/terms"
end