├── LICENSE.TXT ├── README.md ├── composer.json └── src ├── Facades └── PaytabsFacade.php ├── Http └── Controllers │ └── PaytabsController.php ├── Models └── PaytabsInvoice.php ├── Paytabs.php ├── PaytabsServiceProvider.php ├── config └── paytabs.php ├── database └── migrations │ └── 2021_01_24_205114_create_paytabs_invoices_table.php └── routes └── web.php /LICENSE.TXT: -------------------------------------------------------------------------------- 1 | Copyright (C) 2012 Yoshimasa Niwa 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Issues](https://img.shields.io/github/issues/baselrabia/paytabs-with-laravel.svg?style=flat-square)](https://github.com/baselrabia/paytabs-with-laravel/issues) 2 | [![Stars](https://img.shields.io/github/stars/baselrabia/paytabs-with-laravel.svg?style=flat-square)](https://github.com/baselrabia/paytabs-with-laravel/stargazers) 3 | [![Latest Version](https://img.shields.io/github/tag/baselrabia/paytabs-with-laravel.svg?style=flat-square&label=release)](https://github.com/baselrabia/paytabs-with-laravel/tags) 4 | [![Software License](https://img.shields.io/github/license/baselrabia/paytabs-with-laravel.svg?style=flat-square)](LICENSE) 5 | [![Total Downloads](https://img.shields.io/packagist/dt/baselrabia/paytabs-with-laravel.svg?style=flat-square)](https://packagist.org/packages/baselrabia/paytabs-with-laravel) 6 | 7 |

8 | paytabs Logo 9 |

10 |

11 | Happy Logo 12 |

13 | 14 |

Paytabs With Laravel🥳

15 | 16 | 17 | ## Installation 18 | Begin by installing this package through Composer. Just run following command to terminal- 19 | 20 | ```php 21 | composer require baselrabia/paytabs-with-laravel 22 | ``` 23 | 24 | Once this operation completes the package will automatically be discovered for **Laravel 5.6 and above**, 25 | 26 | - Run this line to publish package files in your app 27 | 28 | ```php 29 | php artisan vendor:publish --provider="Basel\Paytabs\PaytabsServiceProvider" 30 | ``` 31 | - after that fire the migration command 32 | 33 | ```php 34 | php artisan migrate 35 | ``` 36 | - last step add those two fields in your `.env` file ,edit it's value with your own 37 | 38 | ```php 39 | merchant_email=**************@gmail.com 40 | merchant_secretKey=**************************************************************** 41 | ``` 42 | And make sure to change your `APP_URL` 43 | ```php 44 | APP_URL=http://localhost:8000 45 | ``` 46 | Otherwise, the final step is to add the service provider. Open `config/app.php`, and add a new item to the providers array. 47 | ```php 48 | 'providers' => [ 49 | ... 50 | Basel\Paytabs\PaytabsServiceProvider::class, 51 | ], 52 | ``` 53 | 54 | - Now add the Aliase 55 | 56 | ```php 57 | 'aliases' => [ 58 | ... 59 | 'Paytabs' => Basel\Paytabs\Facades\PaytabsFacade::class, 60 | 61 | ], 62 | 63 | ``` 64 | ## what's happining there: 65 | the package publish 3 files 66 | ```php 67 | 1- App/Http/Controllers/PaytabsController.php 68 | 2- App/Models/PaytabsInvoice.php 69 | 3- config/paytabs.php 70 | ``` 71 | - you are free to change what you want in the logic of these files {{ Without Deleteing 🧐}} 72 | - the result of success payment will process making a paytabs invoice through the model `App/Models/PaytabsInvoice.php` 73 | - the config file have differnt values for response languague, currancy, email and secert_key 74 | 75 | ### the package has 2 routes 76 | ### Create Payment Page: 77 | ```php 78 | http://localhost:8000/paytabs_payment 79 | ``` 80 | which call the function ( `PaytabsController@index` ) by GET Request 81 | 82 | ### Verify Payment: 83 | ```php 84 | http://localhost:8000/paytabs_response 85 | ``` 86 | the return response from paytabs which call the function ( `PaytabsController@response` ) by Post Request 87 | 88 | ## test card: 89 | 90 | ### Checkout Process Demo 91 | 92 | Please use these ‘test card’ details for your demo 93 | 94 | ```php 95 | 96 | Name on Card: John Doe 97 | Card Number: 4000 0000 0000 0051 98 | Expiry: 02/22 CVV: 111 99 | ``` 100 | 101 | the link for any updates => 102 | https://site.paytabs.com/en/checkout-process-demo/ 103 | 104 | 105 | # Contributing 106 | If you think something important is missing or should be different based on your experience, I'd love to hear it! If you have suggestions for improving this package, open an issue with your suggestion. 107 | 108 | 109 | 110 | 111 |

How to Contribute 💪

112 | 113 | ``` 114 | - Fork the project 115 | 116 | - Create a new branch with your changes: 117 | $ git checkout -b my-feature 118 | 119 | - Save your changes and create a commit message telling you what you did: 120 | $ git commit -m "feature: My new feature" 121 | 122 | - Submit your changes: 123 | $ git push origin my-feature 124 | ``` 125 | 126 | 127 |

License 📝

128 | 129 |

130 | This repository is under MIT license. You can see the LICENSE file for more details. 😉 131 |

132 | 133 | --- 134 | 135 | 136 | >This project was developed with ❤️ by **[@Basel Rabia](https://www.linkedin.com/in/baselrabia/)**
137 | If it helped you, give it ⭐, it will help me too 😉 138 | 139 | 140 | 141 |
142 | 143 | [![Linkedin Badge](https://img.shields.io/badge/-Basel%20Rabia-292929?style=flat-square&logo=Linkedin&logoColor=white&link=https://www.linkedin.com/in/baselrabia/)](https://www.linkedin.com/in/baselrabia/) 144 | 145 |
146 | 147 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "baselrabia/paytabs-with-laravel", 3 | "description": "integrate paytabs with laravel", 4 | "type": "library", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "baselrabia", 9 | "email": "baselrabia@gmail.com" 10 | } 11 | ], 12 | "minimum-stability": "stable", 13 | "require": { 14 | "php": "^7.2" 15 | }, 16 | "autoload": { 17 | "psr-4": { 18 | "Basel\\Paytabs\\": "src/" 19 | } 20 | }, 21 | "extra": { 22 | "laravel": { 23 | "providers": [ 24 | "Basel\\Paytabs\\PaytabsServiceProvider" 25 | ], 26 | "aliases": { 27 | "Paytabs": "Basel\\Paytabs\\Facades\\PaytabsFacade" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Facades/PaytabsFacade.php: -------------------------------------------------------------------------------- 1 | create_pay_page(array( 18 | 19 | //Customer's Personal Information 20 | 'cc_first_name' => "john", //This will be prefilled as Credit Card First Name 21 | 'cc_last_name' => "Doe", //This will be prefilled as Credit Card Last Name 22 | 'cc_phone_number' => "00973", 23 | 'phone_number' => "33333333", 24 | 'email' => "customer@gmail.com", 25 | 26 | //Customer's Billing Address (All fields are mandatory) 27 | //When the country is selected as USA or CANADA, the state field should contain a String of 2 characters containing the ISO state code otherwise the payments may be rejected. 28 | //For other countries, the state can be a string of up to 32 characters. 29 | 'billing_address' => "manama bahrain", 30 | 'city' => "manama", 31 | 'state' => "manama", 32 | 'postal_code' => "00973", 33 | 'country' => "BHR", 34 | 35 | //Customer's Shipping Address (All fields are mandatory) 36 | 'address_shipping' => "Juffair bahrain", 37 | 'city_shipping' => "manama", 38 | 'state_shipping' => "manama", 39 | 'postal_code_shipping' => "00973", 40 | 'country_shipping' => "BHR", 41 | 42 | //Product Information 43 | "products_per_title" => "Product1 || Product 2 || Product 4", //Product title of the product. If multiple products then add “||” separator 44 | 'quantity' => "1 || 1 || 1", //Quantity of products. If multiple products then add “||” separator 45 | 'unit_price' => "2 || 2 || 6", //Unit price of the product. If multiple products then add “||” separator. 46 | "other_charges" => "91.00", //Additional charges. e.g.: shipping charges, taxes, VAT, etc. 47 | 'amount' => "101.00", //Amount of the products and other charges, it should be equal to: amount = (sum of all products’ (unit_price * quantity)) + other_charges 48 | 'discount' => "1", //Discount of the transaction. The Total amount of the invoice will be= amount - discount 49 | 50 | //Invoice Information 51 | 'title' => "John Doe", // Customer's Name on the invoice 52 | "reference_no" => "1231231", //Invoice reference number in your system 53 | 54 | )); 55 | 56 | 57 | // dd($result); 58 | 59 | if ($result->response_code == 4012) { 60 | return redirect($result->payment_url); 61 | } 62 | if ($result->response_code == 4094) { 63 | return $result->details; 64 | } 65 | 66 | return $result->result; 67 | } 68 | 69 | public function response(Request $request) 70 | { 71 | 72 | $result = Paytabs::getInstance()->verify_payment($request->payment_reference); 73 | 74 | if ($result->response_code == 100) { 75 | //success 76 | $this->createInvoice((array)$result); 77 | } 78 | return $result->result; 79 | } 80 | 81 | public function createInvoice($request) 82 | { 83 | $request['order_id'] = $request["reference_no"]; 84 | PaytabsInvoice::create($request); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/Models/PaytabsInvoice.php: -------------------------------------------------------------------------------- 1 | merchant_email = config('paytabs.merchant_email'); 19 | $this->merchant_secretKey = config('paytabs.merchant_secretKey'); 20 | } 21 | 22 | public static function getInstance() 23 | { 24 | if (self::$instance == null) { 25 | self::$instance = new Paytabs(); 26 | } 27 | self::$instance->api_key = ""; 28 | return self::$instance; 29 | } 30 | 31 | 32 | function authentication(){ 33 | $obj = json_decode($this->runPost(self::AUTHENTICATION, array("merchant_email"=> $this->merchant_email, "merchant_secretKey"=> $this->merchant_secretKey))); 34 | if($obj->access == "granted") 35 | $this->api_key = $obj->api_key; 36 | else 37 | $this->api_key = ""; 38 | return $this->api_key; 39 | } 40 | 41 | function create_pay_page($values) { 42 | $values['merchant_email'] = $this->merchant_email; 43 | $values['secret_key'] = $this->merchant_secretKey; 44 | $values['ip_customer'] = $_SERVER['REMOTE_ADDR']; 45 | $values['ip_merchant'] = isset($_SERVER['SERVER_ADDR'])? $_SERVER['SERVER_ADDR'] : '::1'; 46 | $values['currency'] = config('paytabs.currency'); 47 | $values['msg_lang'] = config('paytabs.msg_lang'); 48 | $values['site_url'] = config('paytabs.site_url'); 49 | $values['return_url'] = config('paytabs.return_url'); 50 | $values['cms_with_version'] = config('paytabs.cms_with_version'); 51 | $values['paypage_info'] = config('paytabs.paypage_info'); 52 | 53 | return json_decode($this->runPost(self::PAYPAGE_URL, $values)); 54 | } 55 | 56 | function send_request(){ 57 | $values['ip_customer'] = $_SERVER['REMOTE_ADDR']; 58 | $values['ip_merchant'] = isset($_SERVER['SERVER_ADDR'])? $_SERVER['SERVER_ADDR'] : '::1'; 59 | return json_decode($this->runPost(self::TESTING, $values)); 60 | } 61 | 62 | 63 | function verify_payment($payment_reference){ 64 | $values['merchant_email'] = $this->merchant_email; 65 | $values['secret_key'] = $this->merchant_secretKey; 66 | $values['payment_reference'] = $payment_reference; 67 | return json_decode($this->runPost(self::VERIFY_URL, $values)); 68 | } 69 | 70 | function runPost($url, $fields) { 71 | $fields_string = ""; 72 | foreach ($fields as $key => $value) { 73 | $fields_string .= $key . '=' . $value . '&'; 74 | } 75 | rtrim($fields_string, '&'); 76 | $ch = curl_init(); 77 | $ip = $_SERVER['REMOTE_ADDR']; 78 | 79 | $ip_address = array( 80 | "REMOTE_ADDR" => $ip, 81 | "HTTP_X_FORWARDED_FOR" => $ip 82 | ); 83 | curl_setopt($ch, CURLOPT_URL, $url); 84 | curl_setopt($ch, CURLOPT_HTTPHEADER, $ip_address); 85 | curl_setopt($ch, CURLOPT_POST, count($fields)); 86 | curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); 87 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 88 | curl_setopt($ch, CURLOPT_REFERER, 1); 89 | 90 | $result = curl_exec($ch); 91 | curl_close($ch); 92 | return $result; 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/PaytabsServiceProvider.php: -------------------------------------------------------------------------------- 1 | loadRoutesFrom(__DIR__ . '/routes/web.php'); 17 | $this->loadMigrationsFrom(__DIR__ . '/database/migrations'); 18 | 19 | $this->mergeConfigFrom( 20 | __DIR__ . '/config/paytabs.php', 21 | 'paytabs' 22 | ); 23 | $this->publishes([ 24 | __DIR__ . '/config/paytabs.php' => config_path('paytabs.php'), 25 | __DIR__ . '/Models/PaytabsInvoice.php' => app_path('Models/PaytabsInvoice.php'), 26 | __DIR__ . '/Http/Controllers/PaytabsController.php' => app_path('Http/Controllers/PaytabsController.php') 27 | ]); 28 | } 29 | 30 | /** 31 | * Register the application services. 32 | * 33 | * @return void 34 | */ 35 | public function register() 36 | { 37 | $this->app->singleton('Paytabs', function() { 38 | return Paytabs::getInstance(); 39 | }); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/config/paytabs.php: -------------------------------------------------------------------------------- 1 | env('merchant_email'), 8 | 9 | "merchant_secretKey" => env('merchant_secretKey'), 10 | 11 | #################################### 12 | // Website Information 13 | #################################### 14 | 15 | 'currency' => "USD", 16 | //Currency of the amount stated. 3 character ISO currency code 17 | 18 | "msg_lang" => "en", 19 | //Language of the PayPage to be created. Invalid or blank entries will default to English.(Englsh/Arabic) 20 | 21 | "site_url" => env('APP_URL'), //should be like that in local => 'http://localhost:8000' 22 | //The requesting website be exactly the same as the website/URL associated with your PayTabs Merchant Account 23 | 24 | 'return_url' => env('APP_URL') . "/paytabs_response", //should be like that in local => 'http://localhost:8000/paytabs_response' 25 | 26 | "cms_with_version" => "API USING PHP", 27 | 28 | "paypage_info" => "1" 29 | 30 | 31 | 32 | ]; 33 | -------------------------------------------------------------------------------- /src/database/migrations/2021_01_24_205114_create_paytabs_invoices_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | 19 | //'order_id', 'result', 'response_code', 'pt_invoice_id','amount', "currency", "transaction_id", "card_brand", "card_first_six_digits", "card_last_four_digits" 20 | /* 21 | +"result": "The payment is completed successfully!" 22 | +"response_code": "100" 23 | +"pt_invoice_id": "548647" 24 | +"amount": 100 25 | +"currency": "USD" 26 | +"reference_no": "1231231"//order_id 27 | +"transaction_id": "740459" 28 | +"card_brand": "Visa" 29 | +"card_first_six_digits": "400000" 30 | +"card_last_four_digits": "0051" 31 | */ 32 | 33 | $table->unsignedBigInteger('order_id'); 34 | $table->text('result'); 35 | $table->unsignedInteger('response_code'); 36 | $table->unsignedInteger('pt_invoice_id')->nullable(); 37 | $table->float('amount')->nullable(); 38 | $table->string('currency')->nullable(); 39 | $table->unsignedInteger('transaction_id')->nullable(); 40 | $table->string('card_brand')->nullable(); 41 | $table->unsignedInteger('card_first_six_digits')->nullable(); 42 | $table->unsignedInteger('card_last_four_digits')->nullable(); 43 | 44 | 45 | 46 | $table->timestamps(); 47 | }); 48 | } 49 | 50 | /** 51 | * Reverse the migrations. 52 | * 53 | * @return void 54 | */ 55 | public function down() 56 | { 57 | Schema::dropIfExists('paytabs_invoices'); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/routes/web.php: -------------------------------------------------------------------------------- 1 | 'App\Http\Controllers'], function () { 7 | Route::get('/paytabs_payment', 'PaytabsController@index')->name('Paytabs.index'); 8 | Route::post('/paytabs_response', 'PaytabsController@response')->name('Paytabs.result'); 9 | }); 10 | --------------------------------------------------------------------------------