Migration Guide: Upgrading from MoneyHash SDK for Flutter Version 2.0 to 2.1
This guide is designed to help you smoothly transition your Flutter 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 and Models documentation, which are located in the same directory as this guide.
Introduction
In MoneyHash 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. - Renaming of
CardCollector
toCardForm
: Simplifies the card form creation process. - **Renaming of
cardFormCollector
to [cardForm
] Parameter while initializing the SecureTextField. - Deprecation of
CardCollector.setTokenizeCardInfo
: No longer needed in the new version. - Introduction of
pay
andcreateCardToken
methods inCardForm
: Provides direct methods for payment processing and card token creation. - Deprecation of
CardCollector.collect("intentId", shouldSaveCard)
: Replaced withcardForm.collect()
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:
Future<IntentMethods> getIntentMethods(String intentId, IntentType intentType)
-
Replacement Method:
getMethods
Future<IntentMethods> getMethods(GetMethodsParams methodsParams)
Changes:
-
The new
getMethods
method requires aGetMethodsParams
object instead of separate parameters. -
Public API Key Requirement: You must set the public API key using
setPublicKey
before callinggetMethods
. -
Constructor Usage: You must use one of the provided constructors for
GetMethodsParams
:GetMethodsParams.withIntent(intentId, intentType)
GetMethodsParams.withCurrency(currency: ..., customer: ..., flowId: ..., amount: ...)
2. CardCollector.collect
Deprecated
CardCollector.collect
Deprecated-
Deprecated Method:
Future<VaultData?> collect(String intentId, bool shouldSaveCard)
-
Replacement Method:
collect
Future<VaultData?> collect()
Changes:
- The
collect
method no longer accepts parameters. - The method now relies on the public API key set via
setPublicKey
.
3. CardCollector.setTokenizeCardInfo
Deprecated
CardCollector.setTokenizeCardInfo
Deprecated-
Deprecated Method:
CardCollector.setTokenizeCardInfo(tokenizeCardInfo);
-
Reason: The
tokenizeCardInfo
is now handled internally, and you no longer need to set it manually.
New Additions and Updates
1. New Methods in CardForm
CardForm
-
pay
Method: Processes a payment using the collected card data.See
pay
.Future<IntentDetails?> pay( String intentId, VaultData cardData, bool saveCard, Map<String, String>? billingData, Map<String, String>? shippingData, )
-
createCardToken
Method: Creates a token for the collected card data.See
createCardToken
.Future<IntentStateDetails?> createCardToken( String cardIntentId, VaultData cardData, )
2. Renaming of CardCollector
to CardForm
CardCollector
to CardForm
- Old Class Name:
CardCollector
- New Class Name:
CardForm
Changes:
- The class used to build and manage the card form is now simply
CardForm
. - Methods previously called on
CardCollector
are now called onCardForm
.
3. Adding Public API Key with setPublicKey
setPublicKey
-
Method:
setPublicKey
void setPublicKey(String publicKey)
Purpose:
- You must set the public API key before performing operations like collecting card data or retrieving payment methods.
4. 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
.
Step-by-Step Migration Instructions
1. Updating getIntentMethods
to getMethods
getIntentMethods
to getMethods
Before:
var intentMethods = await moneyHashSDK.getIntentMethods("intentId", IntentType.payment);
After:
moneyHashSDK.setPublicKey("your_public_api_key"); // Ensure the public key is set
// Using the withIntent constructor if you have an intent ID
var methodsParams = GetMethodsParams.withIntent(
"intentId",
IntentType.payment,
);
// Or using the withCurrency constructor if you want to get methods based on currency
var methodsParams = GetMethodsParams.withCurrency(
currency: "USD",
customer: "customer_id", // Optional
flowId: "flow_id", // Optional
amount: 100.0, // Optional
);
var intentMethods = await moneyHashSDK.getMethods(methodsParams);
Action Required:
- Replace
getIntentMethods
withgetMethods
. - Create a
GetMethodsParams
object using one of the provided constructors:- Use
GetMethodsParams.withIntent(intentId, intentType)
if you have an intent ID. - Use
GetMethodsParams.withCurrency(...)
if you want to retrieve methods based on currency.
- Use
- Do not set parameters directly; use the constructors to ensure required fields are provided.
- Set the public API key before calling
getMethods
.
2. Refactoring CardCollector
to CardForm
CardCollector
to CardForm
Before:
CardCollector cardCollector = cardFormBuilder.build();
VaultData? cardData = await cardCollector.collect("intentId", true);
After:
moneyHashSDK.setPublicKey("your_public_api_key"); // Ensure the public key is set
CardForm cardForm = cardFormBuilder.build();
// Configure cardForm as needed
VaultData? cardData = await cardForm.collect();
Action Required:
- Replace
CardCollector
withCardForm
. - Use the
collect
method without parameters. - Ensure the public API key is set before collecting card data.
3. Adjusting CardCollector
Usage
CardCollector
UsageDeprecated Method:
cardCollector.setTokenizeCardInfo(tokenizeCardInfo);
Action Required:
- Remove any calls to
setTokenizeCardInfo
. - The
CardForm
now handles tokenization information internally.
4. Implementing the setPublicKey
Method
setPublicKey
MethodBefore:
- Public API key was not required for certain operations.
After:
-
Set the public API key before performing operations that require it:
moneyHashSDK.setPublicKey("your_public_api_key");
-
Operations that require the public API key:
- Collecting card data using
cardForm.collect()
. - Retrieving payment methods using
getMethods
.
- Collecting card data using
Action Required:
- Call
setPublicKey
with your public API key before performing relevant operations.
5. Handling New Intent States
When Creating a Card Token:
- Possible States:
Example:
IntentStateDetails? intentState = await cardForm.createCardToken("cardIntentId", cardData!);
if (intentState is CardIntentSuccessful) {
// Handle success
print("Card token created successfully.");
} else if (intentState is CardIntentFailed) {
// Handle failure
print("Card token creation failed: ${intentState.errorMessage}");
}
Action Required:
- Implement handling for these new states in your code when creating card tokens.
Code Examples Before and After Migration
1. getIntentMethods
vs. getMethods
getIntentMethods
vs. getMethods
Before (Version 2.0):
var intentMethods = await moneyHashSDK.getIntentMethods("intentId", IntentType.payment);
After (Version 2.1):
moneyHashSDK.setPublicKey("your_public_api_key"); // Ensure the public key is set
// Using the withIntent constructor
var methodsParams = GetMethodsParams.withIntent(
"intentId",
IntentType.payment,
);
var intentMethods = await moneyHashSDK.getMethods(methodsParams);
Or, if you don't have an intent ID and want to retrieve methods based on currency:
moneyHashSDK.setPublicKey("your_public_api_key"); // Ensure the public key is set
// Using the withCurrency constructor
var methodsParams = GetMethodsParams.withCurrency(
currency: "USD",
customer: "customer_id", // Optional
flowId: "flow_id", // Optional
amount: 100.0, // Optional
);
var intentMethods = await moneyHashSDK.getMethods(methodsParams);
Important: You must use one of the provided constructors (withIntent
or withCurrency
) and cannot set the parameters directly.
2. CardCollector.collect
vs. CardForm.collect
CardCollector.collect
vs. CardForm.collect
Before:
CardCollector cardCollector = cardFormBuilder.build();
VaultData? cardData = await cardCollector.collect("intentId", true);
After:
moneyHashSDK.setPublicKey("your_public_api_key"); // Ensure the public key is set
CardForm cardForm = cardFormBuilder.build();
VaultData? cardData = await cardForm.collect();
3. CardCollector
Adjustments
CardCollector
AdjustmentsBefore:
CardCollector cardCollector = CardCollector();
cardCollector.setTokenizeCardInfo(tokenizeCardInfo);
// ... other configurations
After:
CardForm cardForm = CardForm();
// ... configure cardForm as needed
Action Required:
- Replace
CardCollector
withCardForm
. - Remove any calls to
setTokenizeCardInfo
.
Additional Resources
- MoneyHash SDK API Documentation
- MoneyHash SDK - CardForm Documentation
- MoneyHash SDK Models Documentation
- GitHub Issue.
Updated about 1 month ago