Skip to content

fea: add PIX donation flow to /contributing page#258

Open
marco-souza wants to merge 5 commits intomainfrom
feat/pix-donations
Open

fea: add PIX donation flow to /contributing page#258
marco-souza wants to merge 5 commits intomainfrom
feat/pix-donations

Conversation

@marco-souza
Copy link
Copy Markdown
Contributor

Summary

Implements self-service PIX donations directly on the /contributing page, replacing the old contact-form-based flow.

Visitors can now select a suggested amount (R$ 25, R$ 50, R$ 100) or enter a custom value (R$ 5–R$ 10,000) and instantly receive a scannable QR code + Copia e Cola to complete their donation — no backend, no contact form needed.

Closes #248

What's Included

Core Libraries

  • src/lib/pix.ts — EMV QRCPS-MPM PIX BR Code generator with CRC16-CCITT checksum
  • src/lib/qrcode.ts — Zero-dependency QR code SVG generator (byte mode, EC level M, versions 1–10)

API Endpoints (Cloudflare Workers)

  • GET /api/pix-qr?amount=X — Returns QR code as image/svg+xml
  • GET /api/pix-result?amount=X — Returns HTML fragment (QR img + Copia e Cola + copy button)
  • Caching: ETag-based with 304 support, long-lived CDN cache headers

UI Components

  • DonationForm.astro (Alpine.js) — Amount selector with validation, suggested buttons, large donation info message
  • DonationResult.astro (htmx) — Lazy-fetched result pane with loading skeleton, clipboard copy, Alpine re-initialization after swap

Integration

  • /contributing page updated — PIX section immediately after hero, highlighted background, responsive grid layout
  • i18n — 24 new keys under contributing.donations.pix.* (all pt-BR)
  • No-JS fallback<noscript> with contact link
  • Dark mode — QR contrast adjustments
  • Large donations — Friendly message + link to /contact for amounts > R$ 10,000

Tests (56 passing)

Suite Count Type
pix.test.ts 15 Unit (PIX BR Code)
qrcode.test.ts 16 Unit (QR SVG)
pix-endpoints.test.ts 25 Integration (endpoints)
pix-donation.spec.ts 8 scenarios E2E (Playwright)

Files Changed

  • 15 files, +2,471 −13 lines
  • Dependencies added: alpinejs, htmx.org

How to Test

bun dev                    # Start dev server → http://localhost:4321/contributing
bun test src/lib/*.test.ts src/__tests__/*.test.ts  # 56 tests
bun run build              # Verify production build

Screenshots

Add screenshots after running bun dev and visiting /contributing

Implements self-service PIX donations with instant QR code generation:

**Libraries (src/lib/)**
- pix.ts: EMV QRCPS-MPM PIX BR Code generator with CRC16-CCITT
- qrcode.ts: Zero-dependency QR code SVG generator (byte mode, EC level M)

**API Endpoints (src/pages/api/)**
- /api/pix-qr: Returns QR code SVG with caching (ETag/304)
- /api/pix-result: Returns HTML fragment with QR img + Copia e Cola

**Components (src/components/)**
- DonationForm.astro: Alpine.js amount selector (buttons + custom input)
- DonationResult.astro: htmx-powered result pane with Alpine re-init

**Page Integration**
- /contributing: Replaced old CTA-based donations with PIX section
- i18n: Added 24 new keys under contributing.donations.pix.*

**Tests (56 passing)**
- pix.test.ts: 15 unit tests for PIX BR Code generation
- qrcode.test.ts: 16 unit tests for QR code SVG
- pix-endpoints.test.ts: 25 integration tests for API endpoints
- pix-donation.spec.ts: Playwright E2E smoke test

Dependencies added: alpinejs, htmx.org
Closes #248
@github-actions
Copy link
Copy Markdown
Contributor

❌ Playwright E2E — Some tests failed

Detail Link
Workflow run View run
HTML report Download the playwright-report artifact from the run page above
Traces & videos Download the playwright-results artifact (attached when tests fail)

How to view the HTML report locally:

  1. Download and unzip the playwright-report artifact.
  2. Run bunx playwright show-report <path-to-report> to open it in your browser.

Traces and videos are captured on first retry (failures only).

…ntive text

- Remove client:load from DonationForm (Astro components can't be hydrated)
- Move Alpine initialization to Layout.astro (global Alpine.start())
- Fix TypeScript-in-JS syntax error in DonationForm inline script
- Use data-* attributes for i18n strings instead of define:vars
- Use is:inline scripts for Alpine registration and htmx hooks
- Change layout to single-column: result replaces form area inline
- Add incentive text explaining how donations fund the community
- 56 tests passing, build clean, lint OK
@github-actions
Copy link
Copy Markdown
Contributor

❌ Playwright E2E — Some tests failed

Detail Link
Workflow run View run
HTML report Download the playwright-report artifact from the run page above
Traces & videos Download the playwright-results artifact (attached when tests fail)

How to view the HTML report locally:

  1. Download and unzip the playwright-report artifact.
  2. Run bunx playwright show-report <path-to-report> to open it in your browser.

Traces and videos are captured on first retry (failures only).

Swap the client-side interactivity stack from Alpine.js + htmx to Datastar,
which provides both reactivity (signals) and hypermedia in a single library.

Changes:
- Remove alpinejs, htmx.org dependencies
- Add @sudodevnull/datastar and @starfederation/datastar-sdk
- Replace DonationForm.astro + DonationResult.astro with single
  DonationSection.astro using Datastar signals and attributes
- Layout loads Datastar globally via module import
- All interactivity uses data-* attributes:
  data-signals (state), data-bind (two-way binding),
  data-on:click (events), data-show (visibility),
  data-text (content), data-class (class toggling)
- PIX code generated client-side via bundled pix.ts library
- QR code loaded via <img> pointing to /api/pix-qr endpoint
- i18n strings passed via define:vars script globals

Build: passes, Tests: 56/56, Lint: clean
@github-actions
Copy link
Copy Markdown
Contributor

❌ Playwright E2E — Some tests failed

Detail Link
Workflow run View run
HTML report Download the playwright-report artifact from the run page above
Traces & videos Download the playwright-results artifact (attached when tests fail)

How to view the HTML report locally:

  1. Download and unzip the playwright-report artifact.
  2. Run bunx playwright show-report <path-to-report> to open it in your browser.

Traces and videos are captured on first retry (failures only).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PIX for donations

1 participant