ios 向 Stripe 提交付款请求时出现“无此类令牌”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33137053/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 07:59:36  来源:igfitidea点击:

'No such token' error upon submitting payment request to Stripe

iosnode.jsstripe-paymentsstripe-connect

提问by Jordan H

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 STPPaymentCardTextFieldto 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:

我正在使用 Stripe API 设置付款,以允许用户在 iPad 上登录他们的 Stripe 帐户并接受任何人的付款。为此,我使用 Stripe Connect 登录他们并保存他们的帐户 ID,然后我使用STPPaymentCardTextField获取信用卡详细信息,然后使用 Stripe iOS SDK 我提交卡(带有测试卡信息- 4242...) 并通过createTokenWithCard. 这成功地返回了一个令牌。此时,我需要将该令牌以及目标帐户 ID(在用户登录后提供给应用程序)和其他信息(货币、金额等)提交到我自己的服务器,以将付款提交给 Stripe。我已验证信息正在提交并转发到 Stripe,但 Stripe 返回错误:

{ 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)
  })
})

回答by jflinter

Are you sure you're using the same API keys on your server and client?
Your server should be using your (live/test) secret key, and your iOS app should be using your (live/ test) publishable key as mentioned here on Stripe Testing.

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

回答by Hamza Khan

I had been facing same issue for my test environment and the mistake i had been doing, i was adding the token received by Stripe like this one source: 'tok_18nnwSJ6tVEvTdcVs3dNIhGs', but for the test environment we have to use source: 'tok_visa'.

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

Here is the list of test sources provided by Stripe. https://stripe.com/docs/testing#cards

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

It created customer for me, let me know if it helped anyone else as well.

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

回答by Usher

The accepted answer does not work for me. I am using correct key for client and server, but still the issue is still there. I am sending source from iOS to the server as well, based on stripe example RocketRides, it is sending source ID of the credit card, which is "card_xxx", and that is not gonna work. You will have to add "customer" attribute for the call on your server side.

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

For example: (python)

例如:(蟒蛇)

stripe.Charge.create(amount=1000, currency='usd', source="card_xxxxx", **customer**='cus_xxxx', application_fee=600,destination={'account': 'acct_xxxx'})

回答by Sam L

Neither of the answers here worked for me.

这里的答案都不适合我。

I was trying to use Stripe's PHP library to charge a card that I already had on file like this...

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

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

And I was receiving the no such token error above.

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

To get it to work, I also had to provide the customer id like so...

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

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