Skip to content

Commit b94e744

Browse files
chore: wip
1 parent a57d4ae commit b94e744

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

resources/stores/payment.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import type Stripe from 'stripe'
22
import type { StripePaymentMethod } from '../types/billing'
3+
import mitt from 'mitt'
4+
5+
const emitter = mitt()
36

47
const apiUrl = `http://localhost:3008`
58

@@ -29,6 +32,7 @@ export const usePaymentStore = defineStore('payment', {
2932
const client: any = await response.json()
3033
const clientSecret = client.client_secret
3134

35+
3236
return clientSecret
3337
},
3438

@@ -46,6 +50,8 @@ export const usePaymentStore = defineStore('payment', {
4650

4751
const client: any = await response.json()
4852

53+
emitter.emit('subscription:created')
54+
4955
return client
5056
},
5157

@@ -67,6 +73,8 @@ export const usePaymentStore = defineStore('payment', {
6773
if (response.status !== 204) {
6874
await response.json()
6975
}
76+
77+
emitter.emit('subscription:canceled')
7078
},
7179

7280
async fetchUserPaymentMethods(): Promise<void> {
@@ -83,6 +91,8 @@ export const usePaymentStore = defineStore('payment', {
8391

8492
this.paymentMethods = res.data
8593
}
94+
95+
emitter.emit('paymentMethods:fetched')
8696
},
8797

8898
async deletePaymentMethod(paymentMethod: string): Promise<void> {
@@ -103,6 +113,8 @@ export const usePaymentStore = defineStore('payment', {
103113
catch (err: any) {
104114
console.log(err)
105115
}
116+
117+
emitter.emit('paymentMethod:deleted')
106118
},
107119

108120
async updateDefaultPaymentMethod(paymentMethod: string): Promise<void> {
@@ -123,6 +135,8 @@ export const usePaymentStore = defineStore('payment', {
123135
catch (err: any) {
124136
console.log(err)
125137
}
138+
139+
emitter.emit('paymentMethod:updated')
126140
},
127141

128142
async fetchStripeCustomer(): Promise<void> {
@@ -138,6 +152,8 @@ export const usePaymentStore = defineStore('payment', {
138152
const res = await response.json()
139153
this.stripeCustomer = res
140154
}
155+
156+
emitter.emit('customer:fetched')
141157
},
142158

143159
async fetchDefaultPaymentMethod(): Promise<void> {
@@ -154,6 +170,8 @@ export const usePaymentStore = defineStore('payment', {
154170

155171
this.defaultPaymentMethod = res
156172
}
173+
174+
emitter.emit('paymentMethod:fetched')
157175
},
158176

159177
async fetchUserActivePlan(): Promise<void> {
@@ -172,6 +190,8 @@ export const usePaymentStore = defineStore('payment', {
172190
} else {
173191
this.activeSubscription = {}
174192
}
193+
194+
emitter.emit('subscription:fetched')
175195
},
176196
},
177197

0 commit comments

Comments
 (0)