Stripe API 无效请求:必须提供来源或客户 [英] Stripe API Invalid Request: Must provide source or customer

查看:50
本文介绍了Stripe API 无效请求:必须提供来源或客户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 Stripe API 并构建自定义结帐功能 - 我的错误特别提示我必须提供来源或客户.这是我用于创建费用的控制器:

我以为我使用以下代码成功创建了源和/或客户(我还在我的条带仪表板上包含了帖子日志)

 Stripe::Charge.create(:金额=>@数量,:货币=>'美元',:来源=>参数[:stripeToken],)条纹::客户.创建(:email =>参数[:stripeEmail],:来源=>参数[:stripeToken])错误": {"code": "parameter_missing","doc_url": "https://stripe.com/docs/error-codes/parameter-missing","message": "必须提供来源或客户.",类型":invalid_request_error"}}

我确实浏览了更新 2:当我发送费用时,我看到正在创建一个客户.

更新 3:Source 属性设置为 stripeToken 参数,表示提供的支付方式.令牌由 Checkout 自动创建.- 这似乎可能与我的问题有关 - 也许它没有正确发布?

解决方案

所以它确实是一个令牌请求 - 因为我使用测试卡进行测试,所以我想我必须通过一个测试令牌来确保测试卡会起作用.

我相信我使用的 Rails 参数 (: source => params[:stripeToken]) 适用于生产,但不适用于检查给定的卡片.如果有人像我一样遇到这个问题(当然这可能不是第一次在 SO 上被问到)

使用 Stripe API 时,您会看到测试卡号旁边有一个令牌选项卡 - 我认为出于某种原因,这些是可选的或用于其他用途".他们不是.

您需要确保令牌与您计划使用的任何测试卡相匹配(我认为)

我的 Stripe 控制器现在看起来像这样

Stripe::Charge.create({:金额=>@数量,:货币=>'美元',:来源=>'tok_visa', #params[:stripeToken] 可能用于生产,我认为这是用于测试.,:描述 =>'您对维多利亚大学的捐赠',:statement_descriptor =>'维多利亚大学'# 似乎测试令牌必须设置为字符串.})

决定在那里留下我的评论 - 因为为什么不呢?

P.S 对于不同的卡支付类型,您需要不同的令牌类型.如果你换卡 - 也换代币!!!!- 令牌位于测试卡号旁边.

I'm working on the Stripe API and building a custom checkout function - My error is specifically telling me I must provide a source or customer. This is my controller for creating charges:

I thought I was successfully creating a source and/or customer with the following code (I also included the post logs on my stripe dashboard)

 Stripe::Charge.create(
    :amount => @amount,
    :currency => 'usd',
    :source => params[:stripeToken],
)
Stripe::Customer.create(
    :email => params[:stripeEmail],
    :source => params[:stripeToken]
  )
  "error": {
    "code": "parameter_missing",
    "doc_url": "https://stripe.com/docs/error-codes/parameter-missing",
    "message": "Must provide source or customer.",
    "type": "invalid_request_error"
  }
}

I did go through the docs but I guess I'm still a little lost

Thanks for any assistance!

Update: here is the return of my API POST requests. Update2: I see that a customer is being created when I send a charge.

Update 3: Source property is set to the stripeToken parameter, representing the payment method provided. The token is automatically created by Checkout. - this seems possibly connected to my issue - maybe it's not correctly posting?

解决方案

So it did turn out to be a token request - since I was using a test card for test purposes I imagine I had to pass a test token to ensure that the test card would work.

I believe the Rails Params I was using (: source => params[:stripeToken] ) are fine for production but not when checking against given cards. In case someone comes across this as I did (and of course this probably isn't the first time it was asked on SO)

When using the Stripe API you see there is a token tab beside the test card numbers - I assumed those were optional or "for something else" for some reason. THEY ARE NOT.

You'll want to make sure the token matches whatever test card you plan on using (I think)

My Stripe controller now looks like this

Stripe::Charge.create({
    :amount => @amount,
    :currency => 'usd',
    :source => 'tok_visa',  #params[:stripeToken] might be for in production I think this is for testing.,
    :description => 'Your Donation to Victoria University',
    :statement_descriptor => 'Victoria University'

    # it seems test tokens must be set as string.
  })

Decided to leave my comments in there - because why not?

P.S You'll need different token types for different card payment types. If you switch cards - switch tokens as well !!!! - the tokens are tabbed beside the test card numbers.

这篇关于Stripe API 无效请求:必须提供来源或客户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆