@blocklet/payment-js 1.23.4 → 1.23.6
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/lib/index.d.ts +11 -0
- package/lib/index.js +1 -0
- package/lib/resources/payment-currency.d.ts +12 -0
- package/lib/resources/payment-currency.js +4 -0
- package/lib/util.d.ts +44 -0
- package/lib/util.js +74 -0
- package/package.json +5 -5
package/lib/index.d.ts
CHANGED
|
@@ -124,6 +124,16 @@ declare const _default: {
|
|
|
124
124
|
getRechargeConfig: (_params: string, data?: never) => Promise<import("sequelize").InferAttributes<import("@blocklet/payment-types").PaymentCurrency, {
|
|
125
125
|
omit: never;
|
|
126
126
|
}>>;
|
|
127
|
+
checkRecurringSupport: (data: {
|
|
128
|
+
currency_ids: string[];
|
|
129
|
+
}, params?: never) => Promise<{
|
|
130
|
+
supported: boolean;
|
|
131
|
+
unsupported_currencies: Array<{
|
|
132
|
+
id: string;
|
|
133
|
+
name: string;
|
|
134
|
+
symbol: string;
|
|
135
|
+
}>;
|
|
136
|
+
}>;
|
|
127
137
|
};
|
|
128
138
|
paymentMethods: {
|
|
129
139
|
create: (data: Partial<import("sequelize").InferAttributes<import("@blocklet/payment-types").PaymentMethod, {
|
|
@@ -539,3 +549,4 @@ declare const _default: {
|
|
|
539
549
|
};
|
|
540
550
|
export default _default;
|
|
541
551
|
export * from '@blocklet/payment-types';
|
|
552
|
+
export * from './util';
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import type { RechargeConfig } from '@blocklet/payment-types';
|
|
2
|
+
type CheckRecurringSupportParams = {
|
|
3
|
+
currency_ids: string[];
|
|
4
|
+
};
|
|
5
|
+
type CheckRecurringSupportResponse = {
|
|
6
|
+
supported: boolean;
|
|
7
|
+
unsupported_currencies: Array<{
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
symbol: string;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
2
13
|
declare const _default: {
|
|
3
14
|
create: (data: Partial<import("sequelize").InferAttributes<import("@blocklet/payment-types").PaymentCurrency, {
|
|
4
15
|
omit: never;
|
|
@@ -22,5 +33,6 @@ declare const _default: {
|
|
|
22
33
|
getRechargeConfig: (_params: string, data?: never) => Promise<import("sequelize").InferAttributes<import("@blocklet/payment-types").PaymentCurrency, {
|
|
23
34
|
omit: never;
|
|
24
35
|
}>>;
|
|
36
|
+
checkRecurringSupport: (data: CheckRecurringSupportParams, params?: never) => Promise<CheckRecurringSupportResponse>;
|
|
25
37
|
};
|
|
26
38
|
export default _default;
|
|
@@ -26,4 +26,8 @@ exports.default = {
|
|
|
26
26
|
method: 'GET',
|
|
27
27
|
path: '/api/payment-currencies/{id}/recharge-config',
|
|
28
28
|
}),
|
|
29
|
+
checkRecurringSupport: (0, resource_1.createResourceCreateMethod)({
|
|
30
|
+
method: 'POST',
|
|
31
|
+
path: '/api/payment-currencies/check-recurring-support',
|
|
32
|
+
}),
|
|
29
33
|
};
|
package/lib/util.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
declare const CURRENCY_SYMBOLS: Record<string, string>;
|
|
2
|
+
/**
|
|
3
|
+
* Format credit amount for display in data contexts (balances, transactions, notifications)
|
|
4
|
+
* - If currency has symbol mapping (USD -> $): shows "$20 credits"
|
|
5
|
+
* - If no symbol mapping: shows "20 minutes" or "20 arcsphere credits"
|
|
6
|
+
*
|
|
7
|
+
* @param formattedAmount - Already formatted amount string (e.g., "20", "1,000.50")
|
|
8
|
+
* @param currencySymbol - Currency symbol (USD, EUR, minutes, etc.)
|
|
9
|
+
* @param showUnit - Whether to show the unit for non-mapped currencies (default: true)
|
|
10
|
+
* @returns Formatted credit string
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { formatCreditAmount } from '@blocklet/payment-js';
|
|
15
|
+
*
|
|
16
|
+
* formatCreditAmount("20", "USD") // "$20 credits"
|
|
17
|
+
* formatCreditAmount("100", "minutes") // "100 minutes"
|
|
18
|
+
* formatCreditAmount("50", "arcsphere credits") // "50 arcsphere credits"
|
|
19
|
+
* formatCreditAmount("50", "custom", false) // "50"
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatCreditAmount(formattedAmount: string, currencySymbol?: string, showUnit?: boolean): string;
|
|
23
|
+
/**
|
|
24
|
+
* Get currency symbol mapping
|
|
25
|
+
* @param currencySymbol - Currency code (USD, EUR, etc.)
|
|
26
|
+
* @returns Symbol string or undefined if no mapping exists
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import { getCurrencySymbol } from '@blocklet/payment-js';
|
|
31
|
+
*
|
|
32
|
+
* getCurrencySymbol('USD'); // "$"
|
|
33
|
+
* getCurrencySymbol('EUR'); // "€"
|
|
34
|
+
* getCurrencySymbol('minutes'); // undefined
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function getCurrencySymbol(currencySymbol: string): string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Check if a currency has a symbol mapping
|
|
40
|
+
* @param currencySymbol - Currency code
|
|
41
|
+
* @returns true if currency has a symbol mapping
|
|
42
|
+
*/
|
|
43
|
+
export declare function hasCurrencySymbol(currencySymbol: string): boolean;
|
|
44
|
+
export { CURRENCY_SYMBOLS };
|
package/lib/util.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CURRENCY_SYMBOLS = void 0;
|
|
4
|
+
exports.formatCreditAmount = formatCreditAmount;
|
|
5
|
+
exports.getCurrencySymbol = getCurrencySymbol;
|
|
6
|
+
exports.hasCurrencySymbol = hasCurrencySymbol;
|
|
7
|
+
const CURRENCY_SYMBOLS = {
|
|
8
|
+
USD: '$',
|
|
9
|
+
EUR: '€',
|
|
10
|
+
GBP: '£',
|
|
11
|
+
JPY: '¥',
|
|
12
|
+
CNY: '¥',
|
|
13
|
+
KRW: '₩',
|
|
14
|
+
INR: '₹',
|
|
15
|
+
AUD: 'A$',
|
|
16
|
+
CAD: 'C$',
|
|
17
|
+
CHF: 'Fr',
|
|
18
|
+
HKD: 'HK$',
|
|
19
|
+
SGD: 'S$',
|
|
20
|
+
NZD: 'NZ$',
|
|
21
|
+
};
|
|
22
|
+
exports.CURRENCY_SYMBOLS = CURRENCY_SYMBOLS;
|
|
23
|
+
/**
|
|
24
|
+
* Format credit amount for display in data contexts (balances, transactions, notifications)
|
|
25
|
+
* - If currency has symbol mapping (USD -> $): shows "$20 credits"
|
|
26
|
+
* - If no symbol mapping: shows "20 minutes" or "20 arcsphere credits"
|
|
27
|
+
*
|
|
28
|
+
* @param formattedAmount - Already formatted amount string (e.g., "20", "1,000.50")
|
|
29
|
+
* @param currencySymbol - Currency symbol (USD, EUR, minutes, etc.)
|
|
30
|
+
* @param showUnit - Whether to show the unit for non-mapped currencies (default: true)
|
|
31
|
+
* @returns Formatted credit string
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* import { formatCreditAmount } from '@blocklet/payment-js';
|
|
36
|
+
*
|
|
37
|
+
* formatCreditAmount("20", "USD") // "$20 credits"
|
|
38
|
+
* formatCreditAmount("100", "minutes") // "100 minutes"
|
|
39
|
+
* formatCreditAmount("50", "arcsphere credits") // "50 arcsphere credits"
|
|
40
|
+
* formatCreditAmount("50", "custom", false) // "50"
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
function formatCreditAmount(formattedAmount, currencySymbol, showUnit = true) {
|
|
44
|
+
const mappedSymbol = CURRENCY_SYMBOLS[currencySymbol || ''];
|
|
45
|
+
if (mappedSymbol) {
|
|
46
|
+
return `${mappedSymbol}${formattedAmount} credits`;
|
|
47
|
+
}
|
|
48
|
+
return `${formattedAmount}${showUnit && currencySymbol ? ` ${currencySymbol}` : ''}`;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get currency symbol mapping
|
|
52
|
+
* @param currencySymbol - Currency code (USD, EUR, etc.)
|
|
53
|
+
* @returns Symbol string or undefined if no mapping exists
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* import { getCurrencySymbol } from '@blocklet/payment-js';
|
|
58
|
+
*
|
|
59
|
+
* getCurrencySymbol('USD'); // "$"
|
|
60
|
+
* getCurrencySymbol('EUR'); // "€"
|
|
61
|
+
* getCurrencySymbol('minutes'); // undefined
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
function getCurrencySymbol(currencySymbol) {
|
|
65
|
+
return CURRENCY_SYMBOLS[currencySymbol];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Check if a currency has a symbol mapping
|
|
69
|
+
* @param currencySymbol - Currency code
|
|
70
|
+
* @returns true if currency has a symbol mapping
|
|
71
|
+
*/
|
|
72
|
+
function hasCurrencySymbol(currencySymbol) {
|
|
73
|
+
return currencySymbol in CURRENCY_SYMBOLS;
|
|
74
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-js",
|
|
3
|
-
"version": "1.23.
|
|
3
|
+
"version": "1.23.6",
|
|
4
4
|
"description": "Node.js client for Payment Kit",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"types",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"url": "https://github.com/blocklet/payment-kit/issues"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@blocklet/constant": "^1.17.
|
|
40
|
-
"@blocklet/payment-types": "1.23.
|
|
41
|
-
"@blocklet/sdk": "^1.17.
|
|
39
|
+
"@blocklet/constant": "^1.17.6",
|
|
40
|
+
"@blocklet/payment-types": "1.23.6",
|
|
41
|
+
"@blocklet/sdk": "^1.17.6"
|
|
42
42
|
},
|
|
43
43
|
"importSort": {
|
|
44
44
|
".js, .jsx, .mjs": {
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"type-fest": "^4.41.0",
|
|
65
65
|
"typescript": "5.5.4"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "0026a41a10475159d72ade801561d6cbce0008fe"
|
|
68
68
|
}
|