@pulgueta/wompi

Examples

Card checkout

Tokenize a card, sign the amount and create a Wompi sandbox transaction — shown for Astro, Next.js, TanStack Start and Elysia.

Live The form below calls the same SDK methods you'd use in production. Enter your publicKey, privateKey and integrityKey below to charge a sandbox card, then check the framework examples to adapt the server route to your stack.

Try it

Your sandbox keys

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

Not set

Submits to POST /api/examples/checkout with the sandbox keys you saved above. Sandbox cards only. Add your keys to enable this form.

Submit the form to see the SDK call in action.

Framework examples

Four steps regardless of framework — fetch the acceptance token, tokenize the card, sign the amount, create the transaction. Pick your stack:

src/pages/api/checkout.ts
import type { APIRoute } from "astro";
import { WompiClient } from "@pulgueta/wompi";
import { getSignatureKey } from "@pulgueta/wompi/server";
import { WOMPI_PUBLIC_KEY, WOMPI_PRIVATE_KEY, WOMPI_INTEGRITY_KEY } from "astro:env/server";

export const prerender = false;

export const POST: APIRoute = async ({ request }) => {
  const { card, customerEmail, amountInCents } = await request.json();

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

  const [merchantError, merchant] = await wompi.merchants.getMerchant();
  if (merchantError) return Response.json({ error: merchantError.message }, { status: 502 });

  const [tokenError, token] = await wompi.tokens.tokenizeCard(card);
  if (tokenError) return Response.json({ error: tokenError.message }, { status: 422 });

  const reference = `order-${Date.now()}`;
  const signature = await getSignatureKey({ reference, amountInCents, integrityKey: WOMPI_INTEGRITY_KEY });

  const [transactionError, transaction] = await wompi.transactions.createTransaction({
    acceptance_token: merchant.presigned_acceptance!.acceptance_token,
    amount_in_cents: amountInCents,
    currency: "COP",
    signature,
    customer_email: customerEmail,
    reference,
    payment_method: { type: "CARD", token: token.id, installments: 1 },
  });

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