feat(PayPal): add PendingPaymentStore for auto-link session persistence#1640
Conversation
Introduces PendingPaymentStore, the in-memory session store used by the PayPal auto-link on manual return feature to track a pending billing agreement token across the app-switch round trip. Part 1 of a multi-PR split of the original PayPal auto-link on manual return feature (previously braintree#1633).
|
I see this PR doesn't follow our standard template. Please take a look at this PR to see our inner sourcing process and follow the steps as listed. Thank you! |
|
To add to @saralvasquez comment, this also is pointing to the main branch instead of a feature branch. Based on the PR description I am guessing claude nuked the template. Please open following the correct template and update the base branch to reflect that this will go into a feature branch before main. |
|
Thanks for the feedback! Quick clarification on the base branch: I'm contributing via a fork ( For reference, the original #1633 /#1634 split used the same approach: both targeted If you'd prefer this series (5 PRs total) to target a dedicated integration branch instead of |
|
That's fair @pedrofsn - I have gone ahead and created |
Thanks @jaxdesmarais, appreciate you setting that up! Rebased this PR onto Kicking off the inner source process now: /inner source PRs 2-5 in this series will also target this branch going forward. |
|
Marking this as draft while it's pending tech lead review, per the inner source process. |
Summary of changes
Adds
PendingPaymentStore, the in-memory session store used by the PayPal auto-link on manual return feature to carry a pending billing agreement token across the App Switch round trip.Background
When a user approves a PayPal Billing Agreement (BA) via App Switch and returns to the merchant app, the return can fail to convert into a tokenized payment method in two cases:
Today, when
handleOpen(url)is never called, the SDK has no reference to the approved BA token and cannot tokenize it — the BA is approved on PayPal's side but the merchant never receives a nonce.This PR is PR 1 of a multi-PR series that adds "auto-link on manual return": the SDK persists the BA token before app switch and retries tokenization when the user returns, regardless of how they returned. This PR introduces only the storage primitive; no tokenization logic and no
PayPalClientwiring are included here, so each PR in the series stays independently reviewable.Changes:
PendingPaymentStore(internal, in-memory, process-level singleton): holds aPendingSession(BA token + correlation ID + merchant account ID + intent + payment type + timestamp/TTL) and aCompletableDeferred<PayPalAccountNonce>used by later PRs to guarantee exactly one BTGW tokenization call across the multiple entry points (return-handling and re-click) that can race to trigger it.Steps to Test
This PR only adds a storage primitive with no wiring into the checkout flow yet, so it has no end-user-visible behavior to exercise manually. Verification is via the included unit tests:
./gradlew :PayPal:testDebugUnitTest --tests "*.PendingPaymentStoreUnitTest"PendingSession.isExpired()correctly reflects TTL boundaries,getOrCreateDeferred()returns the same deferred to a second caller while the first remains the initiator, andclear()resets all fields and cancels any in-flight deferred.AI Usage
Which AI Agent Was Used?
How was AI used?
Code generation and unit test authoring for
PendingPaymentStore, based on an existing HLD/LLD design and a prior reference implementation for this feature.Estimated AI Code Contribution
Checklist
Authors
Inner Source Process
Internal to PayPal contributors should fill out this section. All others can delete.
PR should follow these steps before codeowners review will begin:
/inner sourceon this PR — this will automatically add theinner sourceandtech lead review requiredlabels. Open the PR in a draft state./readyon this PR — this will automatically remove thetech lead review requiredlabel. Move the PR to ready to review.Inner Source Checklist
PR series
Part of a 5-PR series re-splitting the original "auto-link on manual return" feature (previously opened as #1633 and #1634, closed for being too large to review):
PendingPaymentStore(session persistence)AutoLinkTokenizeUseCase(tokenization logic) - stacked on this PRPayPalClientwiring (handleReturnToApp + re-click) - stacked on PR 2PayPalLauncher/PayPalPaymentAuthResult/Demo wiring - stacked on PR 3AppForegroundDetectormerchant-independent foreground trigger - stacked on PR 4Please review/merge in order 1 -> 5.