feature(PayPal): collect and send device_info to determine app switch eligibility#1600
Open
santugowda wants to merge 5 commits into
Open
feature(PayPal): collect and send device_info to determine app switch eligibility#1600santugowda wants to merge 5 commits into
santugowda wants to merge 5 commits into
Conversation
… eligibility Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
0025eb8 to
f30f4ca
Compare
Contributor
|
@santugowda please follow the |
- Wrap ActivityManager.getMemoryInfo() in withContext(Dispatchers.IO) to avoid Binder IPC on Dispatchers.Main - Switch getJSONObject → optJSONObject in injectDeviceInfo for defense-in-depth (outer guard already ensures the key exists, but this makes the function safe in isolation) - Extract hardcoded "ANDROID" string to OS_TYPE_VALUE constant in PayPalRequest - Rename MODEL_KEY → DEVICE_MODEL_KEY for consistency with sibling constants - Promote activityManager to class field in unit tests with non-zero default memory values in beforeEach, removing per-test mock duplication - Add instrumentation test for PayPalVaultRequest app switch nested structure - Add unit test for vault path device_info injection - Add unit test for no-op when app switch enabled but no app link present Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Author
|
/inner source |
Author
|
@anbojorquez @ayer-ribeiro could you please review this PR? Thanks! |
…eInfo ActivityManager.getMemoryInfo(), Build.MODEL, and JSON operations are not I/O-bound; no dispatcher switch is needed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Author
|
/ready |
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.
Summary of changes
Sends device information as a nested
app_switch_contextobject in PayPal Hermes requests whenenablePayPalAppSwitchis enabled. This data allows the PayPal server to determine app switch eligibility.Background
The PayPal App Switch flow launches the PayPal native app directly, bypassing browser checkout. On low-RAM devices, running two apps simultaneously (the merchant app + PayPal app) can cause the OS to kill the merchant app in the background due to memory pressure — leading to a broken checkout experience when the user tries to return.
The PayPal server uses
memory_available_mbandmemory_total_mbto gate app switch eligibility — if the device doesn't have enough free RAM, the server skips app switch and falls back to browser checkout (Chrome Custom Tab), which is lighter on memory.Currently the BT Android SDK sends
app_switch_context(OS type, OS version, app link URL) but not device memory info. Withoutdevice_info, the server cannot make the eligibility decision and defaults to browser checkout.This PR adds collection and injection of:
model— device model (e.g.SM-A166U) for any device-specific overrides the server may havememory_available_mb— free RAM at request timememory_total_mb— total device RAMThese are injected into the request body under
app_switch_context.device_info, giving the server everything it needs to decide whether to serve an app switch URL or a browser URL in the response.JSON structure sent to BTGW:
{ "launch_paypal_app": true, "app_switch_context": { "device_info": { "model": "SM-A166U", "memory_available_mb": 350, "memory_total_mb": 4096 }, "native_app": { "app_url": "https://...", "os_type": "ANDROID", "os_version": "35" } } }Changes:
PayPalVaultRequest/PayPalCheckoutRequest: replaced flatos_type,os_version,merchant_app_return_urlkeys with nestedapp_switch_context.native_appobjectPayPalInternalClient:injectDeviceInfo()addsdevice_info(model, memory_available_mb, memory_total_mb) intoapp_switch_contextPayPalRequest: updated constants for new nested key structureSteps to Test
enablePayPalAppSwitch = trueonPayPalCheckoutRequestorPayPalVaultRequestpaypal_hermes/create_payment_resourceorpaypal_hermes/setup_billing_agreementapp_switch_context.device_infois present in the request body withmodel,memory_available_mb, andmemory_total_mbAI Usage
Which AI Agent Was Used?
How was AI used?
Code generation, cross-codebase analysis (Android SDK, BTGW, backend), refactoring from flat to nested JSON structure, and writing tests.
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.Demo
Request body sent (key fields):
{ "launch_paypal_app": true, "app_switch_context": { "native_app": { "app_url": "https://mobile-sdk-demo-site-838cead5d3ab.herokuapp.com/braintree-payments", "os_type": "ANDROID", "os_version": "36" }, "device_info": { "model": "SM-A166U", "memory_available_mb": 900, "memory_total_mb": 10000 } } }token=232345522J779231L
EC flow
paypal_appswitch_test.mp4
Billing Successful app-switch
BillingWithSupportedDevice.mp4
Billing on Low Ram device not app-switching
BillingWithLowRamDevice.mp4
Inner Source Checklist