-
Notifications
You must be signed in to change notification settings - Fork 34
/
custom.html
89 lines (81 loc) · 3.1 KB
/
custom.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<html ng-app="customExample">
<head>
<title>Custom Example - Angular Stripe Checkout</title>
</head>
<body>
<ng-view></ng-view>
<script type="text/ng-template" id="main.html">
<h1>No Stripe Checkout here</h1>
<a href="#!/buy">Go to buy page</a>
</script>
<script type="text/ng-template" id="buy.html">
<h1>Stripe Checkout has been loaded</h1>
<button ng-click="ctrl.doCheckout()">Buy</button>
</script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.6/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.6/angular-route.js"></script>
<script src="../angular-stripe-checkout.js"></script>
<script>
angular.module("customExample",["ngRoute","stripe.checkout"])
.config(function($routeProvider, StripeCheckoutProvider) {
// You can use the provider to set defaults for all handlers
// you create. Any of the options you'd pass to
// StripeCheckout.configure() are valid.
StripeCheckoutProvider.defaults({
key: "YOUR PUBLISHABLE STRIPE KEY"
});
$routeProvider
.when("/",{
templateUrl: "main.html"
})
.when("/buy",{
templateUrl: "buy.html",
controller: "CustomExampleController as ctrl",
resolve: {
// checkout.js isn't fetched until this is resolved.
stripe: StripeCheckoutProvider.load
}
});
})
.run(function($log, StripeCheckout) {
// You can set defaults here, too.
StripeCheckout.defaults({
opened: function() {
$log.debug("Stripe Checkout opened");
},
closed: function() {
$log.debug("Stripe Checkout closed");
}
});
})
.controller("CustomExampleController",function($log, StripeCheckout) {
// You should configure a handler when the view is loaded,
// just as you would if you were using checkout.js directly.
var handler = StripeCheckout.configure({
name: "Custom Example",
token: function(token, args) {
$log.debug("Got stripe token: " + token.id);
}
});
this.doCheckout = function(token, args) {
var options = {
description: "Ten dollahs!",
amount: 1000
};
// 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);
},function() {
alert("Stripe Checkout closed without making a sale :(");
});
};
});
</script>
</body>
</html>