@spreeloop/mtn_momo
Version:
A mtn momo api integration package
81 lines • 2.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Routes = void 0;
const constants_1 = require("../../utils/constants");
const livePaymentUrl = "https://proxy.momoapi.mtn.com";
const sandboxPaymentUrl = "https://sandbox.momodeveloper.mtn.com";
/**
* Mtn Momo API routes builder.
* @class
*/
class Routes {
/**
* Creates a new instance of the class route.
*
* @param {string} targetEnvironment - The optional target environment.
*/
constructor(targetEnvironment) {
/**
* Returns the base route for the API.
*
* @return {string} The base route for the API.
*/
this.baseRoute = () => this.baseUrl;
switch (targetEnvironment) {
case constants_1.TargetEnvironment.sandbox:
this.baseUrl = sandboxPaymentUrl;
break;
case constants_1.TargetEnvironment.prod:
this.baseUrl = livePaymentUrl;
break;
default:
this.baseUrl = livePaymentUrl;
}
}
/**
* Initializes the payment.
*
* @return {string} The endpoint URL for the payment.
*/
initPayment() {
return `${this.baseRoute()}/collection/v1_0/requesttopay`;
}
/**
* Generates the payment status URL based on the provided parameters.
*
* @param {object} params - The parameters for generating the payment status URL.
* - {string} params.referenceId - The reference id.
* @return {string} The payment status URL.
*/
paymentStatus(params) {
return `${this.baseRoute()}/collection/v1_0/requesttopay/${params.referenceId}`;
}
/**
* Generates the access token endpoint.
*
* @return {string} The access token endpoint.
*/
accessToken() {
return `${this.baseRoute()}/collection/token/`;
}
/**
* Generates the api user endpoint.
*
* @return {string} The api user endpoint.
*/
apiUser() {
return `${this.baseRoute()}/v1_0/apiuser`;
}
/**
* Generates the api key endpoint.
*
* @param {object} params - The parameters for generating the api key URL.
* - {string} params.referenceId - The reference id.
* @return {string} The api key endpoint.
*/
apiKey(params) {
return `${this.baseRoute()}/v1_0/apiuser/${params.referenceId}/apikey`;
}
}
exports.Routes = Routes;
//# sourceMappingURL=routes.js.map