UNPKG

@johntad/m-pesa

Version:

A TypeScript SDK for integrating M-Pesa mobile payment services into applications, enabling seamless money transfers and transactions.

38 lines (37 loc) 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.B2CResponse = void 0; /** * Represents the response object from the B2C Pay Out API. */ class B2CResponse { constructor(ConversationID, OriginatorConversationID, ResponseCode, ResponseDescription) { this.ConversationID = ConversationID; this.OriginatorConversationID = OriginatorConversationID; this.ResponseCode = ResponseCode; this.ResponseDescription = ResponseDescription; } /** * Factory method to create an instance from API response data. * @param data - The raw response data from the API. * @returns An instance of B2CResponse. */ static fromApiResponse(data) { return new B2CResponse(data.ConversationID, data.OriginatorConversationID, data.ResponseCode, data.ResponseDescription); } /** * Determines if the response indicates success. * @returns True if the response was successful, false otherwise. */ isSuccess() { return this.ResponseCode === '0'; } /** * Returns a formatted string for logging or displaying the response. * @returns A formatted string summarizing the response. */ toString() { return `B2C Response: ${this.ResponseDescription} (Code: ${this.ResponseCode})`; } } exports.B2CResponse = B2CResponse;