thawani-nodejs
Version:
Node.js library for Thawani Payment Gateway
46 lines • 1.72 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseResource = void 0;
const axios_1 = __importDefault(require("axios"));
const constants_1 = require("../constants");
class BaseResource {
constructor(config) {
this.config = config;
this.client = axios_1.default.create({
baseURL: config.isSandbox
? constants_1.API_BASE_URL.sandbox
: constants_1.API_BASE_URL.production,
timeout: config.timeout,
headers: {
'thawani-api-key': config.secretKey,
'Content-Type': 'application/json'
}
});
this.setupInterceptors();
}
setupInterceptors() {
this.client.interceptors.response.use((response) => { var _a; return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.data) || response.data; }, (error) => {
var _a;
if (error.response) {
const errorMessage = ((_a = error.response.data) === null || _a === void 0 ? void 0 : _a.description) || error.message;
console.error('API Error:', errorMessage);
throw new Error(`Thawani API Error: ${errorMessage}`);
}
throw error;
});
}
async request(config) {
try {
return await this.client.request(config);
}
catch (error) {
console.error('Request Error:', error);
throw error;
}
}
}
exports.BaseResource = BaseResource;
//# sourceMappingURL=base.js.map