@stacksjs/payments 0.70.22 → 0.70.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.js +8 -4907
- package/dist/{charge.d.ts → src/billable/charge.d.ts} +3 -3
- package/dist/{checkout.d.ts → src/billable/checkout.d.ts} +3 -3
- package/dist/{customer.d.ts → src/billable/customer.d.ts} +3 -3
- package/dist/src/billable/index.d.ts +13 -0
- package/dist/{intent.d.ts → src/billable/intent.d.ts} +3 -3
- package/dist/src/billable/invoice.d.ts +6 -0
- package/dist/{payment-method.d.ts → src/billable/payment-method.d.ts} +12 -9
- package/dist/{price.d.ts → src/billable/price.d.ts} +2 -1
- package/dist/src/billable/product.d.ts +37 -0
- package/dist/src/billable/setup-products.d.ts +2 -0
- package/dist/{subscription.d.ts → src/billable/subscription.d.ts} +4 -3
- package/dist/src/billable/transaction.d.ts +14 -0
- package/dist/src/billable/webhook.d.ts +130 -0
- package/dist/src/drivers/stripe.d.ts +8 -0
- package/dist/src/index.d.ts +13 -0
- package/dist/src/payment.d.ts +147 -0
- package/package.json +16 -9
- package/dist/index.d.ts +0 -3
- package/dist/invoice.d.ts +0 -6
- package/dist/setup-products.d.ts +0 -12
- package/dist/stripe.d.ts +0 -146
- package/dist/transaction.d.ts +0 -8
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { UserModel } from '
|
|
2
|
-
|
|
1
|
+
import type { UserModel } from '@stacksjs/orm';
|
|
2
|
+
import type Stripe from 'stripe';
|
|
3
|
+
export declare const manageCharge: ManageCharge;
|
|
3
4
|
export declare interface ManageCharge {
|
|
4
5
|
createPayment: (user: UserModel, amount: number, options: Stripe.PaymentIntentCreateParams) => Promise<Stripe.Response<Stripe.PaymentIntent>>
|
|
5
6
|
findPayment: (id: string) => Promise<Stripe.PaymentIntent | null>
|
|
6
7
|
refund: (paymentIntentId: string, options?: Stripe.RefundCreateParams) => Promise<Stripe.Response<Stripe.Refund>>
|
|
7
8
|
charge: (user: UserModel, amount: number, paymentMethod: string, options: Stripe.PaymentIntentCreateParams) => Promise<Stripe.Response<Stripe.PaymentIntent>>
|
|
8
9
|
}
|
|
9
|
-
export declare const manageCharge: ManageCharge;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { UserModel } from '
|
|
2
|
-
|
|
1
|
+
import type { UserModel } from '@stacksjs/orm';
|
|
2
|
+
import type Stripe from 'stripe';
|
|
3
|
+
export declare const manageCheckout: Checkout;
|
|
3
4
|
export declare interface Checkout {
|
|
4
5
|
create: (user: UserModel, params: Stripe.Checkout.SessionCreateParams) => Promise<Stripe.Response<Stripe.Checkout.Session>>
|
|
5
6
|
}
|
|
6
|
-
export declare const manageCheckout: Checkout;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { StripeCustomerOptions } from '@stacksjs/types';
|
|
2
|
-
import type { UserModel } from '
|
|
3
|
-
|
|
2
|
+
import type { UserModel } from '@stacksjs/orm';
|
|
3
|
+
import type Stripe from 'stripe';
|
|
4
|
+
export declare const manageCustomer: ManageCustomer;
|
|
4
5
|
export declare interface ManageCustomer {
|
|
5
6
|
stripeId: (user: UserModel) => string
|
|
6
7
|
hasStripeId: (user: UserModel) => boolean
|
|
@@ -12,4 +13,3 @@ export declare interface ManageCustomer {
|
|
|
12
13
|
deleteStripeUser: (user: UserModel) => Promise<Stripe.Response<Stripe.DeletedCustomer>>
|
|
13
14
|
syncStripeCustomerDetails: (user: UserModel, options: StripeCustomerOptions) => Promise<Stripe.Response<Stripe.Customer>>
|
|
14
15
|
}
|
|
15
|
-
export declare const manageCustomer: ManageCustomer;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Core Billable Modules
|
|
2
|
+
export * from './charge';
|
|
3
|
+
export * from './checkout';
|
|
4
|
+
export * from './customer';
|
|
5
|
+
export * from './intent';
|
|
6
|
+
export * from './invoice';
|
|
7
|
+
export * from './payment-method';
|
|
8
|
+
export * from './price';
|
|
9
|
+
export * from './product';
|
|
10
|
+
export * from './setup-products';
|
|
11
|
+
export * from './subscription';
|
|
12
|
+
export * from './transaction';
|
|
13
|
+
export * from './webhook';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { UserModel } from '
|
|
2
|
-
|
|
1
|
+
import type { UserModel } from '@stacksjs/orm';
|
|
2
|
+
import type Stripe from 'stripe';
|
|
3
|
+
export declare const manageSetupIntent: SetupIntent;
|
|
3
4
|
export declare interface SetupIntent {
|
|
4
5
|
create: (user: UserModel, params: Stripe.SetupIntentCreateParams) => Promise<Stripe.Response<Stripe.SetupIntent>>
|
|
5
6
|
}
|
|
6
|
-
export declare const manageSetupIntent: SetupIntent;
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { UserModel } from '
|
|
3
|
-
|
|
1
|
+
import { PaymentMethod } from '@stacksjs/orm';
|
|
2
|
+
import type { ModelRow, UserModel } from '@stacksjs/orm';
|
|
3
|
+
import type { Selectable } from '@stacksjs/database';
|
|
4
|
+
import type Stripe from 'stripe';
|
|
5
|
+
export declare const managePaymentMethod: ManagePaymentMethod;
|
|
4
6
|
export declare interface ManagePaymentMethod {
|
|
5
7
|
addPaymentMethod: (user: UserModel, paymentMethod: string | Stripe.PaymentMethod) => Promise<Stripe.Response<Stripe.PaymentMethod>>
|
|
6
8
|
updatePaymentMethod: (user: UserModel, paymentMethodId: string, updateParams?: Stripe.PaymentMethodUpdateParams) => Promise<Stripe.Response<Stripe.PaymentMethod>>
|
|
7
9
|
setUserDefaultPayment: (user: UserModel, paymentMethodId: string) => Promise<Stripe.Response<Stripe.Customer>>
|
|
8
10
|
setDefaultPaymentMethod: (user: UserModel, paymentMethodId: number) => Promise<Stripe.Response<Stripe.Customer>>
|
|
9
|
-
storePaymentMethod: (user: UserModel, paymentMethodId: Stripe.PaymentMethod) => Promise<
|
|
10
|
-
deletePaymentMethod: (user: UserModel, paymentMethodId: number) => Promise<Stripe.Response<Stripe.PaymentMethod>>
|
|
11
|
-
retrievePaymentMethod: (user: UserModel, paymentMethodId: number) => Promise<
|
|
12
|
-
retrieveDefaultPaymentMethod: (user: UserModel) => Promise<
|
|
13
|
-
listPaymentMethods: (user: UserModel, cardType?: string) => Promise<PaymentMethodsTable[]>
|
|
11
|
+
storePaymentMethod: (user: UserModel, paymentMethodId: Stripe.PaymentMethod) => Promise<PaymentMethodInstance>
|
|
12
|
+
deletePaymentMethod: (user: UserModel, paymentMethodId: string | number) => Promise<Stripe.Response<Stripe.PaymentMethod>>
|
|
13
|
+
retrievePaymentMethod: (user: UserModel, paymentMethodId: number) => Promise<PaymentMethodInstance | undefined>
|
|
14
|
+
retrieveDefaultPaymentMethod: (user: UserModel) => Promise<PaymentMethodInstance | undefined>
|
|
15
|
+
listPaymentMethods: (user: UserModel, cardType?: string) => Promise<Selectable<PaymentMethodsTable>[]>
|
|
14
16
|
}
|
|
15
|
-
|
|
17
|
+
declare type PaymentMethodInstance = NonNullable<Awaited<ReturnType<typeof PaymentMethod.find>>>;
|
|
18
|
+
declare type PaymentMethodsTable = ModelRow<typeof PaymentMethod>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type Stripe from 'stripe';
|
|
2
|
+
export declare const managePrice: PriceManager;
|
|
1
3
|
export declare interface PriceManager {
|
|
2
4
|
retrieveByLookupKey: (lookupKey: string) => Promise<Stripe.Price | undefined>
|
|
3
5
|
createOrGet: (lookupKey: string, params: Stripe.PriceCreateParams) => Promise<Stripe.Price>
|
|
4
6
|
}
|
|
5
|
-
export declare const managePrice: PriceManager;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type Stripe from 'stripe';
|
|
2
|
+
export declare const manageProduct: ProductManager;
|
|
3
|
+
export declare const managePriceExtended: ExtendedPriceManager;
|
|
4
|
+
export declare const manageCoupon: CouponManager;
|
|
5
|
+
export declare interface ProductManager {
|
|
6
|
+
create: (params: Stripe.ProductCreateParams) => Promise<Stripe.Response<Stripe.Product>>
|
|
7
|
+
retrieve: (productId: string) => Promise<Stripe.Response<Stripe.Product>>
|
|
8
|
+
update: (productId: string, params: Stripe.ProductUpdateParams) => Promise<Stripe.Response<Stripe.Product>>
|
|
9
|
+
list: (params?: Stripe.ProductListParams) => Promise<Stripe.Response<Stripe.ApiList<Stripe.Product>>>
|
|
10
|
+
archive: (productId: string) => Promise<Stripe.Response<Stripe.Product>>
|
|
11
|
+
createWithPrice: (product: Stripe.ProductCreateParams, price: Omit<Stripe.PriceCreateParams, 'product'>) => Promise<{ product: Stripe.Product, price: Stripe.Price }>
|
|
12
|
+
search: (query: string, params?: Stripe.ProductSearchParams) => Promise<Stripe.Response<Stripe.ApiSearchResult<Stripe.Product>>>
|
|
13
|
+
}
|
|
14
|
+
// =============================================================================
|
|
15
|
+
// Extended Price Management
|
|
16
|
+
// =============================================================================
|
|
17
|
+
export declare interface ExtendedPriceManager {
|
|
18
|
+
create: (params: Stripe.PriceCreateParams) => Promise<Stripe.Response<Stripe.Price>>
|
|
19
|
+
retrieve: (priceId: string) => Promise<Stripe.Response<Stripe.Price>>
|
|
20
|
+
update: (priceId: string, params: Stripe.PriceUpdateParams) => Promise<Stripe.Response<Stripe.Price>>
|
|
21
|
+
list: (params?: Stripe.PriceListParams) => Promise<Stripe.Response<Stripe.ApiList<Stripe.Price>>>
|
|
22
|
+
listByProduct: (productId: string, params?: Stripe.PriceListParams) => Promise<Stripe.Response<Stripe.ApiList<Stripe.Price>>>
|
|
23
|
+
search: (query: string, params?: Stripe.PriceSearchParams) => Promise<Stripe.Response<Stripe.ApiSearchResult<Stripe.Price>>>
|
|
24
|
+
archive: (priceId: string) => Promise<Stripe.Response<Stripe.Price>>
|
|
25
|
+
}
|
|
26
|
+
// =============================================================================
|
|
27
|
+
// Coupon and Promotion Code Management
|
|
28
|
+
// =============================================================================
|
|
29
|
+
export declare interface CouponManager {
|
|
30
|
+
create: (params: Stripe.CouponCreateParams) => Promise<Stripe.Response<Stripe.Coupon>>
|
|
31
|
+
retrieve: (couponId: string) => Promise<Stripe.Response<Stripe.Coupon>>
|
|
32
|
+
update: (couponId: string, params: Stripe.CouponUpdateParams) => Promise<Stripe.Response<Stripe.Coupon>>
|
|
33
|
+
delete: (couponId: string) => Promise<Stripe.Response<Stripe.DeletedCoupon>>
|
|
34
|
+
list: (params?: Stripe.CouponListParams) => Promise<Stripe.Response<Stripe.ApiList<Stripe.Coupon>>>
|
|
35
|
+
createPromotionCode: (params: Stripe.PromotionCodeCreateParams) => Promise<Stripe.Response<Stripe.PromotionCode>>
|
|
36
|
+
retrievePromotionCode: (code: string) => Promise<Stripe.PromotionCode | null>
|
|
37
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { UserModel } from '
|
|
2
|
-
|
|
1
|
+
import type { UserModel } from '@stacksjs/orm';
|
|
2
|
+
import type Stripe from 'stripe';
|
|
3
|
+
export declare const manageSubscription: SubscriptionManager;
|
|
3
4
|
export declare interface SubscriptionManager {
|
|
4
5
|
create: (user: UserModel, type: string, lookupKey: string, params: Partial<Stripe.SubscriptionCreateParams>) => Promise<Stripe.Response<Stripe.Subscription>>
|
|
5
6
|
update: (user: UserModel, type: string, lookupKey: string, params: Partial<Stripe.SubscriptionUpdateParams>) => Promise<Stripe.Response<Stripe.Subscription>>
|
|
@@ -8,4 +9,4 @@ export declare interface SubscriptionManager {
|
|
|
8
9
|
isValid: (user: UserModel, type: string) => Promise<boolean>
|
|
9
10
|
isIncomplete: (user: UserModel, type: string) => Promise<boolean>
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
+
declare type SubscriptionsTable = Record<string, unknown>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PaymentTransaction } from '@stacksjs/orm';
|
|
2
|
+
import type { ModelRow, UserModel } from '@stacksjs/orm';
|
|
3
|
+
export declare const manageTransaction: ManageTransaction;
|
|
4
|
+
export declare interface StoreTransactionOptions {
|
|
5
|
+
brand: string
|
|
6
|
+
provider_id: string
|
|
7
|
+
description?: string
|
|
8
|
+
type?: string
|
|
9
|
+
}
|
|
10
|
+
export declare interface ManageTransaction {
|
|
11
|
+
store: (user: UserModel, productId: number, options: StoreTransactionOptions) => Promise<PaymentTransactionsTable | undefined>
|
|
12
|
+
list: (user: UserModel) => Promise<PaymentTransactionsTable[]>
|
|
13
|
+
}
|
|
14
|
+
declare type PaymentTransactionsTable = ModelRow<typeof PaymentTransaction>;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type Stripe from 'stripe';
|
|
2
|
+
/**
|
|
3
|
+
* Register a webhook event handler
|
|
4
|
+
*/
|
|
5
|
+
export declare function onWebhookEvent(eventType: WebhookEventType, handler: WebhookHandler): void;
|
|
6
|
+
/**
|
|
7
|
+
* Register multiple webhook handlers at once
|
|
8
|
+
*/
|
|
9
|
+
export declare function registerWebhookHandlers(handlerMap: Record<WebhookEventType, WebhookHandler>): void;
|
|
10
|
+
/**
|
|
11
|
+
* Construct and verify a webhook event from the raw request.
|
|
12
|
+
*
|
|
13
|
+
* `tolerance` (in seconds) controls how much clock skew between Stripe and
|
|
14
|
+
* this server is acceptable before signatures are rejected. Stripe's SDK
|
|
15
|
+
* default is 300s; tightening this is recommended in production but the
|
|
16
|
+
* previous code dropped the value entirely, so a configured tolerance was
|
|
17
|
+
* silently ignored.
|
|
18
|
+
*/
|
|
19
|
+
export declare function constructEvent(payload: string | Buffer, signature: string, secret: string, tolerance?: number): Stripe.Event;
|
|
20
|
+
/**
|
|
21
|
+
* Handle an incoming webhook event
|
|
22
|
+
*/
|
|
23
|
+
export declare function handleWebhookEvent(event: Stripe.Event): Promise<{ handled: boolean, eventType: string, errors?: string[] }>;
|
|
24
|
+
/**
|
|
25
|
+
* Process a webhook request
|
|
26
|
+
*/
|
|
27
|
+
export declare function processWebhook(payload: string | Buffer, signature: string, config: WebhookConfig): Promise<{ success: boolean, eventType?: string, error?: string }>;
|
|
28
|
+
/**
|
|
29
|
+
* Register payment intent handlers
|
|
30
|
+
*/
|
|
31
|
+
export declare function onPaymentIntent(handlers: {
|
|
32
|
+
succeeded?: WebhookHandler
|
|
33
|
+
failed?: WebhookHandler
|
|
34
|
+
created?: WebhookHandler
|
|
35
|
+
canceled?: WebhookHandler
|
|
36
|
+
}): void;
|
|
37
|
+
/**
|
|
38
|
+
* Register subscription handlers
|
|
39
|
+
*/
|
|
40
|
+
export declare function onSubscription(handlers: {
|
|
41
|
+
created?: WebhookHandler
|
|
42
|
+
updated?: WebhookHandler
|
|
43
|
+
deleted?: WebhookHandler
|
|
44
|
+
trialWillEnd?: WebhookHandler
|
|
45
|
+
}): void;
|
|
46
|
+
/**
|
|
47
|
+
* Register invoice handlers
|
|
48
|
+
*/
|
|
49
|
+
export declare function onInvoice(handlers: {
|
|
50
|
+
paid?: WebhookHandler
|
|
51
|
+
paymentFailed?: WebhookHandler
|
|
52
|
+
created?: WebhookHandler
|
|
53
|
+
finalized?: WebhookHandler
|
|
54
|
+
}): void;
|
|
55
|
+
/**
|
|
56
|
+
* Register checkout session handlers
|
|
57
|
+
*/
|
|
58
|
+
export declare function onCheckout(handlers: {
|
|
59
|
+
completed?: WebhookHandler
|
|
60
|
+
expired?: WebhookHandler
|
|
61
|
+
}): void;
|
|
62
|
+
/**
|
|
63
|
+
* Register charge handlers
|
|
64
|
+
*/
|
|
65
|
+
export declare function onCharge(handlers: {
|
|
66
|
+
succeeded?: WebhookHandler
|
|
67
|
+
failed?: WebhookHandler
|
|
68
|
+
refunded?: WebhookHandler
|
|
69
|
+
disputed?: WebhookHandler
|
|
70
|
+
}): void;
|
|
71
|
+
/**
|
|
72
|
+
* Extract payment intent from event
|
|
73
|
+
*/
|
|
74
|
+
export declare function getPaymentIntent(event: Stripe.Event): Stripe.PaymentIntent | null;
|
|
75
|
+
/**
|
|
76
|
+
* Extract subscription from event
|
|
77
|
+
*/
|
|
78
|
+
export declare function getSubscription(event: Stripe.Event): Stripe.Subscription | null;
|
|
79
|
+
/**
|
|
80
|
+
* Extract invoice from event
|
|
81
|
+
*/
|
|
82
|
+
export declare function getInvoice(event: Stripe.Event): Stripe.Invoice | null;
|
|
83
|
+
/**
|
|
84
|
+
* Extract checkout session from event
|
|
85
|
+
*/
|
|
86
|
+
export declare function getCheckoutSession(event: Stripe.Event): Stripe.Checkout.Session | null;
|
|
87
|
+
/**
|
|
88
|
+
* Extract charge from event
|
|
89
|
+
*/
|
|
90
|
+
export declare function getCharge(event: Stripe.Event): Stripe.Charge | null;
|
|
91
|
+
/**
|
|
92
|
+
* Extract customer from event
|
|
93
|
+
*/
|
|
94
|
+
export declare function getCustomer(event: Stripe.Event): Stripe.Customer | null;
|
|
95
|
+
declare const handlers: Map<WebhookEventType, WebhookHandler[]>;
|
|
96
|
+
export declare const manageWebhook: {
|
|
97
|
+
|
|
98
|
+
};
|
|
99
|
+
export declare interface WebhookConfig {
|
|
100
|
+
secret: string
|
|
101
|
+
tolerance?: number
|
|
102
|
+
}
|
|
103
|
+
export type WebhookEventType = | 'payment_intent.succeeded'
|
|
104
|
+
| 'payment_intent.payment_failed'
|
|
105
|
+
| 'payment_intent.created'
|
|
106
|
+
| 'payment_intent.canceled'
|
|
107
|
+
| 'customer.subscription.created'
|
|
108
|
+
| 'customer.subscription.updated'
|
|
109
|
+
| 'customer.subscription.deleted'
|
|
110
|
+
| 'customer.subscription.trial_will_end'
|
|
111
|
+
| 'customer.created'
|
|
112
|
+
| 'customer.updated'
|
|
113
|
+
| 'customer.deleted'
|
|
114
|
+
| 'invoice.paid'
|
|
115
|
+
| 'invoice.payment_failed'
|
|
116
|
+
| 'invoice.finalized'
|
|
117
|
+
| 'invoice.created'
|
|
118
|
+
| 'checkout.session.completed'
|
|
119
|
+
| 'checkout.session.expired'
|
|
120
|
+
| 'charge.succeeded'
|
|
121
|
+
| 'charge.failed'
|
|
122
|
+
| 'charge.refunded'
|
|
123
|
+
| 'charge.dispute.created'
|
|
124
|
+
| 'charge.dispute.closed'
|
|
125
|
+
| 'payment_method.attached'
|
|
126
|
+
| 'payment_method.detached'
|
|
127
|
+
| 'setup_intent.succeeded'
|
|
128
|
+
| 'setup_intent.setup_failed'
|
|
129
|
+
| string;
|
|
130
|
+
export type WebhookHandler = (_event: Stripe.Event) => Promise<void> | void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import Stripe from 'stripe';
|
|
2
|
+
/**
|
|
3
|
+
* Lazy-initialized Stripe instance.
|
|
4
|
+
* Only throws when you actually try to use Stripe, not at module load time.
|
|
5
|
+
* This allows the payments package to be imported without a configured key
|
|
6
|
+
* (e.g., in tests, CLI, or environments that don't use Stripe).
|
|
7
|
+
*/
|
|
8
|
+
export declare const stripe: Stripe;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payments Package
|
|
3
|
+
*
|
|
4
|
+
* Provides payment processing capabilities with Stripe integration.
|
|
5
|
+
*/
|
|
6
|
+
// Main Payment facade
|
|
7
|
+
export * from './payment';
|
|
8
|
+
export { default as Payment } from './payment';
|
|
9
|
+
// Billable modules
|
|
10
|
+
export * from './billable';
|
|
11
|
+
// Stripe driver and SDK
|
|
12
|
+
export * from './drivers/stripe';
|
|
13
|
+
export * as Stripe from 'stripe';
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { UserModel } from '@stacksjs/orm';
|
|
2
|
+
import type Stripe from 'stripe';
|
|
3
|
+
/**
|
|
4
|
+
* Create a one-time charge
|
|
5
|
+
*/
|
|
6
|
+
export declare function charge(user: UserModel, amount: number, paymentMethod: string, options?: Partial<Stripe.PaymentIntentCreateParams>): Promise<Stripe.PaymentIntent>;
|
|
7
|
+
/**
|
|
8
|
+
* Create a payment intent (for client-side confirmation)
|
|
9
|
+
*/
|
|
10
|
+
export declare function createPayment(user: UserModel, amount: number, options?: Partial<Stripe.PaymentIntentCreateParams>): Promise<Stripe.PaymentIntent>;
|
|
11
|
+
/**
|
|
12
|
+
* Refund a payment
|
|
13
|
+
*/
|
|
14
|
+
export declare function refund(paymentIntentId: string, amount?: number, options?: Partial<Stripe.RefundCreateParams>): Promise<Stripe.Refund>;
|
|
15
|
+
/**
|
|
16
|
+
* Create a Stripe Checkout session
|
|
17
|
+
*/
|
|
18
|
+
export declare function checkout(user: UserModel, lineItems: Stripe.Checkout.SessionCreateParams.LineItem[], options?: Partial<Stripe.Checkout.SessionCreateParams>): Promise<Stripe.Checkout.Session>;
|
|
19
|
+
/**
|
|
20
|
+
* Create a subscription checkout session
|
|
21
|
+
*/
|
|
22
|
+
export declare function subscriptionCheckout(user: UserModel, priceId: string, options?: Partial<Stripe.Checkout.SessionCreateParams>): Promise<Stripe.Checkout.Session>;
|
|
23
|
+
/**
|
|
24
|
+
* Create a new subscription
|
|
25
|
+
*/
|
|
26
|
+
export declare function subscribe(user: UserModel, lookupKey: string, options?: Partial<Stripe.SubscriptionCreateParams>): Promise<Stripe.Subscription>;
|
|
27
|
+
/**
|
|
28
|
+
* Cancel a subscription
|
|
29
|
+
*/
|
|
30
|
+
export declare function cancelSubscription(subscriptionId: string, immediately?: boolean): Promise<Stripe.Subscription>;
|
|
31
|
+
/**
|
|
32
|
+
* Check if user has an active subscription
|
|
33
|
+
*/
|
|
34
|
+
export declare function hasActiveSubscription(user: UserModel, type?: string): Promise<boolean>;
|
|
35
|
+
/**
|
|
36
|
+
* Update subscription to a new price
|
|
37
|
+
*/
|
|
38
|
+
export declare function changeSubscription(user: UserModel, newLookupKey: string, type?: string): Promise<Stripe.Subscription>;
|
|
39
|
+
/**
|
|
40
|
+
* Get or create a Stripe customer for a user
|
|
41
|
+
*/
|
|
42
|
+
export declare function getOrCreateCustomer(user: UserModel, options?: Stripe.CustomerCreateParams): Promise<Stripe.Customer>;
|
|
43
|
+
/**
|
|
44
|
+
* Update customer details
|
|
45
|
+
*/
|
|
46
|
+
export declare function updateCustomer(user: UserModel, options: Stripe.CustomerCreateParams): Promise<Stripe.Customer>;
|
|
47
|
+
/**
|
|
48
|
+
* Delete a customer from Stripe
|
|
49
|
+
*/
|
|
50
|
+
export declare function deleteCustomer(user: UserModel): Promise<Stripe.DeletedCustomer>;
|
|
51
|
+
/**
|
|
52
|
+
* Add a payment method to a customer
|
|
53
|
+
*/
|
|
54
|
+
export declare function addPaymentMethod(user: UserModel, paymentMethodId: string): Promise<Stripe.PaymentMethod>;
|
|
55
|
+
/**
|
|
56
|
+
* Set the default payment method
|
|
57
|
+
*/
|
|
58
|
+
export declare function setDefaultPaymentMethod(user: UserModel, paymentMethodId: string): Promise<Stripe.Customer>;
|
|
59
|
+
/**
|
|
60
|
+
* Remove a payment method.
|
|
61
|
+
* Accepts either a numeric database ID or a Stripe payment method ID string (pm_xxx).
|
|
62
|
+
*/
|
|
63
|
+
export declare function removePaymentMethod(user: UserModel, paymentMethodId: string | number): Promise<Stripe.PaymentMethod>;
|
|
64
|
+
/**
|
|
65
|
+
* Create a setup intent for adding payment methods
|
|
66
|
+
*/
|
|
67
|
+
export declare function createSetupIntent(user: UserModel, options?: Partial<Stripe.SetupIntentCreateParams>): Promise<Stripe.SetupIntent>;
|
|
68
|
+
/**
|
|
69
|
+
* Get user's invoices
|
|
70
|
+
*/
|
|
71
|
+
export declare function getInvoices(user: UserModel): Promise<Stripe.ApiList<Stripe.Invoice>>;
|
|
72
|
+
/**
|
|
73
|
+
* Create an invoice
|
|
74
|
+
*/
|
|
75
|
+
export declare function createInvoice(customerId: string, options?: Partial<Stripe.InvoiceCreateParams>): Promise<Stripe.Invoice>;
|
|
76
|
+
/**
|
|
77
|
+
* Pay an invoice
|
|
78
|
+
*/
|
|
79
|
+
export declare function payInvoice(invoiceId: string): Promise<Stripe.Invoice>;
|
|
80
|
+
/**
|
|
81
|
+
* Create a product with a price
|
|
82
|
+
*/
|
|
83
|
+
export declare function createProduct(name: string, price: number, options?: {
|
|
84
|
+
currency?: string
|
|
85
|
+
interval?: 'day' | 'week' | 'month' | 'year'
|
|
86
|
+
description?: string
|
|
87
|
+
metadata?: Stripe.MetadataParam
|
|
88
|
+
}): Promise<{ product: Stripe.Product, price: Stripe.Price }>;
|
|
89
|
+
/**
|
|
90
|
+
* Get a price by lookup key
|
|
91
|
+
*/
|
|
92
|
+
export declare function getPrice(lookupKey: string): Promise<Stripe.Price | undefined>;
|
|
93
|
+
/**
|
|
94
|
+
* List all products
|
|
95
|
+
*/
|
|
96
|
+
export declare function listProducts(options?: Stripe.ProductListParams): Promise<Stripe.ApiList<Stripe.Product>>;
|
|
97
|
+
/**
|
|
98
|
+
* Create a discount coupon
|
|
99
|
+
*/
|
|
100
|
+
export declare function createCoupon(options: {
|
|
101
|
+
percentOff?: number
|
|
102
|
+
amountOff?: number
|
|
103
|
+
currency?: string
|
|
104
|
+
duration?: 'forever' | 'once' | 'repeating'
|
|
105
|
+
durationInMonths?: number
|
|
106
|
+
name?: string
|
|
107
|
+
maxRedemptions?: number
|
|
108
|
+
}): Promise<Stripe.Coupon>;
|
|
109
|
+
/**
|
|
110
|
+
* Create a promotion code from a coupon
|
|
111
|
+
*/
|
|
112
|
+
export declare function createPromoCode(couponId: string, code: string, options?: Partial<Stripe.PromotionCodeCreateParams>): Promise<Stripe.PromotionCode>;
|
|
113
|
+
/**
|
|
114
|
+
* Validate a promo code
|
|
115
|
+
*/
|
|
116
|
+
export declare function validatePromoCode(code: string): Promise<Stripe.PromotionCode | null>;
|
|
117
|
+
/**
|
|
118
|
+
* Format amount for display.
|
|
119
|
+
*
|
|
120
|
+
* Currency defaults to the project's configured payment currency
|
|
121
|
+
* (`config.payment.currency` / `STRIPE_CURRENCY`), falling back to USD only
|
|
122
|
+
* when nothing else is set. Locale follows the same pattern via
|
|
123
|
+
* `config.app.locale` so EU merchants see €1.234,56 not $1,234.56.
|
|
124
|
+
*/
|
|
125
|
+
export declare function formatAmount(amount: number, currency?: string): string;
|
|
126
|
+
/**
|
|
127
|
+
* Convert dollars to cents
|
|
128
|
+
*/
|
|
129
|
+
export declare function toCents(dollars: number): number;
|
|
130
|
+
/**
|
|
131
|
+
* Convert cents to dollars
|
|
132
|
+
*/
|
|
133
|
+
export declare function toDollars(cents: number): number;
|
|
134
|
+
// =============================================================================
|
|
135
|
+
// Payment Facade Object
|
|
136
|
+
// =============================================================================
|
|
137
|
+
export declare const Payment: {
|
|
138
|
+
webhook: unknown;
|
|
139
|
+
customer: unknown;
|
|
140
|
+
subscription: unknown;
|
|
141
|
+
invoice: unknown;
|
|
142
|
+
paymentMethod: unknown;
|
|
143
|
+
product: unknown;
|
|
144
|
+
price: unknown;
|
|
145
|
+
coupon: unknown
|
|
146
|
+
};
|
|
147
|
+
export default Payment;
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/payments",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.70.
|
|
4
|
+
"version": "0.70.25",
|
|
5
5
|
"description": "The Stacks payments package. Currently supporting Stripe.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
|
-
"contributors": [
|
|
7
|
+
"contributors": [
|
|
8
|
+
"Chris Breuer <chris@stacksjs.com>"
|
|
9
|
+
],
|
|
8
10
|
"license": "MIT",
|
|
9
11
|
"funding": "https://github.com/sponsors/chrisbbreuer",
|
|
10
12
|
"homepage": "https://github.com/stacksjs/stacks/tree/main/storage/framework/core/payments#readme",
|
|
@@ -27,26 +29,31 @@
|
|
|
27
29
|
],
|
|
28
30
|
"exports": {
|
|
29
31
|
".": {
|
|
32
|
+
"bun": "./src/index.ts",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
30
34
|
"import": "./dist/index.js"
|
|
31
35
|
},
|
|
32
36
|
"./*": {
|
|
37
|
+
"bun": "./src/*",
|
|
33
38
|
"import": "./dist/*"
|
|
34
39
|
}
|
|
35
40
|
},
|
|
36
41
|
"module": "dist/index.js",
|
|
37
42
|
"types": "dist/index.d.ts",
|
|
38
|
-
"files": [
|
|
43
|
+
"files": [
|
|
44
|
+
"README.md",
|
|
45
|
+
"dist"
|
|
46
|
+
],
|
|
39
47
|
"scripts": {
|
|
40
48
|
"build": "bun build.ts",
|
|
41
49
|
"typecheck": "bun tsc --noEmit",
|
|
42
50
|
"prepublishOnly": "bun run build"
|
|
43
51
|
},
|
|
44
52
|
"devDependencies": {
|
|
45
|
-
"@stacksjs/config": "0.70.
|
|
46
|
-
"
|
|
47
|
-
"@stacksjs/utils": "0.70.
|
|
48
|
-
"@stripe/stripe-js": "^
|
|
49
|
-
"
|
|
50
|
-
"stripe": "^17.7.0"
|
|
53
|
+
"@stacksjs/config": "0.70.23",
|
|
54
|
+
"better-dx": "^0.2.12",
|
|
55
|
+
"@stacksjs/utils": "0.70.23",
|
|
56
|
+
"@stripe/stripe-js": "^8.7.0",
|
|
57
|
+
"stripe": "^21.0.1"
|
|
51
58
|
}
|
|
52
59
|
}
|
package/dist/index.d.ts
DELETED
package/dist/invoice.d.ts
DELETED
package/dist/setup-products.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Err } from '@stacksjs/error-handling';
|
|
2
|
-
|
|
3
|
-
declare interface PriceParams {
|
|
4
|
-
unit_amount: number
|
|
5
|
-
currency: string
|
|
6
|
-
product: string
|
|
7
|
-
lookup_key: string
|
|
8
|
-
recurring?: {
|
|
9
|
-
interval: 'day' | 'month' | 'week' | 'year'
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export declare function createStripeProduct(): Promise<Ok<string, never> | Err<string, any>>;
|