UNPKG

@spreeloop/mtn_momo

Version:
99 lines 3.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MtnMomoPaymentFake = void 0; const constants_1 = require("../utils/constants"); const routes_1 = require("../routes/routes"); /** * Implements the MTN MOMO fake payment for testing purposes. */ class MtnMomoPaymentFake { /** * Creates a new instance of the MtnMomoPaymentFake class. * * @param {MtnMomoPaymentConfigs} config - The configuration for the payment instance. */ constructor(config) { this.config = config; this.route = new routes_1.Routes(); } /** * Gets a fake access token. * * @return {Promise<GetAccessTokenResponse>} the access token response */ async getAccessToken() { return { data: "fake-access-token", raw: { access_token: "fake-access-token", expires_in: 3600, token_type: "Bearer", scope: "fake-scope", }, }; } /** * Initializes the MTN MOMO payment in fake mode. * * @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(request, accessToken) { const ocpApimSubscription = this.config.ocpApimSubscriptionKey; const amount = request.amount; const xReferenceId = request.xReferenceId; const externalId = request.externalId; const userNumber = request.userPhoneNumber; const apiKey = this.config.apiKey; const apiUserKey = this.config.apiUserKey; if (!(ocpApimSubscription && amount && xReferenceId && userNumber && externalId && apiKey && apiUserKey)) { return { error: constants_1.ApiErrorType.invalidData, }; } return { data: { status: 202, }, raw: { status: 202, }, }; } /** * Gets the status of a payment in fake mode. * * @param {GetMtnMomoPaymentRequest} checkStatusParams - 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) { const ocpApimSubscription = this.config.ocpApimSubscriptionKey; const xReferenceId = request.referenceId; const apiUser = this.config.apiUserKey; const apiKey = this.config.apiKey; if (!(ocpApimSubscription && xReferenceId && apiKey && apiUser)) { return { error: constants_1.ApiErrorType.invalidData, }; } return { data: { status: constants_1.MtnMomoPaymentStatus.SUCCESSFUL_PAYMENT, }, raw: { status: constants_1.MtnMomoPaymentStatus.SUCCESSFUL_PAYMENT, referenceId: xReferenceId, }, }; } } exports.MtnMomoPaymentFake = MtnMomoPaymentFake; //# sourceMappingURL=fake.js.map