Здравствуйте, я создаю сайт, на котором я выполняю планы и подписки с полосой, чтобы зарегистрироваться.
Я не знаю, что изменилось, но мой сайт работал правильно, а потом я начал получатьэта ошибка, и я пробовал несколько вещей, но я не могу это исправить.
Это ошибка, которую я получаю
Stripe::InvalidRequestError in Users::RegistrationsController#create
Invalid source object: must be a dictionary or a non-empty string. See API docs at https://stripe.com/docs'
Extracted source (around line #28):
26 def save_with_subscription
27 if valid?
28 customer = Stripe::Customer.create(email: email, plan: plan_id, source: stripe_card_token)
29 self.stripe_customer_token = customer.id
30 save!
31 end
Это мой JavaScriptфайл интенсивный_план.js
/* global $, Stripe */
//Document ready.
$(document).on('turbolinks:load', function(){
var theFormIntensive = $('#intensive_form');
var submitBtnIntensive = $('#form-signup-btn-intensive');
//Set Stripe public key.
Stripe.setPublishableKey( $('meta[name="stripe-key"]').attr('content') );
//When user clicks form submit btn,
submitBtnIntensive.click(function(event){
//prevent default submission behavior.
event.preventDefault();
submitBtnIntensive.val("Procesando").prop('disabled', true);
//Collect the credit card fields.
var ccNum = $('#card_number').val(),
cvcNum = $('#card_code').val(),
expMonth = $('#card_month').val(),
expYear = $('#card_year').val();
//Use Stripe JS library to check for card errors.
var error = false;
//Validate card number.
if(!Stripe.card.validateCardNumber(ccNum)) {
error = true;
alert('The credit card number appears to be invalid');
}
//Validate CVC number.
if(!Stripe.card.validateCVC(cvcNum)) {
error = true;
alert('The CVC number appears to be invalid');
}
//Validate expiration date.
if(!Stripe.card.validateExpiry(expMonth, expYear)) {
error = true;
alert('The expiration date appears to be invalid');
}
if (error) {
//If there are card errors, don't send to Stripe.
submitBtnIntensive.prop('disabled', false).val("Sign Up");
} else {
//Send the card info to Stripe.
Stripe.createToken({
number: ccNum,
cvc: cvcNum,
exp_month: expMonth,
exp_year: expYear
}, stripeResponseHandler);
}
return false;
});
//Stripe will return a card token.
function stripeResponseHandler(status, response) {
//Get the token from the response.
var token = response.id;
//Inject the card token in a hidden field.
theFormIntensive.append( $('<input type="hidden" name="user[stripe_card_token]">').val(token) );
//Submit form to our Rails app.
theFormIntensive.get(0).submit();
}
});
Это мой user.rb файл модели
class User < ApplicationRecord
belongs_to :plan
############################################################################################
## PeterGate Roles ##
## The :user role is added by default and shouldn't be included in this list. ##
## The :root_admin can access any page regardless of access settings. Use with caution! ##
## The multiple option can be set to true if you need users to have multiple roles. ##
petergate(roles: [:site_admin], multiple: false) ##
############################################################################################
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :validatable
validates_presence_of :name
# If pro user passes validations (email,password, etc..),
# then call Stripe and tell Stripe to set up a subscription
# upon charging the customer's card.
# Sripe responds back with customer data.
# Store customer.id as the customer token and save the user.
attr_accessor :stripe_card_token
def save_with_subscription
if valid?
customer = Stripe::Customer.create(email: email, plan: plan_id, source: stripe_card_token)
self.stripe_customer_token = customer.id
save!
end
end
def first_name
self.name.split.first
end
def last_name
self.name.split.last
end
end
Я считаю, что главная проблема в том, что я не получаюверните stripe_card_token из stripe, и значение будет пустым, но я не знаю, что делать, есть идеи?