我正在制作一个Rails应用程序,允许用户以$ X/yr成为订阅用户,我被困在订阅页面上,无论我做什么,stripeToken都没有附加到请求和CreateSubscription.rb说"这个客户没有附加付款来源".我的turbolinks被禁用了.
我的条带日志说它正在获取POST主体的请求:电子邮件:"raf6000@gmail.com"计划:"praducks-annual"但错误被抛出如下 - 因为没有源对象附加到请求 - 错误:type:"invalid_request_error"消息:"此客户没有附加的付款来源"
CreateSubscription.rb
class CreateSubscription
def self.call(plan, email_address, token)
user, raw_token = CreateUser.call(email_address)
subscription = Subscription.new(
plan: plan,
user: user
)
begin
stripe_sub = nil
if user.stripe_customer_id.blank?
puts "Customer is new"
puts token.nil?
customer = Stripe::Customer.create(
source: token,
email: user.email,
plan: plan.stripe_id,
)
user.stripe_customer_id = customer.id
user.save!
stripe_sub = customer.subscriptions.first
else
puts "Customer exists"
customer = Stripe::Customer.retrieve(user.stripe_customer_id)
# Check if the customer was a stripe customer, but had no source added
# If no source …Run Code Online (Sandbox Code Playgroud)