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 newgetMethods
method. - Introduction of
pay
andcreateCardToken
methods inuseSecureCardForm
: Provides direct methods for payment processing and card token creation. - Deprecation of
collect("intentId", shouldSaveCard)
: Replaced withcollect()
without parameters. - Addition of
setPublicKey
method inMoneyHashSDK
: Requires setting the public API key before performing certain operations. - New Intent States: Two new states,
CardIntentSuccessful
andCardIntentFailed
, 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:
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 replacesgetIntentMethods
. - Public API Key Requirement: You must set the public API key using
setPublicKey
before callinggetMethods
. - Method Overloads: You can call
getMethods
either withintentId
andintentType
, or withcurrency
,amount
,customer
, andflowId
.
2. collect
Method Changes
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
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
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
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 2 months ago