@spreeloop/orange_money
Version:
A orange money api integration package
51 lines • 2.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPaymentStatus = void 0;
const https_1 = require("../../utils/https");
const constants_1 = require("../utils/constants");
/**
* Gets the mobile payment status.
*
* @param {Object} options - The options object.
* @param {GetOrangeMoneyPaymentRequest} options.mobileStatusVerificationParams - The parameters for mobile status verification.
* @param {string} endPoint - The init payment end point.
* @param {OrangeMoneyPaymentParams} paymentServiceConfig - The mobile payment config parameters.
* - {TargetEnvironment} PaymentServiceConfig.targetEnvironment - The target environment.
* - {string} PaymentServiceConfig.apiUserName - The api user name.
* - {string} PaymentServiceConfig.xAuthToken - The x-auth-token.
* - {string} PaymentServiceConfig.apiPassword - The api password.
* - {string} [PaymentServiceConfig.orangeMoneyVersion] - The orange money version.
* - {LoggerInterface} PaymentServiceConfig.logger - The logger interface.
* @return {Promise<GetOrangeMoneyPaymentResponse>} The promise that resolves to the mobile payment check status response.
*/
async function getPaymentStatus({ mobileStatusVerificationParams, paymentServiceConfig, endPoint, }) {
const logger = paymentServiceConfig.logger;
const headers = {
[constants_1.ApiKey.keyAuthorization]: `Bearer ${mobileStatusVerificationParams.accessToken}`,
[constants_1.ApiKey.keyContentType]: constants_1.ConstantRequestField.typeJson,
[constants_1.ApiKey.keyXAuthToken]: paymentServiceConfig.xAuthToken,
};
logger.info(`[ORANGE MONEY] Checks the ORANGE MONEY Payment status with route: ${endPoint}`);
const response = await (0, https_1.getRequest)({
headers: headers,
route: endPoint,
logger: logger,
});
const responseData = response === null || response === void 0 ? void 0 : response.response;
if (responseData && (0, https_1.isSuccessfulCodeResponse)(responseData.status)) {
logger.log(`[ORANGE MONEY] Status verification successful with result ${JSON.stringify(responseData.data)}`);
return {
data: {
status: responseData.data.data.status,
},
raw: responseData.data,
};
}
logger.warn(`[ORANGE MONEY] Status verification failed with error data: ${JSON.stringify(response.error)}`);
return {
raw: response.error,
error: constants_1.ApiErrorType.failedToCheckPaymentStatus,
};
}
exports.getPaymentStatus = getPaymentStatus;
//# sourceMappingURL=get_payment_status.js.map