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
- Deprecation of
getIntentMethods: Replaced with the newgetMethodsmethod. - Introduction of
payandcreateCardTokenmethods inuseSecureCardForm: Provides direct methods for payment processing and card token creation. - Deprecation of
collect("intentId", shouldSaveCard): Replaced withcollect()without parameters. - Addition of
setPublicKeymethod inMoneyHashSDK: Requires setting the public API key before performing certain operations. - New Intent States: Two new states,
CardIntentSuccessfulandCardIntentFailed, specifically for handling card token creation outcomes.
Deprecated Methods and Their Replacements
1. getIntentMethods Deprecated
getIntentMethods Deprecated-
Deprecated Method:
getIntentMethods(intentId: string, intentType: IntentType): Promise<IntentMethods> -
Replacement Method:
getMethodsgetMethods(intentId: string, intentType: IntentType): Promise<IntentMethods> // or moneyHashSDK.getMethods({ currency: string, amount: number, customer: string, flowId: string, }): Promise<IntentMethods>
Changes:
- The new
getMethodsmethod replacesgetIntentMethods. - Public API Key Requirement: You must set the public API key using
setPublicKeybefore callinggetMethods. - Method Overloads: You can call
getMethodseither withintentIdandintentType, or withcurrency,amount,customer, andflowId.
2. collect Method Changes
collect Method Changes-
Deprecated Usage:
const cardData = await collect('intentId', shouldSaveCard); -
Replacement Method:
collectconst cardData = await collect();
Changes:
- The
collectmethod 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
useSecureCardForm-
payMethod: 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> -
createCardTokenMethod: Creates a token for the collected card data.See
createCardToken.createCardToken({ cardIntentId: string, cardData: VaultData, }): Promise<IntentStateDetails>
2. Adding Public API Key with setPublicKey
setPublicKey-
Method:
setPublicKeysetPublicKey(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
CardIntentSuccessful: Indicates that the card token was created successfully.CardIntentFailed: Indicates that the card token creation failed.
Usage:
- Handle these new states when you attempt to create a card token using
createCardToken.
Additional Resources
- MoneyHash SDK API Documentation
- MoneyHash SDK - SecureCardForm Documentation
- MoneyHash SDK Models Documentation
- GitHub Issue.
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.
Updated about 1 year ago