@spreeloop/orange_money
Version:
A orange money api integration package
43 lines • 2.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPayToken = void 0;
const https_1 = require("../../utils/https");
const constants_1 = require("../utils/constants");
/**
* Gets a pay token using the provided payment configuration.
*
* @param {OrangeMoneyPaymentConfigs} paymentConfig - The payment configuration.
* @param {string} accessToken - The payment configuration.
* @param {string} endPoint - The payToken endpoint.
* @return {Promise<GetPayTokenResponse>} The generated pay token response.
*/
const getPayToken = async (paymentConfig, accessToken, endPoint) => {
var _a, _b, _c, _d, _e;
const logger = paymentConfig.logger;
logger.info(`Request to generate the pay-token token using the provided payment configuration: ${JSON.stringify(paymentConfig)}`);
const headers = {
[constants_1.ApiKey.keyAuthorization]: `Bearer ${accessToken}`,
[constants_1.ApiKey.keyContentType]: constants_1.ConstantRequestField.typeJson,
[constants_1.ApiKey.keyXAuthToken]: paymentConfig.xAuthToken,
};
const result = await (0, https_1.postRequest)({
headers: headers,
logger: logger,
route: endPoint,
});
const payToken = (_c = (_b = (_a = result.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.payToken;
if (result.error || !payToken) {
logger.warn(`Request failed to generate the pay-token. Error retrieved: ${JSON.stringify(result.error)}`);
return {
raw: result.error,
error: constants_1.ApiErrorType.failedToGeneratePayToken,
};
}
logger.info(`Pay-token generated successfully with data: ${JSON.stringify((_d = result.response) === null || _d === void 0 ? void 0 : _d.data)}`);
return {
raw: (_e = result.response) === null || _e === void 0 ? void 0 : _e.data,
data: payToken,
};
};
exports.getPayToken = getPayToken;
//# sourceMappingURL=get_pay_token.js.map