首页 文章

向Stripe提交付款请求时出现'No such token'错误

提问于
浏览
27

我'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'使用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 }

如果我们直接提交信用卡信息,完全避免令牌,则付款成功 . 这个令牌有问题,我们不确定它为什么会失败 . 这可能会出错?

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

3 回答

  • 46

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

    例如:(python)

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

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

  • 0

    这里的答案都不适用于我 .

    我试图使用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',
    ]);
    

相关问题