UNPKG

node-ecpay-aio

Version:

A production-ready ECPay AIO SDK for Node.js with TypeScript support.

38 lines (37 loc) 1.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Merchant = void 0; const config_1 = require("../config"); const schema_1 = require("../schema"); class Merchant { constructor(mode, config, ecpayServiceUrls) { this.version = '5.4.1'; this.ecpayServiceUrls = config_1.ECPayServiceUrls; schema_1.MerchantConfigSchema.validateSync(config); this.mode = mode; this.config = config; this.config.PlatformID = this.config.PlatformID || ''; // always empty string if not given if (typeof ecpayServiceUrls === 'object') { this.ecpayServiceUrls = this._mergeServiceUrls(ecpayServiceUrls); // will validate urls while merging } } createPayment(PaymentCtor, baseParams, params) { return new PaymentCtor(this, baseParams, params); } createQuery(QueryCtor, params) { return new QueryCtor(this, params); } createAction(ActionCtor, params) { return new ActionCtor(this, params); } _mergeServiceUrls(customUrls) { let _serviceUrls = Object.assign({}, this.ecpayServiceUrls); Object.keys(customUrls).forEach((key) => { let serviceName = key; schema_1.ServiceUrlSchema.validateSync(customUrls[serviceName]); _serviceUrls[serviceName] = Object.assign(Object.assign({}, this.ecpayServiceUrls[serviceName]), customUrls[serviceName]); }); return _serviceUrls; } } exports.Merchant = Merchant;