@pulgueta/wompi

Examples

Payment link

A live Astro API route that creates a hosted Wompi checkout link and returns its public URL.

Live Generate a hosted checkout link without ever touching card details. Submit the form to call POST /api/examples/payment-link, which proxies to wompi.paymentLinks.createPaymentLink and returns the public URL.

Try it

Your sandbox keys

Bring your own Wompi test keys to run the examples below.

Not set

Submits to POST /api/examples/payment-link with the sandbox keys you saved above. Add your keys to enable this form.

Submit the form to receive a hosted checkout URL.

The API route

The route is intentionally tiny: a single SDK call, two branches, no integrity signature handshake. Wompi computes the signature server-side when you create the link.

src/pages/api/examples/payment-link.ts
import type { APIRoute } from "astro";
import { WompiClient } from "@pulgueta/wompi";

export const prerender = false;

export const POST: APIRoute = async ({ request }) => {
  // The visitor's own sandbox keys ride along as request headers — never env.
  const publicKey = request.headers.get("x-wompi-public-key");
  const privateKey = request.headers.get("x-wompi-private-key");
  if (!publicKey || !privateKey) {
    return Response.json({ configured: false, message: "Provide your sandbox keys." });
  }

  const { name, description, amountInCents, singleUse, collectShipping } = await request.json();

  const wompi = new WompiClient({ publicKey, privateKey, sandbox: true });

  const [error, response] = await wompi.paymentLinks.createPaymentLink({
    name,
    description,
    single_use: singleUse,
    collect_shipping: collectShipping,
    amount_in_cents: amountInCents,
    currency: "COP",
  });

  if (error) return Response.json({ error: error.message }, { status: 422 });

  const link = response;
  return Response.json({
    paymentLink: {
      id: link.id,
      url: link.checkout_url,
      name: link.name ?? name,
      amountInCents: link.amount_in_cents ?? amountInCents,
      singleUse: link.single_use ?? singleUse,
    },
  });
};
ts
// In your own app, read the keys from the server environment — never the client.
import { WOMPI_PUBLIC_KEY, WOMPI_PRIVATE_KEY } from "astro:env/server";

const wompi = new WompiClient({
  publicKey: WOMPI_PUBLIC_KEY,
  privateKey: WOMPI_PRIVATE_KEY,
  sandbox: true,
});

Reconciling paid links

Each transaction Wompi creates against a hosted link carries the link's id under payment_link_id. List or filter transactions to reconcile the link against the payment.

ts
// After the customer pays, the resulting transaction carries the link's id.
const [error, response] = await wompi.transactions.listTransactions({
  payment_method_type: "CARD",
  from_date: "2026-01-01",
  until_date: "2026-12-31",
});

const paidByLink = response?.filter((t) => t.payment_link_id === link.id) ?? [];
Navigation