@classytic/revenue 0.2.3 → 1.0.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.
- package/README.md +498 -499
- package/dist/actions-CwG-b7fR.d.ts +519 -0
- package/dist/core/index.d.ts +884 -0
- package/dist/core/index.js +2941 -0
- package/dist/core/index.js.map +1 -0
- package/dist/enums/index.d.ts +130 -0
- package/dist/enums/index.js +167 -0
- package/dist/enums/index.js.map +1 -0
- package/dist/index-BnJWVXuw.d.ts +378 -0
- package/dist/index-ChVD3P9k.d.ts +504 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +4353 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/index.d.ts +132 -0
- package/dist/providers/index.js +122 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/retry-80lBCmSe.d.ts +234 -0
- package/dist/schemas/index.d.ts +894 -0
- package/dist/schemas/index.js +524 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/validation.d.ts +309 -0
- package/dist/schemas/validation.js +249 -0
- package/dist/schemas/validation.js.map +1 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.js +1632 -0
- package/dist/services/index.js.map +1 -0
- package/dist/split.enums-DHdM1YAV.d.ts +255 -0
- package/dist/split.schema-BPdFZMbU.d.ts +958 -0
- package/dist/utils/index.d.ts +24 -0
- package/dist/utils/index.js +1067 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +48 -32
- package/core/builder.js +0 -219
- package/core/container.js +0 -119
- package/core/errors.js +0 -262
- package/dist/types/core/builder.d.ts +0 -97
- package/dist/types/core/container.d.ts +0 -57
- package/dist/types/core/errors.d.ts +0 -122
- package/dist/types/enums/escrow.enums.d.ts +0 -24
- package/dist/types/enums/index.d.ts +0 -69
- package/dist/types/enums/monetization.enums.d.ts +0 -6
- package/dist/types/enums/payment.enums.d.ts +0 -16
- package/dist/types/enums/split.enums.d.ts +0 -25
- package/dist/types/enums/subscription.enums.d.ts +0 -15
- package/dist/types/enums/transaction.enums.d.ts +0 -24
- package/dist/types/index.d.ts +0 -22
- package/dist/types/providers/base.d.ts +0 -126
- package/dist/types/schemas/escrow/hold.schema.d.ts +0 -54
- package/dist/types/schemas/escrow/index.d.ts +0 -6
- package/dist/types/schemas/index.d.ts +0 -506
- package/dist/types/schemas/split/index.d.ts +0 -8
- package/dist/types/schemas/split/split.schema.d.ts +0 -142
- package/dist/types/schemas/subscription/index.d.ts +0 -152
- package/dist/types/schemas/subscription/info.schema.d.ts +0 -128
- package/dist/types/schemas/subscription/plan.schema.d.ts +0 -39
- package/dist/types/schemas/transaction/common.schema.d.ts +0 -12
- package/dist/types/schemas/transaction/gateway.schema.d.ts +0 -86
- package/dist/types/schemas/transaction/index.d.ts +0 -202
- package/dist/types/schemas/transaction/payment.schema.d.ts +0 -145
- package/dist/types/services/escrow.service.d.ts +0 -51
- package/dist/types/services/monetization.service.d.ts +0 -193
- package/dist/types/services/payment.service.d.ts +0 -112
- package/dist/types/services/transaction.service.d.ts +0 -40
- package/dist/types/utils/category-resolver.d.ts +0 -46
- package/dist/types/utils/commission-split.d.ts +0 -56
- package/dist/types/utils/commission.d.ts +0 -29
- package/dist/types/utils/hooks.d.ts +0 -17
- package/dist/types/utils/index.d.ts +0 -6
- package/dist/types/utils/logger.d.ts +0 -12
- package/dist/types/utils/subscription/actions.d.ts +0 -28
- package/dist/types/utils/subscription/index.d.ts +0 -2
- package/dist/types/utils/subscription/period.d.ts +0 -47
- package/dist/types/utils/transaction-type.d.ts +0 -102
- package/enums/escrow.enums.js +0 -36
- package/enums/index.d.ts +0 -116
- package/enums/index.js +0 -110
- package/enums/monetization.enums.js +0 -15
- package/enums/payment.enums.js +0 -64
- package/enums/split.enums.js +0 -37
- package/enums/subscription.enums.js +0 -33
- package/enums/transaction.enums.js +0 -69
- package/index.js +0 -76
- package/providers/base.js +0 -162
- package/schemas/escrow/hold.schema.js +0 -62
- package/schemas/escrow/index.js +0 -15
- package/schemas/index.d.ts +0 -33
- package/schemas/index.js +0 -27
- package/schemas/split/index.js +0 -16
- package/schemas/split/split.schema.js +0 -86
- package/schemas/subscription/index.js +0 -17
- package/schemas/subscription/info.schema.js +0 -115
- package/schemas/subscription/plan.schema.js +0 -48
- package/schemas/transaction/common.schema.js +0 -22
- package/schemas/transaction/gateway.schema.js +0 -69
- package/schemas/transaction/index.js +0 -20
- package/schemas/transaction/payment.schema.js +0 -110
- package/services/escrow.service.js +0 -353
- package/services/monetization.service.js +0 -671
- package/services/payment.service.js +0 -517
- package/services/transaction.service.js +0 -142
- package/utils/category-resolver.js +0 -74
- package/utils/commission-split.js +0 -180
- package/utils/commission.js +0 -83
- package/utils/hooks.js +0 -44
- package/utils/index.d.ts +0 -164
- package/utils/index.js +0 -16
- package/utils/logger.js +0 -36
- package/utils/subscription/actions.js +0 -68
- package/utils/subscription/index.js +0 -20
- package/utils/subscription/period.js +0 -123
- package/utils/transaction-type.js +0 -254
|
@@ -1,145 +0,0 @@
|
|
|
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';
|
|
@@ -1,51 +0,0 @@
|
|
|
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;
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Monetization Service
|
|
3
|
-
* Uses DI container for all dependencies
|
|
4
|
-
*/
|
|
5
|
-
export class MonetizationService {
|
|
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 monetization (purchase, subscription, or free item)
|
|
15
|
-
*
|
|
16
|
-
* @param {MonetizationCreateParams} params - Monetization parameters
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* // One-time purchase
|
|
20
|
-
* await revenue.monetization.create({
|
|
21
|
-
* data: {
|
|
22
|
-
* organizationId: '...',
|
|
23
|
-
* customerId: '...',
|
|
24
|
-
* referenceId: order._id,
|
|
25
|
-
* referenceModel: 'Order',
|
|
26
|
-
* },
|
|
27
|
-
* planKey: 'one_time',
|
|
28
|
-
* monetizationType: 'purchase',
|
|
29
|
-
* gateway: 'bkash',
|
|
30
|
-
* amount: 1500,
|
|
31
|
-
* });
|
|
32
|
-
*
|
|
33
|
-
* // Recurring subscription
|
|
34
|
-
* await revenue.monetization.create({
|
|
35
|
-
* data: {
|
|
36
|
-
* organizationId: '...',
|
|
37
|
-
* customerId: '...',
|
|
38
|
-
* referenceId: subscription._id,
|
|
39
|
-
* referenceModel: 'Subscription',
|
|
40
|
-
* },
|
|
41
|
-
* planKey: 'monthly',
|
|
42
|
-
* monetizationType: 'subscription',
|
|
43
|
-
* gateway: 'stripe',
|
|
44
|
-
* amount: 2000,
|
|
45
|
-
* });
|
|
46
|
-
*
|
|
47
|
-
* @returns {Promise<MonetizationCreateResult>} Result with subscription, transaction, and paymentIntent
|
|
48
|
-
*/
|
|
49
|
-
create(params: MonetizationCreateParams): Promise<MonetizationCreateResult>;
|
|
50
|
-
/**
|
|
51
|
-
* Activate subscription after payment verification
|
|
52
|
-
*
|
|
53
|
-
* @param {String} subscriptionId - Subscription ID or transaction ID
|
|
54
|
-
* @param {Object} options - Activation options
|
|
55
|
-
* @returns {Promise<Object>} Updated subscription
|
|
56
|
-
*/
|
|
57
|
-
activate(subscriptionId: string, options?: any): Promise<any>;
|
|
58
|
-
/**
|
|
59
|
-
* Renew subscription
|
|
60
|
-
*
|
|
61
|
-
* @param {String} subscriptionId - Subscription ID
|
|
62
|
-
* @param {Object} params - Renewal parameters
|
|
63
|
-
* @param {String} params.gateway - Payment gateway name (default: 'manual') - Use ANY registered provider name: 'manual', 'bkash', 'nagad', 'stripe', etc.
|
|
64
|
-
* @param {String} params.entity - Logical entity identifier (optional, inherits from subscription)
|
|
65
|
-
* @param {Object} params.paymentData - Payment method details
|
|
66
|
-
* @param {Object} params.metadata - Additional metadata
|
|
67
|
-
* @param {String} params.idempotencyKey - Idempotency key for duplicate prevention
|
|
68
|
-
* @returns {Promise<Object>} { subscription, transaction, paymentIntent }
|
|
69
|
-
*/
|
|
70
|
-
renew(subscriptionId: string, params?: {
|
|
71
|
-
gateway: string;
|
|
72
|
-
entity: string;
|
|
73
|
-
paymentData: any;
|
|
74
|
-
metadata: any;
|
|
75
|
-
idempotencyKey: string;
|
|
76
|
-
}): Promise<any>;
|
|
77
|
-
/**
|
|
78
|
-
* Cancel subscription
|
|
79
|
-
*
|
|
80
|
-
* @param {String} subscriptionId - Subscription ID
|
|
81
|
-
* @param {Object} options - Cancellation options
|
|
82
|
-
* @param {Boolean} options.immediate - Cancel immediately vs at period end
|
|
83
|
-
* @param {String} options.reason - Cancellation reason
|
|
84
|
-
* @returns {Promise<Object>} Updated subscription
|
|
85
|
-
*/
|
|
86
|
-
cancel(subscriptionId: string, options?: {
|
|
87
|
-
immediate: boolean;
|
|
88
|
-
reason: string;
|
|
89
|
-
}): Promise<any>;
|
|
90
|
-
/**
|
|
91
|
-
* Pause subscription
|
|
92
|
-
*
|
|
93
|
-
* @param {String} subscriptionId - Subscription ID
|
|
94
|
-
* @param {Object} options - Pause options
|
|
95
|
-
* @returns {Promise<Object>} Updated subscription
|
|
96
|
-
*/
|
|
97
|
-
pause(subscriptionId: string, options?: any): Promise<any>;
|
|
98
|
-
/**
|
|
99
|
-
* Resume subscription
|
|
100
|
-
*
|
|
101
|
-
* @param {String} subscriptionId - Subscription ID
|
|
102
|
-
* @param {Object} options - Resume options
|
|
103
|
-
* @returns {Promise<Object>} Updated subscription
|
|
104
|
-
*/
|
|
105
|
-
resume(subscriptionId: string, options?: any): Promise<any>;
|
|
106
|
-
/**
|
|
107
|
-
* List subscriptions with filters
|
|
108
|
-
*
|
|
109
|
-
* @param {Object} filters - Query filters
|
|
110
|
-
* @param {Object} options - Query options (limit, skip, sort)
|
|
111
|
-
* @returns {Promise<Array>} Subscriptions
|
|
112
|
-
*/
|
|
113
|
-
list(filters?: any, options?: any): Promise<any[]>;
|
|
114
|
-
/**
|
|
115
|
-
* Get subscription by ID
|
|
116
|
-
*
|
|
117
|
-
* @param {String} subscriptionId - Subscription ID
|
|
118
|
-
* @returns {Promise<Object>} Subscription
|
|
119
|
-
*/
|
|
120
|
-
get(subscriptionId: string): Promise<any>;
|
|
121
|
-
/**
|
|
122
|
-
* Calculate period end date based on plan key
|
|
123
|
-
* @private
|
|
124
|
-
*/
|
|
125
|
-
private _calculatePeriodEnd;
|
|
126
|
-
/**
|
|
127
|
-
* Trigger event hook (fire-and-forget, non-blocking)
|
|
128
|
-
* @private
|
|
129
|
-
*/
|
|
130
|
-
private _triggerHook;
|
|
131
|
-
}
|
|
132
|
-
export default MonetizationService;
|
|
133
|
-
export type MonetizationCreateParams = {
|
|
134
|
-
/**
|
|
135
|
-
* - Monetization data
|
|
136
|
-
*/
|
|
137
|
-
data: {
|
|
138
|
-
organizationId?: string;
|
|
139
|
-
customerId?: string;
|
|
140
|
-
referenceId?: string;
|
|
141
|
-
referenceModel?: string;
|
|
142
|
-
};
|
|
143
|
-
/**
|
|
144
|
-
* - Plan key ('monthly', 'quarterly', 'yearly', 'one_time', etc.)
|
|
145
|
-
*/
|
|
146
|
-
planKey: string;
|
|
147
|
-
/**
|
|
148
|
-
* - Amount (0 for free)
|
|
149
|
-
*/
|
|
150
|
-
amount: number;
|
|
151
|
-
/**
|
|
152
|
-
* - Currency code
|
|
153
|
-
*/
|
|
154
|
-
currency?: string;
|
|
155
|
-
/**
|
|
156
|
-
* - Payment gateway name
|
|
157
|
-
*/
|
|
158
|
-
gateway?: string;
|
|
159
|
-
/**
|
|
160
|
-
* - Logical entity identifier
|
|
161
|
-
*/
|
|
162
|
-
entity?: string;
|
|
163
|
-
/**
|
|
164
|
-
* - Monetization type
|
|
165
|
-
*/
|
|
166
|
-
monetizationType?: "free" | "subscription" | "purchase";
|
|
167
|
-
/**
|
|
168
|
-
* - Payment method details
|
|
169
|
-
*/
|
|
170
|
-
paymentData?: any;
|
|
171
|
-
/**
|
|
172
|
-
* - Additional metadata
|
|
173
|
-
*/
|
|
174
|
-
metadata?: any;
|
|
175
|
-
/**
|
|
176
|
-
* - Idempotency key
|
|
177
|
-
*/
|
|
178
|
-
idempotencyKey?: string;
|
|
179
|
-
};
|
|
180
|
-
export type MonetizationCreateResult = {
|
|
181
|
-
/**
|
|
182
|
-
* - Subscription record (if Subscription model exists)
|
|
183
|
-
*/
|
|
184
|
-
subscription: any | null;
|
|
185
|
-
/**
|
|
186
|
-
* - Transaction record
|
|
187
|
-
*/
|
|
188
|
-
transaction: any | null;
|
|
189
|
-
/**
|
|
190
|
-
* - Payment intent from provider
|
|
191
|
-
*/
|
|
192
|
-
paymentIntent: any | null;
|
|
193
|
-
};
|
|
@@ -1,112 +0,0 @@
|
|
|
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;
|
|
81
|
-
export type PaymentVerifyResult = {
|
|
82
|
-
/**
|
|
83
|
-
* - Updated transaction
|
|
84
|
-
*/
|
|
85
|
-
transaction: any;
|
|
86
|
-
/**
|
|
87
|
-
* - Payment result from provider
|
|
88
|
-
*/
|
|
89
|
-
paymentResult: any;
|
|
90
|
-
/**
|
|
91
|
-
* - Payment status
|
|
92
|
-
*/
|
|
93
|
-
status: string;
|
|
94
|
-
};
|
|
95
|
-
export type PaymentRefundResult = {
|
|
96
|
-
/**
|
|
97
|
-
* - Original transaction (updated)
|
|
98
|
-
*/
|
|
99
|
-
transaction: any;
|
|
100
|
-
/**
|
|
101
|
-
* - New refund transaction record
|
|
102
|
-
*/
|
|
103
|
-
refundTransaction: any;
|
|
104
|
-
/**
|
|
105
|
-
* - Refund result from provider
|
|
106
|
-
*/
|
|
107
|
-
refundResult: any;
|
|
108
|
-
/**
|
|
109
|
-
* - Transaction status after refund
|
|
110
|
-
*/
|
|
111
|
-
status: string;
|
|
112
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
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;
|
|
@@ -1,46 +0,0 @@
|
|
|
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;
|
|
@@ -1,56 +0,0 @@
|
|
|
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;
|
|
@@ -1,29 +0,0 @@
|
|
|
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;
|
|
@@ -1,17 +0,0 @@
|
|
|
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;
|