stripe.tokens.create returns 没有
stripe.tokens.create returns nothing
我有以下代码
import { STRIPE_SK } from '../../constants';
const secretKey = STRIPE_SK
const stripe = require('stripe')(secretKey);
export async function createToken(){
try{
console.log("Start process")
const token = await stripe.tokens.create({
card: {
number: '4242424242424242',
exp_month: 12,
exp_year: 2022,
cvc: '314',
},
});
console.log("Token - ", token)
return token
}catch(err){
console.log(err)
throw err
}
}
我想获得令牌,但我什么也没得到。没有错误就没有成功
the result of the function in the console
我刚刚复制粘贴了您的功能的内容并且它起作用了:我在我的日志中看到了一个卡片令牌。当运行这段代码时,你需要确保:
- 您实际上是在后端代码中的某处调用您的函数。
- 您在正确的地方查看日志。您的屏幕截图看起来像一个浏览器控制台,您只能在其中看到前端日志。对于后端日志,您应该查看启动 node.js 服务器的终端。
- 并且您使用的是测试 API 密钥(而不是实际密钥),因为您目前没有处理真实的卡片。
也就是说,我不建议使用此代码,因为发送原始卡号存在 PCI 合规性问题。相反,您应该按照 this Stripe guide 接受付款。
我有以下代码
import { STRIPE_SK } from '../../constants';
const secretKey = STRIPE_SK
const stripe = require('stripe')(secretKey);
export async function createToken(){
try{
console.log("Start process")
const token = await stripe.tokens.create({
card: {
number: '4242424242424242',
exp_month: 12,
exp_year: 2022,
cvc: '314',
},
});
console.log("Token - ", token)
return token
}catch(err){
console.log(err)
throw err
}
}
我想获得令牌,但我什么也没得到。没有错误就没有成功
the result of the function in the console
我刚刚复制粘贴了您的功能的内容并且它起作用了:我在我的日志中看到了一个卡片令牌。当运行这段代码时,你需要确保:
- 您实际上是在后端代码中的某处调用您的函数。
- 您在正确的地方查看日志。您的屏幕截图看起来像一个浏览器控制台,您只能在其中看到前端日志。对于后端日志,您应该查看启动 node.js 服务器的终端。
- 并且您使用的是测试 API 密钥(而不是实际密钥),因为您目前没有处理真实的卡片。
也就是说,我不建议使用此代码,因为发送原始卡号存在 PCI 合规性问题。相反,您应该按照 this Stripe guide 接受付款。