Skip to content

Commit c28d2b9

Browse files
chore: wip
1 parent 4edcd74 commit c28d2b9

File tree

15 files changed

+432
-370
lines changed

15 files changed

+432
-370
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Action } from '@stacksjs/actions'
2+
import User from '../../../storage/framework/orm/src/models/User.ts'
3+
4+
export default new Action({
5+
name: 'FetchTransactionHistoryAction',
6+
description: 'Fetch the users transaction history',
7+
method: 'GET',
8+
async handle() {
9+
const user = await User.find(1)
10+
11+
const subscription = await user?.subscriptionHistory()
12+
13+
return subscription
14+
},
15+
})

resources/stores/payment.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const usePaymentStore = defineStore('payment', {
7171
}
7272
await response.json()
7373

74-
dispatch('subscription:created')
74+
dispatch('subscription:created')
7575
},
7676

7777
async cancelPlan(): Promise<void> {
@@ -92,7 +92,7 @@ export const usePaymentStore = defineStore('payment', {
9292
if (response.status !== 204)
9393
await response.json()
9494

95-
dispatch('subscription:canceled')
95+
dispatch('subscription:canceled')
9696
},
9797

9898
async fetchUserPaymentMethods(): Promise<void> {
@@ -110,7 +110,7 @@ export const usePaymentStore = defineStore('payment', {
110110
this.paymentMethods = res.data
111111
}
112112

113-
dispatch('paymentMethods:fetched')
113+
dispatch('paymentMethods:fetched')
114114
},
115115

116116
async deletePaymentMethod(paymentMethod: string): Promise<void> {
@@ -132,7 +132,7 @@ export const usePaymentStore = defineStore('payment', {
132132
console.log(err)
133133
}
134134

135-
dispatch('paymentMethod:deleted')
135+
dispatch('paymentMethod:deleted')
136136
},
137137

138138
async updateDefaultPaymentMethod(paymentMethod: string): Promise<void> {
@@ -154,7 +154,7 @@ export const usePaymentStore = defineStore('payment', {
154154
console.log(err)
155155
}
156156

157-
dispatch('paymentMethod:updated')
157+
dispatch('paymentMethod:updated')
158158
},
159159

160160
async fetchStripeCustomer(): Promise<void> {
@@ -171,7 +171,7 @@ export const usePaymentStore = defineStore('payment', {
171171
this.stripeCustomer = res
172172
}
173173

174-
dispatch('customer:fetched')
174+
dispatch('customer:fetched')
175175
},
176176

177177
async fetchDefaultPaymentMethod(): Promise<void> {
@@ -189,7 +189,7 @@ export const usePaymentStore = defineStore('payment', {
189189
this.defaultPaymentMethod = res
190190
}
191191

192-
dispatch('paymentMethod:fetched')
192+
dispatch('paymentMethod:fetched')
193193
},
194194

195195
async fetchUserActivePlan(): Promise<void> {
@@ -210,7 +210,7 @@ export const usePaymentStore = defineStore('payment', {
210210
this.activeSubscription = {}
211211
}
212212

213-
dispatch('subscription:fetched')
213+
dispatch('subscription:fetched')
214214
},
215215
},
216216

routes/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ route.post('/ai/ask', 'Actions/AI/AskAction')
2626
route.post('/ai/summary', 'Actions/AI/SummaryAction')
2727

2828
route.get('/stripe/fetch-customer', 'Actions/Payment/FetchStripeCustomerAction')
29+
route.get('/stripe/fetch-transaction-history', 'Actions/Payment/FetchStripeCustomerAction')
2930
route.get('/stripe/fetch-user-subscriptions', 'Actions/Payment/FetchUserSubscriptionsAction')
3031
route.get('/stripe/fetch-active-subscription', 'Actions/Payment/FetchActiveSubscriptionAction')
3132
route.get('/stripe/default-payment-method', 'Actions/Payment/FetchDefaultPaymentMethodAction')

storage/framework/.eslintrc-auto-import.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@
415415
"word": true,
416416
"wordBoundary": true,
417417
"wordChar": true,
418-
"usePaymentStore": true
418+
"usePaymentStore": true,
419+
"saas": true
419420
}
420421
}

storage/framework/core/components/dialog/src/App.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<script lang="ts" setup>
22
import { defineCustomElement, ref } from 'vue'
3+
import { Dialog, DialogPanel } from './components'
34
import Hero from './components/Hero.vue'
45
import Installation from './components/Installation.vue'
5-
import Options from './components/Options.vue'
66
import Transitions from './components/Transitions.vue'
77
import Usage from './components/Usage.vue'
8-
import { useSEOHeader } from './composables/useSEOHeader'
98
10-
import { Dialog, DialogOverlay, DialogPanel } from './components'
9+
import { useSEOHeader } from './composables/useSEOHeader'
1110
1211
useSEOHeader()
1312

storage/framework/core/components/dialog/src/components/Dialog.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ defineCustomElement({
3131
<template>
3232
<div class="fixed inset-0 z-50 overflow-y-auto">
3333
<div
34-
class="z-20 min-h-full flex items-end justify-center p-4 text-center sm:items-center sm:p-0 bg-gray-500 bg-opacity-75 transition-opacity"
34+
class="z-20 min-h-full flex items-end justify-center bg-gray-500 bg-opacity-75 p-4 text-center transition-opacity sm:items-center sm:p-0"
3535
@click.self="emit('close', false)"
3636
>
3737
<slot />

storage/framework/core/components/dialog/src/components/DialogPanel.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defineCustomElement({
77
</script>
88

99
<template>
10-
<div class="z-60 overflow-hidden rounded-lg bg-white px-4 pb-4 pt-5 text-left shadow-xl sm:my-8 sm:max-w-lg sm:w-full sm:p-6" @click.stop >
10+
<div class="z-60 overflow-hidden rounded-lg bg-white px-4 pb-4 pt-5 text-left shadow-xl sm:my-8 sm:max-w-lg sm:w-full sm:p-6" @click.stop>
1111
<slot>
1212
<p>Default modal content goes here.</p>
1313
</slot>

storage/framework/core/components/dialog/src/components/Transitions.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script lang="ts" setup>
22
import type { Transition } from '../types'
33
import { computed, ref } from 'vue'
4-
import { useCopyCode } from '../composables/useCopyCode'
54
import { Dialog, DialogPanel } from '../components'
5+
import { useCopyCode } from '../composables/useCopyCode'
66
77
const currentTransition = ref<Transition>('fade')
88
const transitionList = ref<Transition[]>(['fade', 'pop', 'fadeInRightBig', 'jackInTheBox', 'slideInDown', 'slideInRight', 'custom-transition'])

storage/framework/core/events/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ interface StacksEvents {
158158
'customer:fetched': any
159159
'paymentMethod:fetched': any
160160
'subscription:fetched': any
161+
'paymentMethod:deleted': any
161162
}
162163

163164
const events: Emitter<StacksEvents> = mitt<StacksEvents>()

storage/framework/core/orm/src/utils.ts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -909,10 +909,6 @@ export async function generateModelString(
909909

910910
const relations = await getRelations(model, modelName)
911911

912-
if (modelName === 'User') {
913-
console.log(relations)
914-
}
915-
916912
for (const relationInstance of relations) {
917913
relationImports += `import ${relationInstance.model} from './${relationInstance.model}'\n\n`
918914
}
@@ -1192,8 +1188,12 @@ export async function generateModelString(
11921188
return customer
11931189
}
11941190
1195-
async isSubscribed(type: string): Promise<boolean> {
1196-
return await manageSubscription.isValid(this, type)
1191+
async subscriptionHistory(): Promise<Stripe.Response<Stripe.ApiList<Stripe.Invoice>>> {
1192+
return manageInvoice.list(this)
1193+
}
1194+
1195+
async stripeSubscriptions(): Promise<Stripe.Response<Stripe.ApiList<Stripe.Invoice>>> {
1196+
return manageInvoice.list(this)
11971197
}
11981198
11991199
async activeSubscription() {
@@ -1214,20 +1214,6 @@ export async function generateModelString(
12141214
return undefined
12151215
}
12161216
1217-
async activeSubscription() {
1218-
const subscriptions = await this.subscriptions()
1219-
1220-
if (subscriptions.length) {
1221-
const subscription = subscriptions[0]
1222-
1223-
const providerSubscription = await manageSubscription.retrieve(this, subscription?.provider_id || '')
1224-
1225-
return { subscription, providerSubscription}
1226-
}
1227-
1228-
return undefined
1229-
}
1230-
12311217
async isIncomplete(type: string): Promise<boolean> {
12321218
return await manageSubscription.isIncomplete(this, type)
12331219
}
@@ -1435,7 +1421,7 @@ export async function generateModelString(
14351421
const fillable = JSON.stringify(getFillableAttributes(model.attributes, otherModelRelations))
14361422

14371423
return `import type { Generated, Insertable, Selectable, Updateable } from 'kysely'
1438-
import { manageCharge, manageCheckout, manageCustomer, managePaymentMethod, manageSubscription, managePrice, manageSetupIntent, type Stripe } from '@stacksjs/payments'
1424+
import { manageCharge, manageCheckout, manageCustomer, manageInvoice, managePaymentMethod, manageSubscription, managePrice, manageSetupIntent, type Stripe } from '@stacksjs/payments'
14391425
import { db, sql } from '@stacksjs/database'
14401426
import type { CheckoutLineItem, CheckoutOptions, StripeCustomerOptions } from '@stacksjs/types'
14411427
import { HttpError } from '@stacksjs/error-handling'

0 commit comments

Comments
 (0)