如何将条带令牌从 angularjs 传递到 nodejs 或修复错误 nodejs 帖子
How do I pass a stripe token from angularjs to nodejs or fix error nodejs post?
我正在尝试设置条纹付款,但遇到错误:类型错误:无法在 Layer.handle [作为handle_request]读取/Users/andreykondratyuk/websites/talllly/src/server/app.js:56:37
处未定义的
属性"id"。
形式:
<form stripe-form="stripeCallback" name="checkoutForm">
<input ng-model="number" placeholder="Card Number" payments-format="card" payments-validate="card" name="card" />
<input ng-model="expiry" placeholder="Expiration" payments-format="expiry" payments-validate="expiry" name="expiry" />
<input ng-model="cvc" placeholder="CVC" payments-format="cvc" payments-validate="cvc" name="cvc" />
<button type="submit">Submit</button>
<div ng-if="checkoutForm.card.$invalid"> Error: invalid card number! </div>
</form>
在控制器中
// Stripe Response Handler
$scope.stripeCallback = function (code, result) {
console.log(result);
if (result.error) {
window.alert('it failed! error: ' + result.error.message);
} else {
// Simple POST request example (passing data) :
$http.post('/charge', result)
.success(function(data, status, headers, config) {
alert(data);
})
.error(function(data, status, headers, config) {
alert(data);
});
}
};
在后端应用上.js
app.post('/charge', function(req, res) {
console.log(req);
var stripeToken = req.body.token.id;
var charge = stripe.charges.create({
amount: 10000, // amount in cents, again
currency: "usd",
card: stripeToken,
description: "email@email.com"
}, function(err, charge) {
if (err && err.type === 'StripeCardError') {
console.log(JSON.stringify(err, null, 2));
}
res.send("completed payment!");
});
});
我做错了什么?
令牌 id 在响应体上作为id
,条带没有返回令牌对象.js调用,检查文档。
所以在节点你的行:
var stripeToken = req.body.token.id;
应该是:
var stripeToken = req.body.id;
相关文章:
- nodejs-expressjs上传图像并显示它们
- TypeError:在不兼容的接收器nodejs上调用了方法Uint8Array.length
- NodeJS-readline暂停和恢复事件发射器(逐行读取)
- NodeJS日期格式不起作用
- Nested Q.all nodejs
- Nodejs API控制器,用于在API之间切换
- 否'访问控制允许来源'标头存在于IISNOde中请求的资源(AngularJS+NodeJs)上
- 如何在大型nodeJS代码的基础上逐步引入typescript
- 在Nodejs中Express输入DEBUG=app时权限被拒绝/bin
- 无法使用nodeJS在html中设置Image src
- 与域在同一台计算机上运行的NODEJS服务器的CORS错误
- 刷新导致我的帖子“;张贴“;再一次
- NodeJS API调用中Array中的Push和Pull元素
- 基于api密钥的NodeJS web服务
- 在gump和nodejs中使用Typescript时,未定义对require和exports的引用
- “util.inherits”和在NodeJS中扩展原型之间的区别
- 将一个方法转换为promise:Nodejs
- 如何将条带令牌从 angularjs 传递到 nodejs 或修复错误 nodejs 帖子
- SailsJS挂起ajax帖子(NodeJS)
- nodejs的角度帖子