php Stripe:没有这样的令牌......测试模式中存在类似的对象,但使用实时模式密钥来发出此请求
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28952987/
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
Stripe: No such token.. a similar object exists in test mode, but a live mode key was used to make this request
提问by Julien
When using Stripe in live mode I get this PHP error:
在实时模式下使用 Stripe 时,我收到此 PHP 错误:
No such token tok_fgfhn.. a similar object exists in test mode, but a live mode key was used to make this request
没有这样的令牌 tok_fgfhn .. 测试模式中存在类似的对象,但使用实时模式密钥来发出此请求
Everything works well in Stripe test mode, and and I've switched to a live API key.
在 Stripe 测试模式下一切正常,而且我已经切换到实时 API 密钥。
I create a new customer like this:
我创建了一个这样的新客户:
$token = $_POST['stripeToken'];
$email = $_POST['email'];
$customer = \Stripe\Customer::create(array(
'email' => $email,
'card' => $token
));
//charge for user ads
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => $amount,
'currency' => 'eur'
));
I've tested many hours but I still get this error. How can I fix it?
我已经测试了很多小时,但仍然出现此错误。我该如何解决?
采纳答案by Jake T.
It sounds like you're trying to charge a customer who exists on your test account, not on your live account. Make sure you are making a new customer with your live keys and using their token to create the charge.
听起来您正在尝试向存在于您的测试帐户而非真实帐户中的客户收费。确保您正在使用您的实时密钥创建新客户并使用他们的令牌来创建费用。
回答by devXen
Look into the javascript that uses test public API key to retrieve token. Change it to your live public API key.
查看使用测试公共 API 密钥检索令牌的 javascript。将其更改为您的实时公共 API 密钥。
It should be something like this
它应该是这样的
Stripe.setPublishableKey('pk_test_axEdfdasdfasfsadfsad');
回答by A.Aleem11
You will have two different keys in your stripe account. Kindly make sure you've replace both test keys with live keys:
您的条带帐户中将有两个不同的密钥。请确保您已用实时密钥替换了两个测试密钥:
live sectret key: sk_live_00000000000000000000000
实时秘钥:sk_live_00000000000000000000000
live publish key: pk_live_00000000000000000000000
实时发布密钥:pk_live_00000000000000000000000
1- Secret key will replace in all your php scripts where're charging
1- 密钥将替换所有正在收费的 php 脚本
\Stripe\Stripe::setApiKey("sk_live_00000000000000000000");
2- Publish key will replace in your .JS file through which you're validating your payment form this same file also creates token after successful validation. It may call stripe.js or may other name you need to locate this file it will have publish key that you need to replace from test to live:
2- 发布密钥将替换您正在验证付款表单的 .JS 文件,该文件也会在成功验证后创建令牌。它可能会调用 stripe.js 或您需要的其他名称来定位此文件,它将具有您需要从测试替换为实时的发布密钥:
Stripe.setPublishableKey('pk_live_0000000000000'); //this would be publish key
function stripeResponseHandler(status, response) { //token function
if (response.error) {
// re-enable the submit button
$('.submit-button').removeAttr("disabled");
// show hidden div
document.getElementById('a_x200').style.display = 'block';
// show the errors on the form
$(".payment-errors").html(response.error.message);
} else {
var form$ = $("#payment-form");
// token contains id, last4, and card type
var token = response['id'];
// insert the token into the form so it gets submitted to the server
form$.append("<input type='hidden' name='stripeToken' value='" + token + "' />");
// and submit
form$.get(0).submit();
}
}
回答by Daniel Costa
After spending some hours on it. I'm letting this here if it might help someone else:
在花了几个小时之后。如果它可以帮助其他人,我会在这里放它:
I've an application deployed on Heroku with the secret and publishable key stored in environment variable on heroku.
我在 Heroku 上部署了一个应用程序,其秘密和可发布密钥存储在 heroku 的环境变量中。
I use <%= ENV.fetch('STRIPE_PU_KEY') %>
in a .coffee.erb
我<%= ENV.fetch('STRIPE_PU_KEY') %>
在一个.coffee.erb
Be aware if you change and restart your server it won't be enough. You will need to regenerate your application.js otherwise it will still take the catched value.
请注意,如果您更改并重新启动服务器,这还不够。您将需要重新生成 application.js,否则它仍将采用捕获的值。
Hope it helps
希望能帮助到你