Stripe :: InvalidRequestError:此客户没有附加的付款来源

时间:2017-01-18 21:37:58

标签: ruby-on-rails ruby stripe-payments

我试图在Upskill的基本Web开发人员课程的113讲课结束时进行测试注册,但是我得到了以下错误,并且我一直在以前的讲座中进行过一遍又一遍,并且无法查明哪里出错了。

Stripe::InvalidRequestError in Users::RegistrationsController#create

This customer has no attached payment source

Extracted source (around line #10):

8  def save_with_subscription
9    if valid?
10      customer = Stripe::Customer.create(description: email, plan: plan_id, card: stripe_card_token)
11      self.stripe_customer_token = customer.id
12      save!
13    end

Rails.root: /home/ubuntu/workspace/saasapp

Application Trace | Framework Trace | Full Trace
app/models/user.rb:10:in `save_with_subscription'
app/controllers/users/registrations_controller.rb:7:in `block in create'
app/controllers/users/registrations_controller.rb:3:in `create'
Request

Parameters:

{"utf8"=>"✓",
"authenticity_token"=>"/4EiUCLerdc0o+vIbZWWZzxC3cm1TSjyWGs/lYq/H4RiT6zwohUJUQnZaIrxADF2RiWcs6G3BDXiRDQT/bEa4Q==",
"plan"=>"2",
"user"=>{"email"=>"test@example.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"},
"commit"=>"Sign up"}

Toggle session dump
Toggle env dump
Response

Headers:

None

LOG

Started POST "/users" for 81.140.28.63 at 2017-01-18 21:24:44 +0000
Cannot render console from 81.140.28.63! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
    Processing by Users::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"GIGatf9j6proPQgjnjCwR6r6BBeDLCYa2lhOG453bQLwln1wTOEbVSPaPow6ZLGBcGpvX3Qm1Fw03vpQc0Xtsg==", "plan"=>"2", "user"=>{"email"=>"test@example.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
   (0.1ms)  begin transaction
  User Exists (0.3ms)  SELECT  1 AS one FROM "users" WHERE "users"."email" = ? LIMIT ?  [["email", "test@example.com"], ["LIMIT", 1]]
   (0.2ms)  rollback transaction
  User Exists (0.2ms)  SELECT  1 AS one FROM "users" WHERE "users"."email" = ? LIMIT ?  [["email", "test@example.com"], ["LIMIT", 1]]
  Plan Load (0.1ms)  SELECT  "plans".* FROM "plans" WHERE "plans"."id" = ? LIMIT ?  [["id", 2], ["LIMIT", 1]]
Completed 500 Internal Server Error in 905ms (ActiveRecord: 0.9ms)



Stripe::InvalidRequestError (This customer has no attached payment source):

app/models/user.rb:10:in `save_with_subscription'
app/controllers/users/registrations_controller.rb:7:in `block in create'
app/controllers/users/registrations_controller.rb:3:in `create'
  Rendering /usr/local/rvm/gems/ruby-2.3.0@saasapp/gems/actionpack-5.0.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout
  Rendering /usr/local/rvm/gems/ruby-2.3.0@saasapp/gems/actionpack-5.0.0/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
  Rendered /usr/local/rvm/gems/ruby-2.3.0@saasapp/gems/actionpack-5.0.0/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (9.5ms)
  Rendering /usr/local/rvm/gems/ruby-2.3.0@saasapp/gems/actionpack-5.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
  Rendered /usr/local/rvm/gems/ruby-2.3.0@saasapp/gems/actionpack-5.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (4.3ms)
  Rendering /usr/local/rvm/gems/ruby-2.3.0@saasapp/gems/actionpack-5.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
  Rendered /usr/local/rvm/gems/ruby-2.3.0@saasapp/gems/actionpack-5.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.7ms)
  Rendered /usr/local/rvm/gems/ruby-2.3.0@saasapp/gems/actionpack-5.0.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (43.3ms)

3 个答案:

答案 0 :(得分:0)

我建议将请求分开以查看它的哪个部分实际上已失败。我怀疑这是因为它正在发生的事情只是因为其他事情正在发生而且它无法显示有意义的错误信息。

试试这个:

cus = Stripe::Customer.create(description: email)
self.stripe_customer_token = cus.id
cus.sources.create(source: stripe_card_token)
sub = Stripe::Subscription.create(customer: cus.id, plan: plan_id)
save!

答案 1 :(得分:0)

我刚刚遇到同样的问题。 我修复了错字但仍然遇到了同样的错误。看起来课程视频中使用的测试卡号可能是另一个来源 错误也是。我使用了以下页面中的测试编号,所有测试编号都按预期工作。

https://stripe.com/docs/testing#cards

只是我的2个人!

答案 2 :(得分:-1)

非常感谢您花时间回复。所以我给了它几天,昨晚又看了一遍,结果证明这是一个相当简单和愚蠢的错误。

在课程视频和注释中,教师更正了users.js文件中的拼写错误,在该文件中,他为表单中的提交按钮引用了错误的ID。他打字了

var submitBtn = $('#form-submit-btn');

但他在表格

中使用了以下内容
var submitBtn = $('#form-signup-btn');

虽然我更改了我的users.js文件以匹配更正,但不知怎的,我实际上使用了#form-submit-btn'所以当我按照课程更正了users.js文件时,我确实引起了问题。