@xuda.io/account_module 1.2.86 → 1.2.88
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 +55 -54
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1393,6 +1393,48 @@ exports.get_account_rt_info = async function (uid) {
|
|
|
1393
1393
|
return account_info;
|
|
1394
1394
|
};
|
|
1395
1395
|
|
|
1396
|
+
// exports.validate_account_topup = async function (uid, items = []) {
|
|
1397
|
+
// const stripe_module = require(`${module_path}/stripe_module`);
|
|
1398
|
+
|
|
1399
|
+
// const { code, data } = await stripe_module.get_billing_metrics({ uid });
|
|
1400
|
+
// if (code < 0) {
|
|
1401
|
+
// throw new Error(data);
|
|
1402
|
+
// }
|
|
1403
|
+
// let topup = 0;
|
|
1404
|
+
// for (const item of items) {
|
|
1405
|
+
// topup += get_prices(uid, item);
|
|
1406
|
+
// }
|
|
1407
|
+
|
|
1408
|
+
// // if ((!data?.customer_obj?.default_source, { billing_problem: true, topup })) {
|
|
1409
|
+
// // throw new Error("no card on file");
|
|
1410
|
+
// // }
|
|
1411
|
+
// debugger;
|
|
1412
|
+
// if (data?.balance?.past_due) {
|
|
1413
|
+
// throw new Error(`past_due ${data?.balance?.past_due}`, {
|
|
1414
|
+
// billing_problem: true,
|
|
1415
|
+
// topup,
|
|
1416
|
+
// });
|
|
1417
|
+
// }
|
|
1418
|
+
|
|
1419
|
+
// const balance = data?.balance?.account || 0; // minus balance represents positive balance
|
|
1420
|
+
|
|
1421
|
+
// if (balance > 0) {
|
|
1422
|
+
// throw new Error(`negative balance ${-balance}`, {
|
|
1423
|
+
// billing_problem: true,
|
|
1424
|
+
// topup: topup - balance, // ask for whole balance
|
|
1425
|
+
// });
|
|
1426
|
+
// }
|
|
1427
|
+
|
|
1428
|
+
// if (topup + balance > 0) {
|
|
1429
|
+
// throw new Error(`not enough balance ${topup + balance}`, {
|
|
1430
|
+
// billing_problem: true,
|
|
1431
|
+
// topup, //-(topup + balance)
|
|
1432
|
+
// });
|
|
1433
|
+
// }
|
|
1434
|
+
|
|
1435
|
+
// return true;
|
|
1436
|
+
// };
|
|
1437
|
+
|
|
1396
1438
|
exports.validate_account_topup = async function (uid, items = []) {
|
|
1397
1439
|
const stripe_module = require(`${module_path}/stripe_module`);
|
|
1398
1440
|
|
|
@@ -1408,74 +1450,33 @@ exports.validate_account_topup = async function (uid, items = []) {
|
|
|
1408
1450
|
// if ((!data?.customer_obj?.default_source, { billing_problem: true, topup })) {
|
|
1409
1451
|
// throw new Error("no card on file");
|
|
1410
1452
|
// }
|
|
1411
|
-
|
|
1453
|
+
|
|
1412
1454
|
if (data?.balance?.past_due) {
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1455
|
+
let err = new Error(`past_due ${data?.balance?.past_due}`);
|
|
1456
|
+
err.billing_problem = true;
|
|
1457
|
+
err.topup = topup;
|
|
1458
|
+
throw err;
|
|
1417
1459
|
}
|
|
1418
1460
|
|
|
1419
1461
|
const balance = data?.balance?.account || 0; // minus balance represents positive balance
|
|
1420
1462
|
|
|
1421
1463
|
if (balance > 0) {
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1464
|
+
let err = new Error(`negative balance ${-balance}`);
|
|
1465
|
+
err.billing_problem = true;
|
|
1466
|
+
err.topup = topup - balance; // ask for whole balance
|
|
1467
|
+
throw err;
|
|
1426
1468
|
}
|
|
1427
1469
|
|
|
1428
1470
|
if (topup + balance > 0) {
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1471
|
+
let err = new Error(`not enough balance ${topup + balance}`);
|
|
1472
|
+
err.billing_problem = true;
|
|
1473
|
+
err.topup = topup;
|
|
1474
|
+
throw err;
|
|
1433
1475
|
}
|
|
1434
1476
|
|
|
1435
1477
|
return true;
|
|
1436
1478
|
};
|
|
1437
1479
|
|
|
1438
|
-
// exports.validate_account_topup2 = async function (uid, items = []) {
|
|
1439
|
-
// const stripe_module = require(`${module_path}/stripe_module`);
|
|
1440
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1460
|
-
// const balance = data?.balance?.account || 0; // minus balance represents positive balance
|
|
1461
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1476
|
-
// return true;
|
|
1477
|
-
// };
|
|
1478
|
-
|
|
1479
1480
|
const get_prices = function (uid, item) {
|
|
1480
1481
|
let price;
|
|
1481
1482
|
|