【发布时间】:2016-01-04 16:27:58
【问题描述】:
我正在使用Angular-Stripe-Checkout library 创建一个stripeToken,就像在这个example 中一样。一些亮点如下所示。
与许多 angular-stripe 库和示例一样,它仅显示如何创建 stripeToken。
但是,我不清楚在检索到 stripeToken 后如何实际向用户收费?
在 Stripe 上,他们有 instructions 关于如何使用 node.js 向用户收费。但我不清楚如何设置它并使其与 Angular 兼容。
代码亮点
html
<button ng-click="product.doCheckout()">Buy</button>
js
// note: StripeCheckout is injected in the controller
product.doCheckout = function(token, args) {
// You should configure a handler when the view is loaded,
// just as you would if you were using checkout.js directly.
//
// Unlike a vanilla Stripe Checkout handler, this one can be
// reused as many times as you like.
var handler = StripeCheckout.configure({
name: "Custom Example",
token: function(token, args) {
console.log(token.id)
//$log.debug("Got stripe token: " + token.id);
}
});
var options = {
description: "Ten dollahs!",
amount: 10000
};
// The default handler API is enhanced by having open()
// return a promise. This promise can be used in lieu of or
// in addition to the token callback (or you can just ignore
// it if you like the default API).
//
// The rejection callback doesn't work in IE6-7.
handler.open(options)
.then(function(result) {
alert("Got Stripe token: " + result[0].id);
console.log(result);
var stripe = window.Stripe;
var stripeToken = result[0].id;
//
// what next?
},function() {
alert("Stripe Checkout closed without making a sale :(");
}
);
};
【问题讨论】:
标签: javascript angularjs stripe-payments