我之前修复了我的models / user.rb文件以及我的layout / applications.html.erb文件,并且能够使用Stripe处理信用卡。
然而,当我第二天再次尝试时,它突然停止工作。我收到了错误:
Devise中的Stripe :: InvalidRequestError :: RegistrationsController #create
您为'card'传递了一个空字符串。我们假设空值是试图取消设置参数;但是'卡'不能被取消。您应该从请求中删除“卡片”或提供非空值
这两个文件都有任何想法,为什么它不起作用?如果您需要我提供更多信息,请告诉我
以下是存储库的链接 - https://github.com/matthewwoo/boldesttea
模型/ user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
#validates :name, presence: true
after_create :create_a_customer
attr_accessor :stripe_card_token
def create_a_customer
token = self.stripe_card_token
customer = Stripe::Customer.create(
:card => token,
:plan => 1,
:email => self.email
)
end
end
布局/ application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Boldesttea</title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "https://js.stripe.com/v1/", type: 'text/javascript' %>
<%= javascript_tag "alert('#{Rails.configuration.stripe[:publishable_key]}')", type: 'text/javascript' %>
<%= javascript_tag "Stripe.publishableKey = '#{Rails.configuration.stripe[:publishable_key]}';", type: 'text/javascript' %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class='key'>
<%= puts Rails.configuration.stripe[:publishable_key] %>
</div>
<%= render 'layouts/header'%>
<% flash.each do |name, msg| %>
<%= content_tag(:div, msg, class: "alert alert-info") %>
<% end %>
<%= yield %>
</body>
</html>