Skip to content

Options

const pybara = Pybara.checkout({
recipientPrincipal: 'xxxxx-xxxxx-…',
siteUrl: 'https://example.com',
siteName: 'Example Charity',
currency: 'EUR',
});
await pybara.open({
amount: '25',
frequency: 'monthly',
durationMonths: 12,
donorEmail: 'donor@example.com',
onSuccess: (result) => console.log('paid:', result.blockIndex),
onError: (err) => console.error(err.code, err.message),
});

Bound once per checkout. The three fields without ? are required.

Pybara.checkout({
// ── Required ──
recipientPrincipal: string; // your Pybara Wallet principal — the one the site's _pybara-payto DNS record lists
siteUrl: string; // the site's URL as registered in the wallet, e.g. 'https://example.com' — a bare domain reads as https
siteName: string; // the name the donor sees; also stored as the subscription name on recurring donations
// ── Site ──
currency?: string; // ISO 4217, uppercase, e.g. 'EUR' — open()'s currency when it passes none; no default of its own
siteCountry?: string; // your site's base country (ISO 3166-1 alpha-2)
platform?: string; // default 'pybara-js' — your integration's slug in the payment log (a-z, 0-9, -, at most 64); a label, never used for a decision
// ── Success screen ──
thankYouMessage?: string; // replaces the success screen's title
locale?: string; // the checkout's language, a BCP 47 tag ('fr', 'de-DE'), usually your site's; otherwise the donor's own
thankYouRedirectUrl?: string; // where to send the donor when they close it
// ── Terms forwarding ──
// Set by integrations that collect acceptance themselves; settle stores them with the payment log.
recipientTosVersion?: string; // terms version you accepted, as site operator, e.g. '1-0'
recipientTosAcceptedAt?: string; // its ISO 8601 UTC timestamp
pluginVersion?: string; // the integration forwarding the donation — set by Pybara plugins only; skips the embed gate
// ── Environment ──
staging?: boolean; // default false — staging canisters and staging.pybara.io; never on a live site
debug?: boolean; // default false — console diagnostics
// ── Availability ──
onAvailability?: (availability: Availability) => void; // whether a donation would go through, before any click — see below
});

With onAvailability set, Pybara tells the page whether a donation would go through right now, so the page shows Pybara only when it works and the minimum before the donor meets it. It’s called once on its own, when the checkout is ready, then after each .precheck({ amount, currency }): call that whenever the form’s amount or currency changes, and only the latest is answered.

const pybara = Pybara.checkout({
recipientPrincipal, siteUrl, siteName, currency: 'EUR',
onAvailability: ({ status, message }) => {
payButton.hidden = status === 'unavailable';
payButton.disabled = status === 'below-minimum';
hint.textContent = status === 'below-minimum' ? message : '';
},
});
amountInput.addEventListener('input', () => pybara.precheck({ amount: amountInput.value }));
status Meaning What to do
available Nothing against the donation Show Pybara
unavailable Nothing on the page can fix it: the site isn’t registered, its DNS record or terms are missing, the currency isn’t served, or the page isn’t on the site’s own domain (a preview URL) Hide Pybara
below-minimum The amount is under Pybara’s minimum; minimum is { amount, currency } Keep Pybara, disable its button, show message (“Minimum €0.70”)
retry-later A rate or a DNS answer couldn’t be read right now Keep Pybara: the click tries again

message is in the donor’s language, ready to show. detail, in English, says what’s missing and who fixes it (usually the site owner, in Pybara Wallet), and is printed to the console too. reason is a code for debugging, which may change: never branch on it. Without onAvailability nothing changes — .open() checks everything at the click, as always.

A “Pybara” button, served by Pybara, that opens this checkout on the donor’s click. The recipe is on Pybara next to PayPal.

pybara.buttons({
createPayment: () => ({ amount: '25' }), // required: the donation from the form, as open() takes it, without callbacks; may return a promise
style?: { color?, shape?, height?, borderRadius? }, // 'brand' | 'black' | 'white', 'pill' | 'rect' | 'sharp', 25–55 px, px overriding shape: PayPal's names and range
hideWhenUnavailable?: boolean, // default false — the slot stays, empty, when Pybara can't be used here
onStateChange?: (availability) => void, // the availability answer, once per answer
onSuccess?, onError?, onClose?, // as open()'s
}).render('#pybara-button'); // an element or a selector; call again for another button; .destroy() removes them

Call it on the donor’s click. It resolves once the checkout surface is up; the result arrives on the callbacks. The recipe is on Your own Donate button.

pybara.open({
// ── The amount ──
amount?: string | number; // decimal string in the currency's major units: '12.34' for €12.34, '1000' for ¥1,000 — a number is turned into one; omit it and the checkout asks the donor
suggestedAmounts?: (string | number)[]; // without amount: up to four, shown as buttons beside the amount field; ask the site owner which, if any
currency?: string; // ISO 4217 — required unless set in Pybara.checkout(); a multi-currency site passes it on every call
uiPath?: string; // which of your surfaces opened the checkout — 'form' for your own (the default), 'button' when a rendered Pybara button did; a lowercase slug, logged as the donation's ui_path
// ── Recurring ──
// Omit both for a one-time donation.
frequency?: 'weekly' | 'monthly' | 'yearly' | 'every2min'; // pull interval ('every2min' is for testing)
durationMonths?: number; // 3, 6, 12 or 24, checked by the checkout — omit for an unlimited subscription
// ── Donor fields ──
// Prefill for donors you already know; every one is sanitized on the settle path.
donorIsAnonymous?: boolean; // hide the donor's identity on the public record
donorMessage?: string; // seeds the message field the donor can edit on the confirm screen
wantsTaxReceipt?: boolean; // pre-ticks "I'd like a tax receipt" — shown only when your site is linked to a nonprofit in Pybara Wallet
donorFirstName?: string;
donorLastName?: string;
donorEmail?: string; // prefills the receipt-address field — a donor who leaves an email gets a donation record
donorCompany?: string;
donorCountry?: string;
donorAddressLine1?: string; // the address fields count as provided only as a complete set
donorAddressLine2?: string;
donorAddressCity?: string;
donorAddressState?: string;
donorAddressPostalCode?: string;
donorAddressCountry?: string;
// ── Callbacks ──
onSuccess?: (result: CheckoutResult) => void; // called once the donation is confirmed on-chain
onError?: (error: Error) => void; // called when the checkout refuses (EmbeddedError, with a code) — the frame closes first
onClose?: () => void; // called when the donor closes the checkout — after success or on manual close
});

An amount is a decimal string in the currency’s major units — '12.34' for €12.34, '1000' for ¥1,000, '1500' for 1,500 Ft — the form PayPal’s API takes. Your page never needs to know how many decimals a currency has: the checkout reads the amount with the currency’s ISO 4217 minor units, and refuses one the currency can’t hold ('12.345' EUR, '1000.5' JPY). A number is accepted too and turned into its decimal text (12.34 → '12.34'); a float artefact such as 0.1 + 0.2 is refused rather than rounded.

The checkout converts the amount to USD itself, with Pybara’s own exchange rates, and if it is below the minimum a token can carry, shows that minimum to the donor, in their currency.

onSuccess receives a CheckoutResult: blockIndex (the ledger block), reference (your siteName echoed back), token (the symbol settled, e.g. 'ckUSDC'), payerPrincipal, recipientPrincipal, and recurring/frequency/durationMonths/isUnlimited echoing the call.

Errors thrown by open() are PybaraErrors with a code:

Code Meaning
INVALID_CONFIG a required field is missing or malformed — the message names it, e.g. open(): "currency" is required
GATE_REFUSED the site cannot open a checkout yet — terms not accepted, or a Pybara kill switch is off; the message says which
RECIPIENT_SUSPENDED the recipient is currently unable to accept donations
CHECKOUT_FAILED the checkout frame could not be initialised

Once the checkout is open, a refusal arrives on onError as an EmbeddedError, also with a code. The two an integration can cause:

Code Meaning
INVALID_CHECKOUT the checkout cannot accept what the page sent — the message names the field and what it must be, e.g. checkout.amount "12.345" has more decimals than EUR has (2)
RATE_UNAVAILABLE Pybara’s exchange rate for the currency could not be loaded — let the donor try again

One more comes from the page’s side: FRAME_UNAVAILABLE, when pybara.io could not be reached. The checkout then says, after 15 seconds without its first screen, that it couldn’t load, with Try again and Close; closing reports this code, so the page can offer another way to pay. A .buttons() button that doesn’t load in that time leaves its slot empty and reports unavailable to onStateChange.

Both objects are published as a JSON Schema at /pybara-js/checkout.schema.json — the root validates the checkout() config, #/$defs/payment validates an open() call. It also ships inside the npm package.