ZainCash Laravel is a PHP SDK designed to integrate the ZainCash payment gateway with Laravel applications seamlessly. This package provides an easy-to-use interface for initiating and verifying payments.
You can install the package via Composer:
composer require thejano/zaincash-laravelAfter installing the package, publish the configuration file using:
php artisan vendor:publish --provider="TheJano\ZainCash\Providers\ZainCashPaymentServiceProvider"This will create a config/zaincash.php file where you can set your credentials.
Add your credentials in your .env file:
ZAINCASH_SECRET=your_secret_key
ZAINCASH_MERCHANT_ID=your_merchant_id
ZAINCASH_MSISDN=your_phone_number
ZAINCASH_ENV=staging
ZAINCASH_REDIRECT_URL=https://yourdomain.com/payment/callback
ZAINCASH_PREFIX_ORDER_ID=ORD_You can initiate a payment using the ZainCashPayment facade:
use TheJano\ZainCash\Facades\ZainCashPayment;
$response = ZainCashPayment::initiatePayment(
orderId: '12345',
amount: 1000.00,
serviceType: 'purchase',
redirectUrl: 'https://yourdomain.com/payment/success'
);
$transactionId = $response['id'];
$paymentUrl = ZainCashPayment::getPaymentUrl($transactionId);
return redirect($paymentUrl);use TheJano\ZainCash\Facades\ZainCashPayment;
$token = request('token');
$paymentData = ZainCashPayment::verifyPayment($token);
if ($paymentData) {
// Payment is successful
} else {
// Payment failed
}use TheJano\ZainCash\Facades\ZainCashPayment;
$transactionId = 'some_transaction_id';
$transactionStatus = ZainCashPayment::checkTransaction($transactionId);The package registers ZainCashPaymentServiceProvider automatically. It also provides a facade ZainCashPayment for convenient usage.
This package is open-sourced software licensed under the MIT license.
For more details, visit the official API documentation: