@xuda.io/account_module 1.2.78 → 1.2.79
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 +41 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1405,6 +1405,47 @@ exports.validate_account_topup = async function (uid, items = []) {
|
|
|
1405
1405
|
topup += get_prices(item);
|
|
1406
1406
|
}
|
|
1407
1407
|
|
|
1408
|
+
if ((!data?.customer_obj?.default_source, { billing_problem: true, topup })) {
|
|
1409
|
+
throw new Error("no card on file");
|
|
1410
|
+
}
|
|
1411
|
+
if (data?.balance?.past_due) {
|
|
1412
|
+
throw new Error(`past_due ${data?.balance?.past_due}`, {
|
|
1413
|
+
billing_problem: true,
|
|
1414
|
+
topup,
|
|
1415
|
+
});
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
const balance = data?.balance?.account || 0; // minus balance represents positive balance
|
|
1419
|
+
|
|
1420
|
+
if (balance > 0) {
|
|
1421
|
+
throw new Error(`negative balance ${-balance}`, {
|
|
1422
|
+
billing_problem: true,
|
|
1423
|
+
topup: topup - balance, // ask for whole balance
|
|
1424
|
+
});
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
if (topup + balance > 0) {
|
|
1428
|
+
throw new Error(`not enough balance ${topup + balance}`, {
|
|
1429
|
+
billing_problem: true,
|
|
1430
|
+
topup, //-(topup + balance)
|
|
1431
|
+
});
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
return true;
|
|
1435
|
+
};
|
|
1436
|
+
|
|
1437
|
+
exports.validate_account_topup2 = async function (uid, items = []) {
|
|
1438
|
+
const stripe_module = require(`${module_path}/stripe_module`);
|
|
1439
|
+
|
|
1440
|
+
const { code, data } = await stripe_module.get_billing_metrics({ uid });
|
|
1441
|
+
if (code < 0) {
|
|
1442
|
+
throw new Error(data);
|
|
1443
|
+
}
|
|
1444
|
+
let topup = 0;
|
|
1445
|
+
for (const item of items) {
|
|
1446
|
+
topup += get_prices(item);
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1408
1449
|
if ((!data?.customer_obj?.default_source, { billing_problem: true, topup })) {
|
|
1409
1450
|
throw new Error("no card on file");
|
|
1410
1451
|
}
|