UNPKG

paychangu-js

Version:

Paychangu JavaScript SDK for easy integration of payment services

62 lines (61 loc) 2.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateLevelConfig = exports.validateConfig = void 0; const errors_1 = require("./errors"); function validateConfig(config) { const requiredFields = [ 'public_key', 'tx_ref', 'amount', 'currency', 'callback_url', 'return_url', 'customer', 'customization', ]; for (const field of requiredFields) { if (!(field in config)) { throw new errors_1.PaychanguError(`Missing required field: ${field}`); } } if (typeof config.amount !== 'number' || config.amount <= 0) { throw new errors_1.PaychanguError('Amount must be a positive number'); } if (!config.customer.email || !config.customer.first_name || !config.customer.last_name) { throw new errors_1.PaychanguError('Customer information is incomplete'); } if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(config.customer.email)) { throw new errors_1.PaychanguError('Invalid email format'); } if (!/^[A-Z]{3}$/.test(config.currency)) { throw new errors_1.PaychanguError('Currency must be a 3-letter ISO code'); } } exports.validateConfig = validateConfig; function validateLevelConfig(config) { const requiredFields = [ 'amount', 'currency', 'email', 'first_name', 'last_name', 'callback_url', 'return_url', 'tx_ref', ]; for (const field of requiredFields) { if (!(field in config)) { throw new errors_1.PaychanguError(`Missing required field: ${field}`); } } if (typeof config.amount !== 'number' || config.amount <= 0) { throw new errors_1.PaychanguError('Amount must be a positive number'); } if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(config.email)) { throw new errors_1.PaychanguError('Invalid email format'); } if (!/^[A-Z]{3}$/.test(config.currency)) { throw new errors_1.PaychanguError('Currency must be a 3-letter ISO code'); } } exports.validateLevelConfig = validateLevelConfig;