Stripe API:没有 ID 为 X 的令牌 (stripe.charges.create)
Stripe API: There is no token with ID X (stripe.charges.create)
对 node/express 相当陌生,我正在尝试使用 Stripe 3.3.2 and checkout.js 获得一个简单的虚拟电荷。提交结帐表单后,令牌会毫无问题地返回后端;但是,使用该令牌创建费用会导致以下结果:没有 ID 为 tok_xxxxxxxxxxxxxxxxxxxxxxxx
的令牌
我在这里错过了什么?
/views/premium.小胡子
<a id="subscribe" href="#">Pay with Card</a>
<script>
// Define handler to be called when Stripe returns a card token
function onReceiveToken(token, args) {
// Submit token to server so it can charge the card
$.ajax({
url: '/premium/charge',
type: 'POST',
data: {
stripeToken: token
}
});
}
// Configure Checkout
var checkout = StripeCheckout.configure({
key: 'xx_xxxx_xxxxxxxxxxxxxxxxxxxx',
token: onReceiveToken,
image: '/images/logo/stripe.png',
name: 'Test App',
description: 'Premium Sounds',
amount: 500
});
// Open Checkout when the link is clicked
$('#subscribe').on('click', function() {
checkout.open();
return false;
});
</script>
/routes/stripe/charge.js
var dateUtils = require('date-utils'),
config = require('../../../config/config.js'),
stripe = require('stripe')(config.keys.stripe.test.secret_key),
User = require('../../models/User');
module.exports = function(router, app, passport) {
router.get('/premium/charge', function(req, res) {
res.redirect('/premium');
});
router.post('/premium/charge', function(req, res) {
var token = req.body.stripeToken.id,
card = req.body.stripeToken.card.id;
stripe.charges.create({
amount: 500,
currency: 'USD',
source: token,
description: 'Dummy customer'
}, function(err, charge) {
if (err) {
console.log(err);
} else {
console.log(charge);
}
});
});
}
req.body
{
stripeToken: {
id: 'tok_15jsAF2eZvKYlo2CmvgETnJg',
livemode: 'false',
created: '1427204031',
used: 'false',
object: 'token',
type: 'card',
card: {
id: 'card_15jsAF2eZvKYlo2CdXDcaI0h',
object: 'card',
last4: '4242',
brand: 'Visa',
funding: 'credit',
exp_month: '9',
exp_year: '2018',
country: 'US',
name: 'sd@smm.com',
address_line1: '',
address_line2: '',
address_city: '',
address_state: '',
address_zip: '',
address_country: '',
cvc_check: 'pass',
address_line1_check: '',
address_zip_check: '',
dynamic_last4: ''
},
email: 'sd@smm.com',
verification_allowed: 'true',
client_ip: '74.110.163.89'
}
}
条纹响应
{
[Error: There is no token with ID tok_xxxxxxxxxxxxxxxxxx.]
type: 'StripeInvalidRequest',
stack: 'Error: There is no token with ID (node.js:442:13)',
rawType: 'invalid_request_error',
code: undefined,
param: 'source',
message: 'There is no token with ID tok_xxxxxxxxxxxxxxxxxx.',
detail: undefined,
raw: {
type: 'invalid_request_error',
message: 'There is no token with ID tok_xxxxxxxxxxxxxxxxxx.',
param: 'source'
}
}
Stripe 支持很棒。对于那些将来偶然发现这个问题的人,会将其标记为正确答案。
99.9% 的情况下您看到此错误是因为您没有使用 public 密钥创建令牌。检查以确保它是 correct/set。
对 node/express 相当陌生,我正在尝试使用 Stripe 3.3.2 and checkout.js 获得一个简单的虚拟电荷。提交结帐表单后,令牌会毫无问题地返回后端;但是,使用该令牌创建费用会导致以下结果:没有 ID 为 tok_xxxxxxxxxxxxxxxxxxxxxxxx
的令牌我在这里错过了什么?
/views/premium.小胡子
<a id="subscribe" href="#">Pay with Card</a>
<script>
// Define handler to be called when Stripe returns a card token
function onReceiveToken(token, args) {
// Submit token to server so it can charge the card
$.ajax({
url: '/premium/charge',
type: 'POST',
data: {
stripeToken: token
}
});
}
// Configure Checkout
var checkout = StripeCheckout.configure({
key: 'xx_xxxx_xxxxxxxxxxxxxxxxxxxx',
token: onReceiveToken,
image: '/images/logo/stripe.png',
name: 'Test App',
description: 'Premium Sounds',
amount: 500
});
// Open Checkout when the link is clicked
$('#subscribe').on('click', function() {
checkout.open();
return false;
});
</script>
/routes/stripe/charge.js
var dateUtils = require('date-utils'),
config = require('../../../config/config.js'),
stripe = require('stripe')(config.keys.stripe.test.secret_key),
User = require('../../models/User');
module.exports = function(router, app, passport) {
router.get('/premium/charge', function(req, res) {
res.redirect('/premium');
});
router.post('/premium/charge', function(req, res) {
var token = req.body.stripeToken.id,
card = req.body.stripeToken.card.id;
stripe.charges.create({
amount: 500,
currency: 'USD',
source: token,
description: 'Dummy customer'
}, function(err, charge) {
if (err) {
console.log(err);
} else {
console.log(charge);
}
});
});
}
req.body
{
stripeToken: {
id: 'tok_15jsAF2eZvKYlo2CmvgETnJg',
livemode: 'false',
created: '1427204031',
used: 'false',
object: 'token',
type: 'card',
card: {
id: 'card_15jsAF2eZvKYlo2CdXDcaI0h',
object: 'card',
last4: '4242',
brand: 'Visa',
funding: 'credit',
exp_month: '9',
exp_year: '2018',
country: 'US',
name: 'sd@smm.com',
address_line1: '',
address_line2: '',
address_city: '',
address_state: '',
address_zip: '',
address_country: '',
cvc_check: 'pass',
address_line1_check: '',
address_zip_check: '',
dynamic_last4: ''
},
email: 'sd@smm.com',
verification_allowed: 'true',
client_ip: '74.110.163.89'
}
}
条纹响应
{
[Error: There is no token with ID tok_xxxxxxxxxxxxxxxxxx.]
type: 'StripeInvalidRequest',
stack: 'Error: There is no token with ID (node.js:442:13)',
rawType: 'invalid_request_error',
code: undefined,
param: 'source',
message: 'There is no token with ID tok_xxxxxxxxxxxxxxxxxx.',
detail: undefined,
raw: {
type: 'invalid_request_error',
message: 'There is no token with ID tok_xxxxxxxxxxxxxxxxxx.',
param: 'source'
}
}
Stripe 支持很棒。对于那些将来偶然发现这个问题的人,会将其标记为正确答案。
99.9% 的情况下您看到此错误是因为您没有使用 public 密钥创建令牌。检查以确保它是 correct/set。