node.js - 条纹 - 创造电荷
问题描述
致力于整合菌柄。一切似乎都在前端工作,但在服务器端代码上,令牌是空的,它没有成功地向 Stripe 收费。似乎无法弄清楚我要去哪里错了。
app.post('/apple-pay', function(req, res, next) {
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
var stripe = require("stripe")("sk_test_XXX");
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
const token = req.body.stripeToken;
console.log(token)
const charge = stripe.charges.create({
amount: 999,
currency: 'usd',
description: 'Example charge',
source: token,
}, function(err, charge) {
if(err){
req.flash("error", err.message);
res.redirect("back");
} else {
}
});
});
解决方案
在另一个问题的前端代码中,您将 POST 正文传递为
JSON.stringify({token: ev.token.id})
这意味着 Stripe 令牌实际上在token
POST 参数中,而不是stripeToken
. 所以你需要做
const token = req.body.token;
反而。
推荐阅读
- swift - TextFields 不会使用展开函数 Swift 中的值进行更新
- typescript - 为 VSCode 扩展 API 创建每个单词的独特悬停?
- php - 如何修复 PHP 中的“指定的 DSN 包含驱动程序和应用程序之间的体系结构不匹配”错误
- cabal - IHaskell 用于新型阴谋集团项目?
- r - 如何使用 sf 包从 3D 数据中提取建筑面积
- reactjs - react.js 中如何使用 localStorage?
- kotlin - Android协程没有完成
- java - FTPClient.retrieveFile 返回 false,但文件仍在下载
- termux - 打开 termux:127|:/data/data/com.termux/files/home 后出错
- vert.x - 如何在 vertx future compose 中使用中间结果?