A comprehensive NestJS module for integrating with Paystack API
npm install @scwar/nestjs-paystackA comprehensive NestJS module for integrating with the Paystack API. This package provides a complete wrapper around all Paystack API endpoints with robust error handling, retries, and TypeScript support.
- ๐ Complete API Coverage: All Paystack API endpoints implemented
- ๐ Automatic Retries: Built-in retry mechanism with exponential backoff
- ๐ก๏ธ Robust Error Handling: Comprehensive error handling with detailed error messages
- ๐ TypeScript Support: Full type definitions for all API requests and responses
- ๐งช Comprehensive Testing: Extensive test coverage for all endpoints
- โก Performance: Uses native fetch API for optimal performance
- ๐ง Configurable: Easy configuration through NestJS module options
``bash`
npm install @scwar/nestjs-paystack
`typescript
import { PaystackModule } from '@scwar/nestjs-paystack';
@Module({
imports: [
PaystackModule.forRoot({
secretKey: 'your-paystack-secret-key',
baseUrl: 'https://api.paystack.co',
timeout: 30000,
retries: 3,
}),
],
})
export class AppModule {}
`
`typescript
import { PaystackService } from '@scwar/nestjs-paystack';
@Injectable()
export class PaymentService {
constructor(private readonly paystackService: PaystackService) {}
async createTransaction(amount: number, email: string) {
return this.paystackService.transaction.initialize({
amount: amount * 100, // Convert to kobo
email,
callback_url: 'https://your-domain.com/verify',
});
}
}
`
`typescript`
interface PaystackModuleOptions {
secretKey: string;
baseUrl?: string;
timeout?: number;
retries?: number;
retryDelay?: number;
maxRetryDelay?: number;
}
The package provides comprehensive error handling with detailed error messages:
`typescript`
try {
const result = await this.paystackService.transaction.initialize(data);
} catch (error) {
if (error instanceof PaystackError) {
console.log('Paystack Error:', error.message);
console.log('Error Code:', error.code);
console.log('HTTP Status:', error.status);
}
}
Automatic retries with exponential backoff for failed requests:
`typescript`
// Configure retries in module options
PaystackModule.forRoot({
secretKey: 'your-key',
retries: 3, // Number of retry attempts
retryDelay: 1000, // Initial delay in ms
maxRetryDelay: 10000, // Maximum delay in ms
})
`bashRun tests
npm test
Version Management & Releases
This package includes an automated version bumping system that follows semantic versioning and conventional commits.
$3
The system automatically determines the appropriate version bump based on your commits:
`bash
Automatically determine and bump version
npm run version:autoManual version bumps
npm run version:patch # 1.0.0 โ 1.0.1
npm run version:minor # 1.0.0 โ 1.1.0
npm run version:major # 1.0.0 โ 2.0.0
`$3
All commits must follow the Conventional Commits specification:
`bash
Feature commits (minor version bump)
git commit -m "feat: add new payment method"Bug fix commits (patch version bump)
git commit -m "fix: resolve authentication issue"Breaking change commits (major version bump)
git commit -m "feat!: breaking change in API"Documentation commits (no version bump)
git commit -m "docs: update README with examples"Test commits (no version bump)
git commit -m "test: add unit tests for payment service"
`$3
#### Automated Release (Recommended)
`bash
Complete release process with automatic version bump
npm run release:autoManual release with specific version bump
npm run release:patch
npm run release:minor
npm run release:major
`#### Manual Release Steps
`bash
1. Bump version and update changelog
npm run version:auto2. Build and test
npm run build && npm test3. Commit changes
git add .
git commit -m "chore: bump version to $(node -p \"require('./package.json').version\")"4. Create tag
git tag "v$(node -p \"require('./package.json').version\")"5. Push changes and tag
git push && git push --tags6. Publish to npm
npm publish
`$3
The changelog is automatically updated with each version bump:
`bash
Update changelog with recent changes
npm run changelog:updateGenerate full changelog from git history
npm run changelog:generate -- --full
`$3
The package includes GitHub Actions workflows for:
- CI: Automated testing, linting, and quality checks
- Release: Automated version bumping, changelog updates, and npm publishing
- Security: Dependency audits and vulnerability checks
$3
Pre-commit hooks ensure code quality:
- Linting and formatting checks
- Test execution
- Conventional commit message validation
Contributing
1. Fork the repository
2. Create your feature branch (
git checkout -b feature/amazing-feature)
3. Commit your changes using conventional commit format
4. Push to the branch (git push origin feature/amazing-feature`)Important: All commits must follow the conventional commit format to ensure proper version bumping.
This project is licensed under the MIT License - see the LICENSE file for details.
For support, please open an issue on GitHub or contact the maintainers.
See CHANGELOG.md for a list of changes and version history.