-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardWidget.js
More file actions
43 lines (38 loc) · 933 Bytes
/
CardWidget.js
File metadata and controls
43 lines (38 loc) · 933 Bytes
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
export class CardWidget {
stripe = null
card = null
style = {
base: {
color: '#32325d',
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
fontSmoothing: 'antialiased',
fontSize: '16px',
'::placeholder': {
color: '#aab7c4'
}
},
invalid: {
color: '#fa755a',
iconColor: '#fa755a'
}
}
constructor(stripe) {
this.stripe = stripe
}
mount() {
const elements = this.stripe.elements()
this.card = elements.create('card', { style: this.style, hidePostalCode: true })
this.card.mount('#card-element')
}
destroy() {
this.card.destroy()
}
async createToken() {
try {
const result = await this.stripe.createToken(this.card)
return result.token
} catch(err) {
console.log(err);
}
}
}