bc-payments-sdk
Version:
BetterCommerce's Payments NodeJS SDK is a complete solution for storefront clients that integrate payments. `bc-payments-sdk` is a single point interface for storefront clients for interacting with payment gateways.
83 lines (82 loc) • 4.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
const uuid_1 = require("uuid");
const api_1 = require("./api");
const RequestMethod_1 = require("../../constants/enums/RequestMethod");
/**
* Class {Logger} provides methods for logging specific activities to an external
* service. The activities that can be logged include payment related activity,
* such as payment status changes, or any other type of activity.
*/
class Logger {
/**
* Logs activity details to the infrastructure logging service.
*
* This method captures various details such as user information, page URL,
* and request data, then sends these details to an external logging API.
*
* @param data - The log activity data containing details of the activity.
* - requestData: The request data associated with the activity.
* - pageUrl: The URL of the page where the activity occurred.
* - objectId: The unique identifier for the logged object.
* - userId: The unique identifier of the user performing the activity.
* - userName: The name of the user performing the activity.
* - ipAddress: The IP address of the user.
* - message: A short message describing the activity.
* @param {object} headers - The headers to include in the logging request.
* @param {object} cookies - The cookies to include in the logging request.
* @returns {Promise<any>} A promise that resolves to the result of the logging operation.
*/
static async logActivity(data, { headers, cookies }) {
const { data: requestData = {}, pageUrl, objectId = "", userId = "", userName = "", ipAddress = "", message = "", } = data;
const logData = {
ipAddress: ipAddress || "",
logLevelId: 20,
objectId: objectId !== null && objectId !== void 0 ? objectId : (0, uuid_1.v4)(),
pageUrl: pageUrl,
requestData: JSON.stringify(requestData),
shortMessage: message,
fullMessage: JSON.stringify(headers),
additionalinfo1: JSON.stringify(cookies),
userId: userId || "",
userName: userName || "",
};
const logResult = await api_1.Api.call(`api/v2/infra/log/create`, RequestMethod_1.RequestMethod.POST, logData, headers, cookies);
return logResult;
}
/**
* Logs payment related activity to the infrastructure logging service.
*
* This method captures various payment related details such as payment method,
* payment status, transaction ID, and request data, then sends these details
* to an external logging API.
*
* @param data - The log payment data containing details of the payment.
* - paymentMethod: The payment method used for the payment.
* - paymentStatus: The payment status associated with the payment.
* - transactionId: The unique identifier for the payment transaction.
* - requestData: The request data associated with the payment.
* @param {object} headers - The headers to include in the logging request.
* @param {object} cookies - The cookies to include in the logging request.
* @returns {Promise<any>} A promise that resolves to the result of the logging operation.
*/
static async logPayment(data, { headers = {}, cookies = {} }) {
const { data: requestData = {}, pageUrl = "", objectId = "", userId = "", userName = "", ipAddress = "", message = "", } = data;
const logData = {
ipAddress: ipAddress || "",
logLevelId: 20,
objectId: objectId !== null && objectId !== void 0 ? objectId : (0, uuid_1.v4)(),
pageUrl: pageUrl,
requestData: JSON.stringify(requestData),
shortMessage: message,
fullMessage: JSON.stringify(headers),
additionalinfo1: JSON.stringify(cookies),
userId: userId || "",
userName: userName || "",
};
const logResult = await api_1.Api.call(`api/v2/infra/log/payment-log`, RequestMethod_1.RequestMethod.POST, logData, headers, cookies);
return logResult;
}
}
exports.Logger = Logger;