react-native-wallet

repository·main·Indexed 41 days ago

https://github.com/expensify/react-native-wallet

A React Native library (version 0.1.23) for seamless in-app Card Push Provisioning into Apple Wallet and Google Wallet. It enables developers to securely add payment cards (Visa, MasterCard, Amex, Discover) directly from their application. The library includes an Expo plugin and provides API functions such as addCardToAppleWallet, addCardToGoogleWallet, and checkWalletAvailability.

Tokens
9.8K
Snippets
40
Records
51
Agent score
48%

What's inside react-native-wallet

  1. Setup the Expo Example App

    main

    To set up the Expo example application, ensure you have Node.js 18+, Expo CLI, Xcode/CocoaPods (for iOS), and the Google TapAndPay SDK (for Android).

    1. Install dependencies: Run npm install.
    2. Configure Google TapAndPay SDK (Android only): Place the SDK zip file in the shared libs directory at apps/libs/expo-example/tapandpay-v18.7.0.zip. The Expo config plugin handles extraction during prebuild.
    3. Generate native projects: Run npx expo prebuild --clean to generate iOS/Android projects, apply the wallet plugin, and extract the SDK.
    npm install
    # Place SDK at apps/libs/expo-example/tapandpay-v18.7.0.zip
    npx expo prebuild --clean
  2. Whitelist your Android app for Google SDK

    main

    To prevent Not verified errors when calling Google SDK functions, you must whitelist your app's package name and SHA-256 fingerprint with Google.

    Prepare the following data:

    • Package name: e.g., com.app.package.name
    • Fingerprint: A SHA-256 checksum (e.g., SHA256: 36:38:63:59:6E:...:00:82:16:4E:FF). You can generate this using apksigner or keytool.

    Submit these details via the official Google documentation instructions to complete the allowlisting process.

  3. Setup Apple Pay In-App Provisioning entitlements for iOS

    main

    Enabling In-App Provisioning on iOS requires specific Apple entitlements that are not enabled by default.

    1. Apply for Entitlements: Submit a request via the In-App Provisioning Submission Form or email iap_entitlements@apple.com.
      • Subject: Apple Pay Entitlements and Allow List Request - [Issuer Name] - [Country Code]
      • Body: Include Issuer Name, Country Code, Team ID, Adam ID, and App Name.
      • Note: Only production Team IDs and Adam IDs are eligible. Enterprise Team IDs are not supported.
    2. Activate Entitlement: Once approved, go to the Apple Developer Portal: Certificates, Identifiers & Profiles -> Profiles -> Our distribution profile -> Edit and add the ApplePay In-App Provisioning Distribution entitlement.
    3. Add to Project: Add the com.apple.developer.payment-pass-provisioning key to your project's .entitlements file.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    	...
    	 <!-- In-App Provisioning special entitlement-->
    	<key>com.apple.developer.payment-pass-provisioning</key>
    	<true/>
    </dict>
    </plist>
  4. Setup the Basic Example App

    main

    To set up the @expensify/react-native-wallet basic example application, follow these steps to install dependencies and configure platform-specific requirements.

    Prerequisites

    • Node.js 18+
    • React Native development environment
    • Android: Google TapAndPay SDK
    • iOS: Xcode and CocoaPods

    Installation Steps

    1. Install Node dependencies (from the repository root):

      npm install
    2. Configure Google TapAndPay SDK (Android only): The SDK must be extracted into the android/libs directory following a Maven repository structure. Do not place the ZIP file itself in this folder.

      mkdir -p android/libs

      Extract the SDK ZIP contents so they reside directly in android/libs/. The expected structure is: android/libs/com/google/android/gms/play-services-tapandpay/[version]/...

    3. Install iOS dependencies:

      cd ios
      pod install
      cd ..
    npm install
    mkdir -p android/libs
    cd ios && pod install && cd ..
  5. Setup Google TapAndPay SDK for Android

    main

    To use Push Provisioning on Android, you must manually integrate the Google TapAndPay SDK.

    1. Request Access: Visit the Google Pay Android Push Provisioning API documentation to request access.
    2. Download and Extract: Once approved, download the TapAndPay SDK and extract its contents into an /android/libs folder in your React Native project root.
    3. Ignore SDK in Git: Add /android/libs to your .gitignore.
    4. Configure Gradle: Connect the SDK in your android/build.gradle file by adding the libs directory to your repositories.
    allprojects {
    	repositories {
    		google()
    		maven { url "file://${rootDir}/libs" }
    	}
    }
  6. Publishing requirements for Android and iOS

    main

    To successfully publish your app with Push Provisioning, follow these platform-specific requirements:

    Android

    • Security & Testing: Follow Google's App Push Provisioning best practices.
    • Review Process: Your app will be reviewed by Google and must pass 4 mandatory test cases regarding card state tracking.
    • Branding: Ensure compliance with Google's branding guidelines.
    • UI Tip: Hide the Add to Google Wallet button once a card has already been added.

    iOS

    • Branding: You must not create your own buttons; use the AddToWalletButton component to comply with Apple's branding guidelines.
    • Review Process: Apple's certification team will verify scenarios like enrolling cards to Apple Watch, handling incoming calls during provisioning, and adding multiple cards from the same issuer.
    • Submission Requirements: You must provide a demo account and a demo video showcasing the In-App Provisioning experience.
    • UI Tip: When a pass is already provisioned, hide the button and replace it with text like Added to Apple Wallet.
  7. Clean and Reload the Basic Example App

    main

    Use these commands to manage the development lifecycle of the example app.

    Reloading the App

    • iOS: Press Cmd ⌘ + R in the simulator.
    • Android: Press R twice or Ctrl/Cmd + M to open the Developer Menu.

    Performing a Clean Build

    If you encounter build issues, use the following commands to clean the project:

    iOS:

    npm run clean-ios
    npm run pods

    Android:

    npm run clean-android
    npm run clean-ios
    npm run pods
    npm run clean-android
  8. Configure the @expensify/react-native-wallet Expo plugin

    main

    The wallet plugin is configured within the plugins array in your app.json. You must provide the googleTapAndPaySdkPath pointing to the location of the Google TapAndPay SDK zip file.

    "plugins": [
      [
        "@expensify/react-native-wallet",
        {
          "googleTapAndPaySdkPath": "../libs/tapandpay-v18.7.0.zip"
        }
      ]
    ]
  9. Android Native Modules and Components in @expensify/react-native-wallet

    main

    On Android, the @expensify/react-native-wallet package exposes two primary interfaces to React Native:

    1. WalletModule: A native module providing core wallet functionality.
    2. RNAddToWalletButtonManager: A View Manager that allows you to use the native 'Add to Wallet' button component within your React Native application.

    These are automatically linked via WalletPackage.