@pybara/donate-widget
v1.0.0-beta.13
Published
Embeddable donation widget for Internet Computer crypto payments — the ready-made form; for a custom form use @pybara/pybara-js
Downloads
1,424
Maintainers
Readme
Pybara Donate Widget
A donation widget for any website: visitors give in crypto on the Internet Computer, from their own wallet, and the donation is paid to yours. One script, no server, no WordPress needed.
Building your own form, or taking payments beyond donations? Use
@pybara/pybara-js—Pybara.checkout()opens the same checkout surface over your UI. This package is the ready-made donation form.
Quick start
<div id="pybara-donate"></div>
<script src="https://cdn.jsdelivr.net/npm/@pybara/donate-widget@beta/dist/pybara-donate.iife.js"></script>
<script>
PybaraDonate.init({
target: '#pybara-donate', // where the widget renders
recipientPrincipal: 'xxxxx-xxxxx-...', // your Pybara Wallet's principal
siteUrl: 'https://example.com', // your site's address
siteName: 'Example Charity', // the name donors see
});
</script>These four options are required; every other one is optional, with the defaults in Configuration.
@beta follows the latest beta. To stay on one version, use it instead, for example @1.0.0-beta.1.
ES module
In a bundled app (Vite, Next.js, …), install the package instead of the script tag:
npm install @pybara/donate-widget@betaimport { init } from '@pybara/donate-widget';
init({
target: '#pybara-donate',
recipientPrincipal: 'xxxxx-xxxxx-...',
siteUrl: 'https://example.com',
siteName: 'Example Charity',
});The package also exports the DonationWidget class (what init returns), destroyAll(), and the config types — all typed.
Before it shows
The widget stays hidden until your site is set up in Pybara Wallet, under Manage › Sites › Add a site without a plugin:
- Your site's DNS record lists your wallet. This needs a domain of your own: a platform subdomain (
*.replit.appand the like) cannot hold the record. - You accept the Pybara Terms of Service for that site, in the same place.
Until then, and whenever Pybara pauses the widget, nothing is shown, and your browser's console says why. The checkout itself pays only a wallet your site's DNS record lists, whatever the page does.
Pricing
A single platform fee per donation: no monthly fees, no setup fees. The rate is a flat 1% for every site, fixed in the settlement canister's code, which is public and cannot change.
The fee also covers the network fees. Donors give the exact amount they choose, and you receive your full share: exactly 99% of every donation. The split is made on-chain by a publicly auditable canister whose code cannot change, and which applies the same 1% to every split.
The one exception is AutoStable: if you have a token converted to a stablecoin as it arrives, set in Pybara Wallet, the conversion's cost is deducted on top of the platform fee.
Configuration
Required
| Option | Type | Description |
|--------|------|-------------|
| target | string \| HTMLElement | CSS selector or element to render into |
| recipientPrincipal | string | Your Pybara Wallet's principal, the one your DNS record lists |
| siteUrl | string | Your site's address, e.g. https://example.com: the origin of the page the widget is on, or the checkout refuses the donation |
| siteName | string | The name donors see |
Optional
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| presetAmounts | number[] | suited to the currency | Up to 6 preset amounts, in the display currency, each above 0 — the checkout shows its own minimum. Default: about $5, $10, $25, $50 in round figures ([5, 10, 25, 50] in EUR, [1000, 2000, 5000, 10000] in JPY) |
| allowCustom | boolean | true | Let donors enter their own amount |
| allowRecurring | boolean | true | Offer recurring donations |
| defaultFrequency | string | 'monthly' | 'weekly', 'monthly' or 'yearly' |
| defaultDurationInMonths | number \| null | 12 | The recurring duration preselected: 3, 6, 12 or 24 months, or null for no end date; donors can change it |
| tokens | string[] | All supported | Tokens donors may give, of those Pybara currently offers: 'ckUSDC', 'ckUSDT', 'ckBTC', 'ckETH', 'ICP' |
| title | string | — | Shown above the amounts |
| description | string | — | Shown below the title |
| buttonLabel | string | Donate, in the widget's language | The button's label |
| thankYouMessage | string | — | Replaces the success screen's title, which is otherwise shown in the donor's language |
| donorMessage | string | — | Prefills the message field donors can write to you on the confirm screen — max 500 characters |
| donorEmail | string | — | Prefills the receipt-address field on the confirm screen — donors who leave an email get a payment record once the donation settles |
| wantsTaxReceipt | boolean | — | Pre-ticks the "I'd like a tax receipt" checkbox on the confirm screen — shown only when your site is linked to a nonprofit in Pybara Wallet; the donor's own choice is what counts |
| thankYouRedirectUrl | string | — | Where to send donors afterwards |
| primaryColor | string | '#7c3aed' | Accent colour (hex) |
| theme | 'light' \| 'dark' \| 'auto' | 'light' | 'auto' follows your page's background and its theme switcher |
| currency | string | 'USD' | Display currency (ISO 4217), e.g. 'EUR' |
| locale | string | Browser's | Interface language: 'en', 'fr', 'de', 'es', 'it', 'pt', 'nl', 'pl', 'ro', 'ja', 'ko' or 'zh-CN' |
| fontUrl | string | — | A .woff2 font of your own; none is loaded otherwise |
| onSuccess | function | — | Called once the donation is made |
| onError | function | — | Called on an error |
| onClose | function | — | Called when the checkout is closed without donating |
| staging | boolean | false | Use Pybara's staging environment, for testing |
| debug | boolean | false | Log details to the console |
The same options are published as a JSON Schema at docs.pybara.com/donate-widget/options.schema.json — for editors and agents that validate a config before writing it. A copy ships in the package as options.schema.json, versioned with the code.
Example with options
PybaraDonate.init({
target: '#pybara-donate',
recipientPrincipal: 'xxxxx-xxxxx-...',
siteUrl: 'https://example.com',
siteName: 'Example Charity',
primaryColor: '#e11d48',
currency: 'EUR',
locale: 'fr',
presetAmounts: [5, 10, 25],
tokens: ['ckUSDC', 'ICP'],
buttonLabel: 'Soutenir',
});Theming
light(default) anddarkcards, orauto, which samples your page's background and follows your theme switcher and the visitor's system setting.- The accent colour is adjusted where needed so text stays readable on the card; buttons keep your exact colour.
- A soft shadow lifts the card off your page. Already showing the widget inside a card of your own? Turn it off, or set your own, on the target element or any parent:
#pybara-donate { --pybara-donate-shadow: none; }. - Your site's styles stay out: the card sets its own font, line height and text styles, so a reset such as
div { line-height: 1 }doesn't reach inside it.
Languages
English, French, German, Spanish, Italian, Portuguese, Dutch, Polish, Romanian, Japanese, Korean and Chinese (simplified), chosen from the visitor's browser unless locale is set. The checkout follows the same language.
Error reports
When the checkout can't open, or fails once open, the widget tells Pybara through @pybara/pybara-js, so a problem can be fixed before you have to write in: the error's code and message, your site's address, the platform and plugin version, and whether it was a donation. Nothing about the donor, and no IP address is stored. Details: the "Error reports" section of @pybara/pybara-js's README.
Content Security Policy
On a site with a strict Content Security Policy, allow:
script-src:https://cdn.jsdelivr.netframe-src:https://pybara.io, where donors payconnect-src:https://icp-api.ioandhttps://*.raw.icp0.io, for Pybara's settings, andhttps://py6mw-3yaaa-aaaas-amwhq-cai.icp0.io, for error reportsimg-src:https://assets.pybara.com
Learn more
License
MIT
