@venturekit/billing 0.0.0-dev.20260307234057
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/LICENSE +191 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/local/cashplus.d.ts +75 -0
- package/dist/local/cashplus.d.ts.map +1 -0
- package/dist/local/cashplus.js +101 -0
- package/dist/local/cashplus.js.map +1 -0
- package/dist/local/cmi.d.ts +62 -0
- package/dist/local/cmi.d.ts.map +1 -0
- package/dist/local/cmi.js +90 -0
- package/dist/local/cmi.js.map +1 -0
- package/dist/local/index.d.ts +12 -0
- package/dist/local/index.d.ts.map +1 -0
- package/dist/local/index.js +12 -0
- package/dist/local/index.js.map +1 -0
- package/dist/local/payzone.d.ts +57 -0
- package/dist/local/payzone.d.ts.map +1 -0
- package/dist/local/payzone.js +83 -0
- package/dist/local/payzone.js.map +1 -0
- package/dist/plans/index.d.ts +124 -0
- package/dist/plans/index.d.ts.map +1 -0
- package/dist/plans/index.js +116 -0
- package/dist/plans/index.js.map +1 -0
- package/dist/stripe/client.d.ts +10 -0
- package/dist/stripe/client.d.ts.map +1 -0
- package/dist/stripe/client.js +23 -0
- package/dist/stripe/client.js.map +1 -0
- package/dist/stripe/customers.d.ts +39 -0
- package/dist/stripe/customers.d.ts.map +1 -0
- package/dist/stripe/customers.js +43 -0
- package/dist/stripe/customers.js.map +1 -0
- package/dist/stripe/index.d.ts +8 -0
- package/dist/stripe/index.d.ts.map +1 -0
- package/dist/stripe/index.js +8 -0
- package/dist/stripe/index.js.map +1 -0
- package/dist/stripe/payments.d.ts +29 -0
- package/dist/stripe/payments.d.ts.map +1 -0
- package/dist/stripe/payments.js +59 -0
- package/dist/stripe/payments.js.map +1 -0
- package/dist/stripe/subscriptions.d.ts +30 -0
- package/dist/stripe/subscriptions.d.ts.map +1 -0
- package/dist/stripe/subscriptions.js +72 -0
- package/dist/stripe/subscriptions.js.map +1 -0
- package/dist/types/config.d.ts +109 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +5 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/invoice.d.ts +80 -0
- package/dist/types/invoice.d.ts.map +1 -0
- package/dist/types/invoice.js +5 -0
- package/dist/types/invoice.js.map +1 -0
- package/dist/types/payment.d.ts +104 -0
- package/dist/types/payment.d.ts.map +1 -0
- package/dist/types/payment.js +5 -0
- package/dist/types/payment.js.map +1 -0
- package/dist/types/subscription.d.ts +92 -0
- package/dist/types/subscription.d.ts.map +1 -0
- package/dist/types/subscription.js +5 -0
- package/dist/types/subscription.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PayZone Integration
|
|
3
|
+
*
|
|
4
|
+
* Payment gateway supporting cards and mobile payments.
|
|
5
|
+
*/
|
|
6
|
+
import type { PayZoneConfig } from '../types';
|
|
7
|
+
/**
|
|
8
|
+
* PayZone payment request
|
|
9
|
+
*/
|
|
10
|
+
export interface PayZonePaymentRequest {
|
|
11
|
+
/** Order ID */
|
|
12
|
+
orderId: string;
|
|
13
|
+
/** Amount in centimes */
|
|
14
|
+
amount: number;
|
|
15
|
+
/** Currency code */
|
|
16
|
+
currency: string;
|
|
17
|
+
/** Customer email */
|
|
18
|
+
email: string;
|
|
19
|
+
/** Customer phone */
|
|
20
|
+
phone?: string;
|
|
21
|
+
/** Description */
|
|
22
|
+
description?: string;
|
|
23
|
+
/** Return URL */
|
|
24
|
+
returnUrl: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* PayZone callback data
|
|
28
|
+
*/
|
|
29
|
+
export interface PayZoneCallbackData {
|
|
30
|
+
/** Transaction ID */
|
|
31
|
+
transaction_id: string;
|
|
32
|
+
/** Order ID */
|
|
33
|
+
order_id: string;
|
|
34
|
+
/** Status */
|
|
35
|
+
status: 'success' | 'failed' | 'pending';
|
|
36
|
+
/** Amount */
|
|
37
|
+
amount: number;
|
|
38
|
+
/** Signature */
|
|
39
|
+
signature: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create PayZone payment
|
|
43
|
+
*/
|
|
44
|
+
export declare function createPayZonePayment(config: PayZoneConfig, input: PayZonePaymentRequest): Promise<{
|
|
45
|
+
paymentUrl: string;
|
|
46
|
+
orderId: string;
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* Verify PayZone callback
|
|
50
|
+
*/
|
|
51
|
+
export declare function verifyPayZoneCallback(config: PayZoneConfig, data: PayZoneCallbackData): Promise<{
|
|
52
|
+
valid: boolean;
|
|
53
|
+
success: boolean;
|
|
54
|
+
orderId: string;
|
|
55
|
+
transactionId?: string;
|
|
56
|
+
}>;
|
|
57
|
+
//# sourceMappingURL=payzone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payzone.d.ts","sourceRoot":"","sources":["../../src/local/payzone.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAY9C;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,eAAe;IACf,OAAO,EAAE,MAAM,CAAC;IAEhB,yBAAyB;IACzB,MAAM,EAAE,MAAM,CAAC;IAEf,oBAAoB;IACpB,QAAQ,EAAE,MAAM,CAAC;IAEjB,qBAAqB;IACrB,KAAK,EAAE,MAAM,CAAC;IAEd,qBAAqB;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,kBAAkB;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,iBAAiB;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,qBAAqB;IACrB,cAAc,EAAE,MAAM,CAAC;IAEvB,eAAe;IACf,QAAQ,EAAE,MAAM,CAAC;IAEjB,aAAa;IACb,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;IAEzC,aAAa;IACb,MAAM,EAAE,MAAM,CAAC;IAEf,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAgClD;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,mBAAmB,GACxB,OAAO,CAAC;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAoBxF"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PayZone Integration
|
|
3
|
+
*
|
|
4
|
+
* Payment gateway supporting cards and mobile payments.
|
|
5
|
+
*/
|
|
6
|
+
import { timingSafeEqual as cryptoTimingSafeEqual } from 'node:crypto';
|
|
7
|
+
/**
|
|
8
|
+
* Timing-safe string comparison to prevent timing attacks
|
|
9
|
+
*/
|
|
10
|
+
function timingSafeEqual(a, b) {
|
|
11
|
+
if (a.length !== b.length)
|
|
12
|
+
return false;
|
|
13
|
+
const bufA = Buffer.from(a);
|
|
14
|
+
const bufB = Buffer.from(b);
|
|
15
|
+
return cryptoTimingSafeEqual(bufA, bufB);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create PayZone payment
|
|
19
|
+
*/
|
|
20
|
+
export async function createPayZonePayment(config, input) {
|
|
21
|
+
const payload = {
|
|
22
|
+
merchant_id: config.merchantId,
|
|
23
|
+
order_id: input.orderId,
|
|
24
|
+
amount: input.amount,
|
|
25
|
+
currency: input.currency,
|
|
26
|
+
email: input.email,
|
|
27
|
+
phone: input.phone,
|
|
28
|
+
description: input.description,
|
|
29
|
+
return_url: input.returnUrl,
|
|
30
|
+
callback_url: config.callbackUrl,
|
|
31
|
+
};
|
|
32
|
+
const response = await fetch(`${config.apiUrl}/payments/create`, {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: {
|
|
35
|
+
'Content-Type': 'application/json',
|
|
36
|
+
'Authorization': `Bearer ${config.apiKey}`,
|
|
37
|
+
},
|
|
38
|
+
body: JSON.stringify(payload),
|
|
39
|
+
});
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
throw new Error(`PayZone API error: ${response.status}`);
|
|
42
|
+
}
|
|
43
|
+
const result = await response.json();
|
|
44
|
+
return {
|
|
45
|
+
paymentUrl: result.payment_url,
|
|
46
|
+
orderId: input.orderId,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Verify PayZone callback
|
|
51
|
+
*/
|
|
52
|
+
export async function verifyPayZoneCallback(config, data) {
|
|
53
|
+
// Verify signature
|
|
54
|
+
const signatureData = [
|
|
55
|
+
config.merchantId,
|
|
56
|
+
data.order_id,
|
|
57
|
+
data.amount.toString(),
|
|
58
|
+
data.status,
|
|
59
|
+
config.apiKey,
|
|
60
|
+
].join('|');
|
|
61
|
+
const expectedSignature = await calculateHmac(signatureData, config.apiKey);
|
|
62
|
+
// Use timing-safe comparison to prevent timing attacks
|
|
63
|
+
const valid = timingSafeEqual(expectedSignature, data.signature);
|
|
64
|
+
return {
|
|
65
|
+
valid,
|
|
66
|
+
success: valid && data.status === 'success',
|
|
67
|
+
orderId: data.order_id,
|
|
68
|
+
transactionId: valid && data.status === 'success' ? data.transaction_id : undefined,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Calculate HMAC-SHA256
|
|
73
|
+
*/
|
|
74
|
+
async function calculateHmac(data, key) {
|
|
75
|
+
const encoder = new TextEncoder();
|
|
76
|
+
const keyData = encoder.encode(key);
|
|
77
|
+
const dataBuffer = encoder.encode(data);
|
|
78
|
+
const cryptoKey = await crypto.subtle.importKey('raw', keyData, { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
|
|
79
|
+
const signature = await crypto.subtle.sign('HMAC', cryptoKey, dataBuffer);
|
|
80
|
+
const hashArray = Array.from(new Uint8Array(signature));
|
|
81
|
+
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=payzone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payzone.js","sourceRoot":"","sources":["../../src/local/payzone.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,IAAI,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGvE;;GAEG;AACH,SAAS,eAAe,CAAC,CAAS,EAAE,CAAS;IAC3C,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACxC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC5B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC5B,OAAO,qBAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAC3C,CAAC;AAgDD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAAqB,EACrB,KAA4B;IAE5B,MAAM,OAAO,GAAG;QACd,WAAW,EAAE,MAAM,CAAC,UAAU;QAC9B,QAAQ,EAAE,KAAK,CAAC,OAAO;QACvB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,KAA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KAAK;QACL,OAAO,EAAE,KAAK,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;QAC3C,OAAO,EAAE,IAAI,CAAC,QAAQ;QACtB,aAAa,EAAE,KAAK,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS;KACpF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,aAAa,CAAC,IAAY,EAAE,GAAW;IACpD,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACpC,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAExC,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAC7C,KAAK,EACL,OAAO,EACP,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,EACjC,KAAK,EACL,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;IAC1E,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;IACxD,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plans & Feature Mapping
|
|
3
|
+
*
|
|
4
|
+
* Defines plans with feature limits and provides a generic mapping
|
|
5
|
+
* between app features and invoice line items.
|
|
6
|
+
*
|
|
7
|
+
* The feature_key is the bridge:
|
|
8
|
+
* - billing_plan_features.feature_key defines what a plan includes
|
|
9
|
+
* - billing_invoice_items.feature_key links usage to the line item
|
|
10
|
+
*
|
|
11
|
+
* This is generic enough to cover most apps:
|
|
12
|
+
* - SaaS seats: feature_key = 'seats'
|
|
13
|
+
* - Storage: feature_key = 'storage_gb'
|
|
14
|
+
* - API calls: feature_key = 'api_calls'
|
|
15
|
+
* - Custom: feature_key = 'whatever_you_need'
|
|
16
|
+
*/
|
|
17
|
+
import type { BillingInterval } from '../types';
|
|
18
|
+
/**
|
|
19
|
+
* A plan feature with its limit and pricing for invoicing.
|
|
20
|
+
*/
|
|
21
|
+
export interface PlanFeature {
|
|
22
|
+
/** Unique key identifying the feature (e.g. 'seats', 'storage_gb') */
|
|
23
|
+
featureKey: string;
|
|
24
|
+
/** Whether this feature is enabled in this plan */
|
|
25
|
+
enabled: boolean;
|
|
26
|
+
/** Usage limit (null = unlimited) */
|
|
27
|
+
limit?: number | null;
|
|
28
|
+
/** Unit price for overage/metered billing (in smallest currency unit) */
|
|
29
|
+
unitPrice?: number;
|
|
30
|
+
/** Human-readable description for invoice line items */
|
|
31
|
+
description: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A plan definition with its features.
|
|
35
|
+
*/
|
|
36
|
+
export interface PlanDefinition {
|
|
37
|
+
id: string;
|
|
38
|
+
name: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
price: number;
|
|
41
|
+
currency: string;
|
|
42
|
+
interval: BillingInterval;
|
|
43
|
+
intervalCount?: number;
|
|
44
|
+
trialDays?: number;
|
|
45
|
+
active: boolean;
|
|
46
|
+
features: PlanFeature[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Define a set of plans for your application.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const plans = definePlans([
|
|
54
|
+
* {
|
|
55
|
+
* id: 'free',
|
|
56
|
+
* name: 'Free',
|
|
57
|
+
* price: 0,
|
|
58
|
+
* currency: 'USD',
|
|
59
|
+
* interval: 'month',
|
|
60
|
+
* active: true,
|
|
61
|
+
* features: [
|
|
62
|
+
* { featureKey: 'seats', enabled: true, limit: 1, description: 'Team seats' },
|
|
63
|
+
* { featureKey: 'storage_gb', enabled: true, limit: 1, description: 'Storage (GB)' },
|
|
64
|
+
* { featureKey: 'api_calls', enabled: true, limit: 1000, description: 'API calls / month' },
|
|
65
|
+
* ],
|
|
66
|
+
* },
|
|
67
|
+
* {
|
|
68
|
+
* id: 'pro',
|
|
69
|
+
* name: 'Pro',
|
|
70
|
+
* price: 2900, // $29.00
|
|
71
|
+
* currency: 'USD',
|
|
72
|
+
* interval: 'month',
|
|
73
|
+
* active: true,
|
|
74
|
+
* features: [
|
|
75
|
+
* { featureKey: 'seats', enabled: true, limit: 10, unitPrice: 500, description: 'Team seats' },
|
|
76
|
+
* { featureKey: 'storage_gb', enabled: true, limit: 50, description: 'Storage (GB)' },
|
|
77
|
+
* { featureKey: 'api_calls', enabled: true, limit: 100000, description: 'API calls / month' },
|
|
78
|
+
* { featureKey: 'priority_support', enabled: true, description: 'Priority support' },
|
|
79
|
+
* ],
|
|
80
|
+
* },
|
|
81
|
+
* ]);
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function definePlans(plans: PlanDefinition[]): PlanDefinition[];
|
|
85
|
+
/**
|
|
86
|
+
* Look up a feature limit for a given plan.
|
|
87
|
+
* Returns the limit (number), null (unlimited), or undefined (feature not in plan).
|
|
88
|
+
*/
|
|
89
|
+
export declare function getFeatureLimit(plan: PlanDefinition, featureKey: string): number | null | undefined;
|
|
90
|
+
/**
|
|
91
|
+
* Check if a feature is enabled for a plan.
|
|
92
|
+
*/
|
|
93
|
+
export declare function hasFeature(plan: PlanDefinition, featureKey: string): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Map feature usage to invoice line items.
|
|
96
|
+
*
|
|
97
|
+
* Given a plan and a usage record (featureKey → quantity used),
|
|
98
|
+
* generates invoice line items. This is the bridge between
|
|
99
|
+
* "what the customer did" and "what we charge them".
|
|
100
|
+
*
|
|
101
|
+
* For features within limits, generates a line item at the plan's base rate.
|
|
102
|
+
* For metered/overage features with unitPrice, generates overage items.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const items = mapUsageToLineItems(proPlan, {
|
|
107
|
+
* seats: 12, // 10 included, 2 overage at $5 each
|
|
108
|
+
* storage_gb: 30, // within limit
|
|
109
|
+
* api_calls: 95000, // within limit
|
|
110
|
+
* });
|
|
111
|
+
* // Returns:
|
|
112
|
+
* // [
|
|
113
|
+
* // { featureKey: 'seats', description: 'Team seats (2 extra)', quantity: 2, unitPrice: 500, amount: 1000 },
|
|
114
|
+
* // ]
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare function mapUsageToLineItems(plan: PlanDefinition, usage: Record<string, number>): Array<{
|
|
118
|
+
featureKey: string;
|
|
119
|
+
description: string;
|
|
120
|
+
quantity: number;
|
|
121
|
+
unitPrice: number;
|
|
122
|
+
amount: number;
|
|
123
|
+
}>;
|
|
124
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plans/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAoB,eAAe,EAAE,MAAM,UAAU,CAAC;AAElE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,sEAAsE;IACtE,UAAU,EAAE,MAAM,CAAC;IACnB,mDAAmD;IACnD,OAAO,EAAE,OAAO,CAAC;IACjB,qCAAqC;IACrC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wDAAwD;IACxD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,eAAe,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAErE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,cAAc,EACpB,UAAU,EAAE,MAAM,GACjB,MAAM,GAAG,IAAI,GAAG,SAAS,CAI3B;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAG5E;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,KAAK,CAAC;IACP,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC,CA2BD"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plans & Feature Mapping
|
|
3
|
+
*
|
|
4
|
+
* Defines plans with feature limits and provides a generic mapping
|
|
5
|
+
* between app features and invoice line items.
|
|
6
|
+
*
|
|
7
|
+
* The feature_key is the bridge:
|
|
8
|
+
* - billing_plan_features.feature_key defines what a plan includes
|
|
9
|
+
* - billing_invoice_items.feature_key links usage to the line item
|
|
10
|
+
*
|
|
11
|
+
* This is generic enough to cover most apps:
|
|
12
|
+
* - SaaS seats: feature_key = 'seats'
|
|
13
|
+
* - Storage: feature_key = 'storage_gb'
|
|
14
|
+
* - API calls: feature_key = 'api_calls'
|
|
15
|
+
* - Custom: feature_key = 'whatever_you_need'
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Define a set of plans for your application.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const plans = definePlans([
|
|
23
|
+
* {
|
|
24
|
+
* id: 'free',
|
|
25
|
+
* name: 'Free',
|
|
26
|
+
* price: 0,
|
|
27
|
+
* currency: 'USD',
|
|
28
|
+
* interval: 'month',
|
|
29
|
+
* active: true,
|
|
30
|
+
* features: [
|
|
31
|
+
* { featureKey: 'seats', enabled: true, limit: 1, description: 'Team seats' },
|
|
32
|
+
* { featureKey: 'storage_gb', enabled: true, limit: 1, description: 'Storage (GB)' },
|
|
33
|
+
* { featureKey: 'api_calls', enabled: true, limit: 1000, description: 'API calls / month' },
|
|
34
|
+
* ],
|
|
35
|
+
* },
|
|
36
|
+
* {
|
|
37
|
+
* id: 'pro',
|
|
38
|
+
* name: 'Pro',
|
|
39
|
+
* price: 2900, // $29.00
|
|
40
|
+
* currency: 'USD',
|
|
41
|
+
* interval: 'month',
|
|
42
|
+
* active: true,
|
|
43
|
+
* features: [
|
|
44
|
+
* { featureKey: 'seats', enabled: true, limit: 10, unitPrice: 500, description: 'Team seats' },
|
|
45
|
+
* { featureKey: 'storage_gb', enabled: true, limit: 50, description: 'Storage (GB)' },
|
|
46
|
+
* { featureKey: 'api_calls', enabled: true, limit: 100000, description: 'API calls / month' },
|
|
47
|
+
* { featureKey: 'priority_support', enabled: true, description: 'Priority support' },
|
|
48
|
+
* ],
|
|
49
|
+
* },
|
|
50
|
+
* ]);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export function definePlans(plans) {
|
|
54
|
+
return plans;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Look up a feature limit for a given plan.
|
|
58
|
+
* Returns the limit (number), null (unlimited), or undefined (feature not in plan).
|
|
59
|
+
*/
|
|
60
|
+
export function getFeatureLimit(plan, featureKey) {
|
|
61
|
+
const feature = plan.features.find((f) => f.featureKey === featureKey);
|
|
62
|
+
if (!feature || !feature.enabled)
|
|
63
|
+
return undefined;
|
|
64
|
+
return feature.limit ?? null;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Check if a feature is enabled for a plan.
|
|
68
|
+
*/
|
|
69
|
+
export function hasFeature(plan, featureKey) {
|
|
70
|
+
const feature = plan.features.find((f) => f.featureKey === featureKey);
|
|
71
|
+
return feature?.enabled ?? false;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Map feature usage to invoice line items.
|
|
75
|
+
*
|
|
76
|
+
* Given a plan and a usage record (featureKey → quantity used),
|
|
77
|
+
* generates invoice line items. This is the bridge between
|
|
78
|
+
* "what the customer did" and "what we charge them".
|
|
79
|
+
*
|
|
80
|
+
* For features within limits, generates a line item at the plan's base rate.
|
|
81
|
+
* For metered/overage features with unitPrice, generates overage items.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const items = mapUsageToLineItems(proPlan, {
|
|
86
|
+
* seats: 12, // 10 included, 2 overage at $5 each
|
|
87
|
+
* storage_gb: 30, // within limit
|
|
88
|
+
* api_calls: 95000, // within limit
|
|
89
|
+
* });
|
|
90
|
+
* // Returns:
|
|
91
|
+
* // [
|
|
92
|
+
* // { featureKey: 'seats', description: 'Team seats (2 extra)', quantity: 2, unitPrice: 500, amount: 1000 },
|
|
93
|
+
* // ]
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export function mapUsageToLineItems(plan, usage) {
|
|
97
|
+
const items = [];
|
|
98
|
+
for (const [featureKey, used] of Object.entries(usage)) {
|
|
99
|
+
const feature = plan.features.find((f) => f.featureKey === featureKey);
|
|
100
|
+
if (!feature || !feature.enabled)
|
|
101
|
+
continue;
|
|
102
|
+
// If feature has a limit and usage exceeds it, and there's a unit price for overage
|
|
103
|
+
if (feature.limit != null && used > feature.limit && feature.unitPrice) {
|
|
104
|
+
const overage = used - feature.limit;
|
|
105
|
+
items.push({
|
|
106
|
+
featureKey,
|
|
107
|
+
description: `${feature.description} (${overage} extra)`,
|
|
108
|
+
quantity: overage,
|
|
109
|
+
unitPrice: feature.unitPrice,
|
|
110
|
+
amount: overage * feature.unitPrice,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return items;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plans/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAoCH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,UAAU,WAAW,CAAC,KAAuB;IACjD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,IAAoB,EACpB,UAAkB;IAElB,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;IACvE,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IACnD,OAAO,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC;AAC/B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,IAAoB,EAAE,UAAkB;IACjE,MAAM,OAAO,GAAG,IAAI,CAA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*/
|
|
8
|
+
export declare function createStripeClient(config: StripeConfig): Promise<import("stripe").Stripe>;
|
|
9
|
+
export declare function getStripeClient(config: StripeConfig): Promise<import("stripe").Stripe>;
|
|
10
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/stripe/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,YAAY,oCAM5D;AAOD,wBAAsB,eAAe,CAAC,MAAM,EAAE,YAAY,oCAKzD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stripe Client
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Create Stripe client
|
|
6
|
+
*/
|
|
7
|
+
export async function createStripeClient(config) {
|
|
8
|
+
const { default: Stripe } = await import('stripe');
|
|
9
|
+
return new Stripe(config.secretKey, {
|
|
10
|
+
apiVersion: config.apiVersion || '2023-10-16',
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get Stripe client (singleton pattern)
|
|
15
|
+
*/
|
|
16
|
+
let stripeInstance = null;
|
|
17
|
+
export async function getStripeClient(config) {
|
|
18
|
+
if (!stripeInstance) {
|
|
19
|
+
stripeInstance = await createStripeClient(config);
|
|
20
|
+
}
|
|
21
|
+
return stripeInstance;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/stripe/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,MAAoB;IAC3D,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;IAEnD,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE;QAClC,UAAU,EAAG,MAAM,CAAC,UAA2B,IAAI,YAAY;KAChE,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,IAAI,cAAc,GAA0D,IAAI,CAAC;AAEjF,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAAoB;IACxD,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,cAAc,GAAG,MAAM,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stripe Customers
|
|
3
|
+
*/
|
|
4
|
+
import type { StripeConfig } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
* Create Stripe customer input
|
|
7
|
+
*/
|
|
8
|
+
export interface CreateStripeCustomerInput {
|
|
9
|
+
email: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
phone?: string;
|
|
12
|
+
metadata?: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a Stripe customer
|
|
16
|
+
*/
|
|
17
|
+
export declare function createStripeCustomer(config: StripeConfig, input: CreateStripeCustomerInput): Promise<import("stripe").Stripe.Response<import("stripe").Stripe.Customer>>;
|
|
18
|
+
/**
|
|
19
|
+
* Update Stripe customer input
|
|
20
|
+
*/
|
|
21
|
+
export interface UpdateStripeCustomerInput {
|
|
22
|
+
email?: string;
|
|
23
|
+
name?: string;
|
|
24
|
+
phone?: string;
|
|
25
|
+
metadata?: Record<string, string>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Update a Stripe customer
|
|
29
|
+
*/
|
|
30
|
+
export declare function updateStripeCustomer(config: StripeConfig, customerId: string, input: UpdateStripeCustomerInput): Promise<import("stripe").Stripe.Response<import("stripe").Stripe.Customer>>;
|
|
31
|
+
/**
|
|
32
|
+
* Get Stripe customer
|
|
33
|
+
*/
|
|
34
|
+
export declare function getStripeCustomer(config: StripeConfig, customerId: string): Promise<import("stripe").Stripe.Response<import("stripe").Stripe.Customer | import("stripe").Stripe.DeletedCustomer>>;
|
|
35
|
+
/**
|
|
36
|
+
* Delete Stripe customer
|
|
37
|
+
*/
|
|
38
|
+
export declare function deleteStripeCustomer(config: StripeConfig, customerId: string): Promise<import("stripe").Stripe.Response<import("stripe").Stripe.DeletedCustomer>>;
|
|
39
|
+
//# sourceMappingURL=customers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customers.d.ts","sourceRoot":"","sources":["../../src/stripe/customers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG7C;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,yBAAyB,+EAUjC;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,yBAAyB,+EAUjC;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,yHAG/E;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CAAC,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,sFAGlF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stripe Customers
|
|
3
|
+
*/
|
|
4
|
+
import { getStripeClient } from './client';
|
|
5
|
+
/**
|
|
6
|
+
* Create a Stripe customer
|
|
7
|
+
*/
|
|
8
|
+
export async function createStripeCustomer(config, input) {
|
|
9
|
+
const stripe = await getStripeClient(config);
|
|
10
|
+
return stripe.customers.create({
|
|
11
|
+
email: input.email,
|
|
12
|
+
name: input.name,
|
|
13
|
+
phone: input.phone,
|
|
14
|
+
metadata: input.metadata,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Update a Stripe customer
|
|
19
|
+
*/
|
|
20
|
+
export async function updateStripeCustomer(config, customerId, input) {
|
|
21
|
+
const stripe = await getStripeClient(config);
|
|
22
|
+
return stripe.customers.update(customerId, {
|
|
23
|
+
email: input.email,
|
|
24
|
+
name: input.name,
|
|
25
|
+
phone: input.phone,
|
|
26
|
+
metadata: input.metadata,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get Stripe customer
|
|
31
|
+
*/
|
|
32
|
+
export async function getStripeCustomer(config, customerId) {
|
|
33
|
+
const stripe = await getStripeClient(config);
|
|
34
|
+
return stripe.customers.retrieve(customerId);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Delete Stripe customer
|
|
38
|
+
*/
|
|
39
|
+
export async function deleteStripeCustomer(config, customerId) {
|
|
40
|
+
const stripe = await getStripeClient(config);
|
|
41
|
+
return stripe.customers.del(customerId);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=customers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customers.js","sourceRoot":"","sources":["../../src/stripe/customers.ts"],"names":[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U,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stripe Integration
|
|
3
|
+
*/
|
|
4
|
+
export { createStripeClient } from './client';
|
|
5
|
+
export { createStripeSubscription, cancelStripeSubscription, updateStripeSubscription, } from './subscriptions';
|
|
6
|
+
export { createStripePaymentIntent, confirmStripePayment, createStripeRefund, } from './payments';
|
|
7
|
+
export { createStripeCustomer, updateStripeCustomer } from './customers';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stripe/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,yBAAyB,EACzB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stripe Integration
|
|
3
|
+
*/
|
|
4
|
+
export { createStripeClient } from './client';
|
|
5
|
+
export { createStripeSubscription, cancelStripeSubscription, updateStripeSubscription, } from './subscriptions';
|
|
6
|
+
export { createStripePaymentIntent, confirmStripePayment, createStripeRefund, } from './payments';
|
|
7
|
+
export { createStripeCustomer, updateStripeCustomer } from './customers';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stripe/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,yBAAyB,EACzB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stripe Payments
|
|
3
|
+
*/
|
|
4
|
+
import type { StripeConfig, CreatePaymentInput, RefundInput } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
* Create a Stripe payment intent
|
|
7
|
+
*/
|
|
8
|
+
export declare function createStripePaymentIntent(config: StripeConfig, input: CreatePaymentInput & {
|
|
9
|
+
stripeCustomerId: string;
|
|
10
|
+
}): Promise<import("stripe").Stripe.Response<import("stripe").Stripe.PaymentIntent>>;
|
|
11
|
+
/**
|
|
12
|
+
* Confirm a Stripe payment intent
|
|
13
|
+
*/
|
|
14
|
+
export declare function confirmStripePayment(config: StripeConfig, paymentIntentId: string, paymentMethodId?: string): Promise<import("stripe").Stripe.Response<import("stripe").Stripe.PaymentIntent>>;
|
|
15
|
+
/**
|
|
16
|
+
* Create a Stripe refund
|
|
17
|
+
*/
|
|
18
|
+
export declare function createStripeRefund(config: StripeConfig, input: RefundInput & {
|
|
19
|
+
stripePaymentIntentId: string;
|
|
20
|
+
}): Promise<import("stripe").Stripe.Response<import("stripe").Stripe.Refund>>;
|
|
21
|
+
/**
|
|
22
|
+
* Get Stripe payment intent
|
|
23
|
+
*/
|
|
24
|
+
export declare function getStripePaymentIntent(config: StripeConfig, paymentIntentId: string): Promise<import("stripe").Stripe.Response<import("stripe").Stripe.PaymentIntent>>;
|
|
25
|
+
/**
|
|
26
|
+
* List Stripe payment methods for customer
|
|
27
|
+
*/
|
|
28
|
+
export declare function listStripePaymentMethods(config: StripeConfig, customerId: string, type?: 'card' | 'us_bank_account'): Promise<import("stripe").Stripe.Response<import("stripe").Stripe.ApiList<import("stripe").Stripe.PaymentMethod>>>;
|
|
29
|
+
//# sourceMappingURL=payments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payments.d.ts","sourceRoot":"","sources":["../../src/stripe/payments.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAG9E;;GAEG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,kBAAkB,GAAG;IAAE,gBAAgB,EAAE,MAAM,CAAA;CAAE,oFAiBzD;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,YAAY,EACpB,eAAe,EAAE,MAAM,EACvB,eAAe,CAAC,EAAE,MAAM,oFAOzB;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,WAAW,GAAG;IAAE,qBAAqB,EAAE,MAAM,CAAA;CAAE,6EASvD;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAAC,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,oFAGzF;AAED;;GAEG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,MAAM,EAClB,IAAI,GAAE,MAAM,GAAG,iBAA0B,qHAO1C"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stripe Payments
|
|
3
|
+
*/
|
|
4
|
+
import { getStripeClient } from './client';
|
|
5
|
+
/**
|
|
6
|
+
* Create a Stripe payment intent
|
|
7
|
+
*/
|
|
8
|
+
export async function createStripePaymentIntent(config, input) {
|
|
9
|
+
const stripe = await getStripeClient(config);
|
|
10
|
+
const paymentIntentData = {
|
|
11
|
+
amount: input.amount,
|
|
12
|
+
currency: input.currency.toLowerCase(),
|
|
13
|
+
customer: input.stripeCustomerId,
|
|
14
|
+
description: input.description,
|
|
15
|
+
metadata: input.metadata,
|
|
16
|
+
};
|
|
17
|
+
if (input.paymentMethodId) {
|
|
18
|
+
paymentIntentData.payment_method = input.paymentMethodId;
|
|
19
|
+
}
|
|
20
|
+
return stripe.paymentIntents.create(paymentIntentData);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Confirm a Stripe payment intent
|
|
24
|
+
*/
|
|
25
|
+
export async function confirmStripePayment(config, paymentIntentId, paymentMethodId) {
|
|
26
|
+
const stripe = await getStripeClient(config);
|
|
27
|
+
return stripe.paymentIntents.confirm(paymentIntentId, {
|
|
28
|
+
payment_method: paymentMethodId,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a Stripe refund
|
|
33
|
+
*/
|
|
34
|
+
export async function createStripeRefund(config, input) {
|
|
35
|
+
const stripe = await getStripeClient(config);
|
|
36
|
+
return stripe.refunds.create({
|
|
37
|
+
payment_intent: input.stripePaymentIntentId,
|
|
38
|
+
amount: input.amount,
|
|
39
|
+
reason: input.reason,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get Stripe payment intent
|
|
44
|
+
*/
|
|
45
|
+
export async function getStripePaymentIntent(config, paymentIntentId) {
|
|
46
|
+
const stripe = await getStripeClient(config);
|
|
47
|
+
return stripe.paymentIntents.retrieve(paymentIntentId);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* List Stripe payment methods for customer
|
|
51
|
+
*/
|
|
52
|
+
export async function listStripePaymentMethods(config, customerId, type = 'card') {
|
|
53
|
+
const stripe = await getStripeClient(config);
|
|
54
|
+
return stripe.paymentMethods.list({
|
|
55
|
+
customer: customerId,
|
|
56
|
+
type,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=payments.js.map
|