Payment link
Create a hosted Wompi checkout link from an Astro API route and return its public URL.
Generate a hosted checkout link without ever touching card details. The route
below calls wompi.paymentLinks.createPaymentLink and returns the public 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.
import type { APIRoute } from "astro";
import { WompiClient } from "@pulgueta/wompi";
export const prerender = false;
export const POST: APIRoute = async ({ request }) => {
const publicKey = process.env.WOMPI_PUBLIC_KEY;
const privateKey = process.env.WOMPI_PRIVATE_KEY;
if (!publicKey || !privateKey) {
return Response.json(
{ configured: false, message: "Sandbox environment is not configured." },
{ status: 503 },
);
}
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,
},
});
};
const wompi = new WompiClient({
publicKey: process.env.WOMPI_PUBLIC_KEY!,
privateKey: process.env.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.
// 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) ?? [];