无法向没有活动卡条的客户收费
Cannot charge a customer that has no active card stripe
我正在使用 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
这是我嵌入的 haml javascript:
.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($('<input type="hidden" name="stripeToken">').val(token));
form.get(0).submit();
}
编辑:
我进入了 stripe 的错误日志,它给了我这个:
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"
我认为你应该将 :card => params[:stripeToken]
放入 Stripe::Customer.create
而不是 Stripe::Charge.create
我联系了 stripe,他们解决了。这是 haml 插入此代码的方式。所以不是这个:
= form_tag charges_path :id => 'payment-form' do
你应该这样做:
= form_tag charges_path do
#payment-form
它会正常工作。
我正在使用 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
这是我嵌入的 haml javascript:
.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($('<input type="hidden" name="stripeToken">').val(token));
form.get(0).submit();
}
编辑: 我进入了 stripe 的错误日志,它给了我这个:
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"
我认为你应该将 :card => params[:stripeToken]
放入 Stripe::Customer.create
而不是 Stripe::Charge.create
我联系了 stripe,他们解决了。这是 haml 插入此代码的方式。所以不是这个:
= form_tag charges_path :id => 'payment-form' do
你应该这样做:
= form_tag charges_path do
#payment-form
它会正常工作。