UNPKG

@spreeloop/mtn_momo

Version:
63 lines 2.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MtnMomoPaymentLive = void 0; const constants_1 = require("../../utils/constants"); const get_access_token_1 = require("../operations/get_access_token"); const get_payment_status_1 = require("../operations/get_payment_status"); const initialize_om_payment_1 = require("../operations/initialize_om_payment"); const routes_1 = require("../routes/routes"); /** * Implements the MTN MOMO live payment. */ class MtnMomoPaymentLive { /** * Creates a new instance of the MtnMomoPaymentLive class. * * @param {MtnMomoPaymentConfigs} config - The configuration for the payment instance. */ constructor(config) { this.config = config; this.route = new routes_1.Routes(constants_1.TargetEnvironment.prod); } /** * Gets an access token. * * @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. * * @param {InitializeMtnMomoPaymentRequest} mobileInitParams - Parameters for mobile initialization * @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. * * @param {GetMtnMomoPaymentRequest} checkStatusParams - The parameters for checking the status. * @return {Promise<GetMtnMomoPaymentResponse>} The response containing the payment status. */ async getMtnMomoPaymentStatus(checkStatusParams, accessToken) { return (0, get_payment_status_1.getPaymentStatus)({ mobileStatusVerificationParams: checkStatusParams, paymentServiceConfig: this.config, endPoint: this.route.paymentStatus({ referenceId: checkStatusParams.referenceId, }), accessToken: accessToken, }); } } exports.MtnMomoPaymentLive = MtnMomoPaymentLive; //# sourceMappingURL=live.js.map