Repository navigation
feat(billing): pay with PayPal buttons instead of a redirect - #29
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
startSubscription/startLifetimecreate the subscription or order through REST. After approval,confirmSubscription/confirmLifetimecheck with PayPal (custom_id, plan, amount, status) before changing the plan. The browser only passes ids. The webhook stays the source of truth.finishSubscription/finishOrdermoved from the return page intosrc/lib/checkout.ts(server-only), used by both the buttons and/billing/return.paypal-payments+paypal-subscriptions) serves both buttons. This pattern matches PayPal's official v6 sample integration.automode can redirect too (some mobile browsers)./billing/returnhandles those returns.Permissions-Policynow allowspaymentfor PayPal's origins only. It waspayment=().Verified
npm run typecheck,npm run lintandnpm run buildpass.createInstancewith both components exposescreatePayPalSubscriptionPaymentSessionandcreatePayPalOneTimePaymentSession, and<paypal-button>renders. With an invalid client ID,findEligibleMethodsthrows, 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:
/billing?status=success, and the plan shows Pro.paypal.comblocked (ad blocker), the redirect buttons appear and still complete.