我正在使用stripe.js切换条带检出.当我输入卡片时,一切都有效,除非它从未通过.每当我点击提交时,我收到的错误是:
Cannot charge a customer that has no active card
我已经尝试过使用测试卡和真实的信用卡号码,他们两个都给了我同样的错误.这是我的stripe.rb:
class ChargesController < ApplicationController before_action :authenticate_user! def new end def create # Amount in cents @amount = 500 customer = Stripe::Customer.create( :email => params[:stripeEmail], :source => params[:stripeToken] ) Stripe.api_key = 'sk_test_string' charge = Stripe::Charge.create( :amount => 1000, :customer => customer.id, :currency => "usd", :card => params[:stripeToken] # replace full card details with the string token from our params ) rescue Stripe::CardError => e flash[:error] = e.message redirect_to new_charge_path end end
这是我的嵌入式javascript的haml:
.well{:style => "margin-left: 0px; position: relative; min-width: 650px; min-height: 180px; max-height: 180px"} = form_tag charges_path :id => 'payment-form' do .row .row %div %label.control-label{:for => "number"} Card Number %input#number{"data-stripe" => "number", :pattern => "[\\d ]*", :placeholder => "**** **** **** ****", :size => "20", :style => "width: 18em", :type => "text", :maxlength => "16"}/ .row %div %label.control-label{:for => "cvc"} CVC %input#cvc{"data-stripe" => "cvc", :pattern => "\\d*", :placeholder => "***", :size => "3", :style => "width: 3em", :type => "text"}/ = image_tag "credit.png" %div %label.control-label Exp (MM/YYYY) %input#exp-month{"data-stripe" => "exp-month", :pattern => "\\d*", :placeholder => "MM", :size => "2", :type => "text"}/ %span / %input#exp-year{"data-stripe" => "exp-year", :pattern => "\\d*", :placeholder => "YYYY", :size => "4", :type => "text"}/ .row .price 5.00 %div %button.btn.btn-primary.btn-large{:type => "submit"} Buy Now :javascript Stripe.setPublishableKey('pk_test_string'); $('#payment-form').submit(function(event) { var form = $(this); form.find('button').prop('disabled', true); Stripe.createToken(form, stripeResponseHandler); return false; }); function stripeResponseHandler(status, response) { var form = $('#payment-form'); if (response.error) { form.find('.payment-errors').text(response.error.message); form.find('button').prop('disabled', false); } else { var token = response.id; form.append($('').val(token)); form.get(0).submit(); }
编辑:我进入了条带上的错误日志,它给了我这个:
error: message: "Cannot charge a customer that has no active card" type: "card_error" param: "card" code: "missing"
但我填写了卡错误,它应该工作.如果它有助于我使用测试键.
编辑2:这是条带发送的内容
id: cus_7gzOPGpAB2DMYY object: "customer" account_balance: 0 created: 1452402410 currency: null default_source: null delinquent: false description: "Thank you" discount: null email: null livemode: false metadata: shipping: null sources: object: "list" data: has_more: false total_count: 0 url: "/v1/customers/cus_7gzOPGpAB2DMYY/sources" subscriptions: object: "list" data: has_more: false total_count: 0 url: "/v1/customers/cus_7gzOPGpAB2DMYY/subscriptions"
Steven Yue.. 6
我想你应该把:card => params[:stripeToken]
进入Stripe::Customer.create
,而不是Stripe::Charge.create
我想你应该把:card => params[:stripeToken]
进入Stripe::Customer.create
,而不是Stripe::Charge.create