Integrate the Monnify payment gateway seamlessly with Node.js applications using the MonnifySDK.
npm install monnify-node
After installation, initialize the SDK with your Monnify credentials.
const MonnifySDK = require('monnify-node');
const sdk = new MonnifySDK(apiKey, secretKey, contractCode, baseUrl);
Parameters:
apiKey
: The Monnify API key assigned to your account.secretKey
: Your confidential Monnify secret.contractCode
: Your business's unique Monnify code.baseUrl
: Base endpoint for Monnify's API.
Begin a payment transaction:
const result = await sdk.initializeTransaction(amount, customerName, customerEmail, paymentDescription, merchantUrl, currencyCode);
Parameters:
- ... [like before] ...
Successful Response:
{
status: 'success',
checkoutUrl: [URL to redirect the user for completing the payment]
}
Error Response:
{
status: 'error',
message: [Error message explaining the issue]
}
... (Detail out the parameters, successful response, and error response for all the other methods, similar to the above format) ...
While the SDK is built to handle many scenarios, some unexpected situations can still arise. It's important to handle errors gracefully:
try {
const response = await sdk.initializeTransaction(...params);
if(response.status === "success") {
// Successful handling code here
} else {
// Handle potential errors or issues
}
} catch (error) {
console.error("Encountered an error:", error.message);
}
With MonnifySDK
, integrating Monnify's payment solutions into your Node.js projects becomes a breeze. Whenever in doubt, lean on this documentation, and always check Monnify's official resources for the latest updates.