voko-sdk
Version:
Process payments with ease
35 lines (34 loc) • 1.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AdapterRegistry = void 0;
const errors_1 = require("../core/errors");
const types_1 = require("../core/types");
class AdapterRegistry {
static factories = new Map();
static register(factory) {
this.factories.set(factory.getProvider(), factory);
}
static createAdapter(config) {
const factory = this.factories.get(config.provider);
if (!factory) {
throw new errors_1.VokoError(`Unsupported provider: ${config.provider}`, types_1.VokoErrorCode.PROVIDER_ERROR);
}
if (!factory.validateConfig(config)) {
throw new errors_1.VokoError(`Invalid configuration for provider: ${config.provider}`, types_1.VokoErrorCode.PROVIDER_ERROR);
}
return factory.create(config);
}
static isSupported(provider) {
return this.factories.has(provider);
}
static getSupportedProviders() {
return Array.from(this.factories.keys());
}
static unregister(provider) {
return this.factories.delete(provider);
}
static clear() {
this.factories.clear();
}
}
exports.AdapterRegistry = AdapterRegistry;