forked from vue-stripe/vue-stripe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
258 lines (252 loc) · 9.04 KB
/
index.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Vue Stripe Checkout by Jofferson R Tiquez</title>
<meta description="Vue Stripe Checkout by Jofferson R Tiquez">
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/@mdi/[email protected]/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-159972005-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-159972005-1');
</script>
</head>
<body>
<div id="app">
<v-app>
<v-app-bar dark class="elevation-1" color="#6772e5" app flat>
<v-btn :href="home" text x-large>Vue Stripe Checkout</v-btn>
<v-spacer></v-spacer>
<v-btn large text href="https://github.com/jofftiquez/vue-stripe-checkout">Star on Github</v-btn>
</v-app-bar>
<v-content>
<v-container>
<v-row justify="center">
<v-col cols="12" sm="10" md="6">
<v-card height="100%">
<v-card-text>
<h1>Recurring Subscription Demo</h1>
</v-card-text>
<v-card-text>
<p>
Create a recurring product with a monthly plan in your Stripe dashboard.
</p>
<v-card flat color="#f1f1f1">
<v-card-text>
<pre>items: {{itemsRecurring}}</pre>
</v-card-text>
</v-card>
</v-card-text>
<v-card-text class="pt-0">
<vue-stripe-checkout
pk="pk_test_INH6o8QUdJyZM1TuGKs5PIsT"
ref="subscribeRef"
:items="itemsRecurring"
:success-url="successUrl"
:cancel-url="cancelUrl"
:client-reference-id="'org-id-abc123'"
>
<template slot="checkout-button">
<v-btn
@click="$refs.subscribeRef.redirectToCheckout()"
color="#42b883"
large
dark
>Subscribe</v-btn>
</template>
</vue-stripe-checkout>
</v-card-text>
</v-card>
</v-col>
<v-col cols="12" sm="10" md="6">
<v-card height="100%">
<v-card-text>
<h1>Subscription Demo using Session</h1>
</v-card-text>
<v-card-text>
<p>
Create a session in your backend and paste the session id below.
</p>
<v-card flat color="#f1f1f1">
<v-card-text>
<v-text-field v-model="sessionId" solo label="Session Id" hint="Session Id starts with cs_test_" persistent-hint />
</v-card-text>
</v-card>
</v-card-text>
<v-card-text class="pt-0">
<vue-stripe-checkout
pk="pk_test_INH6o8QUdJyZM1TuGKs5PIsT"
ref="sessionRef"
:session-id="sessionId"
>
<template slot="checkout-button">
<v-btn
@click="$refs.sessionRef.redirectToCheckout()"
color="#42b883"
large
dark
>Subscribe</v-btn>
</template>
</vue-stripe-checkout>
</v-card-text>
</v-card>
</v-col>
<v-col cols="12" sm="10" md="6">
<v-card height="100%">
<v-card-text>
<h1>One-time Payment Demo</h1>
</v-card-text>
<v-card-text>
<p>
Create a SKU in your Stripe dashboard.
</p>
<v-card flat color="#f1f1f1">
<v-card-text>
<pre>items: {{items}}</pre>
</v-card-text>
</v-card>
</v-card-text>
<v-card-text class="pt-0">
<vue-stripe-checkout
pk="pk_test_INH6o8QUdJyZM1TuGKs5PIsT"
ref="checkoutRef"
:items="items"
:success-url="successUrl"
:cancel-url="cancelUrl"
>
<template slot="checkout-button">
<v-btn
@click="$refs.checkoutRef.redirectToCheckout()"
color="#42b883"
large
dark
>Checkout</v-btn>
</template>
</vue-stripe-checkout>
</v-card-text>
</v-card>
</v-col>
<v-col cols="12" sm="10" md="6">
<v-card height="100%">
<v-card-text>
<h1>Elements Demo</h1>
</v-card-text>
<v-card-text>
<v-card flat color="#f1f1f1">
<v-card-text>
<pre>amount: {{amount}}</pre>
</v-card-text>
</v-card>
<br>
<v-card flat color="#f1f1f1">
<v-card-text>
<vue-stripe-elements
pk="pk_test_INH6o8QUdJyZM1TuGKs5PIsT"
:amount="amount"
ref="elementsRef"
@token="tokenCreated"
@loading="loading = $event"
>
</vue-stripe-elements>
</v-card-text>
</v-card>
<br>
<v-btn @click="$refs.elementsRef.submit()" color="#42b883" dark large>Pay ${{amount / 100}}</v-btn>
</v-card-text>
</v-card>
</v-col>
</v-row>
</v-container>
</v-content>
<v-dialog v-model="dialog" width="700" scrollable>
<v-card>
<v-toolbar flat>
<v-spacer></v-spacer>
<v-btn @click="dialog = false" text>Close</v-btn>
</v-toolbar>
<v-divider></v-divider>
<v-card-text>
<br>
<h1>Token</h1>
<pre>{{token}}</pre>
<br>
<v-divider></v-divider>
<br>
<h1>Charge</h1>
<pre>{{charge}}</pre>
</v-card-text>
</v-card>
</v-dialog>
<v-footer app absolute dark color="#42b883">
<v-col class="text-right pa-1">
Made with ❤️ by <a class="white--text" target="_blank" href="https://twitter.com/jrtiquez">@jrtiquez</a>
</v-col>
</v-footer>
</v-app>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.js"></script>
<script src="./dist/vue-stripe-checkout.js"></script>
<script>
Vue.component('vue-stripe-checkout', VueStripeCheckout.StripeCheckout);
Vue.component('vue-stripe-elements', VueStripeCheckout.StripeElements);
new Vue({
el: '#app',
vuetify: new Vuetify(),
data () {
return {
token: null,
charge: null,
dialog: false,
amount: 10000,
loading: false,
sessionId: '',
items: [
{
sku: 'sku_FdQKocNoVzznpJ',
quantity: 1
}
],
itemsRecurring: [
{
plan: 'plan_GsW5WXeHdTwLbF',
quantity: 1
},
{
plan: 'plan_GsmXPUVY4OelPZ',
quantity: 1
}
],
successUrl: `${document.location.href}success.html`,
cancelUrl: `${document.location.href}cancel.html`,
home: location.href
};
},
methods: {
tokenCreated (token) {
console.warn(token);
this.token = token;
this.charge = {
source: token.card,
amount: this.amount,
description: this.description
}
this.sendTokenToServer(this.charge);
},
sendTokenToServer (charge) {
// Send to server
this.dialog = true;
}
}
});
</script>
</body>
</html>