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
:number
- optionalcustomer
:string
- optionalflowId
:string
- optional
import { MoneyHashSDKBuilder } from '@moneyhash/reactnative-sdk';
const moneyHashSDK = MoneyHashSDKBuilder.build();
// Set your public API key
moneyHashSDK.setPublicKey('your_public_api_key');
// Retrieve available methods
(async () => {
try {
const currency = 'USD';
const amount = 100.0; // Optional
const customer = 'customer_id'; // Optional
const flowId = 'flow_id'; // Optional
const methods = await moneyHashSDK.getMethods({currency, amount, customer, flowId});
console.log('Available Payment Methods:', methods.paymentMethods);
console.log('Available Express Methods:', methods.expressMethods);
console.log('Saved Cards:', methods.savedCards);
console.log('Customer Balances:', methods.customerBalances);
} catch (error) {
console.error('Error retrieving methods:', error);
}
})();
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 { MoneyHashSDKBuilder, IntentType } from '@moneyhash/reactnative-sdk';
const moneyHashSDK = MoneyHashSDKBuilder.build();
// Set your public API key
moneyHashSDK.setPublicKey('your_public_api_key');
// Retrieve available methods using intent
(async () => {
try {
// The intentId should be obtained from your backend after creating an intent
const intentId = 'your_intent_id_here';
const intentType = IntentType.Payment; // or IntentType.Payout
const methods = await moneyHashSDK.getMethods(intentId, intentType);
console.log('Available Payment Methods:', methods.paymentMethods);
console.log('Available Express Methods:', methods.expressMethods);
console.log('Saved Cards:', methods.savedCards);
console.log('Customer Balances:', methods.customerBalances);
} catch (error) {
console.error('Error retrieving methods:', error);
}
})();
Get Intent Details
To access all intent details related to a specific intentId
, use the getIntentDetails
method.
import { MoneyHashSDKBuilder, IntentType } from '@moneyhash/reactnative-sdk';
const moneyHashSDK = MoneyHashSDKBuilder.build();
// Set your public API key
moneyHashSDK.setPublicKey('your_public_api_key');
// Retrieve intent details
(async () => {
try {
const intentId = 'your_intent_id_here';
const intentType = IntentType.Payment; // or IntentType.Payout
const intentDetails = await moneyHashSDK.getIntentDetails(intentId, intentType);
console.log('Intent Details:', intentDetails);
} catch (error) {
console.error('Error retrieving intent details:', error);
}
})();
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 {
MoneyHashSDKBuilder,
IntentType,
MethodType,
MethodMetaData,
} from '@moneyhash/reactnative-sdk';
const moneyHashSDK = MoneyHashSDKBuilder.build();
// Set your public API key
moneyHashSDK.setPublicKey('your_public_api_key');
// Proceed with a selected method
(async () => {
try {
const intentId = 'your_intent_id_here';
const intentType = IntentType.Payment;
const selectedMethodId = 'selected_method_id_here';
const methodType = MethodType.PaymentMethod; // e.g., PaymentMethod, SavedCard, CustomerBalance
// If you are using a saved Card then pass the saved card CVV, provide it in methodMetaData
const methodMetaData = new MethodMetaData();
methodMetaData.cvv = '123'; // CVV if required
const intentResult = await moneyHashSDK.proceedWithMethod(
intentId,
intentType,
selectedMethodId,
methodType,
methodMetaData
);
console.log('Proceeded with method:', intentResult);
} catch (error) {
console.error('Error proceeding with payment:', error);
}
})();
Updated 27 days ago