UNPKG

@johntad/m-pesa

Version:

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

46 lines (45 loc) 1.84 kB
import { StkPushPayloadType, StkPushResponse } from './models/StkPushResponse'; import { B2CPayloadType, B2CResponse } from './models/B2CPaymentResponse'; import { RegisterUrlPayloadType, RegisterUrlResponse } from './models/C2BUrlResponse'; import { LogLevel } from './Logger'; export interface MpesaConfig { environment: 'sandbox' | 'production'; apiKey: string; secretKey: string; timeout?: number; retries?: number; logLevel?: LogLevel; } export declare class MPesa { private static instance; private config; private apiClient; private logger; accessToken: string | null; tokenExpiry: number | null; private constructor(); static getInstance(config: MpesaConfig): MPesa; authenticate(): Promise<void>; private makeAuthorizedRequest; /** * Sends an STK Push request to the M-Pesa API. * @param payload - The payload for the STK Push request. * @returns A StkPushResponse instance representing the response. * @throws StkPushError if the API returns an error response. */ stkPush(payload: StkPushPayloadType): Promise<StkPushResponse>; /** * Registers validation and confirmation URLs with the M-Pesa API. * @param payload - The payload for the Register URL request. * @returns A RegisterUrlResponse instance representing the response. * @throws RegisterUrlError if the API returns an error response. */ registerC2BUrl(payload: RegisterUrlPayloadType): Promise<RegisterUrlResponse>; /** * Sends a B2C Pay Out request to the M-Pesa API. * @param payload - The payload for the B2C Pay Out request. * @returns A B2CResponse instance representing the response. * @throws B2CError if the API returns an error response. */ b2cPayment(payload: B2CPayloadType): Promise<B2CResponse>; }