PaymentClient API Reference
ThePaymentClient
is the main entry point for FundKit integration. It provides a unified interface to interact with multiple payment providers.
Constructor
new PaymentClient(config)
Creates a new PaymentClient instance with provider configurations.
Parameters:
config
(object): Configuration object for providers
Provider | Required Fields | Optional Fields |
---|---|---|
honeycoin | apiKey | environment , baseUrl , timeout |
easypay | apiKey | environment , baseUrl , timeout |
tola | apiKey | environment , baseUrl , timeout |
Methods
collect(request)
Initiates a payment collection request using the best available provider.
Parameters:
request
(CollectionRequest): Payment collection details
Promise<PayClientCollectionResponse>
Example:
amount
: Must be positive integercurrency
: Must be supported by at least one providerphoneNumber
: Must be valid international formatreason
: Required, minimum 3 characters
checkTransactionStatus(transactionId, provider?)
Checks the current status of a transaction.
Parameters:
transactionId
(string): Transaction ID to checkprovider
(string, optional): Specific provider to query
Promise<PayClientTransactionResponse>
Example:
getAvailableProviders()
Returns list of configured and available providers.
Returns: string[]
Example:
getProviderCurrencies(provider?)
Returns supported currencies for a provider or all providers.
Parameters:
provider
(string, optional): Specific provider name
string[] | Record<string, string[]>
Example:
validateRequest(request)
Validates a collection request without executing it.
Parameters:
request
(CollectionRequest): Request to validate
ValidationResult
Example:
Events
The PaymentClient extends EventEmitter and emits various events during operation.Event: transaction:created
Emitted when a new transaction is created.
Event: transaction:updated
Emitted when a transaction status changes.
Event: provider:selected
Emitted when a provider is selected for a transaction.
Event: error
Emitted when an error occurs.
Configuration Options
Environment Settings
Global Options
Error Handling
All methods can throw the following error types:ValidationError
Thrown when request validation fails.
ProviderError
Thrown when a provider API call fails.
ConfigurationError
Thrown when client configuration is invalid.
Type Definitions
TransactionStatus
CurrencyCode
ProviderName
Best Practices
- Always handle errors: Wrap API calls in try-catch blocks
- Validate before submitting: Use
validateRequest()
for client-side validation - Monitor transaction status: Use webhooks or polling for status updates
- Use proper phone format: Always use international format (+country-code)
- Handle provider failures: Implement retry logic for transient failures
- Secure API keys: Never expose API keys in client-side code