UNPKG

onepay-sdk

Version:

A simple payment gateway for Node.js

88 lines (85 loc) 2.5 kB
type SupportedGateway = 'stripe' | 'razorpay'; type KeyProps = { gateway: SupportedGateway; apiKey: string; apiSecret?: string; }; type PaymentPayload = { gateway: SupportedGateway; amount: number; currency: string; description: string; customerEmail?: string; metadata?: Record<string, any>; paymentMethodTypes?: string[]; customerId?: string; receiptId?: string; }; type PaymentResponse = { success: boolean; gateway: SupportedGateway; message?: string; error?: any; } & (StripePaymentResponse | RazorpayPaymentResponse); type StripePaymentResponse = { gateway: 'stripe'; clientSecret?: string; paymentIntentId?: string; }; type RazorpayPaymentResponse = { gateway: 'razorpay'; order?: any; orderId?: string; }; type ValidationResponse = { success: boolean; gateway?: SupportedGateway; message?: string; account?: any; type?: string; }; type PaymentVerificationPayload = { gateway: SupportedGateway; paymentId: string; orderId?: string; signature?: string; }; declare class OnePay { private gatewayInstances; private apiSecrets; constructor(keys: KeyProps[]); validateGateway(gateway: SupportedGateway): Promise<ValidationResponse>; private validateStripe; private validateRazorpay; /** * Create a payment with the specified gateway */ createPayment(payload: PaymentPayload): Promise<PaymentResponse>; /** * Create a payment intent with Razorpay */ private createRazorpayPayment; /** * Create a payment intent with Stripe */ private createStripePayment; /** * Verify a payment */ verifyPayment(payload: PaymentVerificationPayload): Promise<PaymentResponse>; private verifyRazorpayPayment; private verifyStripePayment; /** * Refund a payment */ refundPayment(gateway: SupportedGateway, paymentId: string, amount?: number): Promise<PaymentResponse>; private refundRazorpayPayment; private refundStripePayment; /** * Get payment details */ getPaymentDetails(gateway: SupportedGateway, paymentId: string): Promise<PaymentResponse>; private getRazorpayPaymentDetails; private getStripePaymentDetails; } export { type KeyProps, OnePay, type PaymentPayload, type PaymentResponse, type PaymentVerificationPayload, type RazorpayPaymentResponse, type StripePaymentResponse, type SupportedGateway, type ValidationResponse };