Migration Guide: Upgrading from MoneyHash SDK for React Native Version 2.0 to 2.1

This guide is designed to help you smoothly transition your ReactNative application from MoneyHash SDK version 2.0 to 2.1. Below, you'll find detailed explanations of the changes, deprecated methods, new additions, and the steps you need to take to update your code.

Note: All API and model names are linked to their respective sections in the API documentation, Models documentation, and Card Form Documentation, which are located in the same directory as this guide.


Introduction

In MoneyHash React Native SDK version 2.1, several changes have been made to improve the developer experience and streamline payment processing. This migration guide will help you understand these changes and update your code accordingly.


Overview of Key Changes

  1. Deprecation of getIntentMethods: Replaced with the new getMethods method.
  2. Introduction of pay and createCardToken methods in useSecureCardForm: Provides direct methods for payment processing and card token creation.
  3. Deprecation of collect("intentId", shouldSaveCard): Replaced with collect() without parameters.
  4. Addition of setPublicKey method in MoneyHashSDK: Requires setting the public API key before performing certain operations.
  5. New Intent States: Two new states, CardIntentSuccessful and CardIntentFailed, specifically for handling card token creation outcomes.

Deprecated Methods and Their Replacements

1. getIntentMethods Deprecated

  • Deprecated Method:

    getIntentMethods(intentId: string, intentType: IntentType): Promise<IntentMethods>
    
  • Replacement Method: getMethods

    getMethods(intentId: string, intentType: IntentType): Promise<IntentMethods>
    // or
    moneyHashSDK.getMethods({
      currency: string,
      amount: number,
      customer: string,
      flowId: string,
    }): Promise<IntentMethods>
    

Changes:

  • The new getMethods method replaces getIntentMethods.
  • Public API Key Requirement: You must set the public API key using setPublicKey before calling getMethods.
  • Method Overloads: You can call getMethods either with intentId and intentType, or with currency, amount, customer, and flowId.

2. collect Method Changes

  • Deprecated Usage:

    const cardData = await collect('intentId', shouldSaveCard);
    
  • Replacement Method: collect

    const cardData = await collect();
    

Changes:

  • The collect method no longer accepts parameters.
  • The method now relies on the public API key set via setPublicKey.

New Additions and Updates

1. New Methods in useSecureCardForm

  • pay Method: Processes a payment using the collected card data.

    See pay.

    pay({
      intentId: string,
      cardData: VaultData,
      saveCard?: boolean,
      billingData?: Record<string, string>,
      shippingData?: Record<string, string>,
    }): Promise<IntentDetails>
    
  • createCardToken Method: Creates a token for the collected card data.

    See createCardToken.

    createCardToken({
      cardIntentId: string,
      cardData: VaultData,
    }): Promise<IntentStateDetails>
    


2. Adding Public API Key with setPublicKey

  • Method: setPublicKey

    setPublicKey(publicKey: string): void
    

Purpose:

  • You must set the public API key before performing operations like collecting card data or retrieving payment methods.

3. New Intent States for Card Token Creation

Usage:

  • Handle these new states when you attempt to create a card token using createCardToken.


Additional Resources


By following this migration guide, you should be able to update your React Native application to use MoneyHash SDK version 2.1 smoothly. Make sure to replace any deprecated methods with their new counterparts and adjust your code according to the changes outlined above.