React Native SDK API Documentation
The MoneyHash SDK for React Native 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.
A. Methods That Do Not Require an Intent ID
1. setLogLevel
setLogLevel
setLogLevel(level: LogLevel): void
- Purpose: Sets the logging level for the SDK.
- Parameters:
level
: The desired logging level, of typeLogLevel
. Possible values are:LogLevel.VERBOSE
LogLevel.DEBUG
LogLevel.INFO
LogLevel.WARN
LogLevel.ERROR
LogLevel.ASSERTION
- Returns: This method does not return a value.
- Example:
moneyHash.setLogLevel(LogLevel.DEBUG);
console.log('Log level set to DEBUG');
2. setLocale
setLocale
setLocale(language: Language): void
- Purpose: Sets the locale for the SDK.
- Parameters:
language
: The locale to be set, of typeLanguage
. Supported values are:Language.ENGLISH
for EnglishLanguage.ARABIC
for ArabicLanguage.FRENCH
for French
- Returns: This method does not return a value.
- Example:
moneyHash.setLocale(Language.ENGLISH);
console.log('Locale set to English');
3. setPublicKey
setPublicKey
setPublicKey(publicKey: string): void
- 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.
- Returns: This method does not return a value.
- Example:
moneyHash.setPublicKey('your_public_api_key');
console.log('Public key set successfully');
4. isDeviceCompatibleWithApplePay
isDeviceCompatibleWithApplePay
isDeviceCompatibleWithApplePay(): Promise<boolean>
- Purpose: Checks if the current device is compatible with Apple Pay.
- Returns: A
Promise
that resolves to a boolean indicating compatibility. - Note: This method is only available on iOS devices. On other platforms, it will reject with an error.
- Example:
moneyHash.isDeviceCompatibleWithApplePay()
.then(isCompatible => {
if (isCompatible) {
console.log('Device is compatible with Apple Pay');
} else {
console.log('Device is not compatible with Apple Pay');
}
})
.catch(error => console.error('Error checking Apple Pay compatibility:', error));
B. Methods That Require the Public Key to Be Set
5. getMethods
getMethods
This method is overloaded and can be called in two different ways:
a) Using an Intent ID and Intent Type
getMethods(intentId: string, intentType: IntentType): Promise<IntentMethods>
- Purpose: Retrieves available payment methods for a specific intent.
- Parameters:
intentId
: The unique identifier of the intent.intentType
: The type of the intent, of typeIntentType
.
- Returns: A
Promise
that resolves to anIntentMethods
object containing available methods. - Example:
moneyHash.getMethods('intent_id_here', IntentType.Payment)
.then(methods => console.log('Available methods:', methods))
.catch(error => console.error('Error retrieving methods:', error));
b) Using Currency and Amount
moneyHashSDK.getMethods({
currency: string,
amount: number,
customer: string,
flowId: string,
}): Promise<IntentMethods>
- Purpose: Retrieves available payment methods based on currency and amount.
- Parameters:
currency
: The currency code (e.g.,'USD'
).amount
: The amount as a number.customer
: The customer ID.flowId
: The flow ID.
- Returns: A
Promise
that resolves to anIntentMethods
object containing available methods. - Example:
moneyHash.setPublicKey('your_public_api_key');
moneyHash.getMethods({
currency: 'USD',
amount: 200,
customer: '<customer-id>',
flowId: '<flow-id>',
}).then(methods => console.log('Available methods:', methods))
.catch(error => console.error('Error retrieving methods:', error));
Methods That Require Payment Intent ID
6. getIntentDetails
()
getIntentDetails
()getIntentDetails(intentId: string, intentType: IntentType): Promise<IntentDetails>
- Purpose: Retrieves the details of a specified intent.
- Parameters:
intentId
: The unique identifier of the intent.intentType
: The type of the intent, of typeIntentType
.
- Returns: A
Promise
that resolves to anIntentDetails
object. - Example:
moneyHash.getIntentDetails('Z1ED7zZ', IntentType.Payment)
.then(intentDetails => console.log('Intent details:', intentDetails))
.catch(error => console.error('Error retrieving intent details:', error));
7. resetSelectedMethod
resetSelectedMethod
resetSelectedMethod(intentId: string, intentType: IntentType): Promise<IntentResult>
- 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, of typeIntentType
.
- Returns: A
Promise
that resolves to anIntentResult
object. - Example:
moneyHash.resetSelectedMethod('Z1ED7zZ', IntentType.Payment)
.then(result => console.log('Method reset successfully:', result))
.catch(error => console.error('Error resetting method:', error));
8. renderForm
renderForm
renderForm(intentId: string, intentType: IntentType, embedStyle?: EmbedStyle): Promise<IntentDetails>
- Purpose: Renders the MoneyHash embed form within the React Native application.
- Parameters:
intentId
: The unique identifier of the intent.intentType
: The type of the intent, of typeIntentType
.embedStyle
: Optional. AnEmbedStyle
object to style the embedded form.
- Returns: A
Promise
that resolves to anIntentDetails
object. - Example:
const embedStyle = {
// Define your embed style here
};
moneyHash.renderForm('current_intent_id', IntentType.Payment, embedStyle)
.then(intentDetails => console.log('Form rendered with details:', intentDetails))
.catch(error => console.error('Failed to render form:', error));
9. proceedWithMethod
proceedWithMethod
proceedWithMethod(
intentId: string,
intentType: IntentType,
selectedMethodId: string,
methodType: MethodType,
methodMetaData?: MethodMetaData
): Promise<IntentResult>
- 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, of typeIntentType
.selectedMethodId
: The ID of the selected method.methodType
: The type of the method, of typeMethodType
.methodMetaData
: Optional. AMethodMetaData
object containing additional data.
- Returns: A
Promise
that resolves to anIntentResult
object encapsulating the result of the method selection. - Example:
const methodMetaData = new MethodMetaData();
methodMetaData.cvv = '123';
moneyHash.proceedWithMethod(
'Z1ED7zZ',
IntentType.Payment,
'method_123',
MethodType.PaymentMethod,
methodMetaData
)
.then(result => console.log('Proceeded with method:', result))
.catch(error => console.error('Error proceeding with method:', error));
10. submitForm
submitForm
submitForm(
intentId: string,
selectedMethodId: string,
billingData?: Record<string, string>,
shippingData?: Record<string, string>,
vaultData?: VaultData
): Promise<IntentDetails>
- Purpose: Submits the form data for a payment or payout intent.
- Parameters:
intentId
: The unique identifier of the intent.selectedMethodId
: The ID of the selected method.billingData
: A record of billing data fields and their values (optional).shippingData
: A record of shipping data fields and their values (optional).vaultData
: Optional. AVaultData
object containing card data.
- Returns: A
Promise
that resolves to anIntentDetails
object. - Example:
const billingData = {
// Populate billing data fields
};
const shippingData = {
// Populate shipping data fields
};
const vaultData = // use the card form collect to get the vault data (or use pay directly on the card form)
moneyHash.submitForm('Z1ED7zZ', 'method_123', billingData, shippingData, vaultData)
.then(intentDetails => console.log('Form submitted successfully:', intentDetails))
.catch(error => console.error('Error submitting form:', error));
11. submitCardCVV
submitCardCVV
submitCardCVV(intentId: string, cvv: string): Promise<IntentDetails>
- 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: A
Promise
that resolves to anIntentDetails
object. - Example:
moneyHash.submitCardCVV('Z1ED7zZ', '123')
.then(intentDetails => console.log('CVV submitted successfully:', intentDetails))
.catch(error => console.error('Error submitting CVV:', error));
12. submitPaymentReceipt
submitPaymentReceipt
submitPaymentReceipt(intentId: string, data: string): Promise<IntentDetails>
- 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: A
Promise
that resolves to anIntentDetails
object. - Example:
moneyHash.submitPaymentReceipt('Z1ED7zZ', 'receipt_data_string')
.then(intentDetails => console.log('Receipt submitted successfully:', intentDetails))
.catch(error => console.error('Error submitting receipt:', error));
13. updateFees
updateFees
updateFees(intentId: string, fees: FeeItem[]): Promise<FeesData>
- Purpose: Updates the fees associated with a specified intent.
- Parameters:
intentId
: The unique identifier of the intent.fees
: An array ofFeeItem
objects representing the fees to be updated.
- Returns: A
Promise
that resolves to aFeesData
object. - Example:
const feeItem1 = new FeeItem(new Map([[Language.ENGLISH, 'Service Fee']]), '5.0');
const feeItem2 = new FeeItem(new Map([[Language.ENGLISH, 'Delivery Fee']]), '3.0');
moneyHash.updateFees('Z1ED7zZ', [feeItem1, feeItem2])
.then(feesData => console.log('Fees updated successfully:', feesData))
.catch(error => console.error('Error updating fees:', error));
14. updateDiscount
updateDiscount
updateDiscount(intentId: string, discount: DiscountItem): Promise<DiscountData>
- 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: A
Promise
that resolves to aDiscountData
object. - Example:
const discountTitle = new Map<Language, string>([
[Language.ENGLISH, 'Promo Code'],
]);
const discountItem = new DiscountItem(discountTitle, DiscountType.AMOUNT, '10.0');
moneyHash.updateDiscount('Z1ED7zZ', discountItem)
.then(discountData => console.log('Discount updated successfully:', discountData))
.catch(error => console.error('Error updating discount:', error));
15. proceedWithApplePay
proceedWithApplePay
proceedWithApplePay(
intentId: string,
depositAmount: number,
merchantIdentifier: string,
currencyCode: string,
countryCode: string
): Promise<IntentDetails>
- Purpose: Initiates an Apple Pay transaction for a specified intent.
- Parameters:
intentId
: The unique identifier of the intent.depositAmount
: The amount to be charged.merchantIdentifier
: The merchant identifier for Apple Pay.currencyCode
: The currency code (e.g.,'USD'
).countryCode
: The country code (e.g.,'US'
).
- Returns: A
Promise
that resolves to anIntentDetails
object. - Note: This method is only available on iOS devices. On other platforms, it will reject with an error.
- Example:
moneyHash.proceedWithApplePay(
'Z1ED7zZ',
50.0,
'merchant.com.example',
'USD',
'US'
)
.then(intentDetails => console.log('Apple Pay transaction successful:', intentDetails))
.catch(error => console.error('Error with Apple Pay transaction:', error));
C. Methods That Require Card Intent ID
8. deleteSavedCard
deleteSavedCard
deleteSavedCard(cardTokenId: string, intentSecret: string): Promise<void>
- Purpose: Deletes a saved card using its token ID and associated intent secret.
- Parameters:
cardTokenId
: The token ID of the card to be deleted.intentSecret
: The secret associated with the intent.
- Example:
moneyHash.deleteSavedCard('card_token_123', 'intent_secret_456')
.then(() => console.log('Card deleted successfully:'))
.catch(error => console.error('Error deleting card:', error));
Updated about 1 month ago