@classytic/revenue 0.2.4 → 1.0.1
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 -501
- 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 +4362 -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 +906 -0
- package/dist/schemas/index.js +533 -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-CETjPq10.d.ts +976 -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 -128
- 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 -117
- 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 -675
- package/services/payment.service.js +0 -535
- 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
package/index.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @classytic/revenue
|
|
3
|
-
* Revenue Management System
|
|
4
|
-
*
|
|
5
|
-
* A unified, enterprise-grade revenue management system combining
|
|
6
|
-
* monetization (subscriptions, purchases, proration) and payment processing
|
|
7
|
-
* (verification, refunds, webhooks) into a single, cohesive package.
|
|
8
|
-
*
|
|
9
|
-
* Thin, focused, production-ready library with smart defaults.
|
|
10
|
-
*
|
|
11
|
-
* @version 0.2.0
|
|
12
|
-
* @author Classytic (Classytic)
|
|
13
|
-
* @license MIT
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
// ============ CORE API ============
|
|
17
|
-
export { createRevenue } from './core/builder.js';
|
|
18
|
-
export { Container } from './core/container.js';
|
|
19
|
-
import { createRevenue as _createRevenue } from './core/builder.js';
|
|
20
|
-
import { Container as _Container } from './core/container.js';
|
|
21
|
-
|
|
22
|
-
// ============ ERROR CLASSES ============
|
|
23
|
-
export * from './core/errors.js';
|
|
24
|
-
import { RevenueError } from './core/errors.js';
|
|
25
|
-
|
|
26
|
-
// ============ PROVIDER SYSTEM ============
|
|
27
|
-
export {
|
|
28
|
-
PaymentProvider,
|
|
29
|
-
PaymentIntent,
|
|
30
|
-
PaymentResult,
|
|
31
|
-
RefundResult,
|
|
32
|
-
WebhookEvent,
|
|
33
|
-
} from './providers/base.js';
|
|
34
|
-
import { PaymentProvider as _PaymentProvider } from './providers/base.js';
|
|
35
|
-
// Note: ManualProvider moved to @classytic/revenue-manual (separate package)
|
|
36
|
-
|
|
37
|
-
// ============ SERVICES (ADVANCED USAGE) ============
|
|
38
|
-
export { MonetizationService } from './services/monetization.service.js';
|
|
39
|
-
export { PaymentService } from './services/payment.service.js';
|
|
40
|
-
export { TransactionService } from './services/transaction.service.js';
|
|
41
|
-
export { EscrowService } from './services/escrow.service.js';
|
|
42
|
-
|
|
43
|
-
// ============ ENUMS & SCHEMAS (FOR INJECTION) ============
|
|
44
|
-
export * from './enums/index.js';
|
|
45
|
-
export * from './schemas/index.js';
|
|
46
|
-
|
|
47
|
-
// ============ UTILITIES ============
|
|
48
|
-
export {
|
|
49
|
-
logger,
|
|
50
|
-
setLogger,
|
|
51
|
-
calculateCommission,
|
|
52
|
-
reverseCommission,
|
|
53
|
-
// Split/Escrow utilities
|
|
54
|
-
calculateSplits,
|
|
55
|
-
calculateOrganizationPayout,
|
|
56
|
-
reverseSplits,
|
|
57
|
-
calculateCommissionWithSplits,
|
|
58
|
-
// Subscription utilities
|
|
59
|
-
addDuration,
|
|
60
|
-
calculatePeriodRange,
|
|
61
|
-
calculateProratedAmount,
|
|
62
|
-
resolveIntervalToDuration,
|
|
63
|
-
isSubscriptionActive,
|
|
64
|
-
canRenewSubscription,
|
|
65
|
-
canCancelSubscription,
|
|
66
|
-
canPauseSubscription,
|
|
67
|
-
canResumeSubscription,
|
|
68
|
-
} from './utils/index.js';
|
|
69
|
-
|
|
70
|
-
// ============ DEFAULT EXPORT ============
|
|
71
|
-
export default {
|
|
72
|
-
createRevenue: _createRevenue,
|
|
73
|
-
PaymentProvider: _PaymentProvider,
|
|
74
|
-
RevenueError,
|
|
75
|
-
Container: _Container,
|
|
76
|
-
};
|
package/providers/base.js
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Payment Provider Base Class
|
|
3
|
-
* @classytic/revenue
|
|
4
|
-
*
|
|
5
|
-
* Abstract base class for all payment providers
|
|
6
|
-
* Inspired by: Vercel AI SDK, Stripe SDK
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Payment Intent - standardized response from createIntent
|
|
11
|
-
*/
|
|
12
|
-
export class PaymentIntent {
|
|
13
|
-
constructor(data) {
|
|
14
|
-
this.id = data.id;
|
|
15
|
-
this.sessionId = data.sessionId || null;
|
|
16
|
-
this.paymentIntentId = data.paymentIntentId || null;
|
|
17
|
-
this.provider = data.provider;
|
|
18
|
-
this.status = data.status;
|
|
19
|
-
this.amount = data.amount;
|
|
20
|
-
this.currency = data.currency || 'BDT';
|
|
21
|
-
this.metadata = data.metadata || {};
|
|
22
|
-
this.clientSecret = data.clientSecret;
|
|
23
|
-
this.paymentUrl = data.paymentUrl;
|
|
24
|
-
this.instructions = data.instructions;
|
|
25
|
-
this.raw = data.raw;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Payment Result - standardized response from verifyPayment
|
|
31
|
-
*/
|
|
32
|
-
export class PaymentResult {
|
|
33
|
-
constructor(data) {
|
|
34
|
-
this.id = data.id;
|
|
35
|
-
this.provider = data.provider;
|
|
36
|
-
this.status = data.status; // 'succeeded', 'failed', 'processing'
|
|
37
|
-
this.amount = data.amount;
|
|
38
|
-
this.currency = data.currency || 'BDT';
|
|
39
|
-
this.paidAt = data.paidAt;
|
|
40
|
-
this.metadata = data.metadata || {};
|
|
41
|
-
this.raw = data.raw;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Refund Result - standardized response from refund
|
|
47
|
-
*/
|
|
48
|
-
export class RefundResult {
|
|
49
|
-
constructor(data) {
|
|
50
|
-
this.id = data.id;
|
|
51
|
-
this.provider = data.provider;
|
|
52
|
-
this.status = data.status; // 'succeeded', 'failed', 'processing'
|
|
53
|
-
this.amount = data.amount;
|
|
54
|
-
this.currency = data.currency || 'BDT';
|
|
55
|
-
this.refundedAt = data.refundedAt;
|
|
56
|
-
this.reason = data.reason;
|
|
57
|
-
this.metadata = data.metadata || {};
|
|
58
|
-
this.raw = data.raw;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Webhook Event - standardized webhook event
|
|
64
|
-
*/
|
|
65
|
-
export class WebhookEvent {
|
|
66
|
-
constructor(data) {
|
|
67
|
-
this.id = data.id;
|
|
68
|
-
this.provider = data.provider;
|
|
69
|
-
this.type = data.type; // 'payment.succeeded', 'payment.failed', 'refund.succeeded', etc.
|
|
70
|
-
this.data = data.data;
|
|
71
|
-
this.createdAt = data.createdAt;
|
|
72
|
-
this.raw = data.raw;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Base Payment Provider
|
|
78
|
-
* All payment providers must extend this class
|
|
79
|
-
*/
|
|
80
|
-
export class PaymentProvider {
|
|
81
|
-
constructor(config = {}) {
|
|
82
|
-
this.config = config;
|
|
83
|
-
this.name = 'base'; // Override in subclass
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Create a payment intent
|
|
88
|
-
* @param {Object} params - Payment parameters
|
|
89
|
-
* @param {number} params.amount - Amount in smallest currency unit
|
|
90
|
-
* @param {string} params.currency - Currency code
|
|
91
|
-
* @param {Object} params.metadata - Additional metadata
|
|
92
|
-
* @returns {Promise<PaymentIntent>}
|
|
93
|
-
*/
|
|
94
|
-
async createIntent(params) {
|
|
95
|
-
throw new Error(`${this.constructor.name}: createIntent() must be implemented`);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Verify a payment
|
|
100
|
-
* @param {string} intentId - Payment intent ID
|
|
101
|
-
* @returns {Promise<PaymentResult>}
|
|
102
|
-
*/
|
|
103
|
-
async verifyPayment(intentId) {
|
|
104
|
-
throw new Error(`${this.constructor.name}: verifyPayment() must be implemented`);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Get payment status
|
|
109
|
-
* @param {string} intentId - Payment intent ID
|
|
110
|
-
* @returns {Promise<PaymentResult>}
|
|
111
|
-
*/
|
|
112
|
-
async getStatus(intentId) {
|
|
113
|
-
throw new Error(`${this.constructor.name}: getStatus() must be implemented`);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Refund a payment
|
|
118
|
-
* @param {string} paymentId - Payment ID
|
|
119
|
-
* @param {number} amount - Amount to refund (optional, full refund if not provided)
|
|
120
|
-
* @param {Object} options - Refund options
|
|
121
|
-
* @returns {Promise<RefundResult>}
|
|
122
|
-
*/
|
|
123
|
-
async refund(paymentId, amount, options = {}) {
|
|
124
|
-
throw new Error(`${this.constructor.name}: refund() must be implemented`);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Handle webhook from provider
|
|
129
|
-
* @param {Object} payload - Webhook payload
|
|
130
|
-
* @param {Object} headers - Request headers (for signature verification)
|
|
131
|
-
* @returns {Promise<WebhookEvent>}
|
|
132
|
-
*/
|
|
133
|
-
async handleWebhook(payload, headers = {}) {
|
|
134
|
-
throw new Error(`${this.constructor.name}: handleWebhook() must be implemented`);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Verify webhook signature (optional)
|
|
139
|
-
* @param {Object} payload - Webhook payload
|
|
140
|
-
* @param {string} signature - Webhook signature
|
|
141
|
-
* @returns {boolean}
|
|
142
|
-
*/
|
|
143
|
-
verifyWebhookSignature(payload, signature) {
|
|
144
|
-
// Override in subclass if provider supports webhook signatures
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Get provider capabilities
|
|
150
|
-
* @returns {Object}
|
|
151
|
-
*/
|
|
152
|
-
getCapabilities() {
|
|
153
|
-
return {
|
|
154
|
-
supportsWebhooks: false,
|
|
155
|
-
supportsRefunds: false,
|
|
156
|
-
supportsPartialRefunds: false,
|
|
157
|
-
requiresManualVerification: true,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export default PaymentProvider;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hold/Escrow Schema
|
|
3
|
-
* @classytic/revenue
|
|
4
|
-
*
|
|
5
|
-
* Schema for platform-as-intermediary escrow flow
|
|
6
|
-
* Spread into transaction schema when needed
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { HOLD_STATUS, HOLD_STATUS_VALUES, HOLD_REASON, HOLD_REASON_VALUES } from '../../enums/escrow.enums.js';
|
|
10
|
-
|
|
11
|
-
export const holdSchema = {
|
|
12
|
-
status: {
|
|
13
|
-
type: String,
|
|
14
|
-
enum: HOLD_STATUS_VALUES,
|
|
15
|
-
default: HOLD_STATUS.PENDING,
|
|
16
|
-
index: true,
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
heldAmount: {
|
|
20
|
-
type: Number,
|
|
21
|
-
required: false,
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
releasedAmount: {
|
|
25
|
-
type: Number,
|
|
26
|
-
default: 0,
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
reason: {
|
|
30
|
-
type: String,
|
|
31
|
-
enum: HOLD_REASON_VALUES,
|
|
32
|
-
required: false,
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
holdUntil: {
|
|
36
|
-
type: Date,
|
|
37
|
-
required: false,
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
heldAt: Date,
|
|
41
|
-
releasedAt: Date,
|
|
42
|
-
cancelledAt: Date,
|
|
43
|
-
|
|
44
|
-
releases: [
|
|
45
|
-
{
|
|
46
|
-
amount: Number,
|
|
47
|
-
recipientId: String,
|
|
48
|
-
recipientType: String,
|
|
49
|
-
releasedAt: Date,
|
|
50
|
-
releasedBy: String,
|
|
51
|
-
reason: String,
|
|
52
|
-
metadata: Object,
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
|
|
56
|
-
metadata: {
|
|
57
|
-
type: Object,
|
|
58
|
-
default: {},
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export default holdSchema;
|
package/schemas/escrow/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Escrow Schemas
|
|
3
|
-
* @classytic/revenue
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// Import first
|
|
7
|
-
import { holdSchema } from './hold.schema.js';
|
|
8
|
-
|
|
9
|
-
// Then re-export
|
|
10
|
-
export { holdSchema };
|
|
11
|
-
|
|
12
|
-
// Now it's in scope for default export
|
|
13
|
-
export default {
|
|
14
|
-
holdSchema,
|
|
15
|
-
};
|
package/schemas/index.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TypeScript definitions for @classytic/revenue/schemas
|
|
3
|
-
* Core schemas for injection into your models
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { Schema } from 'mongoose';
|
|
7
|
-
|
|
8
|
-
// ============ TRANSACTION SCHEMAS ============
|
|
9
|
-
|
|
10
|
-
export const currentPaymentSchema: Schema;
|
|
11
|
-
export const paymentSummarySchema: Schema;
|
|
12
|
-
export const paymentDetailsSchema: Schema;
|
|
13
|
-
export const gatewaySchema: Schema;
|
|
14
|
-
export const commissionSchema: Schema;
|
|
15
|
-
|
|
16
|
-
// ============ SUBSCRIPTION SCHEMAS ============
|
|
17
|
-
|
|
18
|
-
export const subscriptionInfoSchema: Schema;
|
|
19
|
-
export const subscriptionPlanSchema: Schema;
|
|
20
|
-
|
|
21
|
-
// ============ DEFAULT EXPORT ============
|
|
22
|
-
|
|
23
|
-
declare const _default: {
|
|
24
|
-
currentPaymentSchema: Schema;
|
|
25
|
-
paymentSummarySchema: Schema;
|
|
26
|
-
paymentDetailsSchema: Schema;
|
|
27
|
-
gatewaySchema: Schema;
|
|
28
|
-
commissionSchema: Schema;
|
|
29
|
-
subscriptionInfoSchema: Schema;
|
|
30
|
-
subscriptionPlanSchema: Schema;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export default _default;
|
package/schemas/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Schema Index
|
|
3
|
-
* @classytic/revenue
|
|
4
|
-
*
|
|
5
|
-
* Core schemas for injection into your models
|
|
6
|
-
*
|
|
7
|
-
* Note: Enums are separate. Import them from '@classytic/revenue/enums'
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
// Re-export core schemas only
|
|
11
|
-
export * from './transaction/index.js';
|
|
12
|
-
export * from './subscription/index.js';
|
|
13
|
-
export * from './escrow/index.js';
|
|
14
|
-
export * from './split/index.js';
|
|
15
|
-
|
|
16
|
-
// Default export with core schemas
|
|
17
|
-
import transactionSchemas from './transaction/index.js';
|
|
18
|
-
import subscriptionSchemas from './subscription/index.js';
|
|
19
|
-
import escrowSchemas from './escrow/index.js';
|
|
20
|
-
import splitSchemas from './split/index.js';
|
|
21
|
-
|
|
22
|
-
export default {
|
|
23
|
-
...transactionSchemas,
|
|
24
|
-
...subscriptionSchemas,
|
|
25
|
-
...escrowSchemas,
|
|
26
|
-
...splitSchemas,
|
|
27
|
-
};
|
package/schemas/split/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Split Payment Schemas
|
|
3
|
-
* @classytic/revenue
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// Import first
|
|
7
|
-
import { splitItemSchema, splitsSchema } from './split.schema.js';
|
|
8
|
-
|
|
9
|
-
// Then re-export
|
|
10
|
-
export { splitItemSchema, splitsSchema };
|
|
11
|
-
|
|
12
|
-
// Now they're in scope for default export
|
|
13
|
-
export default {
|
|
14
|
-
splitItemSchema,
|
|
15
|
-
splitsSchema,
|
|
16
|
-
};
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Split Payment Schema
|
|
3
|
-
* @classytic/revenue
|
|
4
|
-
*
|
|
5
|
-
* Schema for multi-party commission splits
|
|
6
|
-
* Spread into transaction schema when needed
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { SPLIT_TYPE, SPLIT_TYPE_VALUES, SPLIT_STATUS, SPLIT_STATUS_VALUES, PAYOUT_METHOD, PAYOUT_METHOD_VALUES } from '../../enums/split.enums.js';
|
|
10
|
-
|
|
11
|
-
export const splitItemSchema = {
|
|
12
|
-
type: {
|
|
13
|
-
type: String,
|
|
14
|
-
enum: SPLIT_TYPE_VALUES,
|
|
15
|
-
required: true,
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
recipientId: {
|
|
19
|
-
type: String,
|
|
20
|
-
required: true,
|
|
21
|
-
index: true,
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
recipientType: {
|
|
25
|
-
type: String,
|
|
26
|
-
required: true,
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
rate: {
|
|
30
|
-
type: Number,
|
|
31
|
-
required: true,
|
|
32
|
-
min: 0,
|
|
33
|
-
max: 1,
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
grossAmount: {
|
|
37
|
-
type: Number,
|
|
38
|
-
required: true,
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
gatewayFeeRate: {
|
|
42
|
-
type: Number,
|
|
43
|
-
default: 0,
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
gatewayFeeAmount: {
|
|
47
|
-
type: Number,
|
|
48
|
-
default: 0,
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
netAmount: {
|
|
52
|
-
type: Number,
|
|
53
|
-
required: true,
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
status: {
|
|
57
|
-
type: String,
|
|
58
|
-
enum: SPLIT_STATUS_VALUES,
|
|
59
|
-
default: SPLIT_STATUS.PENDING,
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
dueDate: Date,
|
|
63
|
-
paidDate: Date,
|
|
64
|
-
|
|
65
|
-
payoutMethod: {
|
|
66
|
-
type: String,
|
|
67
|
-
enum: PAYOUT_METHOD_VALUES,
|
|
68
|
-
required: false,
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
payoutTransactionId: String,
|
|
72
|
-
|
|
73
|
-
metadata: {
|
|
74
|
-
type: Object,
|
|
75
|
-
default: {},
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export const splitsSchema = {
|
|
80
|
-
splits: {
|
|
81
|
-
type: [splitItemSchema],
|
|
82
|
-
default: [],
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export default splitsSchema;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Subscription Schemas
|
|
3
|
-
* @classytic/revenue
|
|
4
|
-
*
|
|
5
|
-
* Re-exports all subscription-related schemas
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export * from './plan.schema.js';
|
|
9
|
-
export * from './info.schema.js';
|
|
10
|
-
|
|
11
|
-
import planSchemas from './plan.schema.js';
|
|
12
|
-
import infoSchemas from './info.schema.js';
|
|
13
|
-
|
|
14
|
-
export default {
|
|
15
|
-
...planSchemas,
|
|
16
|
-
...infoSchemas,
|
|
17
|
-
};
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Subscription Info Schema
|
|
3
|
-
* @classytic/revenue
|
|
4
|
-
*
|
|
5
|
-
* Complete subscription information schema
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { Schema } from 'mongoose';
|
|
9
|
-
import { subscriptionPlanSchema } from './plan.schema.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Subscription Info Schema
|
|
13
|
-
* Use this in your model: subscription: { type: subscriptionInfoSchema }
|
|
14
|
-
*
|
|
15
|
-
* Complete subscription information
|
|
16
|
-
*/
|
|
17
|
-
export const subscriptionInfoSchema = new Schema({
|
|
18
|
-
isActive: {
|
|
19
|
-
type: Boolean,
|
|
20
|
-
default: false,
|
|
21
|
-
index: true
|
|
22
|
-
},
|
|
23
|
-
plan: {
|
|
24
|
-
type: subscriptionPlanSchema,
|
|
25
|
-
required: true
|
|
26
|
-
},
|
|
27
|
-
startDate: {
|
|
28
|
-
type: Date,
|
|
29
|
-
index: true
|
|
30
|
-
},
|
|
31
|
-
endDate: {
|
|
32
|
-
type: Date,
|
|
33
|
-
index: true
|
|
34
|
-
},
|
|
35
|
-
autoRenew: {
|
|
36
|
-
type: Boolean,
|
|
37
|
-
default: true
|
|
38
|
-
},
|
|
39
|
-
renewalCount: {
|
|
40
|
-
type: Number,
|
|
41
|
-
default: 0,
|
|
42
|
-
min: 0
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
// Cancellation
|
|
46
|
-
canceledAt: {
|
|
47
|
-
type: Date
|
|
48
|
-
},
|
|
49
|
-
cancelAt: {
|
|
50
|
-
type: Date
|
|
51
|
-
},
|
|
52
|
-
cancellationReason: {
|
|
53
|
-
type: String
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
// Pause/Resume
|
|
57
|
-
pausedAt: {
|
|
58
|
-
type: Date
|
|
59
|
-
},
|
|
60
|
-
pauseReason: {
|
|
61
|
-
type: String
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
// Scheduled Plan Changes (Upgrade/Downgrade)
|
|
65
|
-
scheduledChange: {
|
|
66
|
-
type: new Schema({
|
|
67
|
-
// New plan details
|
|
68
|
-
newPlan: {
|
|
69
|
-
type: subscriptionPlanSchema,
|
|
70
|
-
required: true
|
|
71
|
-
},
|
|
72
|
-
// When the change takes effect
|
|
73
|
-
effectiveDate: {
|
|
74
|
-
type: Date,
|
|
75
|
-
required: true
|
|
76
|
-
},
|
|
77
|
-
// Type of change
|
|
78
|
-
changeType: {
|
|
79
|
-
type: String,
|
|
80
|
-
enum: ['upgrade', 'downgrade'],
|
|
81
|
-
required: true
|
|
82
|
-
},
|
|
83
|
-
// Scheduled date
|
|
84
|
-
scheduledAt: {
|
|
85
|
-
type: Date,
|
|
86
|
-
default: Date.now
|
|
87
|
-
},
|
|
88
|
-
// Optional admin price override (for upgrades)
|
|
89
|
-
priceOverride: {
|
|
90
|
-
type: Number,
|
|
91
|
-
min: 0
|
|
92
|
-
},
|
|
93
|
-
// Who scheduled the change
|
|
94
|
-
scheduledBy: {
|
|
95
|
-
type: Schema.Types.ObjectId,
|
|
96
|
-
ref: 'User'
|
|
97
|
-
},
|
|
98
|
-
// Calculation details (for audit trail)
|
|
99
|
-
calculation: {
|
|
100
|
-
type: Schema.Types.Mixed
|
|
101
|
-
}
|
|
102
|
-
}, { _id: false }),
|
|
103
|
-
default: null
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
// Metadata
|
|
107
|
-
metadata: {
|
|
108
|
-
type: Schema.Types.Mixed,
|
|
109
|
-
default: {}
|
|
110
|
-
},
|
|
111
|
-
}, { _id: false });
|
|
112
|
-
|
|
113
|
-
export default {
|
|
114
|
-
subscriptionInfoSchema,
|
|
115
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Subscription Plan Schema
|
|
3
|
-
* @classytic/revenue
|
|
4
|
-
*
|
|
5
|
-
* Schema for subscription plan definitions
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { Schema } from 'mongoose';
|
|
9
|
-
import { PLAN_KEY_VALUES } from '../../enums/index.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Subscription Plan Schema
|
|
13
|
-
* Embedded in subscription info
|
|
14
|
-
*/
|
|
15
|
-
export const subscriptionPlanSchema = new Schema({
|
|
16
|
-
key: {
|
|
17
|
-
type: String,
|
|
18
|
-
required: true,
|
|
19
|
-
enum: PLAN_KEY_VALUES,
|
|
20
|
-
},
|
|
21
|
-
label: {
|
|
22
|
-
type: String,
|
|
23
|
-
required: true,
|
|
24
|
-
},
|
|
25
|
-
duration: {
|
|
26
|
-
type: Number,
|
|
27
|
-
required: true,
|
|
28
|
-
min: 1,
|
|
29
|
-
},
|
|
30
|
-
durationUnit: {
|
|
31
|
-
type: String,
|
|
32
|
-
default: 'days',
|
|
33
|
-
},
|
|
34
|
-
price: {
|
|
35
|
-
type: Number,
|
|
36
|
-
required: true,
|
|
37
|
-
min: 0,
|
|
38
|
-
},
|
|
39
|
-
discount: {
|
|
40
|
-
type: Number,
|
|
41
|
-
default: 0,
|
|
42
|
-
min: 0,
|
|
43
|
-
},
|
|
44
|
-
}, { _id: false });
|
|
45
|
-
|
|
46
|
-
export default {
|
|
47
|
-
subscriptionPlanSchema,
|
|
48
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Common Transaction Fields
|
|
3
|
-
* @classytic/revenue
|
|
4
|
-
*
|
|
5
|
-
* Common field definitions for transaction-related models
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Common Field Definitions
|
|
10
|
-
* Use these for consistent field definitions across models
|
|
11
|
-
*/
|
|
12
|
-
export const commonFields = {
|
|
13
|
-
isNewRequest: {
|
|
14
|
-
type: Boolean,
|
|
15
|
-
default: false,
|
|
16
|
-
index: true,
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export default {
|
|
21
|
-
commonFields,
|
|
22
|
-
};
|