react-native-iaphub

repository·master·Indexed 18 days ago

https://github.com/iaphub/react-native-iaphub

A library for implementing in-app purchases and subscriptions in React Native apps. It provides the core SDK logic for managing transactions and customers, including methods for initialization, user authentication (login/logout), product retrieval, and purchase execution. Version 9.2.1. Note: This package provides the SDK logic only and does not include a UI layer.

Tokens
4.6K
Snippets
18
Records
27
Agent score
63%

What's inside react-native-iaphub

  1. How the new authentication system works in v7

    master

    Version 7 introduces support for anonymous users by default.

    Anonymous Users

    • You can now display products and perform purchases without calling login first.
    • If a user is not logged in, IAPHUB automatically generates an anonymous user ID (prefixed with a:).
    • Security Note: Anonymous purchases are disabled by default. To allow them, set allowAnonymousPurchase: true in the options of the start method.
    • Automatic Transfer: If an anonymous user later calls login, their previous purchases are automatically transferred to their new user ID.

    Manual Migration for Device ID Users

    If you previously used a device ID (e.g., from react-native-device-info) to authenticate users in production, those subscriptions are tied to that device ID. To ensure a smooth transition without forcing a restore:

    1. Call login(deviceId) using the existing device ID. This prevents the user from getting a new ID.
    2. Alternatively, ask users to call the restore() method. This will automatically transfer purchases owned by the device ID to the new anonymous or logged-in user ID.
    // Enabling anonymous purchases during initialization
    await IAPHub.start({
      allowAnonymousPurchase: true
    });
    
    // Logging in a user
    await IAPHub.login('user_id_or_device_id');
    
    // Logging out
    await IAPHub.logout();
    
    // Restoring purchases to migrate from device ID to new ID
    await IAPHub.restore();
  2. Understand the difference between react-native-iaphub and react-native-iaphub-ui

    master

    The react-native-iaphub package provides the core SDK methods required to implement in-app purchases and subscriptions, but it does not include any user interface (UI). You are responsible for building your own UI using these methods.

    If you require a plug-and-play solution with pre-built UI components, use react-native-iaphub-ui instead.

  3. Migrate react-native-iaphub 7.X.X to 8.X.X

    master

    Version 8 of react-native-iaphub implements Google Play Billing Library 5.0. This update is required to correctly detect multiple intro phases and offers in the Google Play Console.

    Installation Steps

    1. Update the npm package:
    npm install react-native-iaphub@latest --save
    1. Update iOS dependencies:
    cd ios && pod install
    npm install react-native-iaphub@latest --save
    # Then in the ios folder
    pod install
  4. Initialize react-native-iaphub in an Expo app

    master

    To use IAPHUB within your project, install the SDK and call Iaphub.start() in your entry file (e.g., App.js) with your credentials from the IAPHUB dashboard.

    Installation:

    npm install react-native-iaphub

    Initialization: Pass an object to Iaphub.start() containing your appId, apiKey, and optional configuration like enableStorekitV2 and lang.

    import Iaphub from 'react-native-iaphub';
    
    Iaphub.start({
      appId: 'YOUR_IAPHUB_APP_ID',
      apiKey: 'YOUR_IAPHUB_API_KEY',
      enableStorekitV2: true,
      lang: 'en',
    });
  5. Migrate react-native-iaphub from 6.X.X to 7.X.X

    master

    Version 7 is a major update that switches to the latest native iOS and Android SDKs. To upgrade, install the latest version and update your iOS dependencies.

    Upgrade Steps

    1. Install the latest version via npm:
      npm install react-native-iaphub@latest --save
    2. Update iOS pods:
      cd ios && pod install

    Dependency Cleanup

    You can now uninstall the react-native-iap dependency as it is no longer required.

    npm install react-native-iaphub@latest --save
    cd ios && pod install
  6. Updated product property names in react-native-iaphub v7

    master

    Several product properties have been renamed to better reflect localization and type clarity:

    Old PropertyNew PropertyDescription
    pricelocalizedPriceThe formatted price string
    priceCurrencycurrencyThe currency code
    priceAmountpriceThe numeric price amount
    titlelocalizedTitleThe localized product title
    descriptionlocalizedDescriptionThe localized product description
    subscriptionIntroPricesubscriptionIntroLocalizedPriceThe introductory price string
    subscriptionIntroPrice(Returns number)The introductory price amount (number)
  7. Use subscriptionIntroPhases instead of deprecated intro properties

    master

    In version 8, several individual subscription intro properties have been removed in favor of a single subscriptionIntroPhases property. This new property provides an ordered list of the intro phases a user is eligible for.

    Removed Properties

    • subscriptionIntroPrice
    • subscriptionIntroLocalizedPrice
    • subscriptionIntroPayment
    • subscriptionIntroDuration
    • subscriptionIntroCycles
    • subscriptionTrialDuration

    New Data Structure

    subscriptionIntroPhases is an array of objects. For example, a subscription with a 1-month free trial followed by a 3-month introductory price of $4.99 would look like this:

    [
      {
        type: "trial",
        price: 0,
        currency: "USD",
        localizedPrice: "FREE",
        cycleDuration: "P1M",
        cycleCount: 1,
        payment: "upfront"
      },
      {
        type: "intro",
        price: 4.99,
        currency: "USD",
        localizedPrice: "$4.99",
        cycleDuration: "P1M",
        cycleCount: 3,
        payment: "as_you_go"
      }
    ]