@blocklet/payment-react 1.16.18 → 1.16.19
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/es/libs/util.js +12 -3
- package/lib/libs/util.js +16 -3
- package/package.json +3 -3
- package/src/libs/util.ts +12 -3
package/es/libs/util.js
CHANGED
|
@@ -105,6 +105,9 @@ export function formatNumber(n, precision = 6, trim = true) {
|
|
|
105
105
|
return right ? [left, trimEnd(right, "0")].filter(Boolean).join(".") : left;
|
|
106
106
|
}
|
|
107
107
|
export const formatPrice = (price, currency, unit_label, quantity = 1, bn = true, locale = "en") => {
|
|
108
|
+
if (!currency) {
|
|
109
|
+
return "";
|
|
110
|
+
}
|
|
108
111
|
if (price.custom_unit_amount) {
|
|
109
112
|
return `Custom (${currency.symbol})`;
|
|
110
113
|
}
|
|
@@ -123,6 +126,9 @@ export const formatPrice = (price, currency, unit_label, quantity = 1, bn = true
|
|
|
123
126
|
return `${amount} ${currency.symbol}`;
|
|
124
127
|
};
|
|
125
128
|
export const formatPriceAmount = (price, currency, unit_label, quantity = 1, bn = true) => {
|
|
129
|
+
if (!currency) {
|
|
130
|
+
return "";
|
|
131
|
+
}
|
|
126
132
|
const unit = getPriceUintAmountByCurrency(price, currency);
|
|
127
133
|
const amount = bn ? fromUnitToToken(new BN(unit).mul(new BN(quantity)), currency.decimal).toString() : +unit * quantity;
|
|
128
134
|
if (price?.type === "recurring" && price.recurring) {
|
|
@@ -174,20 +180,20 @@ export function formatRecurring(recurring, translate = true, separator = "per",
|
|
|
174
180
|
}
|
|
175
181
|
export function getPriceUintAmountByCurrency(price, currency) {
|
|
176
182
|
const options = getPriceCurrencyOptions(price);
|
|
177
|
-
const option = options.find((x) => x.currency_id === currency
|
|
183
|
+
const option = options.find((x) => x.currency_id === currency?.id);
|
|
178
184
|
if (option) {
|
|
179
185
|
if (option.custom_unit_amount) {
|
|
180
186
|
return option.custom_unit_amount.preset || option.custom_unit_amount.presets[0];
|
|
181
187
|
}
|
|
182
188
|
return option.unit_amount;
|
|
183
189
|
}
|
|
184
|
-
if (price.currency_id === currency
|
|
190
|
+
if (price.currency_id === currency?.id) {
|
|
185
191
|
if (price.custom_unit_amount) {
|
|
186
192
|
return price.custom_unit_amount.preset || price.custom_unit_amount.presets[0];
|
|
187
193
|
}
|
|
188
194
|
return price.unit_amount;
|
|
189
195
|
}
|
|
190
|
-
console.warn(`Currency ${currency
|
|
196
|
+
console.warn(`Currency ${currency?.id} not configured for price`, price);
|
|
191
197
|
return "0";
|
|
192
198
|
}
|
|
193
199
|
export function getPriceCurrencyOptions(price) {
|
|
@@ -204,6 +210,9 @@ export function getPriceCurrencyOptions(price) {
|
|
|
204
210
|
];
|
|
205
211
|
}
|
|
206
212
|
export function formatLineItemPricing(item, currency, { trialEnd, trialInDays }, locale = "en") {
|
|
213
|
+
if (!currency) {
|
|
214
|
+
return { primary: "", secondary: "", quantity: "" };
|
|
215
|
+
}
|
|
207
216
|
const price = item.upsell_price || item.price;
|
|
208
217
|
let quantity = t("common.qty", locale, { count: item.quantity });
|
|
209
218
|
if (price.recurring?.usage_type === "metered" || +item.quantity === 1) {
|
package/lib/libs/util.js
CHANGED
|
@@ -174,6 +174,9 @@ function formatNumber(n, precision = 6, trim = true) {
|
|
|
174
174
|
return right ? [left, (0, _trimEnd.default)(right, "0")].filter(Boolean).join(".") : left;
|
|
175
175
|
}
|
|
176
176
|
const formatPrice = (price, currency, unit_label, quantity = 1, bn = true, locale = "en") => {
|
|
177
|
+
if (!currency) {
|
|
178
|
+
return "";
|
|
179
|
+
}
|
|
177
180
|
if (price.custom_unit_amount) {
|
|
178
181
|
return `Custom (${currency.symbol})`;
|
|
179
182
|
}
|
|
@@ -193,6 +196,9 @@ const formatPrice = (price, currency, unit_label, quantity = 1, bn = true, local
|
|
|
193
196
|
};
|
|
194
197
|
exports.formatPrice = formatPrice;
|
|
195
198
|
const formatPriceAmount = (price, currency, unit_label, quantity = 1, bn = true) => {
|
|
199
|
+
if (!currency) {
|
|
200
|
+
return "";
|
|
201
|
+
}
|
|
196
202
|
const unit = getPriceUintAmountByCurrency(price, currency);
|
|
197
203
|
const amount = bn ? (0, _util.fromUnitToToken)(new _util.BN(unit).mul(new _util.BN(quantity)), currency.decimal).toString() : +unit * quantity;
|
|
198
204
|
if (price?.type === "recurring" && price.recurring) {
|
|
@@ -247,20 +253,20 @@ function formatRecurring(recurring, translate = true, separator = "per", locale
|
|
|
247
253
|
}
|
|
248
254
|
function getPriceUintAmountByCurrency(price, currency) {
|
|
249
255
|
const options = getPriceCurrencyOptions(price);
|
|
250
|
-
const option = options.find(x => x.currency_id === currency
|
|
256
|
+
const option = options.find(x => x.currency_id === currency?.id);
|
|
251
257
|
if (option) {
|
|
252
258
|
if (option.custom_unit_amount) {
|
|
253
259
|
return option.custom_unit_amount.preset || option.custom_unit_amount.presets[0];
|
|
254
260
|
}
|
|
255
261
|
return option.unit_amount;
|
|
256
262
|
}
|
|
257
|
-
if (price.currency_id === currency
|
|
263
|
+
if (price.currency_id === currency?.id) {
|
|
258
264
|
if (price.custom_unit_amount) {
|
|
259
265
|
return price.custom_unit_amount.preset || price.custom_unit_amount.presets[0];
|
|
260
266
|
}
|
|
261
267
|
return price.unit_amount;
|
|
262
268
|
}
|
|
263
|
-
console.warn(`Currency ${currency
|
|
269
|
+
console.warn(`Currency ${currency?.id} not configured for price`, price);
|
|
264
270
|
return "0";
|
|
265
271
|
}
|
|
266
272
|
function getPriceCurrencyOptions(price) {
|
|
@@ -278,6 +284,13 @@ function formatLineItemPricing(item, currency, {
|
|
|
278
284
|
trialEnd,
|
|
279
285
|
trialInDays
|
|
280
286
|
}, locale = "en") {
|
|
287
|
+
if (!currency) {
|
|
288
|
+
return {
|
|
289
|
+
primary: "",
|
|
290
|
+
secondary: "",
|
|
291
|
+
quantity: ""
|
|
292
|
+
};
|
|
293
|
+
}
|
|
281
294
|
const price = item.upsell_price || item.price;
|
|
282
295
|
let quantity = (0, _locales.t)("common.qty", locale, {
|
|
283
296
|
count: item.quantity
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.19",
|
|
4
4
|
"description": "Reusable react components for payment kit v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"@babel/core": "^7.25.2",
|
|
93
93
|
"@babel/preset-env": "^7.25.2",
|
|
94
94
|
"@babel/preset-react": "^7.24.7",
|
|
95
|
-
"@blocklet/payment-types": "1.16.
|
|
95
|
+
"@blocklet/payment-types": "1.16.19",
|
|
96
96
|
"@storybook/addon-essentials": "^7.6.20",
|
|
97
97
|
"@storybook/addon-interactions": "^7.6.20",
|
|
98
98
|
"@storybook/addon-links": "^7.6.20",
|
|
@@ -123,5 +123,5 @@
|
|
|
123
123
|
"vite-plugin-babel": "^1.2.0",
|
|
124
124
|
"vite-plugin-node-polyfills": "^0.21.0"
|
|
125
125
|
},
|
|
126
|
-
"gitHead": "
|
|
126
|
+
"gitHead": "a033985b46d5c80b56f2ed9dc86d808fb60d9db1"
|
|
127
127
|
}
|
package/src/libs/util.ts
CHANGED
|
@@ -159,6 +159,9 @@ export const formatPrice = (
|
|
|
159
159
|
bn: boolean = true,
|
|
160
160
|
locale: string = 'en'
|
|
161
161
|
) => {
|
|
162
|
+
if (!currency) {
|
|
163
|
+
return '';
|
|
164
|
+
}
|
|
162
165
|
if (price.custom_unit_amount) {
|
|
163
166
|
return `Custom (${currency.symbol})`;
|
|
164
167
|
}
|
|
@@ -190,6 +193,9 @@ export const formatPriceAmount = (
|
|
|
190
193
|
quantity: number = 1,
|
|
191
194
|
bn: boolean = true
|
|
192
195
|
) => {
|
|
196
|
+
if (!currency) {
|
|
197
|
+
return '';
|
|
198
|
+
}
|
|
193
199
|
const unit = getPriceUintAmountByCurrency(price, currency);
|
|
194
200
|
const amount = bn
|
|
195
201
|
? fromUnitToToken(new BN(unit).mul(new BN(quantity)), currency.decimal).toString()
|
|
@@ -259,7 +265,7 @@ export function formatRecurring(
|
|
|
259
265
|
|
|
260
266
|
export function getPriceUintAmountByCurrency(price: TPrice, currency: TPaymentCurrency) {
|
|
261
267
|
const options = getPriceCurrencyOptions(price);
|
|
262
|
-
const option = options.find((x) => x.currency_id === currency
|
|
268
|
+
const option = options.find((x) => x.currency_id === currency?.id);
|
|
263
269
|
if (option) {
|
|
264
270
|
if (option.custom_unit_amount) {
|
|
265
271
|
return option.custom_unit_amount.preset || option.custom_unit_amount.presets[0];
|
|
@@ -267,14 +273,14 @@ export function getPriceUintAmountByCurrency(price: TPrice, currency: TPaymentCu
|
|
|
267
273
|
return option.unit_amount;
|
|
268
274
|
}
|
|
269
275
|
|
|
270
|
-
if (price.currency_id === currency
|
|
276
|
+
if (price.currency_id === currency?.id) {
|
|
271
277
|
if (price.custom_unit_amount) {
|
|
272
278
|
return price.custom_unit_amount.preset || price.custom_unit_amount.presets[0];
|
|
273
279
|
}
|
|
274
280
|
return price.unit_amount;
|
|
275
281
|
}
|
|
276
282
|
|
|
277
|
-
console.warn(`Currency ${currency
|
|
283
|
+
console.warn(`Currency ${currency?.id} not configured for price`, price);
|
|
278
284
|
return '0';
|
|
279
285
|
}
|
|
280
286
|
|
|
@@ -299,6 +305,9 @@ export function formatLineItemPricing(
|
|
|
299
305
|
{ trialEnd, trialInDays }: { trialEnd: number; trialInDays: number },
|
|
300
306
|
locale: string = 'en'
|
|
301
307
|
): { primary: string; secondary?: string; quantity: string } {
|
|
308
|
+
if (!currency) {
|
|
309
|
+
return { primary: '', secondary: '', quantity: '' };
|
|
310
|
+
}
|
|
302
311
|
const price = item.upsell_price || item.price;
|
|
303
312
|
|
|
304
313
|
let quantity = t('common.qty', locale, { count: item.quantity });
|