import { WebhookEvent, PayoutEvent, PayoutTransactionUpdatedEvent, PayoutUpdatedEvent, TransactionUpdatedEvent, Result } from './schemas.js'; import 'zod'; import 'buffer'; type GetSignatureKeyOptions = { /** Unique merchant reference for the transaction — the same value passed to `createTransaction`. */ reference: string; /** * Transaction amount, already expressed in cents (an integer). This is the exact * same value passed as `amount_in_cents` to `createTransaction` — it is hashed * as-is and must never be multiplied. */ amountInCents: number; /** The merchant integrity secret, available in the Wompi dashboard. */ integrityKey: string; /** ISO-4217 currency code. Defaults to `"COP"`. */ currency?: string; /** * ISO-8601 timestamp. Provide it only when the transaction also sets * `expiration_time`; Wompi hashes it right before the integrity secret. */ expirationTime?: string; }; /** * Compute the Wompi integrity signature for a transaction. * * The signature is the SHA-256 hex digest of * ``, matching * the hash Wompi expects in a transaction's `signature` field. * * @example * ```ts * const signature = await getSignatureKey({ * reference: "ref-12345", * amountInCents: 2_490_000, * integrityKey: process.env.WOMPI_INTEGRITY_KEY!, * }); * ``` * * @throws {WompiError} If `amountInCents` is not a non-negative integer. */ declare const getSignatureKey: (options: GetSignatureKeyOptions) => Promise; /** * Compute the checksum Wompi signs an event with: the SHA-256 hex digest of the * concatenated values of `signature.properties` (resolved against `data`, in * order), followed by `timestamp` and the merchant events secret. */ declare const computeEventChecksum: (event: Pick, eventsKey: string) => Promise; type VerifyWebhookEventOptions = { /** The merchant events secret, available in the Wompi dashboard. */ eventsKey: string; }; /** * Parse and authenticate an event Wompi POSTed to the configured Events URL. * * Accepts the raw request body (string) or the already-parsed JSON object, * validates the envelope shape, recomputes the checksum with the events secret * and compares it in constant time against `signature.checksum`. Events whose * checksum does not match must be discarded — anyone can POST to a public * webhook endpoint. * * @example * ```ts * const [error, event] = await verifyWebhookEvent(await request.text(), { * eventsKey: process.env.WOMPI_EVENTS_KEY!, * }); * if (error) return new Response("Invalid signature", { status: 403 }); * if (isTransactionUpdatedEvent(event)) { * console.log(event.data.transaction.status); * } * ``` */ declare const verifyWebhookEvent: (payload: unknown, options: VerifyWebhookEventOptions) => Promise>; /** Narrow a verified {@link WebhookEvent} to a typed `transaction.updated` event. */ declare const isTransactionUpdatedEvent: (event: WebhookEvent) => event is TransactionUpdatedEvent; /** * Parse and authenticate an event the Payouts API POSTed to the configured * Events URL. * * Payout events are signed exactly like payments webhooks — SHA-256 over the * `signature.properties` values, the `timestamp` and the Payouts events secret * — but their envelope differs: no `environment` field and a camelCased * `sentAt`. The checksum is compared in constant time against * `signature.checksum`; events that fail must be discarded. * * @example * ```ts * const [error, event] = await verifyPayoutEvent(await request.text(), { * eventsKey: process.env.WOMPI_PAYOUTS_EVENTS_KEY!, * }); * if (error) return new Response("Invalid signature", { status: 403 }); * if (isPayoutUpdatedEvent(event)) { * console.log(event.data.payout.status); * } * ``` */ declare const verifyPayoutEvent: (payload: unknown, options: VerifyWebhookEventOptions) => Promise>; /** Narrow a verified {@link PayoutEvent} to a typed `payout.updated` event. */ declare const isPayoutUpdatedEvent: (event: PayoutEvent) => event is PayoutUpdatedEvent; /** Narrow a verified {@link PayoutEvent} to a typed `transaction.updated` event. */ declare const isPayoutTransactionUpdatedEvent: (event: PayoutEvent) => event is PayoutTransactionUpdatedEvent; declare const CHECKOUT_BASE_URL = "https://checkout.wompi.co/p/"; type BuildCheckoutUrlOptions = { /** Merchant public key (`pub_test_…` or `pub_prod_…`). */ publicKey: string; /** Unique merchant reference for the transaction. */ reference: string; /** Amount in cents (integer). */ amountInCents: number; /** ISO-4217 currency code. Defaults to `"COP"`. */ currency?: string; /** URL Wompi redirects the customer to after paying (receives `?id=`). */ redirectUrl?: string; /** ISO-8601 timestamp after which the checkout expires. Included in the signature. */ expirationTime?: string; /** Prefills the checkout's customer form. */ customerData?: { email?: string; fullName?: string; phoneNumber?: string; phoneNumberPrefix?: string; legalId?: string; legalIdType?: string; }; /** Ask Wompi to collect a shipping address. */ collectShipping?: boolean; /** Taxes already included in `amountInCents`. */ taxInCents?: { vat?: number; consumption?: number; }; } & ({ /** Merchant integrity secret; the signature is computed for you. */ integrityKey: string; signature?: never; } | { /** Precomputed integrity signature (see {@link getSignatureKey}). */ signature: string; integrityKey?: never; }); /** * Build a Wompi Web Checkout URL (`https://checkout.wompi.co/p/?…`) for * redirect-based payments. Pass either `integrityKey` (the signature is * computed server-side for you) or a precomputed `signature`. * * Never call this with `integrityKey` from browser code — the integrity secret * must stay on the server. * * @example * ```ts * const url = await buildCheckoutUrl({ * publicKey: process.env.WOMPI_PUBLIC_KEY!, * reference: "order-1042", * amountInCents: 8_900_000, * redirectUrl: "https://example.com/orders/1042", * integrityKey: process.env.WOMPI_INTEGRITY_KEY!, * }); * ``` * * @throws {WompiError} If `amountInCents` is not a non-negative integer. */ declare const buildCheckoutUrl: (options: BuildCheckoutUrlOptions) => Promise; export { type BuildCheckoutUrlOptions, CHECKOUT_BASE_URL, type GetSignatureKeyOptions, type VerifyWebhookEventOptions, buildCheckoutUrl, computeEventChecksum, getSignatureKey, isPayoutTransactionUpdatedEvent, isPayoutUpdatedEvent, isTransactionUpdatedEvent, verifyPayoutEvent, verifyWebhookEvent };