我正在使用Stripe Elements并测试输入表单。我的API请求正在处理中,正在创建客户,但是我收到错误消息。
这是我的控制器:
class ChargesController < ApplicationController
skip_before_action :verify_authenticity_token
protect_from_forgery prepend: true
def new
end
def create
# Amount in cents
@amount = 500
token = params[:stripeToken]
payment_form = params[:payment_form]
customer = Stripe::Customer.create(
:email => params[:stripeEmail],
:source => params[:stripeToken]
)
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => @amount,
:description => 'Rails Stripe customer',
:currency => 'usd',
:source => token
)
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to new_charge_path
end
end
这是我的观点:
每个请求都成功-每个请求都收到错误。
这是我的浏览器控制台的作用:
TypeError: form is null new:88:1
[Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIContentSniffer.getMIMETypeFromContent]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: resource:///modules/FaviconLoader.jsm :: onStopRequest :: line 181" data: no]
当我输入信用卡测试凭据时,我的CMD:
Started POST "/charges" for 127.0.0.1 at 2018-10-26 14:26:53 -0400
Processing by ChargesController#create as HTML
Can't verify CSRF token authenticity.
Redirected to http://localhost:3000/charges/new
Completed 302 Found in 1320ms (ActiveRecord: 0.0ms)
有人对做什么有建议?
一切都与Stripe Checkout完美配合,但是我似乎还无法成功运行Elements。