Invalid API Key provided: pk_live_ in React Form

huangapple go评论57阅读模式
英文:

Invalid API Key provided: pk_live_ in React Form

问题

我确定我已经尝试了一切。

我正在构建一个NextJS应用,并使用以下代码:

import { Elements } from '@stripe/react-stripe-js';

它正在调用以下地址:

https://api.stripe.com/v1/elements/sessions?
key=pk_live_51KpyLFB...jijj%7D
&type=setup_intent&locale=en-US&client_secret=seti_1NFl...wUL
&expand[0]=payment_method_preference.setup_intent.payment_method

Stripe密钥是正确的。但我仍然收到以下错误信息:

{
  "error": {
    "message": "提供了无效的API密钥:pk_live_************************************************************************************************ijj}",
    "type": "invalid_request_error"
  }
}

到底是什么问题?

英文:

I am certain that I've tried everything.

I am building a NextJS app and using the

import { Elements } from '@stripe/react-stripe-js';

It is making a call at

https://api.stripe.com/v1/elements/sessions?
key=pk_live_51KpyLFB...jijj%7D
&type=setup_intent&locale=en-US&client_secret=seti_1NFl...wUL
&expand[0]=payment_method_preference.setup_intent.payment_method

the Stripe keys are correct. And I still get this error.

{
  "error": {
    "message": "Invalid API Key provided: pk_live_************************************************************************************************ijj}",
    "type": "invalid_request_error"
  }
}

What on earth could be wrong??

答案1

得分: 1

在公钥的末尾多余的花括号是问题所在。我认为Stripe的密钥是字母数字组合,不包括符号。

在/elements/sessions URL中,花括号被编码为%7D,所以从可发布密钥的末尾移除它应该可以解决问题(只要可发布密钥与你服务器端使用的秘密密钥相匹配)。

英文:

Adding the answer here so it's not nested in the comments. The issue here is the extra curly brace at the end of the public key. I believe Stripe's keys are alphanumeric and don't include symbols.

In the /elements/sessions URL, the curly brace is encoded to %7D so removing this from the end of the publishable key should work (as long as the publishable key is the correct counterpart to the secret key you're using server side).

huangapple
  • 本文由 发表于 2023年6月6日 05:20:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76410082.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定