API Reference
Payment sources
Turn a card or Nequi token into a long-lived payment source you can re-charge.
A payment source is Wompi's way of storing a tokenized card or Nequi account against a
customer. Once created, you can re-charge it by passing its numeric id into
createTransaction — no further tokenization or acceptance handshake needed.
createPaymentSource(input)
Promote a one-time token into a reusable source. You'll need a fresh acceptance token from
merchants.getMerchant() — Wompi treats this as a
separate customer consent.
// 1. Tokenize the card (or Nequi account) up-front.
const [tokenError, token] = await wompi.tokens.tokenizeCard({
number: "4242424242424242",
cvc: "123",
exp_month: "12",
exp_year: "29",
card_holder: "PEDRO PEREZ",
});
if (tokenError) throw tokenError;
// 2. Fetch a fresh acceptance token from the merchant resource.
const [merchantError, merchant] = await wompi.merchants.getMerchant();
if (merchantError) throw merchantError;
// 3. Convert the card token into a long-lived payment source.
const [error, response] = await wompi.paymentSources.createPaymentSource({
type: "CARD",
token: token.id,
acceptance_token: merchant.presigned_acceptance!.acceptance_token,
customer_email: "buyer@example.com",
});
if (error) throw error;
response.id; // numeric id — store this against your user Input
| Field | Type | Notes |
|---|---|---|
type | "CARD" | "NEQUI" | The token's source kind. |
token | string | Output of tokens.tokenizeCard / tokenizeNequi. |
acceptance_token | string | Fresh value from the merchant resource. |
customer_email | email | The customer this source belongs to. |
getPaymentSource(id)
Look a payment source up by its numeric id.
const [error, response] = await wompi.paymentSources.getPaymentSource(12_345);
if (error) throw error;
response.id;
response.status; // "AVAILABLE" | "PENDING"
response.type; // "CARD" | "NEQUI" Response
| Field | Type | Notes |
|---|---|---|
id | number | Stable, persist this against your user. |
status | "AVAILABLE" | "PENDING" | PENDING for Nequi until the customer approves. |
type | "CARD" | "NEQUI" | undefined | Source kind. |
token | string? | The underlying token. |
customer_email | string? | Owning customer. |
public_data | object? | { type, phone_number? } — safe to surface in the UI. |
Charging a stored source
Drop the id into createTransaction as
payment_source_id. Note the change in auth — using
payment_source_id requires the private key, not the public one.
const [error, response] = await wompi.transactions.createTransaction({
acceptance_token,
amount_in_cents: 990_000,
currency: "COP",
signature,
customer_email: "buyer@example.com",
reference: `recur-${Date.now()}`,
payment_source_id: 12_345, // ← reusing the stored source
});