UNPKG

mpesajs

Version:

A Node.js SDK for seamless integration with M-Pesa payment gateway, providing easy-to-use methods for handling transactions, payments, and API interactions

74 lines (73 loc) 2.81 kB
/** * Response interface for URL registration containing status details */ interface RegisterUrlResponse { responseCode: string; responseMessage: string; customerMessage: string; timestamp: string; } /** * Payload interface for URL registration request */ interface RegisterUrlPayload { ShortCode: string; ResponseType: 'Completed' | 'Cancelled'; CommandID: 'RegisterURL'; ConfirmationURL: string; ValidationURL: string; } /** * Class to handle M-Pesa URL registration functionality * Allows businesses to register their confirmation and validation URLs */ export declare class RegisterUrl { private readonly baseUrl; private readonly apiKey; private readonly rateLimiter; /** * Creates an instance of RegisterUrl * @param apiKey - M-Pesa API key for authentication * @param sandbox - Whether to use sandbox environment */ constructor(apiKey?: string, sandbox?: boolean); /** * Validates that both URLs use HTTPS protocol * @param confirmationUrl - URL for successful transaction notifications * @param validationUrl - URL for transaction validation * @throws Error if URLs don't use HTTPS */ private validateUrls; /** * Builds the payload for URL registration request * @param shortCode - Business short code * @param responseType - Type of response expected * @param commandId - Command identifier * @param confirmationUrl - URL for confirmations * @param validationUrl - URL for validations * @returns Formatted payload object */ private buildPayload; /** * Parses and validates the API response * @param response - Raw API response * @returns Formatted RegisterUrlResponse object * @throws Error if response format is invalid */ private parseResponse; /** * Registers validation and confirmation URLs with M-Pesa * @param shortCode - Business short code or PayBill number * @param responseType - Type of response expected (default: 'Completed') * @param commandId - Command identifier (default: 'RegisterURL') * @param confirmationUrl - HTTPS URL to receive successful transaction confirmations * @param validationUrl - HTTPS URL to validate transactions before processing * @returns Promise containing registration response details * @throws RegisterUrlError if registration fails * @throws NetworkError if network connection fails * @throws ValidationError if URLs are invalid * @throws MpesaError for other API errors */ register(shortCode?: string, responseType?: RegisterUrlPayload['ResponseType'], commandId?: RegisterUrlPayload['CommandID'], confirmationUrl?: string, validationUrl?: string): Promise<RegisterUrlResponse>; } export {};