Node.js 如何正确创建';收费';在Stripe nodejs库中? 客户
我正在使用条带签出自定义集成--以以下方式:Node.js 如何正确创建';收费';在Stripe nodejs库中? 客户,node.js,stripe-payments,Node.js,Stripe Payments,我正在使用条带签出自定义集成--以以下方式: var handler = StripeCheckout.configure({ key: 'YOUR_KEY_HERE', image: 'images/logo-48px.png', token: function(token, args) { $.post("http://localhost:3000/charge", {token: token}, function(res) {
var handler = StripeCheckout.configure({
key: 'YOUR_KEY_HERE',
image: 'images/logo-48px.png',
token: function(token, args) {
$.post("http://localhost:3000/charge", {token: token}, function(res) {
console.log("response from charge: " + res);
})
}
})
使用custom与simple相反-因为simple不允许我进行AJAX调用
服务器
你已经有了你用户信用卡详细信息的代币,现在怎么办?现在你向他们收费
以下是错误:
在我看来,好像我有最近4个月,经历月,经历年,但由于某种原因,我没有数字。有什么建议/提示/想法吗
搜索“卡对象必须有一个“number”的值”
-12结果,没有太大帮助。作为卡的参数必须给出的“token”实际上应该只是token id(例如:“tok_425dVa2eZvKYlo2CLCK8DNwq”),而不是完整的对象。使用“签出”应用程序不会看到卡号
因此,您需要更改:
var stripeToken = req.body.token;
致:
文档中对此卡
选项不是很清楚,但有一个示例。在npm安装条带后
执行此操作
var stripe = require("stripe")("sk_yourstripeserversecretkey");
var chargeObject = {};
chargeObject.amount = grandTotal * 100;
chargeObject.currency = "usd";
chargeObject.source = token-from-client;
chargeObject.description = "Charge for joe@blow.com";
stripe.charges.create(chargeObject)
.then((charge) => {
// New charge created. record charge object
}).catch((err) => {
// charge failed. Alert user that charge failed somehow
switch (err.type) {
case 'StripeCardError':
// A declined card error
err.message; // => e.g. "Your card's expiration year is invalid."
break;
case 'StripeInvalidRequestError':
// Invalid parameters were supplied to Stripe's API
break;
case 'StripeAPIError':
// An error occurred internally with Stripe's API
break;
case 'StripeConnectionError':
// Some kind of error occurred during the HTTPS communication
break;
case 'StripeAuthenticationError':
// You probably used an incorrect API key
break;
case 'StripeRateLimitError':
// Too many requests hit the API too quickly
break;
}
});
还应注意的是,最低金额为0.50英镑(我收取的费用太少了)。我不相信文档中有多不清楚。只花了我大约一个小时!
var stripeToken = req.body.token.id;
var stripe = require("stripe")("sk_yourstripeserversecretkey");
var chargeObject = {};
chargeObject.amount = grandTotal * 100;
chargeObject.currency = "usd";
chargeObject.source = token-from-client;
chargeObject.description = "Charge for joe@blow.com";
stripe.charges.create(chargeObject)
.then((charge) => {
// New charge created. record charge object
}).catch((err) => {
// charge failed. Alert user that charge failed somehow
switch (err.type) {
case 'StripeCardError':
// A declined card error
err.message; // => e.g. "Your card's expiration year is invalid."
break;
case 'StripeInvalidRequestError':
// Invalid parameters were supplied to Stripe's API
break;
case 'StripeAPIError':
// An error occurred internally with Stripe's API
break;
case 'StripeConnectionError':
// Some kind of error occurred during the HTTPS communication
break;
case 'StripeAuthenticationError':
// You probably used an incorrect API key
break;
case 'StripeRateLimitError':
// Too many requests hit the API too quickly
break;
}
});