APIs
The MoneyHash SDK for Flutter offers a comprehensive suite of APIs for managing payment intents, handling various payment methods, and processing transactions. This documentation details the available methods within the MoneyHashSDK
class.
MoneyHash SDK Builder
class MoneyHashSDKBuilder {
MoneyHashSDKBuilder setNativeGooglePayConfig(NativeGooglePayConfig config)
MoneyHashSDK build()
}
- Purpose: Initializes and configures the MoneyHash SDK before use. The
MoneyHashSDKBuilder
allows you to set up configurations such as Google Pay settings before building the SDK instance.
1. setNativeGooglePayConfig
setNativeGooglePayConfig
MoneyHashSDKBuilder setNativeGooglePayConfig(NativeGooglePayConfig config)
- Purpose: Sets the configuration for Google Pay integration.
- Parameters:
config
: An instance ofNativeGooglePayConfig
containing Google Pay environment settings.
- Returns: The
MoneyHashSDKBuilder
instance, allowing for method chaining.
Example:
import 'package:moneyhash/moneyhash.dart';
void main() {
// Create a Google Pay configuration
var googlePayConfig = NativeGooglePayConfig(
environment: GooglePayEnvironment.test, // Use GooglePayEnvironment.production for production
allowedCards: [
AllowedCards.visa,
AllowedCards.mastercard,
],
supportedMethods: [
SupportedMethods.pan_only,
SupportedMethods.cryptogram_3ds,
],
);
// Initialize the SDK using the builder and set the Google Pay configuration
var moneyHashSDK = MoneyHashSDKBuilder()
.setNativeGooglePayConfig(googlePayConfig)
.build();
print("MoneyHash SDK initialized with Google Pay configuration.");
}
2. build
build
MoneyHashSDK build()
- Purpose: Builds and returns an instance of
MoneyHashSDK
with the specified configurations. - Returns: An instance of
MoneyHashSDK
.
Example:
import 'package:moneyhash/moneyhash.dart';
void main() {
// Initialize the SDK using the builder and build the SDK
var moneyHashSDK = MoneyHashSDKBuilder().build();
print("MoneyHash SDK built successfully and ready for use.");
}
MoneyHash SDK API Documentation
A. Methods That Do Not Require an Intent ID
1. Set Logging Level
void setLogLevel(LogLevel logLevel)
- Purpose: Sets the logging level for the SDK.
- Parameters:
logLevel
: The desired logging levelLogLevel
- Example:
moneyHashSDK.setLogLevel(LogLevel.debug);
print("Log level set to debug");
2. Set Locale
void setLocale(Language locale)
- Purpose: Sets the locale for the SDK.
- Parameters:
locale
: TheLanguage
object representing the locale to be set.
- Example:
moneyHashSDK.setLocale(Language.english);
print("Locale set to English");
3. Set Public Key
void setPublicKey(String publicKey)
- Purpose: Sets the public API key for the SDK.
- Parameters:
publicKey
: The public API key to be set.
- Requirements:
- You must have a valid public API key. For detailed instructions on how to obtain a public API key, please refer to the MoneyHash Authentication Documentation.
- Example:
moneyHashSDK.setPublicKey("your_public_api_key");
print("Public key set successfully");
4. Check Apple Pay Compatibility
Important: This method is only available on iOS.
Future<bool> isDeviceCompatibleWithApplePay()
- Purpose: Checks if the current device is compatible with Apple Pay.
- Returns: A
Future<bool>
indicating whether the device supports Apple Pay (true
if compatible,false
otherwise). - Example:
var isCompatible = await moneyHashSDK.isDeviceCompatibleWithApplePay();
print("Device is compatible with Apple Pay: $isCompatible");
5. Check Google Pay Readiness
Important: This method is only available on Android.
Future<bool> isReadyForGooglePay()
- Purpose: Checks if the current device is ready and able to use Google Pay.
- Returns: A
Future<bool>
indicating whether the device supports Google Pay (true
if ready,false
otherwise). - Throws: An
UnsupportedError
if called on a non-Android device. - Example:
void main() async {
try {
bool isReady = await moneyHashSDK.isReadyForGooglePay();
print("Device is ready for Google Pay: $isReady");
} catch (e) {
print("Error checking Google Pay availability: $e");
}
}
B. Methods That Require the Public Key to Be Set
6. Get Methods
Future<IntentMethods> getMethods(GetMethodsParams methodsParams)
- Purpose: Retrieves available payment methods using the public API key and additional parameters.
- Requirements: The public key must be set using
setPublicKey
before calling this method. - Parameters:
methodsParams
: An instance ofGetMethodsParams
containing parameters.
GetMethodsParams
Class
GetMethodsParams
ClassThe GetMethodsParams
class has two constructors, and you must use one of them based on your use case:
-
With Intent:
GetMethodsParams.withIntent(String intentId, IntentType intentType)
-
Purpose: Use this constructor when you have an existing intent ID and intent type.
-
Parameters:
intentId
: The unique identifier of the intent.intentType
: The type of the intent (IntentType.payment
orIntentType.payout
).
-
Example:
var methodsParams = GetMethodsParams.withIntent( "intent_id_here", IntentType.payment, );
-
-
With Currency:
GetMethodsParams.withCurrency({ required String currency, String? customer, String? flowId, double? amount, })
-
Purpose: Use this constructor when you want to retrieve methods based on currency and optional parameters.
-
Parameters:
currency
: Required. The currency code (e.g., "USD").customer
: Optional. The customer ID.flowId
: Optional. The flow ID.amount
: Optional. The amount.
-
Example:
var methodsParams = GetMethodsParams.withCurrency( currency: "USD", customer: "customer_id", flowId: "flow_id", amount: 100.0, );
-
- Returns:
IntentMethods
containing available methods. - Throws: An
MHException
if failed to retrieve the methods. - Example:
try {
moneyHashSDK.setPublicKey("your_public_api_key"); // Ensure the public key is set
// Using withCurrency constructor
var methodsParams = GetMethodsParams.withCurrency(
currency: "USD",
customer: "customer_id",
flowId: "flow_id",
amount: 100.0,
);
var methods = await moneyHashSDK.getMethods(methodsParams);
print("Available methods: $methods");
} catch (e) {
print("Error retrieving methods: $e");
}
Note: You must use one of the provided constructors (withIntent
or withCurrency
) when creating an instance of GetMethodsParams
.
C. Methods That Require a Payment Intent ID
7. Render MoneyHash Embed Form
Future<IntentDetails?> renderForm(
String intentId,
IntentType intentType,
EmbedStyle? embedStyle,
)
- Purpose: Renders the MoneyHash embed form within the Flutter application.
- Parameters:
intentId
: The unique identifier of the intent.intentType
: The type of the intent (IntentType
), eitherpayment
orpayout
.embedStyle
: Optional styling configuration for the embed form.
- Returns:
IntentDetails
ornull
if there is something wrong. - Throws: An
MHException
if something went wrong while rendering the intent. - Example:
try {
var intentDetails = await moneyHashSDK.renderForm(
"current_intent_id",
IntentType.payment,
null, // Optional EmbedStyle
);
print("Form rendered with details: $intentDetails");
} catch (e) {
print("Failed to render form: $e");
}
8. Retrieve Intent Details
Future<IntentDetails> getIntentDetails(String intentId, IntentType intentType)
- Purpose: Retrieves the details of a specified intent.
- Parameters:
intentId
: The unique identifier of the intent.intentType
: The type of the intent (IntentType
), eitherpayment
orpayout
.
- Returns:
IntentDetails
. - Throws: An
MHException
if failed to retrieve the intent details. - Example:
try {
var intentDetails = await moneyHashSDK.getIntentDetails("Z1ED7zZ", IntentType.payment);
print("Intent details: $intentDetails");
} catch (e) {
print("Error retrieving intent details: $e");
}
9. Proceed with Selected Method
Future<IntentResult> proceedWithMethod(
String intentId,
IntentType intentType,
String selectedMethodId,
MethodType methodType,
MethodMetaData? methodMetaData,
)
- Purpose: Proceeds with the selected payment or payout method for a given intent.
- Parameters:
intentId
: The unique identifier of the intent.intentType
: The type of the intent (IntentType
), eitherpayment
orpayout
.selectedMethodId
: The ID of the selected method.methodType
: The type of the method (MethodType
).methodMetaData
: Optional metadata related to the method.
- Returns:
IntentResult
encapsulating the result of the method selection. - Throws: An
MHException
if failed to proceed with the selected method. - Example:
try {
var result = await moneyHashSDK.proceedWithMethod(
"Z1ED7zZ",
IntentType.payment,
"method_123",
MethodType.paymentMethod,
null, // Optional metadata
);
print("Proceeded with method: $result");
} catch (e) {
print("Error proceeding with method: $e");
}
10. Reset Selected Method
Future<IntentResult> resetSelectedMethod(String intentId, IntentType intentType)
- Purpose: Resets the selected payment or payout method for a specified intent.
- Parameters:
intentId
: The unique identifier of the intent.intentType
: The type of the intent (IntentType
), eitherpayment
orpayout
.
- Returns:
IntentResult
with the reset result. - Throws: An
MHException
if failed to reset the selected method. - Example:
try {
var result = await moneyHashSDK.resetSelectedMethod("Z1ED7zZ", IntentType.payment);
print("Method reset successfully: $result");
} catch (e) {
print("Error resetting method: $e");
}
11. Update Fees
Future<FeesData?> updateFees(String intentId, List<FeeItem> fees)
- Purpose: Updates the fees associated with a specified intent.
- Parameters:
intentId
: The unique identifier of the intent.fees
: A list ofFeeItem
objects representing the fees to be updated.
- Returns:
FeesData
if successful. - Throws: An
MHException
if the fees cannot be updated. - Example:
try {
var feeItem1 = FeeItem(title: {Language.english: "Service Fee"}, value: "5.0");
var feeItem2 = FeeItem(title: {Language.english: "Delivery Fee"}, value: "3.0");
var feesData = await moneyHashSDK.updateFees("Z1ED7zZ", [feeItem1, feeItem2]);
print("Fees updated successfully: $feesData");
} catch (e) {
print("Error updating fees: $e");
}
12. Update Discount
Future<DiscountData?> updateDiscount(String intentId, DiscountItem discount)
- Purpose: Updates the discount associated with a specified intent.
- Parameters:
intentId
: The unique identifier of the intent.discount
: ADiscountItem
object representing the discount to be updated.
- Returns:
DiscountData
if successful. - Throws: An
MHException
if the discount cannot be updated. - Example:
try {
var discountItem = DiscountItem(
title: {Language.english: "Promo Code"},
type: DiscountType.amount,
value: "10.0",
);
var discountData = await moneyHashSDK.updateDiscount("Z1ED7zZ", discountItem);
print("Discount updated successfully: $discountData");
} catch (e) {
print("Error updating discount: $e");
}
13. Submit Payment Receipt
Future<IntentDetails?> submitPaymentReceipt(String intentId, String data)
- Purpose: Submits a payment receipt for a specified intent.
- Parameters:
intentId
: The unique identifier of the payment intent.data
: The receipt data to be submitted.
- Returns:
IntentDetails
if successful,null
otherwise. - Throws: An
MHException
if failed to submit the receipt. - Example:
try {
var intentDetails = await moneyHashSDK.submitPaymentReceipt("Z1ED7zZ", "receipt_data_string");
print("Receipt submitted successfully: $intentDetails");
} catch (e) {
print("Error submitting receipt: $e");
}
14. Submit Card CVV
Future<IntentDetails?> submitCardCVV(String intentId, String cvv)
- Purpose: Submits the CVV for a saved card associated with a specified payment intent.
- Parameters:
intentId
: The unique identifier of the payment intent.cvv
: The CVV of the card.
- Returns:
IntentDetails
if successful,null
otherwise. - Throws: An
MHException
if failed to submit the CVV. - Example:
try {
var intentDetails = await moneyHashSDK.submitCardCVV("Z1ED7zZ", "123");
print("CVV submitted successfully: $intentDetails");
} catch (e) {
print("Error submitting CVV: $e");
}
15. Proceed with Apple Pay
Important: This method is only available on iOS.
Future<IntentDetails?> proceedWithApplePay(
String intentId,
double depositAmount,
String merchantIdentifier,
String currencyCode,
String countryCode,
)
- Purpose: Initiates an Apple Pay transaction.
- Parameters:
intentId
: The unique identifier of the payment intent.depositAmount
: The amount to be paid.merchantIdentifier
: A unique identifier for the merchant.currencyCode
: The currency code of the transaction (e.g., "USD").countryCode
: The country code associated with the transaction (e.g., "US").
- Returns:
IntentDetails
if successful, or an error with details if not. - Throws: An
MHException
if failed to proceed with Apple Pay. - Example:
try {
var intentDetails = await moneyHashSDK.proceedWithApplePay(
"intent_id_here",
99.99,
"merchant.com.example",
"USD",
"US",
);
print("Apple Pay transaction initiated: $intentDetails");
} catch (e) {
print("Error initiating Apple Pay transaction: $e");
}
16. Proceed with Google Pay
Important: This method is only available on Android.
Future<IntentDetails?> proceedWithGooglePay(
String intentId,
String currency,
double amount,
String countryCode,
String gateway,
String gatewayMerchantId,
String merchantId,
String merchantName,
)
- Purpose: Initiates a Google Pay transaction for the specified payment intent.
- Requirements:
- The device must be an Android device with Google Pay set up.
- You must have initialized the SDK with the Google Pay configuration using
MoneyHashSDKBuilder
.
- Parameters:
intentId
: The unique identifier of the payment intent.currency
: The currency code of the transaction (e.g., "USD").amount
: The amount to be paid.countryCode
: The country code associated with the transaction (e.g., "US").gateway
: The payment gateway identifier.gatewayMerchantId
: The merchant identifier assigned by the payment gateway.merchantId
: The unique identifier assigned to the merchant by Google Pay.merchantName
: The display name of the merchant.
- Returns: A
Future<IntentDetails?>
containing the intent details if successful, ornull
if there was an issue. - Throws: An
MHException
if failed to proceed with Google Pay, or anUnsupportedError
if called on a non-Android device. - Example:
void main() async {
try {
var intentDetails = await moneyHashSDK.proceedWithGooglePay(
"your_intent_id",
"USD",
99.99,
"US",
"your_gateway",
"your_gateway_merchant_id",
"your_merchant_id",
"Your Merchant Name",
);
print("Google Pay transaction initiated: $intentDetails");
} catch (e) {
print("Error initiating Google Pay transaction: $e");
}
}
D. Methods That Require a Card Intent ID
17. Delete a Saved Card
Future<void> deleteSavedCard(String cardTokenId, String cardIntentId)
- Purpose: Deletes a saved card using its token ID and associated card intent ID.
- Requirements: Requires the card intent ID associated with the card token.
- Parameters:
cardTokenId
: The token ID of the card to be deleted.cardIntentId
: The unique identifier of the card intent.
- Throws: An
MHException
if failed to delete the card. - Example:
try {
await moneyHashSDK.deleteSavedCard("card_token_123", "card_intent_id_456");
print("Card deleted successfully");
} catch (e) {
print("Error deleting card: $e");
}
Updated about 2 months ago