iOS SDK APIs Documentation
The MoneyHash SDK for iOS 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.
Class: MoneyHashSDKBuilder
MoneyHashSDKBuilder
public class MoneyHashSDKBuilder {
public init()
public func setPublicKey(\_ key: String) -> MoneyHashSDKBuilder
public func build() -> MoneyHashSDK
}
1. init
init
public init()
-
Description: Initializes a new instance of
MoneyHashSDKBuilder
. -
Use Case: Start the configuration process for setting up the
MoneyHashSDK
. -
Example:
let sdkBuilder = MoneyHashSDKBuilder()
2. setPublicKey
setPublicKey
public func setPublicKey(_ key: String) -> MoneyHashSDKBuilder
-
Purpose: Sets the public API key for the
MoneyHashSDK
, which is essential for authenticating and authorizing API requests. -
Use Case: Use this method to provide your public API key obtained from the MoneyHash dashboard before building the SDK instance.
-
Parameters:
key
: The public API key as aString
.
-
Returns: The
MoneyHashSDKBuilder
instance to allow method chaining. -
Example:
sdkBuilder.setPublicKey("your_public_api_key")
3. build
build
public func build() -> MoneyHashSDK
-
Description: Builds and returns an instance of
MoneyHashSDK
configured with the provided settings. -
Use Case: After setting all desired configurations using the builder methods, call this method to get the configured
MoneyHashSDK
instance. -
Returns: An instance of
MoneyHashSDK
. -
Example:
let moneyHashSDK = sdkBuilder.build()
Example
// Initialize the builder
let sdkBuilder = MoneyHashSDKBuilder()
// Set the public key (obtained from MoneyHash dashboard)
sdkBuilder.setPublicKey("your_public_api_key")
// Build the MoneyHashSDK instance
let moneyHashSDK = sdkBuilder.build()
// Now you can use the moneyHashSDK instance
moneyHashSDK.setLogLevel(.debug)
Class: MoneyHashSDK
MoneyHashSDK
A. Methods That Do Not Require an Intent ID
1. setLogLevel
setLogLevel
func setLogLevel(logLevel: LogLevel)
- Purpose: Configures the verbosity level of the SDK’s internal logging, allowing developers to control the amount of information logged during runtime.
- Use Case: Use this method to set the desired level of logging output, which is especially useful for debugging during development or troubleshooting in production. Higher log levels like
verbose
provide detailed insights into SDK operations, while lower levels likeerror
focus only on critical issues. - Parameters:
logLevel
: The level of detail for logs, chosen from theLogLevel
enum.
- Returns: This method does not return a value.
- Example:
moneyHashSDK.setLogLevel(.debug)
print("Log level set to DEBUG")
2. setLocale
setLocale
func setLocale(_ locale: Language)
- Purpose: Sets the language preference for the SDK, enabling the display of localized text in the user’s chosen language.
- Use Case: Use this method to change the SDK’s locale to match the app’s localization settings. This helps in providing a localized user experience for customers in different regions. Supported languages include English, Arabic, and French.
- Parameters:
locale
: The locale to be set, chosen from theLanguage
enum.
- Returns: This method does not return a value.
- Example:
moneyHashSDK.setLocale(.english)
print("Locale set to English")
3. setPublicKey
setPublicKey
func setPublicKey(_ key: String)
- Purpose: Registers the public API key for the SDK, allowing it to authenticate requests to MoneyHash's platform.
- Use Case: This method must be called before any other network-based SDK operations to authenticate the application with the MoneyHash platform. The public API key is obtained from the MoneyHash dashboard.
- Parameters:
key
: The public API key, which identifies the application to MoneyHash's API.
- Returns: This method does not return a value.
- Example:
moneyHashSDK.setPublicKey("your_public_api_key")
print("Public key set successfully")
4. isDeviceCompatible
isDeviceCompatible
func isDeviceCompatible() -> Bool
- Purpose: Checks if the current device supports Apple Pay functionality.
- Use Case: Before initiating any Apple Pay transactions, use this method to confirm that the device is capable of processing Apple Pay payments. This is essential for ensuring smooth functionality and providing fallback options on non-compatible devices.
- Returns: A boolean value that indicates whether the device is compatible with Apple Pay (
true
if compatible,false
otherwise). - Example:
let isCompatible = moneyHashSDK.isDeviceCompatible()
if isCompatible {
print("Device is compatible with Apple Pay")
} else {
print("Device is not compatible with Apple Pay")
}
B. Methods That Require the Public Key to Be Set
5. getMethods
(Using Currency and Amount)
getMethods
(Using Currency and Amount)func getMethods(currency: String, amount: Double?, customer: String?, flowId: String?) async throws -> IntentMethods
- Purpose: Retrieves available payment methods for a specific transaction, using the currency and amount as key criteria.
- Use Case: This method is used when setting up a payment session where no intent ID has been created yet. It allows merchants to dynamically fetch the payment methods that are supported for a given currency and amount. Optionally, customer and flow identifiers can be provided to tailor the payment methods to specific customer profiles or workflows.
- Parameters:
currency
: The currency code (e.g.,USD
,EUR
) for the transaction.amount
: The total amount for the transaction.customer
: An optional identifier for the customer making the transaction.flowId
: An optional identifier for a custom flow or transaction process.
- Returns: An
IntentMethods
object containing the available payment methods. - Example:
do {
let methods = try await moneyHashSDK.getMethods(currency: "USD", amount: 200, customer: "customer-id", flowId: "flow-id")
print("Available methods: \(methods)")
} catch {
print("Error retrieving methods: \(error)")
}
C. Methods That Require Payment Intent ID
6. getMethods
(Using Intent ID)
getMethods
(Using Intent ID)func getMethods(intentId: String, intentType: IntentType) async throws -> IntentMethods
- Purpose: Retrieves available payment or payout methods for a specific transaction, based on an existing intent.
- Use Case: This method is ideal when you already have a payment or payout intent created, and you want to fetch the available methods to complete the transaction. It is especially useful for ongoing payment sessions or when reloading payment options for a user.
- Parameters:
intentId
: The unique identifier for the intent.intentType
: The type of the intent, such as.payment
or.payout
.
- Returns: An
IntentMethods
object containing available methods. - Example:
do {
let methods = try await moneyHashSDK.getMethods(intentId: "intent_id_here", intentType: .payment)
print("Available methods: \(methods)")
} catch {
print("Error retrieving methods: \(error)")
}
7. getIntentDetails
getIntentDetails
func getIntentDetails(intentId: String, intentType: IntentType) async throws -> IntentDetails
- Purpose: Fetches the details of an existing payment or payout intent, including transaction status and associated metadata.
- Use Case: This method is typically used when you need to retrieve comprehensive details about a specific intent, such as after a transaction has been initiated or processed. This allows developers to access the full details and intent state.
- Parameters:
intentId
: The unique identifier of the intent.intentType
: The type of the intent, either.payment
or.payout
.
- Returns: An
IntentDetails
object containing the detailed information about the intent. - Example:
do {
let details = try await moneyHashSDK.getIntentDetails(intentId: "intent_id", intentType: .payment)
print("Intent details: \(details)")
} catch {
print("Error retrieving intent details: \(error)")
}
8. resetSelectedMethod
resetSelectedMethod
func resetSelectedMethod(intentId: String, intentType: IntentType) async throws -> MethodsResult
- Purpose: Resets the currently selected payment or payout method for a specified intent, allowing the user to reselect or change the method.
- Use Case: This method is useful when the user wants to change their payment method after a previous selection or if there’s a need to refresh the method selection. It clears the selected method and returns the updated list of available methods.
- Parameters:
intentId
: The unique identifier of the intent.intentType
: The type of the intent (e.g.,.payment
,.payout
).
- Returns: A
MethodsResult
object, containing the available methods after the reset. - Example:
do {
let result = try await moneyHashSDK.resetSelectedMethod(intentId: "intent_id", intentType: .payment)
print("Method reset successfully: \(result)")
} catch {
print("Error resetting method: \(error)")
}
9. renderForm
renderForm
func renderForm(
on viewController: UIViewController,
intentId: String,
embedStyle: EmbedStyle?,
intentType: IntentType,
completionHandler: @escaping (Result<IntentDetails, Error>) -> Void
)
- Purpose: Renders the MoneyHash form within the app's user interface, this will take over the payment or payout process and handle it using MoneyHash embed.
- Parameters:
viewController
: The view controller on which the form will be rendered.intentId
: The unique identifier of the intent.embedStyle
: Optional styling for the embedded form.intentType
: The type of the intent (e.g.,.payment
,.payout
).completionHandler
: A closure that is called when the form
is submitted, providing either IntentDetails
or an error.
- Example:
moneyHashSDK.renderForm(
on: self,
intentId: "intent_id",
embedStyle: nil,
intentType: .payment
) { result in
switch result {
case .success(let details):
print("Form rendered successfully with details: \(details)")
case .failure(let error):
print("Failed to render form: \(error)")
}
}
10. proceedWithMethod
proceedWithMethod
func proceedWithMethod(
intentId: String,
intentType: IntentType,
selectedMethodId: String,
methodType: MethodType,
metaData: MethodMetaData?
) async throws -> MethodsResult
- Purpose: Proceeds with the selected payment or payout method for a given intent, continuing the transaction based on the selected method and any additional metadata provided.
- Use Case: This method is critical in scenarios where the user has chosen a payment method and is ready to proceed with the transaction. Optional metadata such as CVV can be passed to this method to complete the transaction flow.
- Parameters:
intentId
: The unique identifier of the intent.intentType
: The type of the intent, such as.payment
or.payout
.selectedMethodId
: The identifier of the selected payment or payout method.methodType
: The type of method being used (e.g.,.paymentMethod
,.payoutMethod
).metaData
: Optional metadata to be passed along with the selected method (e.g., CVV for cards).
- Returns: A
MethodsResult
object containing the result of the method selection. - Example:
do {
let result = try await moneyHashSDK.proceedWithMethod(
intentId: "intent_id",
intentType: .payment,
selectedMethodId: "method_id",
methodType: .paymentMethod,
metaData: nil
)
print("Proceeded with method successfully: \(result)")
} catch {
print("Error proceeding with method: \(error)")
}
11. submitForm
submitForm
func submitForm(
intentID: String,
selectedMethod: String,
billingData: [String: String]?,
shippingData: [String: String]?,
vaultData: VaultData?,
saveCard: Bool?,
installmentPlanData: InstallmentPlanData?
) async throws -> IntentDetails
- Purpose: Submits the form data related to a payment or payout intent, completing the transaction with the provided billing, shipping, vault data, and optional installment plan data.
- Use Case: Use this method once the user has entered all necessary payment details, including any selected installment plan. It finalizes the transaction and can save the user's card if desired.
- Parameters:
intentID
: The unique identifier of the intent.selectedMethod
: The identifier of the selected payment or payout method.billingData
: Optional dictionary containing billing information.shippingData
: Optional dictionary containing shipping information.vaultData
: Optional tokenized card information from the vault.saveCard
: A Boolean indicating whether the card should be saved for future use.installmentPlanData
: OptionalInstallmentPlanData
object representing the selected installment plan.
- Returns: An
IntentDetails
object containing the submitted details and the result of the transaction. - Example:
do {
let installmentPlanData = InstallmentPlanData(id: "plan_id_123", issuerCode: "issuer_code_456")
let details = try await moneyHashSDK.submitForm(
intentID: "intent_id",
selectedMethod: "method_id",
billingData: ["name": "John Doe"],
shippingData: ["address": "1234 Street"],
vaultData: nil,
saveCard: true,
installmentPlanData: installmentPlanData
)
print("Form submitted successfully with installment plan: \(details)")
} catch {
print("Error submitting form: \(error)")
}
12. submitCardCVV
submitCardCVV
func submitCardCVV(
intentID: String,
cvv: String,
installmentPlanData: InstallmentPlanData?
) async throws -> IntentDetails
- Purpose: Submits the CVV for a saved card associated with a specified payment intent, enabling the completion of a card-based transaction with an optional installment plan.
- Use Case: Use this method when a user selects a saved card and needs to enter the CVV, possibly along with selecting an installment plan.
- Parameters:
intentID
: The unique identifier of the intent.cvv
: The CVV code of the saved card.installmentPlanData
: OptionalInstallmentPlanData
object representing the selected installment plan.
- Returns: An
IntentDetails
object containing the result of the transaction. - Example:
do {
let installmentPlanData = InstallmentPlanData(id: "plan_id_123", issuerCode: "issuer_code_456")
let details = try await moneyHashSDK.submitCardCVV(
intentID: "intent_id",
cvv: "123",
installmentPlanData: installmentPlanData
)
print("CVV submitted successfully with installment plan: \(details)")
} catch {
print("Error submitting CVV: \(error)")
}
- Example:
do {
let details = try await moneyHashSDK.submitCardCVV(intentID: "intent_id", cvv: "123")
print("CVV submitted successfully: \(details)")
} catch {
print("Error submitting CVV: \(error)")
}
13. submitPaymentReceipt
submitPaymentReceipt
func submitPaymentReceipt(intentId: String, data: String) async throws -> IntentDetails
- Purpose: Submits a payment receipt for a specified payment intent, providing confirmation or additional details related to the transaction.
- Use Case: This method is useful when a third-party or manual payment confirmation needs to be submitted, such as when a payment receipt is generated outside the SDK. It allows you to associate the receipt with the transaction for record-keeping and confirmation.
- Parameters:
intentId
: The unique identifier of the payment intent.data
: The receipt data in a string format (could be in JSON or any other format as required).
- Returns: An
IntentDetails
object containing the updated details of the intent. - Example:
do {
let details = try await moneyHashSDK.submitPaymentReceipt(intentId: "intent_id", data: "receipt_data")
print("Receipt submitted successfully: \(details)")
} catch {
print("Error submitting receipt: \(error)")
}
14. updateFees
updateFees
func updateFees(intentId: String, fees: [FeeItem]) async throws -> FeesData
- Purpose: Updates the fees associated with a specified intent, allowing you to adjust or add fees dynamically during a transaction.
- Use Case: This method is useful in scenarios where additional fees (such as service or delivery fees) need to be applied or adjusted after an intent is created. It ensures that the final transaction reflects all applicable fees before completion.
- Parameters:
intentId
: The unique identifier of the intent.fees
: An array ofFeeItem
objects representing the updated fees.
- Returns: A
FeesData
object containing the updated fees. - Example:
let feeItem1 = FeeItem(title: ["en": "Service Fee"], value: "5.0", discount: nil)
let feeItem2 = FeeItem(title: ["en": "Delivery Fee"], value: "3.0", discount: nil)
do {
let updatedFees = try await moneyHashSDK.updateFees(intentId: "intent_id", fees: [feeItem1, feeItem2])
print("Fees updated successfully: \(updatedFees)")
} catch {
print("Error updating fees: \(error)")
}
15. proceedWithApplePay
proceedWithApplePay
func proceedWithApplePay(
intentID: String,
depositAmount: Float,
merchantIdentifier: String,
currencyCode: String,
countryCode: String
) async throws -> IntentDetails
- Purpose: Initiates and processes an Apple Pay transaction for a specified payment intent, leveraging the device’s native Apple Pay capabilities.
- Use Case: This method is used when a user selects Apple Pay as their payment method. It handles the entire Apple Pay flow—from displaying the Apple Pay sheet to processing the payment on successful authorization. This provides a smooth, secure, and familiar payment experience for users with Apple Pay–enabled devices.
- Parameters:
intentID
: The unique identifier of the payment intent.depositAmount
: The total amount to be charged in the transaction.merchantIdentifier
: The merchant identifier registered for Apple Pay, used to verify the merchant during the transaction.currencyCode
: The currency code (e.g.,USD
,EUR
) for the transaction.countryCode
: The country code (e.g.,US
,GB
) associated with the transaction.
- Returns: An
IntentDetails
object containing the updated details after processing the Apple Pay transaction. - Note: Apple Pay transactions can only be processed on devices that support Apple Pay. Use the
isDeviceCompatible
method to ensure compatibility before initiating this payment method. - Example:
do {
let intentDetails = try await moneyHashSDK.proceedWithApplePay(
intentID: "intent_id",
depositAmount: 50.0,
merchantIdentifier: "merchant.com.example",
currencyCode: "USD",
countryCode: "US"
)
print("Apple Pay transaction successful: \(intentDetails)")
} catch {
print("Error with Apple Pay transaction: \(error)")
}
16. updateDiscount
updateDiscount
func updateDiscount(intentId: String, discount: DiscountItem) async throws -> DiscountData
- Purpose: Updates the discount associated with a specified payment intent, allowing the application of a discount to the total transaction amount.
- Use Case: This method is used when a discount needs to be applied or modified for a transaction after the intent has been created. Discounts can be based on promotional codes, loyalty programs, or other incentives, and this method ensures the transaction reflects the correct discount before processing.
- Parameters:
intentId
: The unique identifier of the payment intent for which the discount is being updated.discount
: ADiscountItem
object representing the discount details (e.g., type, value, and localized title).
- Returns: A
DiscountData
object containing the updated discount information. - Example:
let discountTitle = ["en": "Promo Code", "ar": "رمز العرض"]
let discountItem = DiscountItem(title: discountTitle, type: .amount, value: "10.0")
do {
let discountData = try await moneyHashSDK.updateDiscount(intentId: "intent_id", discount: discountItem)
print("Discount updated successfully: \(discountData)")
} catch {
print("Error updating discount: \(error)")
}
17. selectInstallmentPlan
selectInstallmentPlan
func selectInstallmentPlan(
intentId: String,
installmentPlanData: InstallmentPlanData
) async throws -> IntentDetails?
- Purpose: Selects an installment plan for a specified payment intent, updating the intent with the chosen plan.
- Use Case: Use this method when a user selects an installment plan from available options to proceed with a payment intent.
- Parameters:
intentId
: The unique identifier of the payment intent.installmentPlanData
: AnInstallmentPlanData
object containing the ID of the selected installment plan and the issuer code.
- Returns: An optional
IntentDetails
object containing updated information about the intent after the installment plan is selected. - Throws: An
MHError
if the operation fails, such as if the plan is not available or the intent is invalid. - Example:
do {
let installmentPlanData = InstallmentPlanData(id: "plan_id_123", issuerCode: "issuer_code_456")
if let intentDetails = try await moneyHashSDK.selectInstallmentPlan(
intentId: "intent_id",
installmentPlanData: installmentPlanData
) {
print("Installment plan selected successfully: \(intentDetails)")
} else {
print("No intent details returned after selecting installment plan.")
}
} catch {
print("Error selecting installment plan: \(error)")
}
18. getInstallmentPlans
getInstallmentPlans
func getInstallmentPlans(
amount: Double,
currency: String,
first6Digits: String?
) async throws -> [InstallmentPlan]?
- Purpose: Retrieves available installment plans based on the provided amount, currency, and optionally the first six digits of the card number.
- Use Case: Use this method to fetch installment plan options available for a specific transaction, which can then be presented to the user for selection.
- Parameters:
amount
: The amount for which installment plans are to be fetched.currency
: The currency code (e.g., "USD", "EUR").first6Digits
: Optional. The first six digits of the card number to tailor installment plans.
- Returns: An array of
InstallmentPlan
objects representing the available installment plans, ornil
if none are available. - Throws: An
MHError
if the operation fails. - Example:
do {
if let plans = try await moneyHashSDK.getInstallmentPlans(
amount: 500.0,
currency: "USD",
first6Digits: "123456"
) {
print("Available installment plans:")
for plan in plans {
print("Plan ID: \(plan.id ?? "N/A"), Period: \(plan.installmentPeriod ?? 0) months")
}
} else {
print("No installment plans available for the specified criteria.")
}
} catch {
print("Error retrieving installment plans: \(error)")
}
D. Methods That Require Card Intent ID
19. deleteSavedCard
deleteSavedCard
func deleteSavedCard(cardTokenId: String, intentSecret: String) async throws
- Purpose: Deletes a saved card from the system using its token ID, ensuring that the card will no longer be available for future transactions.
- Use Case: This method is ideal when a user wants to remove a saved card for security or personal reasons. The card is identified using its token ID, and the intent secret is required to ensure that the deletion is authorized and secure. Once deleted, the card can no longer be used for payments or stored in the vault.
- Parameters:
cardTokenId
: The token ID of the card to be deleted.intentSecret
: The secret associated with the card intent, used to authorize the deletion.
- Returns: This method does not return a value.
- Example:
do {
try await moneyHashSDK.deleteSavedCard(cardTokenId: "card_token_123", intentSecret: "intent_secret_456")
print("Card deleted successfully")
} catch {
print("Error deleting card: \(error)")
}
Updated about 2 months ago