Skip to content

WEBDEV-9053: Migrate the donation form payment layer into elements - #103

Open
jbuckner wants to merge 1 commit into
WEBDEV-9052-migrate-edit-donationfrom
WEBDEV-9053-migrate-payment-layer
Open

jbuckner wants to merge 1 commit into
WEBDEV-9052-migrate-edit-donationfrom
WEBDEV-9053-migrate-payment-layer

Conversation

@jbuckner

@jbuckner jbuckner commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

WEBDEV-9053. Stacked on #100. Fourth of the five in WEBDEV-8602.

The payment layer of donation-form: the Braintree manager, payment clients, the five provider handlers (credit card, PayPal, Venmo, Apple Pay, Google Pay), the recaptcha manager and the Venmo session restoration handler. It lands under src/elements/ia-donation-form/braintree/. No custom elements in this one, so no story, it's the logic and its tests. The flow handlers go with the modals in the last rung since they render them.

What changed beyond the move:

  • Real @types instead of the vendored 2020 copies. @types/braintree-web 3.143 splits the library module (typeof braintree.client, the thing with create()) from the instance (braintree.Client), where the old copy conflated them. PaymentClientsInterface and the handlers are typed that way now, and everything imports the types (import type * as braintree from 'braintree-web') rather than leaning on the UMD global. A globals.d.ts types window.braintree and window.paypal, which the CDN scripts create. The @types packages are regular dependencies because the published d.ts files reference them.
  • fee_amount_covered is calculated from the fields. submitDonation already recomputed the total because donationInfo can arrive as a plain object (Venmo in Chrome) with none of the class getters. The fee custom field read the feeAmountCovered getter and would have been undefined in that case. Both are calculated the same way now, with a test using a plain object.
  • The hosted fields retry is tidier. No async promise executor, and the timeout is cleared in a finally so a lost race can't leave a rejection with nowhere to go. Same behavior: our own timer races Braintree's create, a timer win retries, up to the max.
  • The recaptcha onload callback is namespaced (iaDonationFormGrecaptchaLoaded). The old package uses donationFormGrecaptchaLoadedCallback, and a page loading both during the switch-over would have had them overwrite each other's callback and hang one form's recaptcha.
  • HostedFieldContainer doesn't import BadgedInput. It only ever set .error on the parent, so it types the parent as an element with an error flag. The badged input element itself arrives with the form elements.
  • Enums are as const objects plus a type, as in the earlier rungs.

Tests moved from web-test-runner and sinon to Vitest, 85 of them. The mocks for the payment libraries live in braintree/test-helpers/*.test-helpers.ts, which the package's !dist/**/*.test* filter keeps out of the published tarball. The Apple Pay session mock now defines STATUS_SUCCESS and STATUS_FAILURE, which the old one didn't, so those assertions compared undefined to undefined and passed regardless.

Verified locally: build, full suite 791 passing, eslint and prettier clean, no circular dependencies.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QnX6VHo3EJRzcKfhzBChCf

The Braintree manager, payment clients and the five provider handlers
(credit card, PayPal, Venmo, Apple Pay, Google Pay) land under
src/elements/ia-donation-form/braintree/, with the recaptcha manager, the
Venmo session restoration handler and DonationFormError alongside. No
custom elements in this rung. The flow handlers go with the modals next.

The vendored 2020 braintree-web and paypal-checkout-components d.ts files
are replaced by the real @types packages, which split the library module
(typeof braintree.client) from the instance (braintree.Client), so the
clients and handlers are typed that way. The fee_amount_covered custom
field is calculated from the fields like the total already was, since
donationInfo can arrive as a plain object. The hosted fields retry no
longer uses an async promise executor and clears its timer whichever way
the race goes. The recaptcha onload callback global is namespaced so it
can't collide with the old package's on a page that loads both.

Tests move from web-test-runner and sinon to Vitest, with the payment
library mocks under test-helpers/.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QnX6VHo3EJRzcKfhzBChCf
@jbuckner
jbuckner added this pull request to stack #101 September 15, 2026 05:05
@github-actions

Copy link
Copy Markdown
PR Preview Action v1.8.1

🚀 View preview at
https://internetarchive.github.io/elements/pr/pr-103/

Built to branch ghpages at 2026-09-15 05:06 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.29452% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.86%. Comparing base (8744ccc) to head (ff43adc).

Files with missing lines Patch % Lines
...aintree/test-helpers/mock-managers.test-helpers.ts 82.14% 15 Missing ⚠️
...providers/venmo/venmo-restoration-state-handler.ts 74.07% 5 Missing and 2 partials ⚠️
...raintree/test-helpers/mock-clients.test-helpers.ts 92.78% 7 Missing ⚠️
...ts/ia-donation-form/braintree/braintree-manager.ts 90.24% 2 Missing and 2 partials ⚠️
src/elements/ia-donation-form/recaptcha-manager.ts 89.65% 0 Missing and 3 partials ⚠️
...ts/ia-donation-form/braintree/payment-providers.ts 93.54% 2 Missing ⚠️
...ntree/payment-providers/credit-card/credit-card.ts 94.73% 1 Missing and 1 partial ⚠️
...-form/braintree/payment-providers/paypal/paypal.ts 85.71% 1 Missing and 1 partial ⚠️
...ents/ia-donation-form/braintree/payment-clients.ts 97.61% 1 Missing ⚠️
...roviders/apple-pay/apple-pay-session-datasource.ts 96.96% 0 Missing and 1 partial ⚠️
... and 1 more
Additional details and impacted files
@@                          Coverage Diff                          @@
##           WEBDEV-9052-migrate-edit-donation     #103      +/-   ##
=====================================================================
+ Coverage                              86.83%   87.86%   +1.02%     
=====================================================================
  Files                                     78      100      +22     
  Lines                                   2530     3114     +584     
  Branches                                 548      611      +63     
=====================================================================
+ Hits                                    2197     2736     +539     
- Misses                                   178      212      +34     
- Partials                                 155      166      +11     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
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.

2 participants