Skip to content

Commit c6ca4d2

Browse files
chore: wip
1 parent f2e2b82 commit c6ca4d2

File tree

8 files changed

+57
-5
lines changed

8 files changed

+57
-5
lines changed

config/payment.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@ import type { PaymentConfig } from '@stacksjs/types'
1010
export default {
1111
driver: 'stripe',
1212

13+
stripe: {
14+
publishable_key: env.STRIPE_PUBLISHABLE_KEY || '',
15+
secret_key: env.STRIPE_SECRET_KEY || '',
16+
},
17+
1318
// wip
1419
} satisfies PaymentConfig

storage/framework/core/actions/src/saas/setup.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import process from 'node:process'
2-
import { createStripeProduct } from '@stacksjs/database'
32
import { log } from '@stacksjs/logging'
3+
import { createStripeProduct } from '@stacksjs/payments'
4+
5+
const result = await createStripeProduct()
46

57
if (result?.isErr()) {
68
console.error(result.error)

storage/framework/core/buddy/src/cli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ async function main() {
6767
cmd.outdated(buddy)
6868
cmd.release(buddy)
6969
cmd.route(buddy)
70+
cmd.saas(buddy)
7071
cmd.seed(buddy)
7172
cmd.setup(buddy)
7273
cmd.test(buddy)

storage/framework/core/buddy/src/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export * from './prepublish'
2424
export * from './projects'
2525
export * from './release'
2626
export * from './route'
27+
export * from './saas'
2728
export * from './seed'
2829
export * from './setup'
2930
export * from './test'

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export * from './checkout'
33
export * from './customer'
44
export * from './payment-method'
55
export * from './price'
6+
export * from './setup-products'
67
export * from './subscription'

storage/framework/core/payments/src/billable/setup-products.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,22 @@ export async function createStripeProduct(): Promise<any> {
77
try {
88
if (plans !== undefined && plans.length) {
99
for (const plan of plans) {
10+
// First, create the product in Stripe
11+
const product = await stripe.product.create({
12+
name: plan.productName,
13+
description: plan.description,
14+
metadata: plan.metadata,
15+
})
16+
17+
// Use the created product's ID to add the pricing options
1018
for (const pricing of plan.pricing) {
1119
await stripe.price.create({
1220
unit_amount: pricing.price,
1321
currency: pricing.currency,
1422
recurring: {
1523
interval: pricing.interval,
1624
},
17-
product_data: {
18-
name: plan.productName,
19-
metadata: plan.metadata,
20-
},
25+
product: product.id,
2126
nickname: pricing.key, // Optional: adds a nickname for easier reference
2227
})
2328
}

storage/framework/core/payments/src/drivers/stripe.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,38 @@ export const price: Price = (() => {
139139
return { retrieve, list, create, update }
140140
})()
141141

142+
export interface Product {
143+
create: (params: Stripe.ProductCreateParams) => Promise<Stripe.Response<Stripe.Product>>
144+
retrieve: (productId: string, params?: Stripe.ProductRetrieveParams) => Promise<Stripe.Response<Stripe.Product>>
145+
update: (productId: string, params: Stripe.ProductUpdateParams) => Promise<Stripe.Response<Stripe.Product>>
146+
delete: (productId: string) => Promise<Stripe.Response<Stripe.DeletedProduct>>
147+
list: (params?: Stripe.ProductListParams) => Promise<Stripe.ApiListPromise<Stripe.Product>>
148+
}
149+
150+
export const product: Product = (() => {
151+
async function create(params: Stripe.ProductCreateParams): Promise<Stripe.Response<Stripe.Product>> {
152+
return await client.products.create(params)
153+
}
154+
155+
async function retrieve(productId: string, params?: Stripe.ProductRetrieveParams): Promise<Stripe.Response<Stripe.Product>> {
156+
return await client.products.retrieve(productId, params)
157+
}
158+
159+
async function update(productId: string, params: Stripe.ProductUpdateParams): Promise<Stripe.Response<Stripe.Product>> {
160+
return await client.products.update(productId, params)
161+
}
162+
163+
async function deleteProduct(productId: string): Promise<Stripe.Response<Stripe.DeletedProduct>> {
164+
return await client.products.del(productId)
165+
}
166+
167+
async function list(params?: Stripe.ProductListParams): Promise<Stripe.ApiListPromise<Stripe.Product>> {
168+
return await client.products.list(params)
169+
}
170+
171+
return { create, retrieve, update, delete: deleteProduct, list }
172+
})()
173+
142174
export interface Refund {
143175
create: (params: Stripe.RefundCreateParams) => Promise<Stripe.Response<Stripe.Refund>>
144176
retrieve: (refundId: string) => Promise<Stripe.Response<Stripe.Refund>>

storage/framework/core/types/src/payments.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import type Stripe from 'stripe'
22

33
export interface PaymentOptions {
44
driver: 'stripe'
5+
6+
stripe: {
7+
publishable_key: string
8+
secret_key: string
9+
}
510
}
611

712
export type PaymentConfig = Partial<PaymentOptions>

0 commit comments

Comments
 (0)