reservease.consumer
Version:
This package allows you to create an amqplib consumer and producer.
88 lines (87 loc) • 3.66 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HubtelPayment = void 0;
const uuid_1 = require("uuid");
const axios_1 = __importDefault(require("axios"));
const InternalApiResponse_1 = require("./InternalApiResponse");
class HubtelPayment {
constructor(clientId, clientSecret, requestPaymentUrl, merchantAccountNumber) {
this.Options = {
url: '',
method: '',
headers: {
'Content-Type': 'application/json',
},
auth: {},
data: {},
};
this._authCredendtial = {
password: clientSecret,
username: clientId,
};
this._requestPaymentUrl = requestPaymentUrl;
this._merchantAccountNumber = merchantAccountNumber;
}
async GetPaymentPayload(params) {
try {
const clientReference = params?.clientReference ?? (0, uuid_1.v4)();
const Payload = {
clientReference,
amount: params?.amount,
title: params?.title,
description: params?.description,
callbackUrl: params?.callbackUrl,
cancellationUrl: params?.cancellationUrl,
returnUrl: params?.returnUrl,
logo: params?.logo,
};
this.Options.url = `${this._requestPaymentUrl}/${this._merchantAccountNumber}`;
this.Options.method = 'POST';
this.Options.auth = this._authCredendtial;
this.Options.data = JSON.stringify(Payload);
const MyOPtions = this.Options;
const response = await (0, axios_1.default)(MyOPtions);
const resp = {
requestData: Payload,
responseData: response.data,
};
return new InternalApiResponse_1.InternalApiResponse(true, resp, response?.data?.message);
}
catch (error) {
return new InternalApiResponse_1.InternalApiResponse(false, undefined, JSON.stringify(error));
}
}
async GetPaymentPayloadV2(params) {
try {
const clientReference = params?.clientReference ?? (0, uuid_1.v4)();
const Payload = {
clientReference,
totalAmount: params?.amount,
description: params?.description,
callbackUrl: params?.callbackUrl,
cancellationUrl: params?.cancellationUrl,
returnUrl: params?.returnUrl,
merchantAccountNumber: this._merchantAccountNumber,
customerMobileNumber: params?.customerMobileNumber,
};
this.Options.url = `${this._requestPaymentUrl}`;
this.Options.method = 'POST';
this.Options.auth = this._authCredendtial;
this.Options.data = JSON.stringify(Payload);
const MyOPtions = this.Options;
const response = await (0, axios_1.default)(MyOPtions);
const resp = {
requestData: Payload,
responseData: response.data,
};
return new InternalApiResponse_1.InternalApiResponse(true, resp, response?.data?.message);
}
catch (error) {
return new InternalApiResponse_1.InternalApiResponse(false, undefined, JSON.stringify(error));
}
}
}
exports.HubtelPayment = HubtelPayment;