Integrate

TypeScript SDK

A small, typed client over the REST API. Same endpoints, same shapes, but with autocomplete and inferred response types.

Install

bash
bun add @meridapay/sdk
# npm:  npm i @meridapay/sdk
# pnpm: pnpm add @meridapay/sdk

The package ships ESM + CJS, works in Node ≥ 18 and any modern runtime that supports fetch (Bun, Deno, Workers, Edge).

Init

Create one client per process and reuse it. The factory reads MERIDA_API_KEY from the environment if you don't pass an apiKey option.

ts
import { createMeridaClient } from "@meridapay/sdk"

export const merida = createMeridaClient({
  apiKey: process.env.MERIDA_API_KEY!,
})

Make calls

The client is generated from our OpenAPI schema. Every endpoint is keyed by its path and method. Bodies, params, and responses are typed:

ts
const { data, error } = await merida.POST("/checkouts", {
  body: {
    product_id: "prod_8f5f7c7e-...",
    customer_email: "[email protected]",
    external_customer_id: "user_123",
    success_url: "https://app.example.com/thanks",
  },
  headers: {
    "idempotency-key": crypto.randomUUID(),
  },
})

if (error) throw new Error(error.error.message)
// data is typed: { url: string, status: "active", amount: string, ... }
return Response.redirect(data.url, 303)

Reads work the same way:

ts
const { data } = await merida.GET("/products")
for (const p of data?.data ?? []) {
  console.log(p.name, p.prices[0]?.amount)
}

Embed entry point

The same package ships the browser embed via a subpath import. It's the same script the <script src=...> tag loads, but as an ES module you can bundle.

ts
import { embed } from "@meridapay/sdk/embed"

const merida = await embed()
merida.attach()

Anchors carrying data-merida-checkout open in the overlay. See Embedded Checkout for the full attribute and event surface.

Errors

Every call returns { data, error }. error is the same JSON shape the REST API returns:

json
{
  "error": {
    "code": "validation_error",
    "message": "discount_code expired",
    "docs": "https://meridapay.com/docs/discounts"
  }
}

Network failures throw. Validation, auth, and not-found responses come back in error.