prestmit-partners-api
v0.0.1
Published
Prestmit Partners API SDK
Readme
Prestmit Partners API Client
A TypeScript/JavaScript client library for interacting with the Prestmit Partners API. This SDK provides a convenient way to integrate with Prestmit's gift card trading, wallet management, and other services in your Node.js applications.
Features
- Gift Card Trading: Buy and sell gift cards programmatically
- Wallet Management: Check balances and transaction history
- Bank Account Integration: Manage Naira and Cedis bank accounts
- TypeScript Support: Full type definitions for better development experience
- Promise-based API: Modern async/await support
- Environment Support: Switch between production and sandbox environments
Installation
npm install prestmit-partners-api
# or
yarn add prestmit-partners-apiPrerequisites
- Node.js 14.x or later
- Prestmit Partner API credentials (API Key and Secret Key)
Usage
Basic Setup
import { PrestmitService } from "prestmit-partners-api";
// Initialize the service with your API credentials
const service = new PrestmitService({
environment: "sandbox", // or 'production'
apiKey: "your-api-key",
secretKey: "your-secret-key",
});Example: Fetching Gift Card Categories
async function getGiftCardCategories() {
try {
const categories = await service.fetchGiftcardCategories();
console.log("Available categories:", categories);
return categories;
} catch (error) {
console.error("Error fetching categories:", error);
throw error;
}
}Example: Selling a Gift Card
async function sellGiftCard(cardDetails) {
try {
const result = await service.sellGiftcard({
categoryID: cardDetails.categoryId,
subCategoryID: cardDetails.subCategoryId,
amount: cardDetails.amount,
rate: cardDetails.rate,
payoutMethod: cardDetails.payoutMethod,
attachments: [cardDetails.receiptImagePath],
// ... other required fields
});
console.log("Gift card sold successfully:", result);
return result;
} catch (error) {
console.error("Error selling gift card:", error);
throw error;
}
}API Reference
PrestmitService
The main class for interacting with the Prestmit API.
Constructor
new PrestmitService(options: PrestmitServiceOptions)Options:
| Parameter | Type | Required | Description | | ----------- | ------------------------- | -------- | -------------------------------- | | environment | 'production' | 'sandbox' | Yes | The API environment to use | | apiKey | string | Yes | Your Prestmit Partner API key | | secretKey | string | Yes | Your Prestmit Partner secret key | | version | string | No | API version (default: 'v1') |
Available Methods
Gift Card Operations
fetchGiftcardCategories(): Get list of available gift card categoriesfetchGiftcardSubcategories(params): Get subcategories for a categoryfetchGiftcardOrderHistory(page): Get gift card order historysellGiftcard(data): Sell a gift card
Wallet Operations
fetchFiatWalletDetails(wallet): Get fiat wallet detailsfetchFiatWithdrawalHistory(page, wallet): Get withdrawal historyfetchWithdrawalReceipt(id): Get withdrawal receipt
Bank Account Operations
addNairaBankAccount(data): Add a Naira bank accountfetchNairaBankAccounts(page): List Naira bank accountsremoveNairaBankAccount(id): Remove a Naira bank accountaddCedisBankAccount(data): Add a Cedis bank accountfetchCedisBankAccounts(page): List Cedis bank accountsremoveCedisBankAccount(id): Remove a Cedis bank account
Error Handling
The SDK throws PrestmitError for API-related errors. Always wrap API calls in try/catch blocks:
try {
const result = await service.someMethod();
} catch (error) {
console.error("API Error:", error.message);
console.error("Status Code:", error.status);
console.error("Error Details:", error.details);
}Development
Prerequisites
- Node.js 14+
- npm or yarn
Setup
- Clone the repository
- Install dependencies:
npm install # or yarn - Create a
.envfile with your test credentials:SECRETE_KEY=your_test_secret_key API_KEY=your_test_api_key
Building
# Build the project
npm run build
# Watch for changes and rebuild
npm run build:watchTesting
# Run tests
npm test
# Run in development mode with hot-reload
npm run devRunning and Testing
Prerequisites
Before running the tests, make sure you have:
- Node.js 14.x or later installed
- Valid Prestmit Partner API credentials (API Key and Secret Key)
- Environment variables set up (see Setup section)
Development Mode
To run in development mode with hot-reloading:
npm run devThis will:
- Watch for file changes and rebuild automatically
- Run the test script from
test-folder/script.ts - Show API responses in the console
Running Specific Examples
The test-folder/script.ts contains various test cases. You can uncomment the specific API call you want to test:
// Example: Test service status
service.checkServiceStatus().then(console.log).catch(console.error);
// Example: Fetch gift card categories
// service.fetchGiftcardCategories()
// .then(console.log)
// .catch(console.error);
// Example: Fetch user profile
// service.fetchUserProfile()
// .then(console.log)
// .catch(console.error);Testing with Different Environments
You can switch between environments by changing the environment parameter when initializing the service:
// For sandbox/testing environment
const sandboxService = new PrestmitService({
environment: "sandbox",
apiKey: "your_sandbox_api_key",
secretKey: "your_sandbox_secret_key",
});
// For production environment
const productionService = new PrestmitService({
environment: "production",
apiKey: "your_production_api_key",
secretKey: "your_production_secret_key",
});Debugging
To enable debug logging, set the DEBUG environment variable:
DEBUG=prestmit:* npm run devThis will show detailed request/response information in the console.
Common Issues
Connection Issues:
- Ensure you have a stable internet connection
- Check if the Prestmit API is accessible from your network
- Verify the API endpoint URLs in
src/core/clients.ts
Authentication Errors:
- Double-check your API key and secret key
- Ensure you're using the correct environment (sandbox vs production)
- Verify that your account has the necessary permissions
Rate Limiting:
- The API might have rate limits
- Add delays between requests if you encounter rate limit errors
TypeScript Errors:
- Run
npm run buildto check for TypeScript compilation errors - Make sure all required environment variables are properly typed
- Run
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For support, please contact Prestmit support at [email protected]
Acknowledgements
- Prestmit for their API
- All contributors who have helped improve this library
