mcire / paytech
Integration of PayTech payment gateway for Laravel
Requires
- php: >=8.0
- guzzlehttp/guzzle: ^7.0
This package is auto-updated.
Last update: 2025-05-29 01:58:32 UTC
README
This package provides an easy integration of the PayTech payment gateway into your Laravel applications.
Installation
🧿 Prerequisite
You have already created a controller for payments, an associated route and a view containing the product purchase form.
composer require guzzlehttp/guzzle
use App\Http\Controllers\PaymentController; Route::post('/checkout', [PaymentController::class, 'payment'])->name('payment.submit'); Route::get('ipn', [PaymentController::class, 'ipn'])->name('paytech-ipn'); Route::get('payment/success', [PaymentController::class, 'paymentSuccessView'])->name('payment.success.view'); Route::get('payment/cancel', [PaymentController::class, 'cancel'])->name('paytech.cancel');
⬇ Install now
composer require mcire/paytech
The package discovery is enabled by default in Laravel 5.5+. If you're using an earlier version, manually add the service provider and facade in config/app.php
:
'providers' => [ // ... Mcire\PayTech\PayTechServiceProvider::class, ], 'aliases' => [ // ... 'PayTech' => Mcire\PayTech\Facades\PayTech::class, ],
Configuration
Publish the configuration file:
php artisan vendor:publish --tag=config
Add the following variables to your .env
file:
PAYTECH_API_KEY=your_api_key PAYTECH_API_SECRET=your_api_secret PAYTECH_ENV=test # or 'prod' for production PAYTECH_IPN_URL=https://your-domain.com/ipn PAYTECH_SUCCESS_URL=https://your-domain.com/success PAYTECH_CANCEL_URL=https://your-domain.com/cancel
Tips for configuring PayTech's IPN locally
PayTech requires the callback route (IPN) to be accessible via HTTPS. This can pose a challenge during local development.
If you don't need to handle IPN calls :
simply configure the IPN URL as follows
PAYTECH_IPN_URL=https://127.0.0.1:8000/ipn
If you need to handle IPN calls locally:
Usage
Initiating a Payment (Put it inside your payment controller)
use Mcire\PayTech\Facades\PayTech; try { $response = PayTech::requestPayment([ 'item_name' => 'Product name', 'item_price' => 1000, // Price in cents 'currency' => 'XOF', 'ref_command' => Str::random(12), // Unique reference 'command_name' => 'Order description', ]); // Redirect to PayTech payment page return redirect($response['redirect_url']); } catch (\Exception $e) { // Error handling abort(500, $e->getMessage()); }
php artisan serve
Available Parameters
Parameter | Type | Description | Required |
---|---|---|---|
item_name | string | Product name | Yes |
item_price | integer | Price in cents | Yes |
currency | string | Currency (XOF, EUR, etc.) | Yes |
ref_command | string | Unique order reference | Yes |
command_name | string | Order description | Yes |
Handling Returns
The package automatically handles three types of returns:
-
IPN (Instant Payment Notification)
- URL configured in
PAYTECH_IPN_URL
- Server-to-server notification from PayTech
- Used to update order status
- URL configured in
-
Success Page
- URL configured in
PAYTECH_SUCCESS_URL
- Redirection after successful payment
- URL configured in
-
Cancel Page
- URL configured in
PAYTECH_CANCEL_URL
- Redirection after payment cancellation
- URL configured in
Environments
The package supports two environments:
- test: For testing (default)
- prod: For production
Configure the environment via the PAYTECH_ENV
variable in your .env
file.
Security
- All requests are made over HTTPS
- API keys are securely stored in the
.env
file - Communications are authenticated via API_KEY and API_SECRET headers
Common Error Codes
Code | Description | Solution |
---|---|---|
400 | Invalid parameters | Check the sent parameters |
401 | Authentication failed | Verify your API keys |
500 | Server error | Contact PayTech support |
Support
For any questions or issues:
- Open an issue on GitHub
- Contact me at mamadoucirecamara99@gmail.com
License
This package is open-sourced software licensed under the MIT license. See the LICENSE file for more details. This package provides an easy integration of the PayTech payment gateway into your Laravel applications.