0
此問題之前已被問過,但沒有任何一個鏈接突出的解決方案,並且在嘗試鏈接中提供的所有方法後問題仍然存在。我正在嘗試生成一個條形碼訂閱計劃,並且每次通過該過程時,我都會看到「此客戶沒有附加付款源」的錯誤消息。正如你在屏幕截圖中看到的那樣,stripe_card_token也被生成了,並且我還有console.log這個令牌也來自JS並且也會被生成。我附上了所有相關的代碼文件。StripeJS錯誤:該客戶沒有附加的支付來源
Github的鏈接,這個項目:https://github.com/arpit016/picture-app
Stripeerror截圖
user.rb文件
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable
belongs_to :plan
attr_accessor :stripe_card_token
def save_with_payment
if valid?
customer = Stripe::Customer.create(
:source => stripe_card_token,
:email => email,
:plan => plan_id
)
self.stripe_customer_token = customer.id
save!
end
end
end
users.js文件
$(document).ready(function() {
Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'));
$('#form-submit-btn').click(function(event) {
event.preventDefault();
$('input[type=submit]').prop('disabled', true);
var error = false;
if (!error) {
Stripe.card.createToken($('#new_user'), stripeResponseHandler);
}
return false;
}); //form submission
function stripeResponseHandler(status, response){
if (status == 200){
//Get a reference to the form
var f = $('#new_user');
//Get the token from the response
var token = response.id;
console.log("Token:" + token);
//Add the token to the form
f.append('<input type="hidden" name="user[stripe_card_token]" value="' + token + '" />');
console.log(f)
//Submit the form
f.get(0).submit();
}
else {
$('#stripe_error').text(response.error.message).show();
$('input[type=submit]').attr('disabled', false)
}
}
});
個
設計修改註冊記憶控制器
class Users::RegistrationsController < Devise::RegistrationsController
before_filter :select_plan, only: [:new]
def create
super do |resource|
if params[:plan]
resource.plan_id = params[:plan]
if resource.plan_id == 2
resource.save_with_payment
else
resource.save
end
end
end
end
def select_plan
unless params[:plan] && (params[:plan] == '1' || params[:plan] == '2')
flash[:warning] = "Please select a valid membership"
redirect_to root_url
end
end
end
@Deepak我已經看到該鏈接,我已經使用卡的來源,而不是在創建客戶 –