@xuda.io/account_module 1.2.84 → 1.2.86
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/index.js +35 -35
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1402,7 +1402,7 @@ exports.validate_account_topup = async function (uid, items = []) {
|
|
|
1402
1402
|
}
|
|
1403
1403
|
let topup = 0;
|
|
1404
1404
|
for (const item of items) {
|
|
1405
|
-
topup += get_prices(item);
|
|
1405
|
+
topup += get_prices(uid, item);
|
|
1406
1406
|
}
|
|
1407
1407
|
|
|
1408
1408
|
// if ((!data?.customer_obj?.default_source, { billing_problem: true, topup })) {
|
|
@@ -1435,46 +1435,46 @@ exports.validate_account_topup = async function (uid, items = []) {
|
|
|
1435
1435
|
return true;
|
|
1436
1436
|
};
|
|
1437
1437
|
|
|
1438
|
-
exports.validate_account_topup2 = async function (uid, items = []) {
|
|
1439
|
-
|
|
1438
|
+
// exports.validate_account_topup2 = async function (uid, items = []) {
|
|
1439
|
+
// const stripe_module = require(`${module_path}/stripe_module`);
|
|
1440
1440
|
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1441
|
+
// const { code, data } = await stripe_module.get_billing_metrics({ uid });
|
|
1442
|
+
// if (code < 0) {
|
|
1443
|
+
// throw new Error(data);
|
|
1444
|
+
// }
|
|
1445
|
+
// let topup = 0;
|
|
1446
|
+
// for (const item of items) {
|
|
1447
|
+
// topup += get_prices(item);
|
|
1448
|
+
// }
|
|
1449
1449
|
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1450
|
+
// if ((!data?.customer_obj?.default_source, { billing_problem: true, topup })) {
|
|
1451
|
+
// throw new Error("no card on file");
|
|
1452
|
+
// }
|
|
1453
|
+
// if (data?.balance?.past_due) {
|
|
1454
|
+
// let err = new Error(`past_due ${data?.balance?.past_due}`);
|
|
1455
|
+
// err.billing_problem = true;
|
|
1456
|
+
// err.topup = topup;
|
|
1457
|
+
// throw err;
|
|
1458
|
+
// }
|
|
1459
1459
|
|
|
1460
|
-
|
|
1460
|
+
// const balance = data?.balance?.account || 0; // minus balance represents positive balance
|
|
1461
1461
|
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1462
|
+
// if (balance > 0) {
|
|
1463
|
+
// let err = new Error(`negative balance ${-balance}`);
|
|
1464
|
+
// err.billing_problem = true;
|
|
1465
|
+
// err.topup = topup - balance; // ask for whole balance
|
|
1466
|
+
// throw err;
|
|
1467
|
+
// }
|
|
1468
1468
|
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1469
|
+
// if (topup + balance > 0) {
|
|
1470
|
+
// let err = new Error(`not enough balance ${topup + balance}`);
|
|
1471
|
+
// err.billing_problem = true;
|
|
1472
|
+
// err.topup = topup;
|
|
1473
|
+
// throw err;
|
|
1474
|
+
// }
|
|
1475
1475
|
|
|
1476
|
-
|
|
1477
|
-
};
|
|
1476
|
+
// return true;
|
|
1477
|
+
// };
|
|
1478
1478
|
|
|
1479
1479
|
const get_prices = function (uid, item) {
|
|
1480
1480
|
let price;
|