Skip to content

Your own Donate button

A site with a Donate button of its own — a tip jar, a “Support us” link, a donation form’s submit — opens Pybara’s checkout from its click with checkout.open(). The button stays yours: its text, its style, its place on the page.

<button id="donate">Donate</button>
<script src="https://cdn.jsdelivr.net/npm/@pybara/pybara-js@0.16/dist/pybara-js.iife.js"><\/script>
<script>
const pybara = Pybara.checkout({
siteUrl: 'https://example.com', // this site, as registered in Pybara Wallet
siteName: 'Example Charity',
recipientPrincipal: 'xxxxx-xxxxx-…', // the site owner's wallet principal
currency: 'USD',
});
document.querySelector('#donate').addEventListener('click', () => pybara.open({}));
<\/script>

With npm, import { Pybara } from '@pybara/pybara-js' gives the same object.

checkout() binds the site config once — background work (registry lookups, terms check, frame prewarm) starts there, so open() is fast on the donor’s click. One donation attempt per open() call.

Called without an amount, as above, open() asks the donor how much, before the wallet. Pass up to four suggestedAmounts, in the site’s currency, and they show as buttons beside the amount field:

donateButton.addEventListener('click', () => pybara.open({ suggestedAmounts: ['5', '10', '25'] }));

Without them, the donor types the amount: the checkout has no presets of its own. Below the minimum, it shows the minimum in the donor’s currency.

A donation form that has already picked an amount passes it, and the checkout goes straight to the wallet:

await pybara.open({
amount: '25', // a decimal string, in the currency
onSuccess: (result) => { /* result.blockIndex, result.token, result.payerPrincipal… */ },
onError: (err) => { /* err.code: 'INVALID_CHECKOUT' | 'RATE_UNAVAILABLE' | … */ },
onClose: () => {},
});

Amounts are decimal strings in the currency’s major units — '12.34', '1000' for JPY — never cents: see Amounts. The callbacks work the same with or without an amount.

Donations are one-time unless you pass frequency. To offer monthly giving too, add a second button:

monthlyButton.addEventListener('click', () => pybara.open({ frequency: 'monthly' }));

frequency is 'weekly', 'monthly' or 'yearly'; add durationMonths (3, 6, 12 or 24) for a subscription with an end, or omit it for one that runs until cancelled. The donor confirms the schedule in the checkout.

Code can’t do these. Whoever adds Pybara to the site relays the site owner’s three steps to them, once: a Pybara Wallet with the site added, its DNS record, and the Pybara Terms of Service.