This is a package to integrate the Casys payment gateway into Laravel. It generates complete scaffolding for simple integration, including support for recurring payments.
- Views
resources/views/vendor/casys
- Configuration
config/casys.php
- Controllers
/Http/Controllers/CasysController/Http/Controllers/RecurringPaymentController
- Recurring Payment Support
/Http/Services/RecurringPayment.php- Example integration for managing recurring payments using SOAP services.
- Routes
- Predefined routes for standard and recurring payments.
Require this package by running:
composer require kalimeromk/casys-laravelAfter installation, publish the package files:
php artisan vendor:publish --provider="Kalimero\Casys\CasysServiceProvider"This will publish the following files:
config/casys.phpresources/views/vendor/casys
Register the route file in your RouteServiceProvider or add the following routes to your existing route file:
use App\Http\Controllers\CasysController;
Route::get('paymentLoader', [CasysController::class, 'index'])->name('loader');
Route::post('payment', [CasysController::class, 'getCasys'])->name('validateAndPay');
Route::post('paymentOKURL', [CasysController::class, 'success'])->name('paymentOKURL');
Route::post('paymentFailURL', [CasysController::class, 'fail'])->name('paymentFailURL');use KalimeroMK\Casys\Controllers\RecurringPaymentController;
Route::post('/recurring-payment', [RecurringPaymentController::class, 'handleRecurringPayment'])->name('recurring.payment');For Laravel <=7, use the controller string syntax:
Route::get('paymentLoader', 'CasysController@index')->name('loader');
Route::post('payment', 'CasysController@getCasys')->name('validateAndPay');
Route::post('paymentOKURL', 'CasysController@success')->name('paymentOKURL');
Route::post('paymentFailURL', 'CasysController@fail')->name('paymentFailURL');Add your credentials to the .env file:
PAY_TO_MERCHANT=your_merchant_id
MERCHANT_NAME=your_merchant_name
AMOUNT_CURRENCY=MKD
PAYMENT_OK_URL=your_success_url
PAYMENT_FAIL_URL=your_fail_url
CASYS_TOKEN=your_tokenFor standard payments, simply pass the amount and client data to the appropriate method in the CasysController. The views provided by the package will handle the UI. If you wish to customize the views, edit the published views in resources/views/vendor/casys.
The package includes support for recurring payments through the RecurringPayment class and RecurringPaymentController. Here’s how you can integrate it:
The recurring payment requires the following parameters:
- RPRef: A string containing details about the recurring payment, formatted as:
RPRef = RequestType,BillingCycle,MaxBCycles,BillingAmount,BillingCycleStart - RPRefID: Unique ID returned during the initial registration of the recurring transaction.
-
Initial Registration The cardholder performs the initial transaction with the
RPRefparameter set. The system returns anRPRefID, which you should store for future recurring payments. -
Subsequent Payments Use the stored
RPRefIDto initiate subsequent payments without user involvement.
Call the /recurring-payment endpoint with the following payload:
{
"merchant_id": "YourMerchantID",
"rp_ref": "R,1M,12,500000,20240101",
"rp_ref_id": "UniqueRPRefID",
"amount": 500000,
"password": "YourMerchantPassword"
}You can use the RecurringPayment service class in your application:
use KalimeroMK\Casys\Services\RecurringPayment;
$recurringPayment = new RecurringPayment();
$response = $recurringPayment->sendPayment(
$merchantId,
$rpRef,
$rpRefId,
$amount,
$password
);
if ($response['success']) {
echo "Recurring payment successful! Reference: " . $response['payment_reference'];
} else {
echo "Recurring payment failed: " . $response['error_description'];
}Handles the standard payment flow, including:
- Loading the payment page (
paymentLoaderroute). - Validating and processing payments (
paymentroute). - Handling success (
paymentOKURLroute) and failure (paymentFailURLroute) callbacks.
Handles recurring payment requests via the /recurring-payment route. Example integration is included for making SOAP calls to the Casys gateway.
This package is in an alpha stage and is designed to be flexible for your specific needs. Suggestions are welcome!