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
MoneyHashSDKBuilderallows you to set up configurations such as Google Pay settings before building the SDK instance.
1. setNativeGooglePayConfig
setNativeGooglePayConfigMoneyHashSDKBuilder setNativeGooglePayConfig(NativeGooglePayConfig config)
- Purpose: Sets the configuration for Google Pay integration.
- Parameters:
config: An instance ofNativeGooglePayConfigcontaining Google Pay environment settings.
- Returns: The
MoneyHashSDKBuilderinstance, 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
buildMoneyHashSDK build()
- Purpose: Builds and returns an instance of
MoneyHashSDKwith 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: TheLanguageobject 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 (trueif compatible,falseotherwise). - 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 (trueif ready,falseotherwise). - Throws: An
UnsupportedErrorif 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
setPublicKeybefore calling this method. - Parameters:
methodsParams: An instance ofGetMethodsParamscontaining 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.paymentorIntentType.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:
IntentMethodscontaining available methods. - Throws: An
MHExceptionif 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), eitherpaymentorpayout.embedStyle: Optional styling configuration for the embed form.
- Returns:
IntentDetailsornullif there is something wrong. - Throws: An
MHExceptionif 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), eitherpaymentorpayout.
- Returns:
IntentDetails. - Throws: An
MHExceptionif 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), eitherpaymentorpayout.selectedMethodId: The ID of the selected method.methodType: The type of the method (MethodType).methodMetaData: Optional metadata related to the method.
- Returns:
IntentResultencapsulating the result of the method selection. - Throws: An
MHExceptionif 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), eitherpaymentorpayout.
- Returns:
IntentResultwith the reset result. - Throws: An
MHExceptionif 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 ofFeeItemobjects representing the fees to be updated.
- Returns:
FeesDataif successful. - Throws: An
MHExceptionif 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: ADiscountItemobject representing the discount to be updated.
- Returns:
DiscountDataif successful. - Throws: An
MHExceptionif 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:
IntentDetailsif successful,nullotherwise. - Throws: An
MHExceptionif 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:
IntentDetailsif successful,nullotherwise. - Throws: An
MHExceptionif 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:
IntentDetailsif successful, or an error with details if not. - Throws: An
MHExceptionif 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, ornullif there was an issue. - Throws: An
MHExceptionif failed to proceed with Google Pay, or anUnsupportedErrorif 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
MHExceptionif 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 1 year ago