50

I'm setting up payments using the Stripe API to allow a user to log into their Stripe account on an iPad and accept payments from anyone. To do this, I'm using Stripe Connect to log them in and save their account id, then I'm using the STPPaymentCardTextField to obtain credit card details, then using the Stripe iOS SDK I'm submitting a card (with the test card info - 4242...) and getting back a token via createTokenWithCard. This successfully returns a token. At this point I need to submit that token along with the destination account id (provided to the app after the user logged in) and other info (currency, amount, etc) to my own server to submit the payment to Stripe. I have verified that information is being submitted and forwarded onto Stripe, but Stripe is returning an error:

{ type: 'invalid_request_error',
app[web.1]:      message: 'No such token: tok_13vxes2eZkKYli2C9bHY1YfX',
app[web.1]:      param: 'source',
app[web.1]:      statusCode: 400,
app[web.1]:      requestId: 'req_7AIT8cEasnzEaq' },
app[web.1]:   requestId: 'req_7AIT8cEasnzEaq',
app[web.1]:   statusCode: 400 }

If we submit the credit card info directly, avoiding the token altogether, the payment succeeds. Something is wrong with this token, and we are not sure why it is failing. What could be going wrong here?

[[STPAPIClient sharedClient] createTokenWithCard:card completion:^(STPToken *token, NSError *error) {
    //submit tokenId and other info to 'charge' endpoint below
}

NodeJS:

app.post('/charge', (req, res, next) => {
  stripe.charges.create({
    amount: req.body.amount,
    currency: req.body.currency,
    source: req.body.token,
    description: req.body.description,
    destination: req.body.destination
  }, (err, charge) => {
    if (err) return next(err)
    res.json(charge)
  })
})
4

5 回答 5

75

您确定在服务器和客户端上使用相同的 API 密钥吗?
您的服务器应该使用您的(实时/测试)密钥,并且您的 iOS 应用程序应该使用您的(实时/测试)可发布密钥,如Stripe Testing中所述。

于 2015-10-14T23:22:21.620 回答
16

我的测试环境遇到了同样的问题,并且我一直在做的错误,我正在添加 Stripe 收到的令牌,就像这个来源:'tok_18nnwSJ6tVEvTdcVs3dNIhGs',但对于测试环境,我们必须使用source:'tok_visa'

这是 Stripe 提供的测试源列表。https://stripe.com/docs/testing#cards

它为我创造了客户,如果它也帮助了其他人,请告诉我。

于 2018-12-22T15:51:11.120 回答
12

接受的答案对我不起作用。我正在为客户端和服务器使用正确的密钥,但问题仍然存在。我也将源从 iOS 发送到服务器,基于条带示例 RocketRides,它正在发送信用卡的源 ID,即“card_xxx”,这是行不通的。您必须在服务器端为调用添加“客户”属性。

例如:(蟒蛇)

stripe.Charge.create(amount=1000, currency='usd', source="card_xxxxx", **customer**='cus_xxxx', application_fee=600,destination={'account': 'acct_xxxx'})
于 2017-12-07T21:19:35.363 回答
3

这里的两个答案都不适合我。

我试图使用 Stripe 的 PHP 库来为一张我已经存档的卡收费......

$charge = \Stripe\Charge::create([
    'amount' => 1000,
    'currency' => 'gbp',
    'card' => 'card_xxx',
    'description' => 'Payment for Sam',
]);

我收到了上面没有这样的令牌错误。

为了让它工作,我还必须像这样提供客户ID......

$charge = \Stripe\Charge::create([
    'amount' => 1000,
    'currency' => 'gbp',
    'customer' => 'cus_xxx',
    'card' => 'card_xxx',
    'description' => 'Payment for Sam',
]);
于 2018-11-16T14:52:06.437 回答
1
  1. 首先检查 api 密钥是否它们在前端和后端是相同的。
  2. 如果您正在使用测试 api 密钥,那么您必须传递source: 'tok_visa'而不是您的卡源令牌source: 'tok_kb3kb23k2bk32bk3b2'
于 2020-07-16T19:33:53.107 回答