Skip to content

Commit

Permalink
Some code rarefaction and add RecurringPayment
Browse files Browse the repository at this point in the history
  • Loading branch information
KalimeroMK committed Nov 23, 2024
1 parent 4d78970 commit 140b69e
Show file tree
Hide file tree
Showing 11 changed files with 846 additions and 652 deletions.
183 changes: 139 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,162 @@
## Laravel >=5

# Casys Laravel Package

This is a package to integrate the Casys payment gateway into Laravel. It generates complete scaffolding for simple integration, including support for recurring payments.

## Features
1. **Views**
- `resources/views/vendor/casys`
2. **Configuration**
- `config/casys.php`
3. **Controllers**
- `/Http/Controllers/CasysController`
- `/Http/Controllers/RecurringPaymentController`
4. **Recurring Payment Support**
- `/Http/Services/RecurringPayment.php`
- Example integration for managing recurring payments using SOAP services.
5. **Routes**
- Predefined routes for standard and recurring payments.

---

This is a package to integrate Casys payment gateway in laravel it generates complete scaffolding for simple integration. It create:<br>
## Views <br>
--resources/view/vendor/casys<br>
## Controller<br>
--/Http/Controllers/CasysController<br>
## Aditional class<br>
--/Http/Helper/Casys.php<br>
## Installation

Require this package in your composer.json `"kalimeromk/casys-laravel": "9999999-dev"`,
and run composer update or run `composer require kalimeromk/casys-laravel`
Require this package by running:

After updating composer you need to run :
```bash
composer require kalimeromk/casys-laravel
```

$ php artisan vendor:publish --provider="Kalimero\Casys\CasysServiceProvider"
After installation, publish the package files:

It will publish the files from this package it will add this files
```bash
php artisan vendor:publish --provider="Kalimero\Casys\CasysServiceProvider"
```

`config/casys.php`,<br />
`app/Http/Controllers/CasysController.php`,<br />
`app/Traits/Casys.php`,<br />
`resources/views/vendor/casys`<br />
`routes/casys.php`<br />
This will publish the following files:
- `config/casys.php`
- `resources/views/vendor/casys`

---

### Laravel
## Laravel Setup

Register the route file in your `RouteServiceProvider` or add the following routes to your existing route file:

Register route file in RouteServiceProvider or add this routes to existing root file
### Standard Payment Routes
```php
use App\Http\Controllers\CasysController;

`use App\Http\Controllers\CasysController;`<br/>
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');
```

`Route::get('paymentLoader', [CasysController::class, 'index'])->name('loader');`<br />
`Route::post('payment', [CasysController::class, 'getCasys'])->name('validateAndPay');`<br />
`Route::post('paymentOKURL', [CasysController::class, 'success'])->name('paymentOKURL');`<br />
`Route::post('paymentFailURL', [CasysController::class, 'fail'])->name('paymentFailURL');`<br />
### Recurring Payment Routes
```php
use KalimeroMK\Casys\Controllers\RecurringPaymentController;

**NOTE:** *This is only needed in Laravel <=7*
Route::post('/recurring-payment', [RecurringPaymentController::class, 'handleRecurringPayment'])->name('recurring.payment');
```

`Route::get('paymentLoader', 'CasysController@index')->name('loader');`<br />
`Route::post('payment', 'CasysController@getCasys')->name('validateAndPay');`<br />
`Route::post('paymentOKURL', 'CasysController@success')->name('paymentOKURL');`<br />
`Route::post('paymentFailURL', 'CasysController@fail')->name('paymentFailURL');`<br />
For Laravel <=7, use the controller string syntax:
```php
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');
```

---

## how to use

Add you credentionals in .env file like this
## How to Use

PAY_TO_MERCHANT= <br>
MERCHANT_NAME= <br>
AMOUNT_CURRENCY=MKD <br>
PAYMENT_OK_URL= <br>
PAYMENT_FAIL_URL= <br>
CASYS_TOKEN= <br>
### Configuration
Add your credentials to the `.env` file:
```env
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_token
```

and now only need to pass amount and client data to the method in controller
### Standard Payments
For 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`.

Views at the moment are coming form the package if you want to use the published one jus edit the controller
---

## Info
### Recurring Payments

The package includes support for recurring payments through the `RecurringPayment` class and `RecurringPaymentController`. Here’s how you can integrate it:

#### **Recurring Payment Parameters**
The recurring payment requires the following parameters:
- **RPRef**: A string containing details about the recurring payment, formatted as:
```plaintext
RPRef = RequestType,BillingCycle,MaxBCycles,BillingAmount,BillingCycleStart
```
- **RPRefID**: Unique ID returned during the initial registration of the recurring transaction.

#### **Example Workflow**
1. **Initial Registration**
The cardholder performs the initial transaction with the `RPRef` parameter set. The system returns an `RPRefID`, which you should store for future recurring payments.

2. **Subsequent Payments**
Use the stored `RPRefID` to initiate subsequent payments without user involvement.

This package is still very alpha and it is not created as a proper package so it can be easy updated to feed you needs
#### **Example Request**
Call the `/recurring-payment` endpoint with the following payload:
```json
{
"merchant_id": "YourMerchantID",
"rp_ref": "R,1M,12,500000,20240101",
"rp_ref_id": "UniqueRPRefID",
"amount": 500000,
"password": "YourMerchantPassword"
}
```

#### **Example Recurring Payment Integration**
You can use the `RecurringPayment` service class in your application:

```php
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'];
}
```

---

### Provided Controllers

#### **CasysController**
Handles the standard payment flow, including:
- Loading the payment page (`paymentLoader` route).
- Validating and processing payments (`payment` route).
- Handling success (`paymentOKURL` route) and failure (`paymentFailURL` route) callbacks.

#### **RecurringPaymentController**
Handles recurring payment requests via the `/recurring-payment` route. Example integration is included for making SOAP calls to the Casys gateway.

---

## Info

- Suggestions are welcome :)
This package is in an alpha stage and is designed to be flexible for your specific needs. **Suggestions are welcome!**
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
"name": "kalimeromk/casys-laravel",
"description": "Integration of casys payment method",
"require": {
"php": ">=7.3.0",
"ext-json": "*"
},
"php": ">=7.4.0",
"ext-json": "*",
"ext-soap": "*"
},
"keywords": [
"laravel",
"casys"
Expand Down
Loading

0 comments on commit 140b69e

Please sign in to comment.