-
-
Notifications
You must be signed in to change notification settings - Fork 147
/
Checkout.vue
75 lines (74 loc) · 1.63 KB
/
Checkout.vue
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
<template>
<div>
<slot name="checkout-button" />
</div>
</template>
<script>
import {
SUPPORTED_LANGS,
SUPPORTED_SUBMIT_TYPES,
BILLING_ADDRESS_COLLECTION_TYPES
} from './contants';
export default {
props: {
items: {
type: Array
},
successUrl: {
type: String,
default: window.location.href
},
cancelUrl: {
type: String,
default: window.location.href
},
submitType: {
type: String,
default: 'auto',
validator: (value) => SUPPORTED_SUBMIT_TYPES.includes(value)
},
billingAddressCollection: {
type: String,
default: 'auto',
validator: (value) => BILLING_ADDRESS_COLLECTION_TYPES.includes(value)
},
clientReferenceId: {
type: String,
},
customerEmail: {
type: String
},
sessionId: {
type: String
},
locale: {
type: String,
default: 'auto',
validator: (value) => SUPPORTED_LANGS.includes(value)
}
},
methods: {
redirectToCheckout () {
try {
this.$emit('loading', true);
this.$stripe.redirectToCheckout({
billingAddressCollection: this.billingAddressCollection,
cancelUrl: this.cancelUrl,
clientReferenceId: this.clientReferenceId,
customerEmail: this.customerEmail,
items: this.items,
locale: this.locale,
sessionId: this.sessionId,
submitType: this.submitType,
successUrl: this.successUrl,
});
} catch (e) {
console.error(e);
this.$emit('error', e);
} finally {
this.$emit('loading', false);
}
}
}
}
</script>