UNPKG

@yengapay/nodejs-sdk

Version:

Official Node.js SDK for YengaPay - Accept mobile money payments and send payouts in West Africa

99 lines (97 loc) 3.16 kB
import { ClientConfig, InitDirectPaymentParams, InitDirectPaymentResponse, ProcessPaymentParams, ProcessPaymentResponse, SendOtpParams, SendOtpResponse, PaymentStatusResponse } from '../types'; /** * Direct Payment Module * * Handles direct payment operations via API */ export declare class DirectPayment { private config; private http; constructor(config: ClientConfig); /** * Initialize a direct payment * * Creates a PaymentIntent and returns available payment operators * * @param params - Payment initialization parameters * @returns Payment intent ID and available operators * * @example * ```typescript * const payment = await client.directPayment.init({ * amount: 1000, * reference: 'ORDER-123', * customerEmailToNotify: 'customer@example.com' * }); * console.log(payment.paymentIntentId); * console.log(payment.availableOperators); * ``` */ init(params: InitDirectPaymentParams): Promise<InitDirectPaymentResponse>; /** * Process payment with selected operator * * Executes the payment transaction with the chosen mobile money operator * * @param params - Payment processing parameters * @returns Payment status and details * * @example * ```typescript * // One-step flow (Orange Money) * const result = await client.directPayment.pay({ * paymentIntentId: 'pi_123...', * operatorCode: 'ORANGE', * countryCode: 'BF', * customerMSISDN: '+22670123456', * otp: '123456' * }); * * // Two-step flow (Moov Money - after sending OTP) * const result = await client.directPayment.pay({ * paymentIntentId: 'pi_123...', * operatorCode: 'MOOV', * countryCode: 'BF', * customerMSISDN: '+22670123456' * }); * ``` */ pay(params: ProcessPaymentParams): Promise<ProcessPaymentResponse>; /** * Send OTP for two-step operators (Coris, Sank) * * Requests an OTP to be sent to the customer's phone * * @param params - OTP request parameters * @returns OTP sent confirmation * * @example * ```typescript * const result = await client.directPayment.sendOtp({ * paymentIntentId: 'pi_123...', * operatorCode: 'CORISM', * countryCode: 'BF', * customerMSISDN: '+22670123456' * }); * console.log(result.message); // "Coris Money vous a envoyé un code OTP par SMS" * ``` */ sendOtp(params: SendOtpParams): Promise<SendOtpResponse>; /** * Get payment status by PaymentIntent ID * * Check if a payment is pending, completed, or failed * * @param paymentIntentId - The PaymentIntent ID to check * @returns Payment status and details * * @example * ```typescript * const status = await client.directPayment.getStatus('pi_123...'); * if (status.status === 'DONE') { * console.log('Payment completed:', status.transactionId); * } * ``` */ getStatus(paymentIntentId: string): Promise<PaymentStatusResponse>; }