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 Documentation.
Get Account Methods
To access the available pay-in methods, saved cards, and customer balances, call the getMethods
method with the appropriate search criteria.
Parameters:
currency
:String
- requiredamount
:Double
- optionalcustomer
:String
- optionalflowId
:String
- optional
import UIKit
// Initialize the SDK using the builder
let sdkBuilder = MoneyHashSDKBuilder()
sdkBuilder.setPublicKey("your_public_api_key")
let moneyHashSDK = sdkBuilder.build()
// Retrieve available methods
Task {
do {
let currency = "USD"
let amount: Double? = 100.0 // Optional
let customer: String? = "customer_id" // Optional
let flowId: String? = "flow_id" // Optional
let methods = try await moneyHashSDK.getMethods(currency: currency, amount: amount, customer: customer, flowId: flowId)
print("Available Payment Methods: \(methods.paymentMethods)")
print("Available Express Methods: \(methods.expressMethods)")
print("Saved Cards: \(methods.savedCards)")
print("Customer Balances: \(methods.customerBalances)")
} catch let error as MHError {
// Handle MHError
print("Error retrieving methods: \(error.message)")
if !error.errors.isEmpty {
for errorInfo in error.errors {
print("Error key: \(errorInfo.key), message: \(errorInfo.message)")
}
}
}
}
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 this functionality, call the getMethods
method with the intent ID and intent type.
Usage Example:
import UIKit
// Initialize the SDK using the builder
let sdkBuilder = MoneyHashSDKBuilder()
sdkBuilder.setPublicKey("your_public_api_key")
let moneyHashSDK = sdkBuilder.build()
// Retrieve available methods using intent
Task {
do {
// The intentId should be obtained from your backend after creating an intent
let intentId = "your_intent_id_here"
let intentType: IntentType = .payment // or .payout
let methods = try await moneyHashSDK.getMethods(intentId: intentId, intentType: intentType)
print("Available Payment Methods: \(methods.paymentMethods)")
print("Available Express Methods: \(methods.expressMethods)")
print("Saved Cards: \(methods.savedCards)")
print("Customer Balances: \(methods.customerBalances)")
} catch let error as MHError {
// Handle MHError
print("Error retrieving methods: \(error.message)")
if !error.errors.isEmpty {
for errorInfo in error.errors {
print("Error key: \(errorInfo.key), message: \(errorInfo.message)")
}
}
}
}
Get Intent Details
To access all intent details related to a specific intentId
, use the getIntentDetails
method.
import UIKit
// Initialize the SDK using the builder
let sdkBuilder = MoneyHashSDKBuilder()
sdkBuilder.setPublicKey("your_public_api_key")
let moneyHashSDK = sdkBuilder.build()
// Retrieve intent details
Task {
do {
let intentId = "your_intent_id_here"
let intentType: IntentType = .payment // or .payout
let intentDetails = try await moneyHashSDK.getIntentDetails(intentId: intentId, intentType: intentType)
print("Intent Details: \(intentDetails)")
} catch let error as MHError {
// Handle MHError
print("Error retrieving intent details: \(error.message)")
if !error.errors.isEmpty {
for errorInfo in error.errors {
print("Error key: \(errorInfo.key), message: \(errorInfo.message)")
}
}
}
}
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 UIKit
// Initialize the SDK using the builder
let sdkBuilder = MoneyHashSDKBuilder()
sdkBuilder.setPublicKey("your_public_api_key")
let moneyHashSDK = sdkBuilder.build()
// Proceed with a selected method
Task {
do {
let intentId = "your_intent_id_here"
let intentType: IntentType = .payment
let selectedMethodId = "selected_method_id_here"
let methodType: IntentMethodType = .paymentMethod // e.g., .paymentMethod, .savedCard, .customerBalance
// If you are using a saved Card then pass the saved card CVV, provide it in methodMetaData
var methodMetaData: IntentMethodMetaData? = nil
if methodType == .savedCard {
methodMetaData = IntentMethodMetaData(cvv: "123") // CVV if required
}
let intentResult = try await moneyHashSDK.proceedWithMethod(
intentId: intentId,
intentType: intentType,
selectedMethodId: selectedMethodId,
methodType: methodType,
metaData: methodMetaData
)
print("Proceeded with method: \(intentResult)")
} catch let error as MHError {
// Handle MHError
print("Error proceeding with payment: \(error.message)")
if !error.errors.isEmpty {
for errorInfo in error.errors {
print("Error key: \(errorInfo.key), message: \(errorInfo.message)")
}
}
}
}
Updated 27 days ago