UNPKG

@sahabaplus/moyasar

Version:

A comprehensive TypeScript SDK for integrating with the Moyasar payment gateway

72 lines 2.81 kB
import type { ApiClient, MoyasarClientTypes } from "../../shared/types/index"; import { WebhookEvent } from "./enums"; import type { Webhook, WebhookPayload, WebhookAttempt, CreateWebhookRequest, UpdateWebhookRequest, ListWebhooksResponse, ListWebhookAttemptsResponse, AvailableEventsResponse, WebhookListOptions, WebhookAttemptListOptions, WebhookVerificationOptions, WebhookEventMap } from "./types"; import { TypedEmitter } from "tiny-typed-emitter"; type WebhookServiceParams<T extends MoyasarClientTypes> = { apiClient: ApiClient<T>; }; export declare class WebhookService<T extends MoyasarClientTypes> extends TypedEmitter<WebhookEventMap<T["metadata"]>> { private readonly apiClient; private readonly events; private readonly paymentUtils; constructor(params: WebhookServiceParams<T>); /** * Create a new webhook */ create(params: CreateWebhookRequest): Promise<Webhook>; /** * List all webhooks */ list(options?: WebhookListOptions): Promise<ListWebhooksResponse>; /** * Retrieve a specific webhook */ retrieve(webhookId: string): Promise<Webhook>; /** * Update a webhook */ update(webhookId: string, params: UpdateWebhookRequest): Promise<Webhook>; /** * Delete a webhook */ delete(webhookId: string): Promise<void>; /** * Get available webhook events */ availableEvents(): Promise<AvailableEventsResponse>; /** * Webhook Attempts Sub-service */ get attempts(): { /** * List all webhook attempts */ list: (options?: WebhookAttemptListOptions) => Promise<ListWebhookAttemptsResponse>; /** * Retrieve a specific webhook attempt */ retrieve: (attemptId: string) => Promise<WebhookAttempt>; }; /** * Process incoming webhook payload * This method should be called from your webhook endpoint */ processWebhook(rawPayload: string | Buffer | WebhookPayload<T["metadata"]>, options: WebhookVerificationOptions): Promise<WebhookPayload<T["metadata"]>>; /** * Utility method to create type-safe event listeners for payment events */ onPaymentEvent(event: WebhookEvent, listener: (payload: WebhookPayload<T["metadata"]>) => void | Promise<void>): this; /** * Utility method to listen to all payment events */ onAnyPaymentEvent(listener: (payload: WebhookPayload<T["metadata"]>) => void | Promise<void>): this; /** * Helper method to extract webhook signature from common header patterns */ extractSignature(headers: Record<string, string | string[]>): string | null; private validateCreateRequest; private validateUpdateRequest; private handleError; } export {}; //# sourceMappingURL=service.d.ts.map