icadpay-sdk v2.1.6
IcadPay SDK
IcadPay SDK is a comprehensive and easy-to-use JavaScript SDK for integrating the IcadPay payment gateway into your web applications. It supports various payment methods, including card payments, USSD payments, QR codes, and bank transfers.
Features: Seamless integration with IcadPay's payment API. Support for multiple payment methods. Flexible configuration for custom integrations. Lightweight and optimized for performance. Built-in TypeScript support.
IcadPay SDK
A simple and robust JavaScript SDK for integrating the IcadPay payment gateway.
š¦ Installation
Install the SDK via npm:
npm install icadpay-sdk
or via yarn:
yarn add icadpay-sdk
š§ Configuration
Using a .env
File
To securely store your API keys and configurations, create a .env
file in your project root and add:
ICADPAY_API_BASE_URL=https://icad-staging.icadpay.com/
MERCHANT_PUBLIC_KEY=your_public_key_here
DEBUG=true
Ensure you load the environment variables in your project:
import dotenv from "dotenv";
dotenv.config();
š Usage
1ļøā£ Initialize the SDK
import IcadPay from "icadpay-sdk";
const icadPay = IcadPay.initialize(process.env.MERCHANT_PUBLIC_KEY, { enableLogging: process.env.DEBUG === "true" });
š Payment Methods
2ļøā£ Initiate Card Payment
const response = await icadPay.initiateCardPayment({
customerId: "12345",
amount: 1000,
transactionRef: "txn_98765",
deviceInformation: { userAgentBrowserValue: "Mozilla/5.0" },
currency: "NGN",
dataBlock: "cardData",
callbackUrl: "https://your-website.com/callback",
customerName: "John Doe",
customerPhone: "555-1234",
customerEmail: "john.doe@example.com",
});
console.log(response);
3ļøā£ Initiate USSD Payment
const response = await icadPay.initiateUssdPayment({
customerId: "12345",
amount: 1000,
transactionRef: "txn_98765",
currency: "NGN",
dataBlock: "ussdData",
callbackUrl: "https://your-website.com/callback",
customerName: "Jane Doe",
customerPhone: "555-6789",
customerEmail: "jane.doe@example.com",
});
4ļøā£ Initiate Bank Transfer
const response = await icadPay.initiateBankTransfer({
customerId: "12345",
amount: 5000,
transactionRef: "txn_56789",
bankAccountNumber: "1234567890",
bankCode: "XYZ",
currency: "NGN",
dataBlock: "bankTransferData",
callbackUrl: "https://your-website.com/callback",
customerName: "Mark Smith",
customerPhone: "555-4321",
customerEmail: "mark.smith@example.com",
});
5ļøā£ Generate QR Code Payment
const response = await icadPay.generateQRCodePayment({
customerId: "12345",
amount: 2000,
transactionRef: "txn_12345",
currency: "NGN",
dataBlock: "qrCodeData",
callbackUrl: "https://your-website.com/callback",
customerName: "Mike Johnson",
customerPhone: "555-9876",
customerEmail: "mike.johnson@example.com",
});
ā Verify Transactions
const response = await icadPay.verifyTransaction("txn_12345");
console.log(response);
ā Error Handling
All API calls throw an error if something goes wrong:
try {
const response = await icadPay.initiateCardPayment({...});
console.log(response);
} catch (error) {
console.error("Payment failed:", error.message);
}
š License
This SDK is licensed under the MIT License.
šØāš» Contributing
We welcome contributions! To contribute:
- Fork the repository
- Create a new branch (
git checkout -b feature-branch
) - Commit your changes (
git commit -m "Added new feature"
) - Push to the branch (
git push origin feature-branch
) - Create a pull request
š Support
For any issues, feel free to open an issue or contact us at support@icadpay.com
.
š Happy Coding!