Overview
The Navio PHP SDK provides a modern, type-safe interface for integrating Navio payments into your PHP applications. Built with PHP 8.1+ features and best practices.Type Safe
Full PHP 8.1+ type hints and return types
Composer Ready
PSR-4 autoloading and easy installation
Simple API
Clean, intuitive interface
Error Handling
Custom exceptions for different error types
Requirements
- PHP 8.1 or higher
- Composer
ext-jsonextensionext-curlextension
Installation
Install via Composer:composer.json:
Quick Start
1. Initialize SDK
2. Create Payment Link
3. Check Payment Status
Complete E-commerce Example
Here’s a complete flow for an e-commerce checkout:Background Job for Status Polling
Set up a cron job or background worker:API Reference
OCPay Class
Main SDK entry point.Constructor
$accessToken: Your API access token$options: Optional Guzzle client configurationtimeout: Request timeout in seconds (default: 30)
Methods
createLink(CreateLinkRequest $request): CreateLinkResponse Creates a payment link. checkPayment(string $paymentRef): CheckPaymentResponse Checks payment status.Data Transfer Objects (DTOs)
ProductInfo
CreateLinkRequest
CreateLinkRequest::FEE_MODE_NO_FEE- Merchant pays (default)CreateLinkRequest::FEE_MODE_SPLIT_FEE- 50/50 splitCreateLinkRequest::FEE_MODE_CUSTOMER_FEE- Customer pays
CreateLinkResponse
CheckPaymentResponse
Exception Handling
All exceptions extendOCPayException:
All exceptions provide:
Important Notes
Merchant Validation Required
Amount Limits
- Minimum: 500 DZD
- Maximum: 500,000 DZD
- Must be whole numbers (integers)
Fee Structure
Low Fees: 0% on balance, only 1% withdrawal fee
Payment Link Expiration
Links expire 20 minutes after creation if payment not initiated.Payment Status Flow
- PENDING - Payment in progress → Poll again later
- CONFIRMED - Payment successful → Fulfill order
- FAILED - Payment declined/expired → Mark order failed
Laravel Integration
For Laravel projects, see the complete integration example in the GitHub repository. Includes:- Service provider setup
- Payment service class
- Controller examples
- Database migrations
- Background job for polling
- Error handling
Testing
Using Sandbox
The API automatically uses sandbox mode for test accounts:Unit Tests
Best Practices
Always Save Payment Reference
Always Save Payment Reference
Store
paymentRef immediately after creating the link. You need it to check payment status.Poll Payment Status
Poll Payment Status
Set up a background job to check payment status every 20 minutes for pending orders.
Handle All Exceptions
Handle All Exceptions
Catch and handle all exception types appropriately. Log errors for debugging.
Secure Your API Key
Secure Your API Key
Store API keys in environment variables, never commit them to version control.
Use HTTPS Only
Use HTTPS Only
Always use HTTPS for redirect URLs and your application endpoints.
Support & Resources
GitHub Repository
Source code, examples, and issues
API Documentation
Detailed API reference
Laravel Example
Complete Laravel integration
Contact Support
Get help from our team
Next Steps
Navio Best Practices
Learn production-ready tips and security best practices

