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 Banktest?
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
145Larapay Version 6+ required PHP 7+
246
47+ ## Installation
3481 . Installing via composer
449
550``` bash
@@ -20,7 +65,247 @@ Tartan\Larapay\LarapayServiceProvider::class,
2065``` bash
2166php 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+ [](https://github.com/iamtartan) | [](https://github.com/miladkian) | [](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+
0 commit comments