Skip to content

Commit b9dde06

Browse files
chore: wip
1 parent 8fa5009 commit b9dde06

File tree

23 files changed

+97
-449
lines changed

23 files changed

+97
-449
lines changed

app/Actions/Payment/CreatePaymentIntentAction.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,23 @@ export default new Action({
99
description: 'Create Payment Intent for stripe',
1010
method: 'POST',
1111
async handle(request: RequestInstance) {
12-
try {
13-
const userId = Number(request.getParam('id'))
14-
const productId = Number(request.get('productId'))
12+
const userId = Number(request.getParam('id'))
13+
const productId = Number(request.get('productId'))
1514

16-
const product = await Product.find(productId)
15+
const product = await Product.find(productId)
1716

18-
const user = await User.find(userId)
17+
const user = await User.find(userId)
1918

20-
if (!product) {
21-
throw new HttpError(422, 'Product not found!')
22-
}
19+
if (!product) {
20+
throw new HttpError(422, 'Product not found!')
21+
}
2322

24-
const paymentIntent = await user?.paymentIntent({
25-
amount: Number(product.unit_price),
26-
currency: 'usd',
27-
payment_method_types: ['card'],
28-
})
23+
const paymentIntent = await user?.paymentIntent({
24+
amount: Number(product.unit_price),
25+
currency: 'usd',
26+
payment_method_types: ['card'],
27+
})
2928

30-
return paymentIntent
31-
}
32-
catch (err) {
33-
throw err
34-
}
29+
return paymentIntent
3530
},
3631
})

app/Actions/Payment/StoreTransactionAction.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,13 @@ export default new Action({
77
description: 'Store transactions',
88
method: 'POST',
99
async handle(request: RequestInstance) {
10-
try {
11-
const userId = Number(request.getParam('id'))
12-
const productId = Number(request.get('productId'))
10+
const userId = Number(request.getParam('id'))
11+
const productId = Number(request.get('productId'))
1312

14-
const user = await User.find(userId)
13+
const user = await User.find(userId)
1514

16-
const transaction = await user?.storeTransaction(productId)
15+
const transaction = await user?.storeTransaction(productId)
1716

18-
return transaction
19-
}
20-
catch (err) {
21-
throw err
22-
}
17+
return transaction
2318
},
2419
})

app/Middleware/BearerToken.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default new Middleware({
77
const bearerToken = request.bearerToken() || ''
88
const validToken = ''
99

10-
// if (!bearerToken || bearerToken !== validToken)
11-
// throw new HttpError(401, 'Unauthorized.')
10+
if (!bearerToken || bearerToken !== validToken)
11+
throw new HttpError(401, 'Unauthorized.')
1212
},
1313
})

resources/functions/billing/payments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function useBillable() {
6767

6868
async function handlePayment(elements: any) {
6969
try {
70-
const data = await confirmPayment(elements)
70+
await confirmPayment(elements)
7171
}
7272
catch (err) {
7373
console.error('Error processing payment:', err)

storage/framework/core/browser/src/utils/billlable.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
import { loadStripe } from '@stripe/stripe-js'
22

3-
interface PaymentMethod {
4-
card: any // Replace `any` with the appropriate type for `elements`
5-
billing_details: {
6-
name: string
7-
}
8-
}
9-
10-
interface PaymentParam {
11-
clientSecret: string
12-
paymentMethod: PaymentMethod
13-
}
14-
153
export const publishableKey: string = import.meta.env.FRONTEND_STRIPE_PUBLIC_KEY || ''
164

175
let client: any
@@ -28,7 +16,6 @@ export async function loadCardElement(clientSecret: string): Promise<any> {
2816
}
2917

3018
export async function loadPaymentElement(clientSecret: string): Promise<any> {
31-
console.log('clientsecret', clientSecret)
3219
client = await loadStripe(publishableKey)
3320

3421
const elements = client.elements({ clientSecret })
@@ -78,8 +65,6 @@ export async function createPaymentMethod(elements: any): Promise<{ paymentInten
7865
card: elements,
7966
})
8067

81-
console.log('data from create payment method', data)
82-
8368
const { paymentIntent, error } = data
8469

8570
return { paymentIntent, error }

storage/framework/core/browser/src/utils/random.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ function random(size: number = 21): string {
7777
return id
7878
}
7979

80-
console.log(random())
81-
8280
export {
8381
customAlphabet,
8482
customRandom,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ export async function generateModelString(
15781578
${relationImports}
15791579
15801580
export interface ${formattedTableName}Table {
1581-
id: Generated<number>
1581+
id: number
15821582
${fieldString}
15831583
}
15841584
@@ -1593,7 +1593,7 @@ export async function generateModelString(
15931593
}
15941594
15951595
export type ${modelName}Type = Selectable<${formattedTableName}Table>
1596-
export type New${modelName} = Insertable<${formattedTableName}Table>
1596+
export type New${modelName} = Partial<Insertable<${formattedTableName}Table>>
15971597
export type ${modelName}Update = Updateable<${formattedTableName}Table>
15981598
export type ${formattedTableName} = ${modelName}Type[]
15991599
@@ -2128,7 +2128,7 @@ export async function generateModelString(
21282128
.where('id', '=', this.id)
21292129
.executeTakeFirst()
21302130
2131-
const model = await this.find(Number(this.id))
2131+
const model = await this.find(this.id)
21322132
21332133
${mittUpdateStatement}
21342134
@@ -2145,7 +2145,7 @@ export async function generateModelString(
21452145
.where('id', '=', this.id)
21462146
.executeTakeFirst()
21472147
2148-
const model = await this.find(Number(this.id))
2148+
const model = await this.find(this.id)
21492149
21502150
21512151
${mittUpdateStatement}

storage/framework/core/payments/src/billable/transaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import type { UserModel } from '../../../../orm/src/models/User'
22
import Product from '../../../../orm/src/models/Product'
33
import { Transaction, type TransactionModel } from '../../../../orm/src/models/Transaction'
44

5-
export interface manageTransaction {
5+
export interface ManageTransaction {
66
store: (user: UserModel, productId: number) => Promise<TransactionModel>
77
}
88

9-
export const manageTransaction: manageTransaction = (() => {
9+
export const manageTransaction: ManageTransaction = (() => {
1010
async function store(user: UserModel, productId: number): Promise<TransactionModel> {
1111
const product = await Product.find(productId)
1212

storage/framework/orm/src/models/AccessToken.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import type { Generated, Insertable, Selectable, Updateable } from 'kysely'
1+
import type { Insertable, Selectable, Updateable } from 'kysely'
22
import { cache } from '@stacksjs/cache'
33
import { db, sql } from '@stacksjs/database'
44
import { HttpError } from '@stacksjs/error-handling'
55

66
import Team from './Team'
77

88
export interface PersonalAccessTokensTable {
9-
id: Generated<number>
9+
id: number
1010
name?: string
1111
token?: string
1212
plain_text_token?: string
@@ -32,7 +32,7 @@ interface AccessTokenResponse {
3232
}
3333

3434
export type AccessTokenType = Selectable<PersonalAccessTokensTable>
35-
export type NewAccessToken = Insertable<PersonalAccessTokensTable>
35+
export type NewAccessToken = Partial<Insertable<PersonalAccessTokensTable>>
3636
export type AccessTokenUpdate = Updateable<PersonalAccessTokensTable>
3737
export type PersonalAccessTokens = AccessTokenType[]
3838

@@ -605,7 +605,7 @@ export class AccessTokenModel {
605605
.where('id', '=', this.id)
606606
.executeTakeFirst()
607607

608-
const model = await this.find(Number(this.id))
608+
const model = await this.find(this.id)
609609

610610
return model
611611
}
@@ -620,7 +620,7 @@ export class AccessTokenModel {
620620
.where('id', '=', this.id)
621621
.executeTakeFirst()
622622

623-
const model = await this.find(Number(this.id))
623+
const model = await this.find(this.id)
624624

625625
return model
626626
}

storage/framework/orm/src/models/Deployment.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Generated, Insertable, Selectable, Updateable } from 'kysely'
1+
import type { Insertable, Selectable, Updateable } from 'kysely'
22
import { randomUUIDv7 } from 'bun'
33
import { cache } from '@stacksjs/cache'
44
import { db, sql } from '@stacksjs/database'
@@ -7,7 +7,7 @@ import { HttpError } from '@stacksjs/error-handling'
77
import User from './User'
88

99
export interface DeploymentsTable {
10-
id: Generated<number>
10+
id: number
1111
commit_sha?: string
1212
commit_message?: string
1313
branch?: string
@@ -37,7 +37,7 @@ interface DeploymentResponse {
3737
}
3838

3939
export type DeploymentType = Selectable<DeploymentsTable>
40-
export type NewDeployment = Insertable<DeploymentsTable>
40+
export type NewDeployment = Partial<Insertable<DeploymentsTable>>
4141
export type DeploymentUpdate = Updateable<DeploymentsTable>
4242
export type Deployments = DeploymentType[]
4343

@@ -648,7 +648,7 @@ export class DeploymentModel {
648648
.where('id', '=', this.id)
649649
.executeTakeFirst()
650650

651-
const model = await this.find(Number(this.id))
651+
const model = await this.find(this.id)
652652

653653
return model
654654
}
@@ -663,7 +663,7 @@ export class DeploymentModel {
663663
.where('id', '=', this.id)
664664
.executeTakeFirst()
665665

666-
const model = await this.find(Number(this.id))
666+
const model = await this.find(this.id)
667667

668668
return model
669669
}

0 commit comments

Comments
 (0)