UNPKG

mds-daraja-sdk

Version:

A simple SDK for integrating with Safaricom's Daraja API for M-Pesa payments.

85 lines (84 loc) 3.07 kB
export interface StkPushRequest { BusinessShortCode: string; Password: string; Timestamp: string; TransactionType: string; Amount: number; PartyA: string; PartyB: string; PhoneNumber: string; CallBackURL: string; AccountReference: string; TransactionDesc: string; } export interface StkPushResponse { MerchantRequestID: string; CheckoutRequestID: string; ResponseCode: string; ResponseDescription: string; CustomerMessage: string; } export declare class SafaricomDarajaApi { private consumerKey; private consumerSecret; private baseUrl; private businessShortCode; private passkey; constructor(consumerKey?: string, consumerSecret?: string, businessShortCode?: string, passkey?: string); /** * Get the access token from Safaricom Daraja API */ getAccessToken(): Promise<string>; /** * Register C2B URLs */ registerUrls(confirmationUrl: string, validationUrl: string, shortCode?: string): Promise<any>; /** * Check Account Balance */ checkBalance(shortCode: string, password: string, timestamp: string, partyA: string): Promise<any>; /** * Initiate an STK Push */ initiateStkPush(stkPushRequest: StkPushRequest): Promise<StkPushResponse>; initiateC2bStkPush(phone: string, amount: number, accountReference?: string, transactionDesc?: string, callbackUrl?: string): Promise<StkPushResponse>; /** * Query a transaction status */ queryTransactionStatus(BusinessShortCode: string, Password: string, Timestamp: string, CheckoutRequestID: string): Promise<any>; /** * Transaction Reversal */ reverseTransaction(shortCode: string, password: string, timestamp: string, transactionID: string): Promise<any>; /** * B2C Payment Request */ b2cPayment(shortCode: string, password: string, amount: number, partyA: string, partyB: string): Promise<any>; /** * Handles the final confirmation of the transaction after processing. * @param confirmationData - The confirmation request data from M-Pesa * @returns An object containing the status of the transaction */ handleTransactionConfirmation(confirmationData: any): { success: boolean; message: string; data?: any; }; private recordTransaction; /**======================================================================= * Handles validation of incoming transactions * @param validationData - The validation request data from M-Pesa * @returns A response indicating whether to accept or reject the transaction */ handleTransactionValidation(validationData: any): { success: boolean; message: string; }; private checkAccountExists; /** * Generate password using short code, passkey, and timestamp */ static generatePassword(shortcode: string, passkey: string, timestamp?: string): string; static generateTimeStamp(): string; } export declare const safaricomDarajaApi: SafaricomDarajaApi;