@xuda.io/account_module 1.2.86 → 1.2.87

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.
Files changed (2) hide show
  1. package/index.js +57 -57
  2. 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
 
@@ -1405,77 +1447,35 @@ exports.validate_account_topup = async function (uid, items = []) {
1405
1447
  topup += get_prices(uid, item);
1406
1448
  }
1407
1449
 
1408
- // if ((!data?.customer_obj?.default_source, { billing_problem: true, topup })) {
1409
- // throw new Error("no card on file");
1410
- // }
1411
- debugger;
1450
+ if ((!data?.customer_obj?.default_source, { billing_problem: true, topup })) {
1451
+ throw new Error("no card on file");
1452
+ }
1412
1453
  if (data?.balance?.past_due) {
1413
- throw new Error(`past_due ${data?.balance?.past_due}`, {
1414
- billing_problem: true,
1415
- topup,
1416
- });
1454
+ let err = new Error(`past_due ${data?.balance?.past_due}`);
1455
+ err.billing_problem = true;
1456
+ err.topup = topup;
1457
+ throw err;
1417
1458
  }
1418
1459
 
1419
1460
  const balance = data?.balance?.account || 0; // minus balance represents positive balance
1420
1461
 
1421
1462
  if (balance > 0) {
1422
- throw new Error(`negative balance ${-balance}`, {
1423
- billing_problem: true,
1424
- topup: topup - balance, // ask for whole balance
1425
- });
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;
1426
1467
  }
1427
1468
 
1428
1469
  if (topup + balance > 0) {
1429
- throw new Error(`not enough balance ${topup + balance}`, {
1430
- billing_problem: true,
1431
- topup, //-(topup + balance)
1432
- });
1470
+ let err = new Error(`not enough balance ${topup + balance}`);
1471
+ err.billing_problem = true;
1472
+ err.topup = topup;
1473
+ throw err;
1433
1474
  }
1434
1475
 
1435
1476
  return true;
1436
1477
  };
1437
1478
 
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
1479
  const get_prices = function (uid, item) {
1480
1480
  let price;
1481
1481
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/account_module",
3
- "version": "1.2.86",
3
+ "version": "1.2.87",
4
4
  "description": "Xuda Account Server Module",
5
5
  "main": "index.js",
6
6
  "dependencies": {