@classytic/revenue 1.1.2 → 1.1.4
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 +8 -7
- package/dist/application/services/index.d.mts +4 -0
- package/dist/application/services/index.mjs +3 -0
- package/dist/base-CsTlVQJe.d.mts +136 -0
- package/dist/base-DCoyIUj6.mjs +152 -0
- package/dist/category-resolver-DV83N8ok.mjs +284 -0
- package/dist/commission-split-BzB8cd39.mjs +485 -0
- package/dist/core/events.d.mts +294 -0
- package/dist/core/events.mjs +100 -0
- package/dist/core/index.d.mts +9 -0
- package/dist/core/index.mjs +8 -0
- package/dist/enums/index.d.mts +157 -0
- package/dist/enums/index.mjs +56 -0
- package/dist/errors-rRdOqnWx.d.mts +787 -0
- package/dist/escrow.enums-CZGrrdg7.mjs +101 -0
- package/dist/{escrow.enums-CE0VQsfe.d.ts → escrow.enums-DwdLuuve.d.mts} +30 -28
- package/dist/idempotency-DaYcUGY1.mjs +172 -0
- package/dist/index-Dsp7H5Wb.d.mts +471 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.mjs +38 -0
- package/dist/infrastructure/plugins/{index.d.ts → index.d.mts} +81 -109
- package/dist/infrastructure/plugins/index.mjs +345 -0
- package/dist/money-CvrDOijQ.mjs +271 -0
- package/dist/money-DPG8AtJ8.d.mts +112 -0
- package/dist/{payment.enums-C1BiGlRa.d.ts → payment.enums-HAuAS9Pp.d.mts} +14 -13
- package/dist/payment.enums-tEFVa-Xp.mjs +69 -0
- package/dist/plugin-BbK0OVHy.d.mts +327 -0
- package/dist/plugin-Cd_V04Em.mjs +210 -0
- package/dist/providers/index.d.mts +3 -0
- package/dist/providers/index.mjs +3 -0
- package/dist/reconciliation/{index.d.ts → index.d.mts} +90 -112
- package/dist/reconciliation/index.mjs +192 -0
- package/dist/retry-HHCOXYdn.d.mts +186 -0
- package/dist/revenue-BhdS7nXh.mjs +553 -0
- package/dist/schemas/index.d.mts +2665 -0
- package/dist/schemas/index.mjs +717 -0
- package/dist/schemas/validation.d.mts +375 -0
- package/dist/schemas/validation.mjs +325 -0
- package/dist/{settlement.enums-ByC1x0ye.d.ts → settlement.enums-DFhkqZEY.d.mts} +31 -29
- package/dist/settlement.schema-DnNSFpGd.d.mts +344 -0
- package/dist/settlement.service-DjzAjezU.d.mts +594 -0
- package/dist/settlement.service-DmdKv0Zu.mjs +2511 -0
- package/dist/split.enums-BrjabxIX.mjs +86 -0
- package/dist/split.enums-DmskfLOM.d.mts +43 -0
- package/dist/tax-BoCt5cEd.d.mts +61 -0
- package/dist/tax-EQ15DO81.mjs +162 -0
- package/dist/transaction.enums-pCyMFT4Z.mjs +96 -0
- package/dist/utils/{index.d.ts → index.d.mts} +91 -161
- package/dist/utils/index.mjs +346 -0
- package/package.json +39 -37
- package/dist/application/services/index.d.ts +0 -6
- package/dist/application/services/index.js +0 -3288
- package/dist/application/services/index.js.map +0 -1
- package/dist/core/events.d.ts +0 -455
- package/dist/core/events.js +0 -122
- package/dist/core/events.js.map +0 -1
- package/dist/core/index.d.ts +0 -13
- package/dist/core/index.js +0 -4591
- package/dist/core/index.js.map +0 -1
- package/dist/enums/index.d.ts +0 -159
- package/dist/enums/index.js +0 -296
- package/dist/enums/index.js.map +0 -1
- package/dist/index-DxIK0UmZ.d.ts +0 -633
- package/dist/index-EnfKzDbs.d.ts +0 -806
- package/dist/index-cLJBLUvx.d.ts +0 -478
- package/dist/index.d.ts +0 -43
- package/dist/index.js +0 -4864
- package/dist/index.js.map +0 -1
- package/dist/infrastructure/plugins/index.js +0 -292
- package/dist/infrastructure/plugins/index.js.map +0 -1
- package/dist/money-widWVD7r.d.ts +0 -111
- package/dist/plugin-Bb9HOE10.d.ts +0 -336
- package/dist/providers/index.d.ts +0 -145
- package/dist/providers/index.js +0 -141
- package/dist/providers/index.js.map +0 -1
- package/dist/reconciliation/index.js +0 -140
- package/dist/reconciliation/index.js.map +0 -1
- package/dist/retry-D4hFUwVk.d.ts +0 -194
- package/dist/schemas/index.d.ts +0 -2655
- package/dist/schemas/index.js +0 -841
- package/dist/schemas/index.js.map +0 -1
- package/dist/schemas/validation.d.ts +0 -384
- package/dist/schemas/validation.js +0 -303
- package/dist/schemas/validation.js.map +0 -1
- package/dist/settlement.schema-CpamV7ZY.d.ts +0 -343
- package/dist/split.enums-DG3TxQf9.d.ts +0 -42
- package/dist/tax-CV8A0sxl.d.ts +0 -60
- package/dist/utils/index.js +0 -1202
- package/dist/utils/index.js.map +0 -1
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
//#region src/shared/utils/formatters/money.ts
|
|
2
|
+
/** Supported currencies with their decimal places */
|
|
3
|
+
const CURRENCIES = {
|
|
4
|
+
USD: {
|
|
5
|
+
code: "USD",
|
|
6
|
+
decimals: 2,
|
|
7
|
+
symbol: "$",
|
|
8
|
+
name: "US Dollar"
|
|
9
|
+
},
|
|
10
|
+
EUR: {
|
|
11
|
+
code: "EUR",
|
|
12
|
+
decimals: 2,
|
|
13
|
+
symbol: "€",
|
|
14
|
+
name: "Euro"
|
|
15
|
+
},
|
|
16
|
+
GBP: {
|
|
17
|
+
code: "GBP",
|
|
18
|
+
decimals: 2,
|
|
19
|
+
symbol: "£",
|
|
20
|
+
name: "British Pound"
|
|
21
|
+
},
|
|
22
|
+
BDT: {
|
|
23
|
+
code: "BDT",
|
|
24
|
+
decimals: 2,
|
|
25
|
+
symbol: "৳",
|
|
26
|
+
name: "Bangladeshi Taka"
|
|
27
|
+
},
|
|
28
|
+
INR: {
|
|
29
|
+
code: "INR",
|
|
30
|
+
decimals: 2,
|
|
31
|
+
symbol: "₹",
|
|
32
|
+
name: "Indian Rupee"
|
|
33
|
+
},
|
|
34
|
+
JPY: {
|
|
35
|
+
code: "JPY",
|
|
36
|
+
decimals: 0,
|
|
37
|
+
symbol: "¥",
|
|
38
|
+
name: "Japanese Yen"
|
|
39
|
+
},
|
|
40
|
+
CNY: {
|
|
41
|
+
code: "CNY",
|
|
42
|
+
decimals: 2,
|
|
43
|
+
symbol: "¥",
|
|
44
|
+
name: "Chinese Yuan"
|
|
45
|
+
},
|
|
46
|
+
AED: {
|
|
47
|
+
code: "AED",
|
|
48
|
+
decimals: 2,
|
|
49
|
+
symbol: "د.إ",
|
|
50
|
+
name: "UAE Dirham"
|
|
51
|
+
},
|
|
52
|
+
SAR: {
|
|
53
|
+
code: "SAR",
|
|
54
|
+
decimals: 2,
|
|
55
|
+
symbol: "﷼",
|
|
56
|
+
name: "Saudi Riyal"
|
|
57
|
+
},
|
|
58
|
+
SGD: {
|
|
59
|
+
code: "SGD",
|
|
60
|
+
decimals: 2,
|
|
61
|
+
symbol: "S$",
|
|
62
|
+
name: "Singapore Dollar"
|
|
63
|
+
},
|
|
64
|
+
AUD: {
|
|
65
|
+
code: "AUD",
|
|
66
|
+
decimals: 2,
|
|
67
|
+
symbol: "A$",
|
|
68
|
+
name: "Australian Dollar"
|
|
69
|
+
},
|
|
70
|
+
CAD: {
|
|
71
|
+
code: "CAD",
|
|
72
|
+
decimals: 2,
|
|
73
|
+
symbol: "C$",
|
|
74
|
+
name: "Canadian Dollar"
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Money class - immutable money representation
|
|
79
|
+
*/
|
|
80
|
+
var Money = class Money {
|
|
81
|
+
amount;
|
|
82
|
+
currency;
|
|
83
|
+
constructor(amount, currency) {
|
|
84
|
+
if (!Number.isInteger(amount)) throw new Error(`Money amount must be integer (smallest unit). Got: ${amount}`);
|
|
85
|
+
this.amount = amount;
|
|
86
|
+
this.currency = currency.toUpperCase();
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Create money from smallest unit (cents, paisa)
|
|
90
|
+
* @example Money.cents(1999, 'USD') // $19.99
|
|
91
|
+
*/
|
|
92
|
+
static cents(amount, currency = "USD") {
|
|
93
|
+
return new Money(Math.round(amount), currency);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Create money from major unit (dollars, taka)
|
|
97
|
+
* @example Money.of(19.99, 'USD') // $19.99 (stored as 1999 cents)
|
|
98
|
+
*/
|
|
99
|
+
static of(amount, currency = "USD") {
|
|
100
|
+
const config = CURRENCIES[currency.toUpperCase()] ?? { decimals: 2 };
|
|
101
|
+
const multiplier = Math.pow(10, config.decimals);
|
|
102
|
+
return new Money(Math.round(amount * multiplier), currency);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Create zero money
|
|
106
|
+
*/
|
|
107
|
+
static zero(currency = "USD") {
|
|
108
|
+
return new Money(0, currency);
|
|
109
|
+
}
|
|
110
|
+
static usd(cents) {
|
|
111
|
+
return Money.cents(cents, "USD");
|
|
112
|
+
}
|
|
113
|
+
static eur(cents) {
|
|
114
|
+
return Money.cents(cents, "EUR");
|
|
115
|
+
}
|
|
116
|
+
static gbp(pence) {
|
|
117
|
+
return Money.cents(pence, "GBP");
|
|
118
|
+
}
|
|
119
|
+
static bdt(paisa) {
|
|
120
|
+
return Money.cents(paisa, "BDT");
|
|
121
|
+
}
|
|
122
|
+
static inr(paisa) {
|
|
123
|
+
return Money.cents(paisa, "INR");
|
|
124
|
+
}
|
|
125
|
+
static jpy(yen) {
|
|
126
|
+
return Money.cents(yen, "JPY");
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Add two money values (must be same currency)
|
|
130
|
+
*/
|
|
131
|
+
add(other) {
|
|
132
|
+
this.assertSameCurrency(other);
|
|
133
|
+
return new Money(this.amount + other.amount, this.currency);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Subtract money (must be same currency)
|
|
137
|
+
*/
|
|
138
|
+
subtract(other) {
|
|
139
|
+
this.assertSameCurrency(other);
|
|
140
|
+
return new Money(this.amount - other.amount, this.currency);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Multiply by a factor (rounds to nearest integer)
|
|
144
|
+
*/
|
|
145
|
+
multiply(factor) {
|
|
146
|
+
return new Money(Math.round(this.amount * factor), this.currency);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Divide by a divisor (rounds to nearest integer)
|
|
150
|
+
*/
|
|
151
|
+
divide(divisor) {
|
|
152
|
+
if (divisor === 0) throw new Error("Cannot divide by zero");
|
|
153
|
+
return new Money(Math.round(this.amount / divisor), this.currency);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Calculate percentage
|
|
157
|
+
* @example money.percentage(10) // 10% of money
|
|
158
|
+
*/
|
|
159
|
+
percentage(percent) {
|
|
160
|
+
return this.multiply(percent / 100);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Allocate money among recipients (handles rounding)
|
|
164
|
+
* @example Money.usd(100).allocate([1, 1, 1]) // [34, 33, 33] cents
|
|
165
|
+
*/
|
|
166
|
+
allocate(ratios) {
|
|
167
|
+
const total = ratios.reduce((a, b) => a + b, 0);
|
|
168
|
+
if (total === 0) throw new Error("Ratios must sum to more than 0");
|
|
169
|
+
let remainder = this.amount;
|
|
170
|
+
const results = [];
|
|
171
|
+
for (let i = 0; i < ratios.length; i++) {
|
|
172
|
+
const share = Math.floor(this.amount * ratios[i] / total);
|
|
173
|
+
results.push(new Money(share, this.currency));
|
|
174
|
+
remainder -= share;
|
|
175
|
+
}
|
|
176
|
+
for (let i = 0; i < remainder; i++) results[i] = new Money(results[i].amount + 1, this.currency);
|
|
177
|
+
return results;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Split equally among n recipients
|
|
181
|
+
*/
|
|
182
|
+
split(parts) {
|
|
183
|
+
return this.allocate(Array(parts).fill(1));
|
|
184
|
+
}
|
|
185
|
+
isZero() {
|
|
186
|
+
return this.amount === 0;
|
|
187
|
+
}
|
|
188
|
+
isPositive() {
|
|
189
|
+
return this.amount > 0;
|
|
190
|
+
}
|
|
191
|
+
isNegative() {
|
|
192
|
+
return this.amount < 0;
|
|
193
|
+
}
|
|
194
|
+
equals(other) {
|
|
195
|
+
return this.amount === other.amount && this.currency === other.currency;
|
|
196
|
+
}
|
|
197
|
+
greaterThan(other) {
|
|
198
|
+
this.assertSameCurrency(other);
|
|
199
|
+
return this.amount > other.amount;
|
|
200
|
+
}
|
|
201
|
+
lessThan(other) {
|
|
202
|
+
this.assertSameCurrency(other);
|
|
203
|
+
return this.amount < other.amount;
|
|
204
|
+
}
|
|
205
|
+
greaterThanOrEqual(other) {
|
|
206
|
+
return this.greaterThan(other) || this.equals(other);
|
|
207
|
+
}
|
|
208
|
+
lessThanOrEqual(other) {
|
|
209
|
+
return this.lessThan(other) || this.equals(other);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Get amount in major unit (dollars, taka)
|
|
213
|
+
*/
|
|
214
|
+
toUnit() {
|
|
215
|
+
const config = CURRENCIES[this.currency] ?? { decimals: 2 };
|
|
216
|
+
return this.amount / Math.pow(10, config.decimals);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Format for display
|
|
220
|
+
* @example Money.usd(1999).format() // "$19.99"
|
|
221
|
+
*/
|
|
222
|
+
format(locale = "en-US") {
|
|
223
|
+
return new Intl.NumberFormat(locale, {
|
|
224
|
+
style: "currency",
|
|
225
|
+
currency: this.currency
|
|
226
|
+
}).format(this.toUnit());
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Format without currency symbol
|
|
230
|
+
*/
|
|
231
|
+
formatAmount(locale = "en-US") {
|
|
232
|
+
const config = CURRENCIES[this.currency] ?? { decimals: 2 };
|
|
233
|
+
return new Intl.NumberFormat(locale, {
|
|
234
|
+
minimumFractionDigits: config.decimals,
|
|
235
|
+
maximumFractionDigits: config.decimals
|
|
236
|
+
}).format(this.toUnit());
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Convert to JSON-serializable object
|
|
240
|
+
*/
|
|
241
|
+
toJSON() {
|
|
242
|
+
return {
|
|
243
|
+
amount: this.amount,
|
|
244
|
+
currency: this.currency
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Create from JSON
|
|
249
|
+
*/
|
|
250
|
+
static fromJSON(json) {
|
|
251
|
+
return new Money(json.amount, json.currency);
|
|
252
|
+
}
|
|
253
|
+
toString() {
|
|
254
|
+
return `${this.currency} ${this.amount}`;
|
|
255
|
+
}
|
|
256
|
+
assertSameCurrency(other) {
|
|
257
|
+
if (this.currency !== other.currency) throw new Error(`Currency mismatch: ${this.currency} vs ${other.currency}. Convert first.`);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* Helper functions for legacy compatibility
|
|
262
|
+
*/
|
|
263
|
+
function toSmallestUnit(amount, currency = "USD") {
|
|
264
|
+
return Money.of(amount, currency).amount;
|
|
265
|
+
}
|
|
266
|
+
function fromSmallestUnit(amount, currency = "USD") {
|
|
267
|
+
return Money.cents(amount, currency).toUnit();
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
//#endregion
|
|
271
|
+
export { fromSmallestUnit as n, toSmallestUnit as r, Money as t };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
//#region src/shared/utils/formatters/money.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Money Utility - Integer-safe currency handling
|
|
4
|
+
* @classytic/revenue
|
|
5
|
+
*
|
|
6
|
+
* Never use floating point for money!
|
|
7
|
+
* All amounts stored as smallest unit (cents, paisa, etc.)
|
|
8
|
+
*
|
|
9
|
+
* Inspired by: Stripe, Dinero.js, tc39/proposal-decimal
|
|
10
|
+
*/
|
|
11
|
+
interface MoneyValue {
|
|
12
|
+
/** Amount in smallest currency unit (cents, paisa, etc.) */
|
|
13
|
+
readonly amount: number;
|
|
14
|
+
/** ISO 4217 currency code */
|
|
15
|
+
readonly currency: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Money class - immutable money representation
|
|
19
|
+
*/
|
|
20
|
+
declare class Money implements MoneyValue {
|
|
21
|
+
readonly amount: number;
|
|
22
|
+
readonly currency: string;
|
|
23
|
+
private constructor();
|
|
24
|
+
/**
|
|
25
|
+
* Create money from smallest unit (cents, paisa)
|
|
26
|
+
* @example Money.cents(1999, 'USD') // $19.99
|
|
27
|
+
*/
|
|
28
|
+
static cents(amount: number, currency?: string): Money;
|
|
29
|
+
/**
|
|
30
|
+
* Create money from major unit (dollars, taka)
|
|
31
|
+
* @example Money.of(19.99, 'USD') // $19.99 (stored as 1999 cents)
|
|
32
|
+
*/
|
|
33
|
+
static of(amount: number, currency?: string): Money;
|
|
34
|
+
/**
|
|
35
|
+
* Create zero money
|
|
36
|
+
*/
|
|
37
|
+
static zero(currency?: string): Money;
|
|
38
|
+
static usd(cents: number): Money;
|
|
39
|
+
static eur(cents: number): Money;
|
|
40
|
+
static gbp(pence: number): Money;
|
|
41
|
+
static bdt(paisa: number): Money;
|
|
42
|
+
static inr(paisa: number): Money;
|
|
43
|
+
static jpy(yen: number): Money;
|
|
44
|
+
/**
|
|
45
|
+
* Add two money values (must be same currency)
|
|
46
|
+
*/
|
|
47
|
+
add(other: Money): Money;
|
|
48
|
+
/**
|
|
49
|
+
* Subtract money (must be same currency)
|
|
50
|
+
*/
|
|
51
|
+
subtract(other: Money): Money;
|
|
52
|
+
/**
|
|
53
|
+
* Multiply by a factor (rounds to nearest integer)
|
|
54
|
+
*/
|
|
55
|
+
multiply(factor: number): Money;
|
|
56
|
+
/**
|
|
57
|
+
* Divide by a divisor (rounds to nearest integer)
|
|
58
|
+
*/
|
|
59
|
+
divide(divisor: number): Money;
|
|
60
|
+
/**
|
|
61
|
+
* Calculate percentage
|
|
62
|
+
* @example money.percentage(10) // 10% of money
|
|
63
|
+
*/
|
|
64
|
+
percentage(percent: number): Money;
|
|
65
|
+
/**
|
|
66
|
+
* Allocate money among recipients (handles rounding)
|
|
67
|
+
* @example Money.usd(100).allocate([1, 1, 1]) // [34, 33, 33] cents
|
|
68
|
+
*/
|
|
69
|
+
allocate(ratios: number[]): Money[];
|
|
70
|
+
/**
|
|
71
|
+
* Split equally among n recipients
|
|
72
|
+
*/
|
|
73
|
+
split(parts: number): Money[];
|
|
74
|
+
isZero(): boolean;
|
|
75
|
+
isPositive(): boolean;
|
|
76
|
+
isNegative(): boolean;
|
|
77
|
+
equals(other: Money): boolean;
|
|
78
|
+
greaterThan(other: Money): boolean;
|
|
79
|
+
lessThan(other: Money): boolean;
|
|
80
|
+
greaterThanOrEqual(other: Money): boolean;
|
|
81
|
+
lessThanOrEqual(other: Money): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Get amount in major unit (dollars, taka)
|
|
84
|
+
*/
|
|
85
|
+
toUnit(): number;
|
|
86
|
+
/**
|
|
87
|
+
* Format for display
|
|
88
|
+
* @example Money.usd(1999).format() // "$19.99"
|
|
89
|
+
*/
|
|
90
|
+
format(locale?: string): string;
|
|
91
|
+
/**
|
|
92
|
+
* Format without currency symbol
|
|
93
|
+
*/
|
|
94
|
+
formatAmount(locale?: string): string;
|
|
95
|
+
/**
|
|
96
|
+
* Convert to JSON-serializable object
|
|
97
|
+
*/
|
|
98
|
+
toJSON(): MoneyValue;
|
|
99
|
+
/**
|
|
100
|
+
* Create from JSON
|
|
101
|
+
*/
|
|
102
|
+
static fromJSON(json: MoneyValue): Money;
|
|
103
|
+
toString(): string;
|
|
104
|
+
private assertSameCurrency;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Helper functions for legacy compatibility
|
|
108
|
+
*/
|
|
109
|
+
declare function toSmallestUnit(amount: number, currency?: string): number;
|
|
110
|
+
declare function fromSmallestUnit(amount: number, currency?: string): number;
|
|
111
|
+
//#endregion
|
|
112
|
+
export { toSmallestUnit as i, MoneyValue as n, fromSmallestUnit as r, Money as t };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/enums/payment.enums.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Payment Enums
|
|
3
4
|
* @classytic/revenue
|
|
@@ -9,11 +10,11 @@
|
|
|
9
10
|
* Payment Status - Library-managed states
|
|
10
11
|
*/
|
|
11
12
|
declare const PAYMENT_STATUS: {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
readonly PENDING: "pending";
|
|
14
|
+
readonly VERIFIED: "verified";
|
|
15
|
+
readonly FAILED: "failed";
|
|
16
|
+
readonly REFUNDED: "refunded";
|
|
17
|
+
readonly CANCELLED: "cancelled";
|
|
17
18
|
};
|
|
18
19
|
type PaymentStatus = typeof PAYMENT_STATUS;
|
|
19
20
|
type PaymentStatusValue = PaymentStatus[keyof PaymentStatus];
|
|
@@ -49,21 +50,21 @@ declare const PAYMENT_STATUS_VALUES: PaymentStatusValue[];
|
|
|
49
50
|
* Add your own: bkash, nagad, rocket, paypal, razorpay, flutterwave, etc.
|
|
50
51
|
*/
|
|
51
52
|
declare const PAYMENT_GATEWAY_TYPE: {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
readonly MANUAL: "manual";
|
|
54
|
+
readonly STRIPE: "stripe";
|
|
55
|
+
readonly SSLCOMMERZ: "sslcommerz";
|
|
55
56
|
};
|
|
56
57
|
type PaymentGatewayType = typeof PAYMENT_GATEWAY_TYPE;
|
|
57
58
|
type PaymentGatewayTypeValue = PaymentGatewayType[keyof PaymentGatewayType];
|
|
58
59
|
declare const PAYMENT_GATEWAY_TYPE_VALUES: PaymentGatewayTypeValue[];
|
|
59
60
|
declare const GATEWAY_TYPES: {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
readonly MANUAL: "manual";
|
|
62
|
+
readonly STRIPE: "stripe";
|
|
63
|
+
readonly SSLCOMMERZ: "sslcommerz";
|
|
63
64
|
};
|
|
64
65
|
declare const GATEWAY_TYPE_VALUES: PaymentGatewayTypeValue[];
|
|
65
66
|
declare function isPaymentStatus(value: unknown): value is PaymentStatusValue;
|
|
66
67
|
declare function isPaymentGatewayType(value: unknown): value is PaymentGatewayTypeValue;
|
|
67
68
|
declare const isGatewayType: typeof isPaymentGatewayType;
|
|
68
|
-
|
|
69
|
-
export {
|
|
69
|
+
//#endregion
|
|
70
|
+
export { PAYMENT_STATUS as a, PaymentGatewayTypeValue as c, isGatewayType as d, isPaymentGatewayType as f, PAYMENT_GATEWAY_TYPE_VALUES as i, PaymentStatus as l, GATEWAY_TYPE_VALUES as n, PAYMENT_STATUS_VALUES as o, isPaymentStatus as p, PAYMENT_GATEWAY_TYPE as r, PaymentGatewayType as s, GATEWAY_TYPES as t, PaymentStatusValue as u };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
//#region src/enums/payment.enums.ts
|
|
2
|
+
/**
|
|
3
|
+
* Payment Enums
|
|
4
|
+
* @classytic/revenue
|
|
5
|
+
*
|
|
6
|
+
* Library-managed payment enums only.
|
|
7
|
+
* Users define their own payment methods in their schema.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Payment Status - Library-managed states
|
|
11
|
+
*/
|
|
12
|
+
const PAYMENT_STATUS = {
|
|
13
|
+
PENDING: "pending",
|
|
14
|
+
VERIFIED: "verified",
|
|
15
|
+
FAILED: "failed",
|
|
16
|
+
REFUNDED: "refunded",
|
|
17
|
+
CANCELLED: "cancelled"
|
|
18
|
+
};
|
|
19
|
+
const PAYMENT_STATUS_VALUES = Object.values(PAYMENT_STATUS);
|
|
20
|
+
/**
|
|
21
|
+
* Common gateway type constants for convenience
|
|
22
|
+
*
|
|
23
|
+
* ⚠️ IMPORTANT: These are NOT restrictions - just common reference values
|
|
24
|
+
*
|
|
25
|
+
* You can register ANY custom gateway provider by passing it to createRevenue():
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const revenue = createRevenue({
|
|
30
|
+
* providers: {
|
|
31
|
+
* manual: new ManualProvider(),
|
|
32
|
+
* bkash: new BkashProvider(), // ✅ Custom gateway
|
|
33
|
+
* nagad: new NagadProvider(), // ✅ Custom gateway
|
|
34
|
+
* stripe: new StripeProvider(), // ✅ Custom gateway
|
|
35
|
+
* paypal: new PaypalProvider(), // ✅ Any gateway you want
|
|
36
|
+
* }
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* // Use by name
|
|
40
|
+
* await revenue.monetization.create({ gateway: 'bkash', ... });
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* Reference values:
|
|
44
|
+
* - MANUAL: Built-in manual provider (@classytic/revenue-manual)
|
|
45
|
+
* - STRIPE: Stripe provider (build with @classytic/revenue-stripe)
|
|
46
|
+
* - SSLCOMMERZ: SSLCommerz provider (build with @classytic/revenue-sslcommerz)
|
|
47
|
+
*
|
|
48
|
+
* Add your own: bkash, nagad, rocket, paypal, razorpay, flutterwave, etc.
|
|
49
|
+
*/
|
|
50
|
+
const PAYMENT_GATEWAY_TYPE = {
|
|
51
|
+
MANUAL: "manual",
|
|
52
|
+
STRIPE: "stripe",
|
|
53
|
+
SSLCOMMERZ: "sslcommerz"
|
|
54
|
+
};
|
|
55
|
+
const PAYMENT_GATEWAY_TYPE_VALUES = Object.values(PAYMENT_GATEWAY_TYPE);
|
|
56
|
+
const GATEWAY_TYPES = PAYMENT_GATEWAY_TYPE;
|
|
57
|
+
const GATEWAY_TYPE_VALUES = PAYMENT_GATEWAY_TYPE_VALUES;
|
|
58
|
+
const paymentStatusSet = new Set(PAYMENT_STATUS_VALUES);
|
|
59
|
+
const paymentGatewayTypeSet = new Set(PAYMENT_GATEWAY_TYPE_VALUES);
|
|
60
|
+
function isPaymentStatus(value) {
|
|
61
|
+
return typeof value === "string" && paymentStatusSet.has(value);
|
|
62
|
+
}
|
|
63
|
+
function isPaymentGatewayType(value) {
|
|
64
|
+
return typeof value === "string" && paymentGatewayTypeSet.has(value);
|
|
65
|
+
}
|
|
66
|
+
const isGatewayType = isPaymentGatewayType;
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
export { PAYMENT_STATUS as a, isPaymentGatewayType as c, PAYMENT_GATEWAY_TYPE_VALUES as i, isPaymentStatus as l, GATEWAY_TYPE_VALUES as n, PAYMENT_STATUS_VALUES as o, PAYMENT_GATEWAY_TYPE as r, isGatewayType as s, GATEWAY_TYPES as t };
|