Error objects with descriptive messages. All SDK methods are async and throw on failure — use try/catch to handle them gracefully in your application.
Error types
Handling errors in your code
Wrap SDK calls in atry/catch block and inspect error.message to determine the failure reason:
Common issues
Missing required fields error
Missing required fields error
The
ProviderFactory validates that all required config keys are present before creating a provider. Make sure your config object includes all of the following:- PesaPal:
baseUrl,PESAPAL_CONSUMER_KEY,PESAPAL_CONSUMER_SECRET - ClickPesa:
baseUrl,CLICKPESA_CLIENT_ID,CLICKPESA_API_KEY
.env file is loaded (e.g. dotenv.config() is called before constructing the SDK) and that none of the values are undefined.Authentication failed
Authentication failed
The provider rejected the token request. Verify that:
- Your API credentials (consumer key/secret or client ID/API key) are correct.
- The
baseUrlmatches the environment you are targeting — sandbox credentials do not work against the production endpoint and vice versa.
Payment request failed
Payment request failed
The provider rejected the payment payload. Check that:
- All required fields for the provider are included and correctly named.
- Data types match what the provider expects (e.g. ClickPesa expects
amountas a string). - For PesaPal,
notification_idis present — this is set automatically when you passipnIdas the second argument topay().
IPN registration not supported
IPN registration not supported
You called
registerIpn() on a ClickPesa SDK instance. ClickPesa does not support IPN registration. Remove the registerIpn() call from your ClickPesa integration and call sdk.pay() directly.Unsupported provider type
Unsupported provider type
An unrecognised value was passed as the
provider option. Use the ProviderType enum to avoid typos: