Skip to content

feat(billing): pay with PayPal buttons instead of a redirect - #29

Merged
kerolosxgad merged 2 commits into
mainfrom
claude/paypal-js-buttons
Dec 3, 2026
Merged

kerolosxgad merged 2 commits into
mainfrom
claude/paypal-js-buttons

Conversation

@kerolosxgad

Copy link
Copy Markdown
Member

What

Checkout on the Billing page now uses the PayPal Web SDK v6 buttons, so buyers approve in PayPal's popup without leaving Postgun. Before, every purchase redirected to PayPal and back.

How

  • The server still owns every payment. startSubscription / startLifetime create the subscription or order through REST. After approval, confirmSubscription / confirmLifetime check with PayPal (custom_id, plan, amount, status) before changing the plan. The browser only passes ids. The webhook stays the source of truth.
  • Shared confirmation. finishSubscription / finishOrder moved from the return page into src/lib/checkout.ts (server-only), used by both the buttons and /billing/return.
  • One SDK instance (paypal-payments + paypal-subscriptions) serves both buttons. This pattern matches PayPal's official v6 sample integration.
  • No new environment variables. The client ID (public by design) is passed to the page as a prop.
  • Fallback. If the SDK is blocked or PayPal isn't eligible, the page shows the existing redirect checkout. Every checkout keeps its return URLs, because the SDK's auto mode can redirect too (some mobile browsers). /billing/return handles those returns.
  • Header. Permissions-Policy now allows payment for PayPal's origins only. It was payment=().

Verified

  • npm run typecheck, npm run lint and npm run build pass.
  • Against the live sandbox SDK: createInstance with both components exposes createPayPalSubscriptionPaymentSession and createPayPalOneTimePaymentSession, and <paypal-button> renders. With an invalid client ID, findEligibleMethods throws, which takes the component to the redirect fallback.

Not tested

The app wasn't run end to end. The local database rejected the configured credentials, and no sandbox PayPal credentials were available. Before merging, run one sandbox purchase of each flow and check:

  • Monthly: the popup opens, you approve, you land on /billing?status=success, and the plan shows Pro.
  • Lifetime: same, and an active monthly subscription is cancelled.
  • The webhook arriving after the in-page confirm doesn't record the payment twice.
  • With paypal.com blocked (ad blocker), the redirect buttons appear and still complete.

Checkout now uses the PayPal Web SDK v6 buttons on the Billing page, so
buyers approve in PayPal's popup without leaving the app.

- The server still creates every subscription and order and confirms it
  with PayPal afterwards (startSubscription/confirmSubscription,
  startLifetime/confirmLifetime). The browser only passes ids.
- Confirmation logic moves to src/lib/checkout.ts, shared with
  /billing/return.
- One SDK instance serves both buttons (paypal-payments and
  paypal-subscriptions). The client ID is passed as a prop, so no new
  environment variable is needed.
- If the SDK is blocked or PayPal isn't eligible, the page falls back to
  the existing redirect checkout. Return URLs stay on every checkout
  because the SDK's auto mode can also redirect.
@kerolosxgad
kerolosxgad merged commit 138f7d7 into main Dec 3, 2026
1 check passed
@kerolosxgad
kerolosxgad deleted the claude/paypal-js-buttons branch December 3, 2026 15:54
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.

1 participant