Get Available Methods
Methods That Require Public Key
These methods depend on the public API key being set in the MoneyHashSDK
using the setPublicKey
method.
To obtain your public API key, please refer to the MoneyHash Integration.
Get Account Methods
To access the available pay-in methods, saved cards, and customer balances, call the getMethods
method with the appropriate search criteria.
Name | Type |
---|---|
currency | String - required |
amount | double - optional |
customer | String - optional |
flowId | String - optional |
operation | IntentOperation - optional |
import 'package:moneyhash/moneyhash.dart';
void main() async {
final moneyHashSDK = MoneyHashSDK();
// Set your public API key
moneyHashSDK.setPublicKey("your_public_api_key");
// Create GetMethodsParams using the withCurrency constructor
final methodsParams = GetMethodsParams.withCurrency(
currency: "USD",
customer: "customer_id",
flowId: "flow_id",
amount: 100.0,
operation: IntentOperation.purchase,
);
try {
// Retrieve available methods
final methods = await moneyHashSDK.getMethods(methodsParams);
print("Available Payment Methods: ${methods.paymentMethods}");
print("Available Express Methods: ${methods.expressMethods}");
print("Saved Cards: ${methods.savedCards}");
print("Customer Balances: ${methods.customerBalances}");
} catch (e) {
print("Error retrieving methods: $e");
}
}
Get Methods For Intent
The getMethods
method allows you to access the available pay-in/pay-out methods, saved cards, and customer balances associated with a specific intent. This can be useful for predefined payment methods or allowing customers to choose their preferred method.
To achieve the functionality, use the getMethods
method with the GetMethodsParams.withIntent
constructor.
Usage Example
import 'package:moneyhash/moneyhash.dart';
void main() async {
final moneyHashSDK = MoneyHashSDK();
// The intentId should be obtained from your backend after creating an intent
final intentId = "your_intent_id_here";
final intentType = IntentType.payment; // or IntentType.payout
// Create GetMethodsParams using the withIntent constructor
final methodsParams = GetMethodsParams.withIntent(
intentId,
intentType,
);
try {
// Retrieve available methods using getMethods
final methods = await moneyHashSDK.getMethods(methodsParams);
print("Available Payment Methods: ${methods.paymentMethods}");
print("Available Express Methods: ${methods.expressMethods}");
print("Saved Cards: ${methods.savedCards}");
print("Customer Balances: ${methods.customerBalances}");
} catch (e) {
print("Error retrieving methods: $e");
}
}
Get Intent Details
To access all intent details related to a specific intentId
, use the getIntentDetails
method.
import 'package:moneyhash/moneyhash.dart';
void main() async {
final moneyHashSDK = MoneyHashSDK();
final intentId = "your_intent_id_here";
try {
final intentDetails = await moneyHashSDK.getIntentDetails(intentId, IntentType.payment);
print("Intent Details: $intentDetails");
} catch (e) {
print("Error retrieving intent details: $e");
}
}
Proceed With Payment
To proceed with a selected payment method, use the proceedWithMethod
method. This method allows you to initiate a payment using the chosen method, such as a payment method ID, saved card ID, or customer balance ID.
import 'package:moneyhash/moneyhash.dart';
void main() async {
final moneyHashSDK = MoneyHashSDK();
final intentId = "your_intent_id_here";
final intentType = IntentType.payment;
final selectedMethodId = "selected_method_id_here";
final methodType = MethodType.paymentMethod; // e.g., paymentMethod, savedCard, customerBalance
final useWalletBalance = true // use the balance in the users wallet to pay if possible
// If you are using a saved Card then pass the saved card CVV, provide it in methodMetaData
final methodMetaData = {
"cvv": "123",
};
try {
final intentResult = await moneyHashSDK.proceedWithMethod(
intentId,
intentType,
selectedMethodId,
methodType,
methodMetaData,
useWalletBalance,
);
print("Proceeded with method: $intentResult");
} catch (e) {
print("Error proceeding with payment: $e");
}
}
Updated 7 days ago