@exode-team/ofd-uz
Version:
Node.js module for interacting with OFD tax system
56 lines (55 loc) • 2.19 kB
JavaScript
;
/**
* OFDClient
*
* @author: exode <hello@exode.ru>
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OFD_PROD_URL = exports.OFD_TEST_URL = void 0;
exports.createTimestamp = createTimestamp;
exports.validatePhoneNumber = validatePhoneNumber;
exports.calculateTotalAmount = calculateTotalAmount;
__exportStar(require("./types"), exports);
__exportStar(require("./client"), exports);
// Constants
exports.OFD_TEST_URL = 'https://test.ofd.uz';
exports.OFD_PROD_URL = 'https://ofd.uz';
// Helper functions
function createTimestamp() {
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0');
const day = String(now.getDate()).padStart(2, '0');
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
function validatePhoneNumber(phone) {
const validPrefixes = ['994', '374', '375', '7', '996', '373', '992', '993', '998', '380'];
if (!/^\d{12}$/.test(phone)) {
return false;
}
const prefix = phone.substring(0, 3);
return validPrefixes.includes(prefix);
}
function calculateTotalAmount(items) {
return items.reduce((total, item) => {
const itemTotal = (item.Price || 0) - (item.Discount || 0) - (item.Other || 0);
return total + itemTotal;
}, 0);
}