@spreeloop/mtn_momo
Version:
A mtn momo api integration package
65 lines • 2.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MtnMomoPaymentSandbox = void 0;
const routes_1 = require("../routes/routes");
const constants_1 = require("../../utils/constants");
const get_access_token_1 = require("../operations/get_access_token");
const initialize_om_payment_1 = require("../operations/initialize_om_payment");
const get_payment_status_1 = require("../operations/get_payment_status");
/**
* Implements the MTN MOMO sandbox payment for testing in sandbox environment.
*/
class MtnMomoPaymentSandbox {
/**
* Creates a new instance of the MtnMomoPaymentSandbox class.
*
* @param {MtnMomoPaymentConfigs} config - The configuration for the payment instance.
*/
constructor(config) {
this.config = config;
this.route = new routes_1.Routes(constants_1.TargetEnvironment.sandbox);
}
/**
* Gets an access token from the sandbox environment.
*
* @return {Promise<GetAccessTokenResponse>} the access token response
*/
async getAccessToken() {
const response = await (0, get_access_token_1.getAccessToken)(this.config, this.route.accessToken());
return response;
}
/**
* Initializes the MTN MOMO payment in sandbox environment.
*
* @param {InitializeMtnMomoPaymentRequest} mobileInitParams - Parameters for mobile initialization
* @param {string} accessToken - The access token for the request
* @return {Promise<InitializeMtnMomoResponse>} A promise that resolves with the mobile payment initialization response
*/
async initializeMtnMomoPayment(mobileInitParams, accessToken) {
return (0, initialize_om_payment_1.initializeMtnMomoPayment)({
mobileInitParams,
paymentConfig: this.config,
endPoint: this.route.initPayment(),
accessToken: accessToken,
});
}
/**
* Gets the status of a payment in sandbox environment.
*
* @param {GetMtnMomoPaymentRequest} request - The parameters for checking the status
* @param {string} accessToken - The access token for the request
* @return {Promise<GetMtnMomoPaymentResponse>} The response containing the payment status
*/
async getMtnMomoPaymentStatus(request, accessToken) {
return (0, get_payment_status_1.getPaymentStatus)({
mobileStatusVerificationParams: request,
paymentServiceConfig: this.config,
endPoint: this.route.paymentStatus({
referenceId: request.referenceId,
}),
accessToken: accessToken,
});
}
}
exports.MtnMomoPaymentSandbox = MtnMomoPaymentSandbox;
//# sourceMappingURL=sandbox.js.map