Skip to content

Commit fb88d23

Browse files
committed
merge master
2 parents 97f633c + 1c6d849 commit fb88d23

31 files changed

+1352
-1367
lines changed

README-old.md

Lines changed: 0 additions & 783 deletions
This file was deleted.

README.md

Lines changed: 288 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,50 @@
1+
# Laravel Iranian Online Payment Component
2+
Online Payment Module handler for Laravel 5+ and 6 known as LaraPay component completely compatible with [BankTest](http://banktest.ir) simulator.
3+
Larapay integrated all Iranian payment gateways to one component.
4+
5+
Here are a few short examples of what you can do:
6+
* create new transaction form your order model and generate bank form
7+
```php
8+
$transaction = $order->createTransaction(Bank::MELLAT);
9+
$form = $transaction->generateForm();
10+
```
11+
* handle bank callback
12+
```php
13+
$transaction = Larapay::verifyTransaction($request);
14+
//if bank support reverse
15+
$transaction->reverseTransaction();
16+
$order = $transaction->model;
17+
```
18+
* get order transaction information
19+
```php
20+
$accomplishedTransactions = $order->accomplishedTransactions;
21+
$allTransactions = $order->transation;
22+
$isPaid = $order->isPaid();
23+
$paidAmount = $order->paidAmount();
24+
```
25+
26+
## What is B‌anktest?
27+
- [BankTest](http://banktest.ir) is a sandbox service for all Iranian online payment gateways
28+
- [بانک تست](http://banktest.ir) یک سرویس شبیه ساز درگاه های پرداخت آنلاین ایرانی برای اهداف توسعه و تست نرم افزار می باشد
29+
30+
31+
## Currenctly support:
32+
33+
- Mellat Bank Gateway - درگاه بانک ملت لاراول
34+
- Saman Bank Gateway - درگاه بانک سامان لاراول
35+
- Saderat/Mabna Card Bank Gateway - درگاه بانک صادرات / مبناکارت لاراول
36+
- Pasargad Bank Gateway - درگاه بانک پاسارگاد لاراول
37+
- Parsian Bank Gateway - درگاه بانک پارسیان لاراول
38+
- Melli/Sadad Bank Gateway (Sadad) - درگاه بانک ملی / سداد لاراول
39+
- Pay.ir Gateway / درگاه پرداخت پی
40+
- Zarinpal Gateway / درگاه پرداخت زرین پال
41+
- ...
42+
- Other gateways, coming soon... لطفا شما هم در تکمیل پکیج مشارکت کنید
43+
44+
## Requirements
145
Larapay Version 6+ required PHP 7+
246

47+
## Installation
348
1. Installing via composer
449

550
```bash
@@ -20,7 +65,247 @@ Tartan\Larapay\LarapayServiceProvider::class,
2065
```bash
2166
php artisan vendor:publish --provider="Tartan\Larapay\LarapayServiceProvider"
2267
```
23-
5. Run install command
68+
69+
5. Run migration
2470
```bash
25-
php artisan larapay:install
26-
```
71+
php artisan migrate
72+
```
73+
74+
## Configuration
75+
If you complete installation step correctly, you can find Larapay config file as larapay.php in you project config file.
76+
77+
for sandbox you should set ```LARAPAY_MODE=development``` in your .env file otherwise set ```LARAPAY_MODE=production```
78+
79+
if you choose development mode, Larapay use banktest.ir for payment gateway.
80+
81+
set your bank username or password in your .env. here are some example:
82+
```
83+
LARAPAY_MODE=development
84+
85+
SAMAN_MERCHANT_ID=bmcf****
86+
SAMAN_MERCHANT_PASS=98221***
87+
88+
MELLAT_USERNAME=user***
89+
MELLAT_PASSWORD=80714***
90+
MELLAT_TERMINAL_ID=747
91+
```
92+
93+
### Setup callback route
94+
you should create a route for handling callback from bank and set your route name in .env
95+
96+
For example create a POST route in routes folder, web.php like this:
97+
```php
98+
Route::post('payment/callback', 'YourController@handleCallback')->name('payment.callback');
99+
```
100+
101+
and set route name in .env file:
102+
103+
```
104+
LARAPAY_PAYMENT_CALLBACK=payment.callback
105+
```
106+
107+
108+
## Usage
109+
110+
### Prepare payable model
111+
112+
Use `Payable` trait in your order model or any other model like user which will get payment feature and implement it.
113+
114+
You can impalement getAmount() method to return `Iranian Rail` amount of your model.
115+
```php
116+
use Tartan\Larapay\Payable;
117+
118+
class Order extends Model
119+
{
120+
use Payable;
121+
122+
public function getAmount(){
123+
return intval($this->amount) * 10;
124+
}
125+
126+
}
127+
```
128+
129+
Now you just have 3 steps to complete your payment:
130+
131+
### 1- create transaction
132+
133+
In your bank controller create a transaction for your order and generate bank for to transfer user to payment gateway.
134+
```php
135+
use Tartan\Larapay\Models\Enum\Bank;
136+
137+
class BankController extends Controller
138+
{
139+
public function index()
140+
{
141+
//your logic and prepare your order
142+
// ...
143+
144+
//if you implement getAmount() method you can set amount to null
145+
$amount = 1200000; //Rial at least 1000
146+
//order or user description
147+
$description = 'I pay my order with Larapay <3';
148+
//some additional data that you need store on transaction
149+
$additionalData = [];
150+
//create transaction
151+
$transaction = $order->createTransaction(Bank::MELLAT, $amount, $description, $additionalData);
152+
153+
//auto submit bank form and transfer user to gateway
154+
$autoSubmit = true;
155+
//callback route name. if you set it on your .env file you can set this to null
156+
$callbackRouteName = 'payment.callback';
157+
//adapter config
158+
$adapterConfig = [];
159+
//generate bank form
160+
$form = $transaction->generateForm($autoSubmit, $callbackRouteName, $adapterConfig);
161+
162+
return view('go-to-bank',[
163+
'form' => $form,
164+
]);
165+
}
166+
}
167+
```
168+
169+
### 2- show bank transfer form
170+
171+
Now you can show you `$form` in your `go-to-bank` view file:
172+
```php
173+
<div>
174+
{!! $form !!}
175+
</div>
176+
```
177+
178+
You can modify bank forms in:
179+
```
180+
resources/views/vendor/larapy
181+
```
182+
183+
### 3- handle callback
184+
185+
After payment, bank call you callback route
186+
187+
```php
188+
use Illuminate\Http\Request;
189+
use Tartan\Larapay\Facades\Larapay;
190+
191+
class YourController extends Controller
192+
{
193+
public function handleCallback(Request $request)
194+
{
195+
try{
196+
$adapterConfig = [];
197+
$transaction = Larapay::verifyTransaction($request, $adapterConfig);
198+
$order = $transaction->model;
199+
//transaction done. payment is successful
200+
} catch (\Exception $e){
201+
// transaction not complete!!!
202+
// show error to your user
203+
}
204+
}
205+
}
206+
```
207+
208+
If you want to revers transaction and your bank support it, you can do this way:
209+
```php
210+
$transaction->reverseTransaction();
211+
```
212+
213+
## Methods
214+
215+
### Methods available in `Paybel` trait and your order model:
216+
217+
* `$order->transactions` : get all transactions of this model
218+
* `$order->accomplishedTransactions`: get all accomplished transactions
219+
* `$order->isPaid()`: return true if this model has at least one accomplished transaction
220+
* `$order->paidAmount()`: return sum of accomplished transactions amount in Rial
221+
* `$order->createTransaction(
222+
$paymentGateway,
223+
$amount = null,
224+
$description = null,
225+
array $additionalData = []
226+
)`: create a transaction.
227+
228+
229+
### Methods available in `LarapayTransaction` model:
230+
231+
* `$transaction->model`: return the model that create this transaction. for example `$order`
232+
* `$transaction->reverseTransaction()`: reverse transaction and get back money to user. (if bank support reverse transaction)
233+
* `$transaction->generateForm($autoSubmit = false, $callback = null)`: generate bank transfer form
234+
* `$transaction->gatewayHandler()`: get gatewayHandler for advance use.
235+
236+
### Fields available in `LarapayTransaction` model:
237+
* `id`
238+
* `created_at`
239+
* `updated_at`
240+
241+
Status in boolean:
242+
* `accomplished`
243+
* `verified`
244+
* `after_verified`
245+
* `reversed`
246+
* `submitted`
247+
* `approved`
248+
* `rejected`
249+
250+
Gate information:
251+
* `payment_method`
252+
* `bank_order_id`
253+
* `gate_name`
254+
* `gate_refid`
255+
* `gate_status`
256+
* `extra_params`
257+
* `additional_data`
258+
259+
Order information:
260+
* `amount`
261+
* `description`
262+
* `paid_at`
263+
264+
265+
## LarapayTransaction
266+
267+
You can use `LarapayTransaction` model to find your transaction:
268+
269+
```php
270+
use Tartan\Larapay\Models\LarapayTransaction;
271+
272+
public function getTransaction($transactionId){
273+
274+
//find single transaction by transaction id
275+
$transaction = LarapayTransaction::find($transactionId);
276+
277+
//get all accomplished transaction
278+
$accomplishedTransactions = LarapayTransaction::where('accomplished',true)->get();
279+
280+
//get all reversed transaction
281+
$reversedTransactions = LarapayTransaction::where('reversed',true)->get();
282+
}
283+
```
284+
285+
This class use SoftDeletes. you can call delete() on your transaction model to softDelete it or forceDelete() to truly remove it from your database.
286+
287+
## Security
288+
289+
If you discover any security related issues, please email [email protected] or [email protected] instead of using the issue tracker.
290+
291+
## Team
292+
293+
This component is developed by the following person(s) and a bunch of [awesome contributors](https://github.com/iamtartan/laravel-online-payment/graphs/contributors).
294+
295+
[![Aboozar Ghaffari](https://avatars2.githubusercontent.com/u/502961?v=3&s=130)](https://github.com/iamtartan) | [![Milad Kianmehr](https://avatars3.githubusercontent.com/u/4578704?v=3&s=130)](https://github.com/miladkian) | [![Sina Miandashti](https://avatars3.githubusercontent.com/u/195868?v=3&s=130)](https://github.com/sinamiandashti)
296+
--- | --- | --- |
297+
[Aboozar Ghaffari](https://github.com/iamtartan) | [Milad Kianmehr](https://github.com/miladkian) | [Sina Miandashti](https://github.com/sinamiandashti)
298+
299+
300+
## Support This Project
301+
302+
Please contribute in package completion. This is the best support.
303+
304+
## License
305+
306+
The Laravel Online Payment Module is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
307+
308+
309+
310+
311+

composer.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "miladkian/laravel-online-payment",
2+
"name": "tartan/laravel-online-payment",
33
"description": "Iranian payment gateways handler for laravel applications",
44
"keywords": ["payment","shetab", "bank", "online payment", "gateway", "iran"],
55
"type": "library",
@@ -10,21 +10,20 @@
1010
"email": "[email protected]"
1111
},
1212
{
13-
"name": "Milad Kian",
13+
"name": "Milad Kianmehr",
1414
"email": "[email protected]"
1515
}
1616
],
1717
"require": {
1818
"php": ">=7.0.0",
1919
"ext-soap" : "*",
20-
"illuminate/contracts": "~5.8.0|^6.0|^7.0",
21-
"illuminate/database": "~5.8.0|^6.0|^7.0",
22-
"illuminate/http": "~5.8.0|^6.0|^7.0",
23-
"illuminate/routing": "~5.8.0|^6.0|^7.0",
24-
"illuminate/support": "~5.8.0|^6.0|^7.0",
25-
"illuminate/view": "~5.8.0|^6.0|^7.0",
26-
"tartan/laravel-xlog": "^1.0",
27-
"tartan/laravel-jalali-date": "^5.0"
20+
"illuminate/contracts": "~5.6.0|^6.0|^7.0",
21+
"illuminate/database": "~5.6.0|^6.0|^7.0",
22+
"illuminate/http": "~5.6.0|^6.0|^7.0",
23+
"illuminate/routing": "~5.6.0|^6.0|^7.0",
24+
"illuminate/support": "~5.6.0|^6.0|^7.0",
25+
"illuminate/view": "~5.6.0|^6.0|^7.0",
26+
"tartan/laravel-xlog": "^1.0"
2827
},
2928
"require-dev": {
3029
"mockery/mockery": "^1.0",

config/larapay.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
|
2424
| specifies ready to serve gateways.
2525
| gateway characters are case sensitive and should be exactly same as their folder name.
26-
| eg, "Jahanpay" is correct not "JahanPay" or "jahanpay"
26+
| eg, "Asanpay" is correct not "AsanPay" or "asanpay"
2727
| the gateways list is comma separated
2828
|
2929
*/
30-
'gateways' => env('LARAPAY_GATES', 'Mellat,Saman,Pasargad'),
30+
'gateways' => env('LARAPAY_GATES', 'Mellat,Saman,Pasargad,Parsian,ZarinPal,Payir,Saderat'),
3131

3232
/*
3333
|--------------------------------------------------------------------------
@@ -118,7 +118,7 @@
118118
| Pay.ir gateway configuration
119119
|--------------------------------------------------------------------------
120120
*/
121-
'pay_ir' => [
121+
'payir' => [
122122
'api' => env('PAY_IR_API_KEY', ''),
123123
],
124124
/*
@@ -147,13 +147,9 @@
147147
],
148148
/*
149149
|--------------------------------------------------------------------------
150-
| Route and Controller config
150+
| Route name for handle payment callback
151151
|--------------------------------------------------------------------------
152-
|
153-
|
154-
|
155-
|
156152
*/
157153

158-
'callback' => 'larapay.callback',
154+
'payment_callback' => env('LARAPAY_PAYMENT_CALLBACK' , '')
159155
];

0 commit comments

Comments
 (0)