1
1
import type Stripe from 'stripe'
2
2
import type { StripePaymentMethod } from '../types/billing'
3
+ import mitt from 'mitt'
4
+
5
+ const emitter = mitt ( )
3
6
4
7
const apiUrl = `http://localhost:3008`
5
8
@@ -29,6 +32,7 @@ export const usePaymentStore = defineStore('payment', {
29
32
const client : any = await response . json ( )
30
33
const clientSecret = client . client_secret
31
34
35
+
32
36
return clientSecret
33
37
} ,
34
38
@@ -46,6 +50,8 @@ export const usePaymentStore = defineStore('payment', {
46
50
47
51
const client : any = await response . json ( )
48
52
53
+ emitter . emit ( 'subscription:created' )
54
+
49
55
return client
50
56
} ,
51
57
@@ -67,6 +73,8 @@ export const usePaymentStore = defineStore('payment', {
67
73
if ( response . status !== 204 ) {
68
74
await response . json ( )
69
75
}
76
+
77
+ emitter . emit ( 'subscription:canceled' )
70
78
} ,
71
79
72
80
async fetchUserPaymentMethods ( ) : Promise < void > {
@@ -83,6 +91,8 @@ export const usePaymentStore = defineStore('payment', {
83
91
84
92
this . paymentMethods = res . data
85
93
}
94
+
95
+ emitter . emit ( 'paymentMethods:fetched' )
86
96
} ,
87
97
88
98
async deletePaymentMethod ( paymentMethod : string ) : Promise < void > {
@@ -103,6 +113,8 @@ export const usePaymentStore = defineStore('payment', {
103
113
catch ( err : any ) {
104
114
console . log ( err )
105
115
}
116
+
117
+ emitter . emit ( 'paymentMethod:deleted' )
106
118
} ,
107
119
108
120
async updateDefaultPaymentMethod ( paymentMethod : string ) : Promise < void > {
@@ -123,6 +135,8 @@ export const usePaymentStore = defineStore('payment', {
123
135
catch ( err : any ) {
124
136
console . log ( err )
125
137
}
138
+
139
+ emitter . emit ( 'paymentMethod:updated' )
126
140
} ,
127
141
128
142
async fetchStripeCustomer ( ) : Promise < void > {
@@ -138,6 +152,8 @@ export const usePaymentStore = defineStore('payment', {
138
152
const res = await response . json ( )
139
153
this . stripeCustomer = res
140
154
}
155
+
156
+ emitter . emit ( 'customer:fetched' )
141
157
} ,
142
158
143
159
async fetchDefaultPaymentMethod ( ) : Promise < void > {
@@ -154,6 +170,8 @@ export const usePaymentStore = defineStore('payment', {
154
170
155
171
this . defaultPaymentMethod = res
156
172
}
173
+
174
+ emitter . emit ( 'paymentMethod:fetched' )
157
175
} ,
158
176
159
177
async fetchUserActivePlan ( ) : Promise < void > {
@@ -172,6 +190,8 @@ export const usePaymentStore = defineStore('payment', {
172
190
} else {
173
191
this . activeSubscription = { }
174
192
}
193
+
194
+ emitter . emit ( 'subscription:fetched' )
175
195
} ,
176
196
} ,
177
197
0 commit comments