Pybara next to PayPal
A donation form that already shows PayPal Buttons gets a matching Pybara button beside them with checkout.buttons(). The button is served by Pybara, opens Pybara’s checkout on the donor’s click, and follows availability by itself.
The code
Section titled “The code”<input id="amount" inputmode="decimal" value="25"> <!-- your form's amount field --><div id="paypal-button-container"></div><div id="pybara-button"></div><p id="pybara-hint"></p>
<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 Org', recipientPrincipal: 'xxxxx-xxxxx-…', // the site owner's wallet principal currency: 'EUR',});
pybara.buttons({ style: { color: 'black', shape: 'rect', height: 45 }, // copy the PayPal button's style as it is createPayment: () => ({ amount: document.querySelector('#amount').value }), onStateChange: ({ message }) => { document.querySelector('#pybara-hint').textContent = message ?? ''; }, onSuccess: (result) => console.log('paid:', result.blockIndex),}).render('#pybara-button');
// Keep the minimum and availability current as the donor edits the amount:document.querySelector('#amount').addEventListener('input', (e) => pybara.precheck({ amount: e.target.value }));<\/script>With npm, import { Pybara } from '@pybara/pybara-js' gives the same object.
The same style options as PayPal
Section titled “The same style options as PayPal”| Option | Values | Default |
|---|---|---|
color |
'brand', 'black', 'white' — PayPal’s names; its 'gold', 'blue' and 'silver' read as 'brand' |
'brand' |
shape |
'pill', 'rect', 'sharp' |
'pill' |
height |
25–55 px, PayPal’s range | 45 |
borderRadius |
Pixels, 0 or more; overrides shape, as PayPal’s does |
— |
The button fills its container’s width and holds no text but “Pybara”: the page around it says what it’s for, as with PayPal’s default button. From the donor’s click until the checkout closes, it shows “Processing…” in the checkout’s language and takes no second click.
One-time and monthly
Section titled “One-time and monthly”Call buttons() twice on the same checkout; the second asks for a subscription:
pybara.buttons({ style, createPayment: () => ({ amount }) }).render('#pybara-once');pybara.buttons({ style, createPayment: () => ({ amount, frequency: 'monthly' }) }).render('#pybara-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.
What the button does by itself
Section titled “What the button does by itself”| Availability | The button |
|---|---|
available |
Shown, clickable |
below-minimum |
Disabled; onStateChange gets message, e.g. “Minimum €0.70”, in the donor’s language |
unavailable |
Its slot stays, empty, so the layout never moves; hideWhenUnavailable: true collapses it instead |
retry-later |
Clickable: the checkout tries again at the click |
unavailable means nothing on the page can fix it: the site isn’t registered yet, its DNS record or terms are missing, the currency isn’t one Pybara serves, or the page isn’t on the site’s own domain (a preview URL). The browser console then says, in English, which it is and who fixes it. See Options for the answer’s fields.
Before it works: the site owner’s steps
Section titled “Before it works: the site owner’s steps”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.