From 3e1977b1e4af505558712ed826ab6e7dee47763f Mon Sep 17 00:00:00 2001 From: Jakub Korytko Date: Thu, 3 Dec 2026 13:03:50 +0100 Subject: [PATCH] feat: make Google OPC support opt-in --- README.md | 8 ++++++-- android/src/main/java/com/expensify/wallet/Utils.kt | 3 +++ .../src/main/java/com/expensify/wallet/WalletModule.kt | 4 ++-- .../main/java/com/expensify/wallet/model/CardData.kt | 1 + apps/common-app/src/CONST.ts | 1 + docs/UAPP.md | 10 ++++++---- src/NativeWallet.ts | 1 + 7 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4e501c82..312fcdfb 100644 --- a/README.md +++ b/README.md @@ -183,7 +183,7 @@ The library offers functions for seamless integration and use of the Apple Walle | **getCardStatusBySuffix** | Retrieves the current status of a card in the wallet. | `lastDigits: string`
(The last few digits of the card number) | `CardStatus` | ✅ | ✅ | | **getCardStatusByIdentifier** | Returns the state of a card based on a platform-specific identifier. On Android, it's `Token Reference ID` and on iOS, it's `Primary Account Identifier`. | `identifier: string`,
`tsp: string` | `CardStatus` | ✅ | ✅ | | **hasEligibleTokenizationTarget** | Checks whether the card can still be added to a Google Wallet target (the phone or a paired wearable). Google recommends it for the "Add to Google Wallet" button when wearables are supported, because a card already on the phone can still be added to a watch. | `last4Digits: string`,
`network: string`,
`issuerName: string` | `boolean` | ❌ | ✅ | -| **addCardToGoogleWallet** | Initiates native Push Provisioning flow for adding a card to the Google Wallet. Requires a handler that returns the payment credentials for the UAPP flow. [Learn more →](./docs/UAPP.md) | `data`: `AndroidCardData`,
`handlePaymentCredentials`: `(data: onPaymentCredentialsRequestPayload) => Promise` | `TokenizationStatus` | ❌ | ✅ | +| **addCardToGoogleWallet** | Initiates native Push Provisioning flow for adding a card to the Google Wallet. Requires a handler that returns the payment credentials, called only for cards with `isGoogleOpaquePaymentCardSupported: true` (UAPP flow). [Learn more →](./docs/UAPP.md) | `data`: `AndroidCardData`,
`handlePaymentCredentials`: `(data: onPaymentCredentialsRequestPayload) => Promise` | `TokenizationStatus` | ❌ | ✅ | | **resumeAddCardToGoogleWallet** | Resumes the Push Provisioning flow for adding a card to the Google Wallet using existing token reference ID. | `data`: `AndroidResumeCardData` | `TokenizationStatus` | ❌ | ✅ | | **listTokens** | Lists all tokens currently stored in the Google Wallet. | None | `TokenInfo[]` | ❌ | ✅ | | **listAppleWalletPasses** | Lists Apple Wallet Secure Element passes available to the app, including activation state and whether the pass is remote (for example on Apple Watch). Filter the result for `activationState === 'requireActivation'` or `activationState === 'pending'` to build a pending-cards UI. | None | `IOSWalletPass[]` | ✅ | ❌ | @@ -203,7 +203,7 @@ A Wallet decline resolves `{ status: 'error', errorDomain, errorCode }` instead | Type | Description | Fields | |------|-------------|--------| | **AndroidWalletData** | Specific information for Android devices required for wallet transactions. | `deviceID: string`,
`walletAccountID: string` | -| **AndroidCardData** | Data related to a card that is to be added on Android platform wallets. | `network: string`,
`opaquePaymentCard: string`,
`cardHolderName: string`,
`lastDigits: string`,
`userAddress: UserAddress`,
`isVirtualCard?: boolean`,
`isBounceProvisioned?: boolean` | +| **AndroidCardData** | Data related to a card that is to be added on Android platform wallets. | `network: string`,
`opaquePaymentCard: string`,
`cardHolderName: string`,
`lastDigits: string`,
`userAddress: UserAddress`,
`isVirtualCard?: boolean`,
`isBounceProvisioned?: boolean`,
`isGoogleOpaquePaymentCardSupported?: boolean` | | **AndroidResumeCardData** | Simplified data structure for resuming card addition to Google Wallet using existing token reference ID. | `network: string`,
`tokenReferenceID: string`,
`cardHolderName?: string`,
`lastDigits?: string` | | **AndroidPaymentCredentialsResponse** | Response object containing encrypted payment credentials for UAPP flow. [Learn more →](./docs/UAPP.md) | `opaquePaymentCard: string`,
`googleOpaquePaymentCard: string` | | **onPaymentCredentialsRequestPayload** | Payload received when Google Wallet requests payment credentials during UAPP provisioning. [Learn more →](./docs/UAPP.md) | `requestId: string`,
`serverSessionId: string`,
`walletId: string`,
`tokenRequestorId: string \| null`,
`opaquePaymentCard: string` | @@ -240,6 +240,10 @@ Indicates whether the card has been provisioned through "bounce provisioning". B This flag helps Google Wallet track cards that were initially added through the Google Wallet app but require additional app-specific configuration or verification. When set to `true`, it signals that this card was previously provisioned through the Google Wallet interface and is now being completed or updated through your application. +#### `isGoogleOpaquePaymentCardSupported?: boolean` + +Tells Google Wallet that your backend can generate the Google OPC, which turns on the UAPP flow for this card. Defaults to `false`, so Google Wallet only asks for the TSP OPC and the payment credentials handler is not called. Set it to `true` only for cards your backend supports UAPP for. See [UAPP](./docs/UAPP.md). + ## Card Status | Type | Possible Values | diff --git a/android/src/main/java/com/expensify/wallet/Utils.kt b/android/src/main/java/com/expensify/wallet/Utils.kt index 7bce2507..54cd7fab 100644 --- a/android/src/main/java/com/expensify/wallet/Utils.kt +++ b/android/src/main/java/com/expensify/wallet/Utils.kt @@ -31,6 +31,8 @@ object Utils { val isVirtual = if (hasKey("isVirtualCard")) this.getBoolean("isVirtualCard") else false val isBounce = if (hasKey("isBounceProvisioned")) this.getBoolean("isBounceProvisioned") else false + val isGoogleOpcSupported = + if (hasKey("isGoogleOpaquePaymentCardSupported")) this.getBoolean("isGoogleOpaquePaymentCardSupported") else false return CardData( network = this.getString("network") ?: "", @@ -40,6 +42,7 @@ object Utils { userAddress = userAddress, isVirtualCard = isVirtual, isBounceProvisioned = isBounce, + isGoogleOpaquePaymentCardSupported = isGoogleOpcSupported, ) } diff --git a/android/src/main/java/com/expensify/wallet/WalletModule.kt b/android/src/main/java/com/expensify/wallet/WalletModule.kt index b08bfaa5..da1a16ca 100644 --- a/android/src/main/java/com/expensify/wallet/WalletModule.kt +++ b/android/src/main/java/com/expensify/wallet/WalletModule.kt @@ -389,9 +389,9 @@ class WalletModule internal constructor(context: ReactApplicationContext) : return future } - // This switch enables the UAPP flow + // This switch enables the UAPP flow, without it Google Wallet only asks for the TSP OPC override fun getGoogleOpaquePaymentCardSupported(): Boolean { - return true + return cardData.isGoogleOpaquePaymentCardSupported } } } diff --git a/android/src/main/java/com/expensify/wallet/model/CardData.kt b/android/src/main/java/com/expensify/wallet/model/CardData.kt index a348ee77..cc49683a 100644 --- a/android/src/main/java/com/expensify/wallet/model/CardData.kt +++ b/android/src/main/java/com/expensify/wallet/model/CardData.kt @@ -11,4 +11,5 @@ data class CardData( val userAddress: UserAddress, val isVirtualCard: Boolean = false, val isBounceProvisioned: Boolean = false, + val isGoogleOpaquePaymentCardSupported: Boolean = false, ) diff --git a/apps/common-app/src/CONST.ts b/apps/common-app/src/CONST.ts index e3130925..6b79e9d7 100644 --- a/apps/common-app/src/CONST.ts +++ b/apps/common-app/src/CONST.ts @@ -19,6 +19,7 @@ const AndroidDummyCardData: AndroidCardData = { userAddress: dummyAddress, isVirtualCard: false, isBounceProvisioned: false, + isGoogleOpaquePaymentCardSupported: true, }; const AndroidDummyResumeCardData: AndroidResumeCardData = { diff --git a/docs/UAPP.md b/docs/UAPP.md index ffb22dad..228b1011 100644 --- a/docs/UAPP.md +++ b/docs/UAPP.md @@ -22,7 +22,7 @@ This library handles the UAPP flow automatically. You just need to set up a hand ## Setup -UAPP is always enabled on Android, so `addCardToGoogleWallet()` requires a payment credentials handler as its second argument: +UAPP is enabled per card with `isGoogleOpaquePaymentCardSupported: true` in the card data. Without it, Google Wallet only asks for the TSP OPC and the handler is not called. `addCardToGoogleWallet()` always takes a payment credentials handler as its second argument: ```typescript import { addCardToGoogleWallet } from '@expensify/react-native-wallet'; @@ -52,7 +52,7 @@ const handlePaymentCredentials = async (data) => { }; // Pass the handler when adding a card -const status = await addCardToGoogleWallet(cardData, handlePaymentCredentials); +const status = await addCardToGoogleWallet({...cardData, isGoogleOpaquePaymentCardSupported: true}, handlePaymentCredentials); ``` ## Backend Implementation @@ -128,7 +128,7 @@ The handler is only called when Google Wallet requests a Google OPC, and it must **Example:** ```typescript const status = await addCardToGoogleWallet( - cardData, + {...cardData, isGoogleOpaquePaymentCardSupported: true}, async (data) => { const credentials = await fetchCredentialsFromBackend(data); return credentials; @@ -138,12 +138,14 @@ const status = await addCardToGoogleWallet( ### AndroidCardData Optional Fields -When using UAPP with `addCardToGoogleWallet()`, the `AndroidCardData` object supports two optional boolean fields: +When using UAPP with `addCardToGoogleWallet()`, the `AndroidCardData` object supports these optional boolean fields: - **`isVirtualCard?: boolean`** - Set to `true` if provisioning a virtual card (digitally-generated card number linked to a physical card account). Virtual cards provide enhanced security for online transactions. - **`isBounceProvisioned?: boolean`** - Set to `true` if the card was initially provisioned through Google Wallet and is now being completed through your app. This is used in bounce provisioning flows where users start in Google Wallet and are redirected to your app for additional verification. +- **`isGoogleOpaquePaymentCardSupported?: boolean`** - Set to `true` to run the UAPP flow for this card. Defaults to `false`, which skips UAPP and never calls the payment credentials handler. + For more details, see the [AndroidCardData Optional Fields](../README.md#androidcarddata-optional-fields) section in the main documentation. ## Testing diff --git a/src/NativeWallet.ts b/src/NativeWallet.ts index 3ace0b95..526a3775 100644 --- a/src/NativeWallet.ts +++ b/src/NativeWallet.ts @@ -29,6 +29,7 @@ type AndroidCardData = { userAddress: UserAddress; isVirtualCard?: boolean; isBounceProvisioned?: boolean; + isGoogleOpaquePaymentCardSupported?: boolean; }; type AndroidResumeCardData = {