@cosmosapp/pay_sdkDefinitionenServer

WebhookManager

Manages webhook endpoints, their delivery audit trail, and the incoming event listener — client.webhooks.

Manages webhook endpoints, their delivery audit trail, and the incoming event listener — client.webhooks. Registering endpoints (server-side CRUD):

Methods

create()

Register a webhook endpoint (the returned instance carries the secret once).

create(options: CreateWebhookEndpointOptions): Promise<WebhookEndpoint>

Parameters

  • options: CreateWebhookEndpointOptions

Returns Promise<WebhookEndpoint>

list()

List the consumer's webhook endpoints.

list(): Promise<WebhookEndpoint[]>

Returns Promise<WebhookEndpoint[]>

fetch()

Get a webhook endpoint by id.

fetch(id: string): Promise<WebhookEndpoint>

Parameters

  • id: string

Returns Promise<WebhookEndpoint>

update()

Update a webhook endpoint (url/description/enabled/eventTypes).

update(id: string, options: UpdateWebhookEndpointOptions): Promise<WebhookEndpoint>

Parameters

  • id: string
  • options: UpdateWebhookEndpointOptions

Returns Promise<WebhookEndpoint>

delete()

Delete a webhook endpoint.

delete(id: string): Promise<WebhookDeletedData>

Parameters

  • id: string

Returns Promise<WebhookDeletedData>

rotateSecret()

Rotate the signing secret (returns a new instance carrying the secret).

rotateSecret(id: string): Promise<WebhookEndpoint>

Parameters

  • id: string

Returns Promise<WebhookEndpoint>

ping()

Send a test event to verify the endpoint.

ping(id: string): Promise<WebhookPingData>

Parameters

  • id: string

Returns Promise<WebhookPingData>

fetchDeliveries()

List delivery attempts for an endpoint (audit trail).

fetchDeliveries(id: string, options?: ListWebhookDeliveriesOptions): Promise<WebhookDeliveryPage>

Parameters

  • id: string
  • options (optional): ListWebhookDeliveriesOptions

Returns Promise<WebhookDeliveryPage>

redeliver()

Manually re-send a past delivery.

redeliver(id: string, deliveryId: string): Promise<WebhookDelivery>

Parameters

  • id: string
  • deliveryId: string

Returns Promise<WebhookDelivery>

process()

Verify a raw incoming webhook request and dispatch it to the listeners registered via {@link WebhookManager.on}. Returns the parsed event. Emits, in order: the raw type (PAYMENT_INTENT_SUCCEEDED), the camelCase alias (paymentIntentSucceeded) and the catch-all event.

process(rawBody: string | Uint8Array, signatureHeader: string | null | undefined, options?: WebhookProcessOptions): AnyWebhookEvent

Parameters

  • rawBody: string | Uint8Array
  • signatureHeader: string | null | undefined
  • options (optional): WebhookProcessOptions

Returns AnyWebhookEvent

createHandler()

Build a Node.js http/https request handler that verifies the signature, dispatches the event to your listeners, and replies 200/400.

createHandler(options?: WebhookHandlerOptions): (req: IncomingMessage, res: ServerResponse) => void

Parameters

  • options (optional): WebhookHandlerOptions

Returns (req: IncomingMessage, res: ServerResponse) => void

middleware()

Express-style middleware. Expects the raw body (e.g. mounted with express.raw({ type: '*​/*' })). On success it attaches the parsed event to req.cosmosEvent and calls next(); on a bad signature it replies 400.

middleware(options?: WebhookHandlerOptions): (req: RequestLike, res: ResponseLike, next: (err?: unknown) => void) => void

Parameters

  • options (optional): WebhookHandlerOptions

Returns (req: RequestLike, res: ResponseLike, next: (err?: unknown) => void) => void

Auf dieser Seite