@classytic/revenue 0.0.23 → 0.1.0

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.
Files changed (60) hide show
  1. package/README.md +170 -24
  2. package/core/builder.js +39 -0
  3. package/dist/types/core/builder.d.ts +87 -0
  4. package/dist/types/core/container.d.ts +57 -0
  5. package/dist/types/core/errors.d.ts +122 -0
  6. package/dist/types/enums/escrow.enums.d.ts +24 -0
  7. package/dist/types/enums/index.d.ts +69 -0
  8. package/dist/types/enums/monetization.enums.d.ts +6 -0
  9. package/dist/types/enums/payment.enums.d.ts +16 -0
  10. package/dist/types/enums/split.enums.d.ts +25 -0
  11. package/dist/types/enums/subscription.enums.d.ts +15 -0
  12. package/dist/types/enums/transaction.enums.d.ts +24 -0
  13. package/dist/types/index.d.ts +22 -0
  14. package/dist/types/providers/base.d.ts +126 -0
  15. package/dist/types/schemas/escrow/hold.schema.d.ts +54 -0
  16. package/dist/types/schemas/escrow/index.d.ts +6 -0
  17. package/dist/types/schemas/index.d.ts +506 -0
  18. package/dist/types/schemas/split/index.d.ts +8 -0
  19. package/dist/types/schemas/split/split.schema.d.ts +142 -0
  20. package/dist/types/schemas/subscription/index.d.ts +152 -0
  21. package/dist/types/schemas/subscription/info.schema.d.ts +128 -0
  22. package/dist/types/schemas/subscription/plan.schema.d.ts +39 -0
  23. package/dist/types/schemas/transaction/common.schema.d.ts +12 -0
  24. package/dist/types/schemas/transaction/gateway.schema.d.ts +86 -0
  25. package/dist/types/schemas/transaction/index.d.ts +202 -0
  26. package/dist/types/schemas/transaction/payment.schema.d.ts +145 -0
  27. package/dist/types/services/escrow.service.d.ts +51 -0
  28. package/dist/types/services/payment.service.d.ts +80 -0
  29. package/dist/types/services/subscription.service.d.ts +138 -0
  30. package/dist/types/services/transaction.service.d.ts +40 -0
  31. package/dist/types/utils/category-resolver.d.ts +46 -0
  32. package/dist/types/utils/commission-split.d.ts +56 -0
  33. package/dist/types/utils/commission.d.ts +29 -0
  34. package/dist/types/utils/hooks.d.ts +17 -0
  35. package/dist/types/utils/index.d.ts +6 -0
  36. package/dist/types/utils/logger.d.ts +12 -0
  37. package/dist/types/utils/subscription/actions.d.ts +28 -0
  38. package/dist/types/utils/subscription/index.d.ts +2 -0
  39. package/dist/types/utils/subscription/period.d.ts +47 -0
  40. package/dist/types/utils/transaction-type.d.ts +102 -0
  41. package/enums/escrow.enums.js +36 -0
  42. package/enums/index.js +36 -0
  43. package/enums/split.enums.js +37 -0
  44. package/index.js +16 -0
  45. package/package.json +91 -74
  46. package/schemas/escrow/hold.schema.js +62 -0
  47. package/schemas/escrow/index.js +15 -0
  48. package/schemas/index.js +6 -0
  49. package/schemas/split/index.js +16 -0
  50. package/schemas/split/split.schema.js +86 -0
  51. package/services/escrow.service.js +353 -0
  52. package/services/payment.service.js +54 -3
  53. package/services/subscription.service.js +15 -9
  54. package/utils/commission-split.js +180 -0
  55. package/utils/index.d.ts +40 -0
  56. package/utils/index.js +7 -0
  57. package/utils/subscription/actions.js +68 -0
  58. package/utils/subscription/index.js +20 -0
  59. package/utils/subscription/period.js +123 -0
  60. package/revenue.d.ts +0 -350
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Current Payment Schema
3
+ * Use this in your model: currentPayment: { type: currentPaymentSchema }
4
+ *
5
+ * Tracks the latest payment transaction for an entity
6
+ */
7
+ export const currentPaymentSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
8
+ _id: false;
9
+ }, {
10
+ status: string;
11
+ transactionId?: import("mongoose").Types.ObjectId;
12
+ amount?: number;
13
+ method?: string;
14
+ reference?: string;
15
+ verifiedAt?: NativeDate;
16
+ verifiedBy?: import("mongoose").Types.ObjectId;
17
+ }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
18
+ status: string;
19
+ transactionId?: import("mongoose").Types.ObjectId;
20
+ amount?: number;
21
+ method?: string;
22
+ reference?: string;
23
+ verifiedAt?: NativeDate;
24
+ verifiedBy?: import("mongoose").Types.ObjectId;
25
+ }>, {}, import("mongoose").ResolveSchemaOptions<{
26
+ _id: false;
27
+ }>> & import("mongoose").FlatRecord<{
28
+ status: string;
29
+ transactionId?: import("mongoose").Types.ObjectId;
30
+ amount?: number;
31
+ method?: string;
32
+ reference?: string;
33
+ verifiedAt?: NativeDate;
34
+ verifiedBy?: import("mongoose").Types.ObjectId;
35
+ }> & {
36
+ _id: import("mongoose").Types.ObjectId;
37
+ } & {
38
+ __v: number;
39
+ }>;
40
+ /**
41
+ * Payment Summary Schema
42
+ * Use this in your model: paymentSummary: { type: paymentSummarySchema }
43
+ *
44
+ * Tracks payment history and totals
45
+ */
46
+ export const paymentSummarySchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
47
+ _id: false;
48
+ }, {
49
+ totalPayments: number;
50
+ totalAmountPaid: number;
51
+ lastPaymentDate?: NativeDate;
52
+ lastPaymentAmount?: number;
53
+ }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
54
+ totalPayments: number;
55
+ totalAmountPaid: number;
56
+ lastPaymentDate?: NativeDate;
57
+ lastPaymentAmount?: number;
58
+ }>, {}, import("mongoose").ResolveSchemaOptions<{
59
+ _id: false;
60
+ }>> & import("mongoose").FlatRecord<{
61
+ totalPayments: number;
62
+ totalAmountPaid: number;
63
+ lastPaymentDate?: NativeDate;
64
+ lastPaymentAmount?: number;
65
+ }> & {
66
+ _id: import("mongoose").Types.ObjectId;
67
+ } & {
68
+ __v: number;
69
+ }>;
70
+ /**
71
+ * Payment Details Schema (for manual payments)
72
+ * Embedded in Transaction model
73
+ */
74
+ export const paymentDetailsSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
75
+ _id: false;
76
+ }, {
77
+ provider?: string;
78
+ walletNumber?: string;
79
+ walletType?: string;
80
+ trxId?: string;
81
+ bankName?: string;
82
+ accountNumber?: string;
83
+ accountName?: string;
84
+ proofUrl?: string;
85
+ }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
86
+ provider?: string;
87
+ walletNumber?: string;
88
+ walletType?: string;
89
+ trxId?: string;
90
+ bankName?: string;
91
+ accountNumber?: string;
92
+ accountName?: string;
93
+ proofUrl?: string;
94
+ }>, {}, import("mongoose").ResolveSchemaOptions<{
95
+ _id: false;
96
+ }>> & import("mongoose").FlatRecord<{
97
+ provider?: string;
98
+ walletNumber?: string;
99
+ walletType?: string;
100
+ trxId?: string;
101
+ bankName?: string;
102
+ accountNumber?: string;
103
+ accountName?: string;
104
+ proofUrl?: string;
105
+ }> & {
106
+ _id: import("mongoose").Types.ObjectId;
107
+ } & {
108
+ __v: number;
109
+ }>;
110
+ /**
111
+ * Tenant Snapshot Schema
112
+ * Captures organization payment details at transaction time (audit trail)
113
+ */
114
+ export const tenantSnapshotSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
115
+ _id: false;
116
+ }, {
117
+ paymentInstructions?: string;
118
+ bkashNumber?: string;
119
+ nagadNumber?: string;
120
+ bankAccount?: string;
121
+ }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
122
+ paymentInstructions?: string;
123
+ bkashNumber?: string;
124
+ nagadNumber?: string;
125
+ bankAccount?: string;
126
+ }>, {}, import("mongoose").ResolveSchemaOptions<{
127
+ _id: false;
128
+ }>> & import("mongoose").FlatRecord<{
129
+ paymentInstructions?: string;
130
+ bkashNumber?: string;
131
+ nagadNumber?: string;
132
+ bankAccount?: string;
133
+ }> & {
134
+ _id: import("mongoose").Types.ObjectId;
135
+ } & {
136
+ __v: number;
137
+ }>;
138
+ declare namespace _default {
139
+ export { currentPaymentSchema };
140
+ export { paymentSummarySchema };
141
+ export { paymentDetailsSchema };
142
+ export { tenantSnapshotSchema };
143
+ }
144
+ export default _default;
145
+ import { Schema } from 'mongoose';
@@ -0,0 +1,51 @@
1
+ export class EscrowService {
2
+ constructor(container: any);
3
+ container: any;
4
+ models: any;
5
+ providers: any;
6
+ config: any;
7
+ hooks: any;
8
+ logger: any;
9
+ /**
10
+ * Hold funds in escrow
11
+ *
12
+ * @param {String} transactionId - Transaction to hold
13
+ * @param {Object} options - Hold options
14
+ * @returns {Promise<Object>} Updated transaction
15
+ */
16
+ hold(transactionId: string, options?: any): Promise<any>;
17
+ /**
18
+ * Release funds from escrow to recipient
19
+ *
20
+ * @param {String} transactionId - Transaction to release
21
+ * @param {Object} options - Release options
22
+ * @returns {Promise<Object>} { transaction, releaseTransaction }
23
+ */
24
+ release(transactionId: string, options?: any): Promise<any>;
25
+ /**
26
+ * Cancel hold and release back to customer
27
+ *
28
+ * @param {String} transactionId - Transaction to cancel hold
29
+ * @param {Object} options - Cancel options
30
+ * @returns {Promise<Object>} Updated transaction
31
+ */
32
+ cancel(transactionId: string, options?: any): Promise<any>;
33
+ /**
34
+ * Split payment to multiple recipients
35
+ * Deducts splits from held amount and releases remainder to organization
36
+ *
37
+ * @param {String} transactionId - Transaction to split
38
+ * @param {Array} splitRules - Split configuration
39
+ * @returns {Promise<Object>} { transaction, splitTransactions, organizationTransaction }
40
+ */
41
+ split(transactionId: string, splitRules?: any[]): Promise<any>;
42
+ /**
43
+ * Get escrow status
44
+ *
45
+ * @param {String} transactionId - Transaction ID
46
+ * @returns {Promise<Object>} Escrow status
47
+ */
48
+ getStatus(transactionId: string): Promise<any>;
49
+ _triggerHook(event: any, data: any): void;
50
+ }
51
+ export default EscrowService;
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Payment Service
3
+ * Uses DI container for all dependencies
4
+ */
5
+ export class PaymentService {
6
+ constructor(container: any);
7
+ container: any;
8
+ models: any;
9
+ providers: any;
10
+ config: any;
11
+ hooks: any;
12
+ logger: any;
13
+ /**
14
+ * Verify a payment
15
+ *
16
+ * @param {String} paymentIntentId - Payment intent ID or transaction ID
17
+ * @param {Object} options - Verification options
18
+ * @param {String} options.verifiedBy - User ID who verified (for manual verification)
19
+ * @returns {Promise<Object>} { transaction, status }
20
+ */
21
+ verify(paymentIntentId: string, options?: {
22
+ verifiedBy: string;
23
+ }): Promise<any>;
24
+ /**
25
+ * Get payment status
26
+ *
27
+ * @param {String} paymentIntentId - Payment intent ID or transaction ID
28
+ * @returns {Promise<Object>} { transaction, status }
29
+ */
30
+ getStatus(paymentIntentId: string): Promise<any>;
31
+ /**
32
+ * Refund a payment
33
+ *
34
+ * @param {String} paymentId - Payment intent ID or transaction ID
35
+ * @param {Number} amount - Amount to refund (optional, full refund if not provided)
36
+ * @param {Object} options - Refund options
37
+ * @param {String} options.reason - Refund reason
38
+ * @returns {Promise<Object>} { transaction, refundResult }
39
+ */
40
+ refund(paymentId: string, amount?: number, options?: {
41
+ reason: string;
42
+ }): Promise<any>;
43
+ /**
44
+ * Handle webhook from payment provider
45
+ *
46
+ * @param {String} provider - Provider name
47
+ * @param {Object} payload - Webhook payload
48
+ * @param {Object} headers - Request headers
49
+ * @returns {Promise<Object>} { event, transaction }
50
+ */
51
+ handleWebhook(providerName: any, payload: any, headers?: any): Promise<any>;
52
+ /**
53
+ * List payments/transactions with filters
54
+ *
55
+ * @param {Object} filters - Query filters
56
+ * @param {Object} options - Query options (limit, skip, sort)
57
+ * @returns {Promise<Array>} Transactions
58
+ */
59
+ list(filters?: any, options?: any): Promise<any[]>;
60
+ /**
61
+ * Get payment/transaction by ID
62
+ *
63
+ * @param {String} transactionId - Transaction ID
64
+ * @returns {Promise<Object>} Transaction
65
+ */
66
+ get(transactionId: string): Promise<any>;
67
+ /**
68
+ * Get provider instance
69
+ *
70
+ * @param {String} providerName - Provider name
71
+ * @returns {Object} Provider instance
72
+ */
73
+ getProvider(providerName: string): any;
74
+ /**
75
+ * Trigger event hook (fire-and-forget, non-blocking)
76
+ * @private
77
+ */
78
+ private _triggerHook;
79
+ }
80
+ export default PaymentService;
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Subscription Service
3
+ * Uses DI container for all dependencies
4
+ */
5
+ export class SubscriptionService {
6
+ constructor(container: any);
7
+ container: any;
8
+ models: any;
9
+ providers: any;
10
+ config: any;
11
+ hooks: any;
12
+ logger: any;
13
+ /**
14
+ * Create a new subscription
15
+ *
16
+ * @param {Object} params - Subscription parameters
17
+ * @param {Object} params.data - Subscription data (organizationId, customerId, referenceId, referenceModel, etc.)
18
+ * @param {String} params.planKey - Plan key ('monthly', 'quarterly', 'yearly')
19
+ * @param {Number} params.amount - Subscription amount
20
+ * @param {String} params.currency - Currency code (default: 'BDT')
21
+ * @param {String} params.gateway - Payment gateway to use (default: 'manual')
22
+ * @param {String} params.entity - Logical entity identifier (e.g., 'Order', 'PlatformSubscription', 'Membership')
23
+ * NOTE: This is NOT a database model name - it's just a logical identifier for categoryMappings
24
+ * @param {String} params.monetizationType - Monetization type ('free', 'subscription', 'purchase')
25
+ * @param {Object} params.paymentData - Payment method details
26
+ * @param {Object} params.metadata - Additional metadata
27
+ * @param {String} params.idempotencyKey - Idempotency key for duplicate prevention
28
+ *
29
+ * @example
30
+ * // With polymorphic reference (recommended)
31
+ * await revenue.subscriptions.create({
32
+ * data: {
33
+ * organizationId: '...',
34
+ * customerId: '...',
35
+ * referenceId: subscription._id, // Links to entity
36
+ * referenceModel: 'Subscription', // Model name
37
+ * },
38
+ * amount: 1500,
39
+ * // ...
40
+ * });
41
+ *
42
+ * @returns {Promise<Object>} { subscription, transaction, paymentIntent }
43
+ */
44
+ create(params: {
45
+ data: any;
46
+ planKey: string;
47
+ amount: number;
48
+ currency: string;
49
+ gateway: string;
50
+ entity: string;
51
+ monetizationType: string;
52
+ paymentData: any;
53
+ metadata: any;
54
+ idempotencyKey: string;
55
+ }): Promise<any>;
56
+ /**
57
+ * Activate subscription after payment verification
58
+ *
59
+ * @param {String} subscriptionId - Subscription ID or transaction ID
60
+ * @param {Object} options - Activation options
61
+ * @returns {Promise<Object>} Updated subscription
62
+ */
63
+ activate(subscriptionId: string, options?: any): Promise<any>;
64
+ /**
65
+ * Renew subscription
66
+ *
67
+ * @param {String} subscriptionId - Subscription ID
68
+ * @param {Object} params - Renewal parameters
69
+ * @param {String} params.gateway - Payment gateway to use (default: 'manual')
70
+ * @param {String} params.entity - Logical entity identifier (optional, inherits from subscription)
71
+ * @param {Object} params.paymentData - Payment method details
72
+ * @param {Object} params.metadata - Additional metadata
73
+ * @param {String} params.idempotencyKey - Idempotency key for duplicate prevention
74
+ * @returns {Promise<Object>} { subscription, transaction, paymentIntent }
75
+ */
76
+ renew(subscriptionId: string, params?: {
77
+ gateway: string;
78
+ entity: string;
79
+ paymentData: any;
80
+ metadata: any;
81
+ idempotencyKey: string;
82
+ }): Promise<any>;
83
+ /**
84
+ * Cancel subscription
85
+ *
86
+ * @param {String} subscriptionId - Subscription ID
87
+ * @param {Object} options - Cancellation options
88
+ * @param {Boolean} options.immediate - Cancel immediately vs at period end
89
+ * @param {String} options.reason - Cancellation reason
90
+ * @returns {Promise<Object>} Updated subscription
91
+ */
92
+ cancel(subscriptionId: string, options?: {
93
+ immediate: boolean;
94
+ reason: string;
95
+ }): Promise<any>;
96
+ /**
97
+ * Pause subscription
98
+ *
99
+ * @param {String} subscriptionId - Subscription ID
100
+ * @param {Object} options - Pause options
101
+ * @returns {Promise<Object>} Updated subscription
102
+ */
103
+ pause(subscriptionId: string, options?: any): Promise<any>;
104
+ /**
105
+ * Resume subscription
106
+ *
107
+ * @param {String} subscriptionId - Subscription ID
108
+ * @param {Object} options - Resume options
109
+ * @returns {Promise<Object>} Updated subscription
110
+ */
111
+ resume(subscriptionId: string, options?: any): Promise<any>;
112
+ /**
113
+ * List subscriptions with filters
114
+ *
115
+ * @param {Object} filters - Query filters
116
+ * @param {Object} options - Query options (limit, skip, sort)
117
+ * @returns {Promise<Array>} Subscriptions
118
+ */
119
+ list(filters?: any, options?: any): Promise<any[]>;
120
+ /**
121
+ * Get subscription by ID
122
+ *
123
+ * @param {String} subscriptionId - Subscription ID
124
+ * @returns {Promise<Object>} Subscription
125
+ */
126
+ get(subscriptionId: string): Promise<any>;
127
+ /**
128
+ * Calculate period end date based on plan key
129
+ * @private
130
+ */
131
+ private _calculatePeriodEnd;
132
+ /**
133
+ * Trigger event hook (fire-and-forget, non-blocking)
134
+ * @private
135
+ */
136
+ private _triggerHook;
137
+ }
138
+ export default SubscriptionService;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Transaction Service
3
+ * Focused on core transaction lifecycle operations
4
+ */
5
+ export class TransactionService {
6
+ constructor(container: any);
7
+ container: any;
8
+ models: any;
9
+ hooks: any;
10
+ logger: any;
11
+ /**
12
+ * Get transaction by ID
13
+ *
14
+ * @param {String} transactionId - Transaction ID
15
+ * @returns {Promise<Object>} Transaction
16
+ */
17
+ get(transactionId: string): Promise<any>;
18
+ /**
19
+ * List transactions with filters
20
+ *
21
+ * @param {Object} filters - Query filters
22
+ * @param {Object} options - Query options (limit, skip, sort, populate)
23
+ * @returns {Promise<Object>} { transactions, total, page, limit }
24
+ */
25
+ list(filters?: any, options?: any): Promise<any>;
26
+ /**
27
+ * Update transaction
28
+ *
29
+ * @param {String} transactionId - Transaction ID
30
+ * @param {Object} updates - Fields to update
31
+ * @returns {Promise<Object>} Updated transaction
32
+ */
33
+ update(transactionId: string, updates: any): Promise<any>;
34
+ /**
35
+ * Trigger event hook (fire-and-forget, non-blocking)
36
+ * @private
37
+ */
38
+ private _triggerHook;
39
+ }
40
+ export default TransactionService;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Resolve category for a transaction based on entity and monetizationType
3
+ *
4
+ * Resolution Logic:
5
+ * 1. If categoryMappings[entity] exists → use it
6
+ * 2. Otherwise → fall back to default library category
7
+ *
8
+ * @param {String} entity - The logical entity/identifier (e.g., 'Order', 'PlatformSubscription', 'Membership')
9
+ * NOTE: This is NOT a database model name - it's just a logical identifier
10
+ * @param {String} monetizationType - The monetization type ('subscription', 'purchase', 'free')
11
+ * @param {Object} categoryMappings - User-defined category mappings from config
12
+ * @returns {String} Category name for the transaction
13
+ *
14
+ * @example
15
+ * // With mapping defined
16
+ * resolveCategory('Order', 'subscription', { Order: 'order_subscription' })
17
+ * // Returns: 'order_subscription'
18
+ *
19
+ * @example
20
+ * // Without mapping, falls back to library default
21
+ * resolveCategory('Order', 'subscription', {})
22
+ * // Returns: 'subscription'
23
+ *
24
+ * @example
25
+ * // Different entities with different mappings
26
+ * const mappings = {
27
+ * Order: 'order_subscription',
28
+ * PlatformSubscription: 'platform_subscription',
29
+ * TenantUpgrade: 'tenant_upgrade',
30
+ * Membership: 'gym_membership',
31
+ * Enrollment: 'course_enrollment',
32
+ * };
33
+ * resolveCategory('PlatformSubscription', 'subscription', mappings)
34
+ * // Returns: 'platform_subscription'
35
+ */
36
+ export function resolveCategory(entity: string, monetizationType: string, categoryMappings?: any): string;
37
+ /**
38
+ * Validate that a category is defined in user's Transaction model enum
39
+ * This is informational - actual validation happens at Mongoose schema level
40
+ *
41
+ * @param {String} category - Category to validate
42
+ * @param {Array<String>} allowedCategories - List of allowed categories
43
+ * @returns {Boolean} Whether category is valid
44
+ */
45
+ export function isCategoryValid(category: string, allowedCategories?: Array<string>): boolean;
46
+ export default resolveCategory;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Calculate multi-party commission splits
3
+ *
4
+ * @param {Number} amount - Transaction amount
5
+ * @param {Array} splitRules - Split configuration
6
+ * @param {Number} gatewayFeeRate - Gateway fee rate (optional)
7
+ * @returns {Array} Split objects
8
+ *
9
+ * @example
10
+ * calculateSplits(1000, [
11
+ * { type: 'platform_commission', recipientId: 'platform', recipientType: 'platform', rate: 0.10 },
12
+ * { type: 'affiliate_commission', recipientId: 'affiliate-123', recipientType: 'user', rate: 0.02 },
13
+ * ], 0.018);
14
+ *
15
+ * Returns:
16
+ * [
17
+ * { type: 'platform_commission', recipientId: 'platform', grossAmount: 100, gatewayFeeAmount: 18, netAmount: 82, ... },
18
+ * { type: 'affiliate_commission', recipientId: 'affiliate-123', grossAmount: 20, gatewayFeeAmount: 0, netAmount: 20, ... },
19
+ * ]
20
+ */
21
+ export function calculateSplits(amount: number, splitRules?: any[], gatewayFeeRate?: number): any[];
22
+ /**
23
+ * Calculate organization payout after splits
24
+ *
25
+ * @param {Number} amount - Total transaction amount
26
+ * @param {Array} splits - Calculated splits
27
+ * @returns {Number} Amount organization receives
28
+ */
29
+ export function calculateOrganizationPayout(amount: number, splits?: any[]): number;
30
+ /**
31
+ * Reverse splits proportionally on refund
32
+ *
33
+ * @param {Array} originalSplits - Original split objects
34
+ * @param {Number} originalAmount - Original transaction amount
35
+ * @param {Number} refundAmount - Amount being refunded
36
+ * @returns {Array} Reversed splits
37
+ */
38
+ export function reverseSplits(originalSplits: any[], originalAmount: number, refundAmount: number): any[];
39
+ /**
40
+ * Build commission object with splits support
41
+ * Backward compatible with existing calculateCommission
42
+ *
43
+ * @param {Number} amount - Transaction amount
44
+ * @param {Number} commissionRate - Platform commission rate
45
+ * @param {Number} gatewayFeeRate - Gateway fee rate
46
+ * @param {Object} options - Additional options
47
+ * @returns {Object} Commission with optional splits
48
+ */
49
+ export function calculateCommissionWithSplits(amount: number, commissionRate: number, gatewayFeeRate?: number, options?: any): any;
50
+ declare namespace _default {
51
+ export { calculateSplits };
52
+ export { calculateOrganizationPayout };
53
+ export { reverseSplits };
54
+ export { calculateCommissionWithSplits };
55
+ }
56
+ export default _default;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Commission Calculation Utility
3
+ * @classytic/revenue
4
+ *
5
+ * Handles platform commission calculation with gateway fee deduction
6
+ */
7
+ /**
8
+ * Build commission object for transaction
9
+ *
10
+ * @param {Number} amount - Transaction amount
11
+ * @param {Number} commissionRate - Commission rate (0 to 1, e.g., 0.10 for 10%)
12
+ * @param {Number} gatewayFeeRate - Gateway fee rate (0 to 1, e.g., 0.018 for 1.8%)
13
+ * @returns {Object} Commission object or null
14
+ */
15
+ export function calculateCommission(amount: number, commissionRate: number, gatewayFeeRate?: number): any;
16
+ /**
17
+ * Reverse commission on refund (proportional)
18
+ *
19
+ * @param {Object} originalCommission - Original commission object
20
+ * @param {Number} originalAmount - Original transaction amount
21
+ * @param {Number} refundAmount - Amount being refunded
22
+ * @returns {Object} Reversed commission or null
23
+ */
24
+ export function reverseCommission(originalCommission: any, originalAmount: number, refundAmount: number): any;
25
+ declare namespace _default {
26
+ export { calculateCommission };
27
+ export { reverseCommission };
28
+ }
29
+ export default _default;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Hook Utilities
3
+ * @classytic/revenue
4
+ *
5
+ * Fire-and-forget hook execution - never blocks main flow
6
+ */
7
+ /**
8
+ * Trigger hooks asynchronously without waiting
9
+ * Errors are logged but never thrown
10
+ *
11
+ * @param {Object} hooks - Hooks object
12
+ * @param {string} event - Event name
13
+ * @param {Object} data - Event data
14
+ * @param {Object} logger - Logger instance
15
+ */
16
+ export function triggerHook(hooks: any, event: string, data: any, logger: any): void;
17
+ export default triggerHook;
@@ -0,0 +1,6 @@
1
+ export * from "./transaction-type.js";
2
+ export * from "./subscription/index.js";
3
+ export { triggerHook } from "./hooks.js";
4
+ export { default as logger, setLogger } from "./logger.js";
5
+ export { calculateCommission, reverseCommission } from "./commission.js";
6
+ export { calculateSplits, calculateOrganizationPayout, reverseSplits, calculateCommissionWithSplits } from "./commission-split.js";
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Set custom logger implementation
3
+ * @param {Object} customLogger - Logger instance with info, warn, error, debug methods
4
+ */
5
+ export function setLogger(customLogger: any): void;
6
+ export namespace logger {
7
+ function info(...args: any[]): void;
8
+ function warn(...args: any[]): void;
9
+ function error(...args: any[]): void;
10
+ function debug(...args: any[]): void;
11
+ }
12
+ export default logger;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Check if subscription is active
3
+ */
4
+ export function isSubscriptionActive(subscription: any): boolean;
5
+ /**
6
+ * Check if can renew
7
+ */
8
+ export function canRenewSubscription(entity: any): boolean;
9
+ /**
10
+ * Check if can cancel
11
+ */
12
+ export function canCancelSubscription(entity: any): boolean;
13
+ /**
14
+ * Check if can pause
15
+ */
16
+ export function canPauseSubscription(entity: any): boolean;
17
+ /**
18
+ * Check if can resume
19
+ */
20
+ export function canResumeSubscription(entity: any): boolean;
21
+ declare namespace _default {
22
+ export { isSubscriptionActive };
23
+ export { canRenewSubscription };
24
+ export { canCancelSubscription };
25
+ export { canPauseSubscription };
26
+ export { canResumeSubscription };
27
+ }
28
+ export default _default;
@@ -0,0 +1,2 @@
1
+ export { addDuration, calculatePeriodRange, calculateProratedAmount, resolveIntervalToDuration } from "./period.js";
2
+ export { isSubscriptionActive, canRenewSubscription, canCancelSubscription, canPauseSubscription, canResumeSubscription } from "./actions.js";