{"id":21966668,"url":"https://github.com/devinweb/laravel-paytabs","last_synced_at":"2025-09-02T15:38:22.472Z","repository":{"id":58924121,"uuid":"534237521","full_name":"devinweb/laravel-paytabs","owner":"devinweb","description":"Laravel package for Paytabs payment gateway","archived":false,"fork":false,"pushed_at":"2022-10-21T11:40:21.000Z","size":138,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-31T03:28:26.842Z","etag":null,"topics":["devinweb","laravel","mena","payment","payment-gateway","payments","paytabs"],"latest_commit_sha":null,"homepage":"https://devinweb.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devinweb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-08T13:58:30.000Z","updated_at":"2025-07-15T15:14:29.000Z","dependencies_parsed_at":"2022-09-21T23:12:41.212Z","dependency_job_id":null,"html_url":"https://github.com/devinweb/laravel-paytabs","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/devinweb/laravel-paytabs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devinweb%2Flaravel-paytabs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devinweb%2Flaravel-paytabs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devinweb%2Flaravel-paytabs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devinweb%2Flaravel-paytabs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devinweb","download_url":"https://codeload.github.com/devinweb/laravel-paytabs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devinweb%2Flaravel-paytabs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273307587,"owners_count":25082412,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["devinweb","laravel","mena","payment","payment-gateway","payments","paytabs"],"created_at":"2024-11-29T13:17:40.874Z","updated_at":"2025-09-02T15:38:22.399Z","avatar_url":"https://github.com/devinweb.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"/art/socialcard.png\" alt=\"Laravel Paytabs\"\u003e\u003c/p\u003e\n\n# Laravel Paytabs\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/devinweb/laravel-paytabs.svg?style=flat-square)](https://packagist.org/packages/devinweb/laravel-paytabs)\n[![Total Downloads](https://img.shields.io/packagist/dt/devinweb/laravel-paytabs.svg?style=flat-square)](https://packagist.org/packages/devinweb/laravel-paytabs)\n\u003ca href=\"https://github.styleci.io/repos/534237521\"\u003e\u003cimg src=\"https://github.styleci.io/repos/534237521/shield?branch=master\" alt=\"StyleCI Shield\"\u003e\u003c/a\u003e\n[![codecov](https://codecov.io/gh/devinweb/laravel-paytabs/branch/master/graph/badge.svg?token=11LZHKWQL4)](https://codecov.io/gh/devinweb/laravel-paytabs)\n![GitHub Actions](https://github.com/devinweb/laravel-paytabs/actions/workflows/main.yml/badge.svg)\n\n\nLaravel Paytabs makes integration with PayTabs payment gateway easier for Laravel developers, and that's by offering a wide range of functions to consume the paytabs transactions API.\n\n## Requirements\nThis package requires php 7.4 or higher.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require devinweb/laravel-paytabs\n```\n## Database migration\nThis package provides a migration to handle the transactions. You need to publish the migration file after the installation.\n```bash\nphp artisan vendor:publish --tag=\"paytabs-migrations\"\n```\nThen, you need to migrate the transactions table.\n```bash\nphp artisan migrate\n```\n# Setup and configuration\nYou can also publish the config file using\n```bash\nphp artisan vendor:publish --tag=\"paytabs-config\"\n```\nAfter that, you can see the file in app/paytabs.php and update it. You might need to change the model variable to use your custom User model.\n\n## Paytabs Keys\n\nBefore being able to use this package, you should configure your paytabs environment in your application's .env file.\n```\nPAYTABS_SERVER_KEY=your-server-key\nPAYTABS_PROFILE_ID=your-profile-id\n# default SAR\nCURRENCY=\n# default SAU\nPAYTABS_REGION=\n# default https://secure.paytabs.sa/\nPAYTABS_API=\nPAYTABS_REDIRECT_URL=your-redirect-url\n```\n\n## Usage\n\n### Transaction type enum\nThe transaction types that Paytabs supports are described by this abstract class. There are five different sorts of transactions: `sale`, `auth`, `refund`, `void`, and `capture`. \nThis class makes it simple to find and use these values:\n```php\nuse Devinweb\\LaravelPaytabs\\Enums\\TransactionType;\n\n$saleType = TransactionType::SALE;\n\n```\nIt can be used also to validate if the given type is a follow-up type or an initiate one.\n```php\nuse Devinweb\\LaravelPaytabs\\Enums\\TransactionType;\n\n$type = TransactionType::SALE;\n$isFollowUp = TransactionType::isFollowUpType($type); // will return false\n$isInitiate = TransactionType::isInitiateType($type); // will return true\n\n```\n### Transaction class enum\n*TansactionClass* describes the possible values that the transaction class could take, just like TransactionType does. The value may be `recurring`, `ecom`, or `moto`. This package currently only supports the `ecom` type.\n\n```php\nuse Devinweb\\LaravelPaytabs\\Enums\\TransactionClass;\n\n$type = TransactionClass::ECOM;\n\n```\nYou can use this static function to obtain the supported values.\n\n```php\nuse Devinweb\\LaravelPaytabs\\Enums\\TransactionClass;\n\n$types = TransactionClass::values;\n\n```\n\n### Initiate a payment (Genarate a hosted payment page)\n\nTo create a paytabs transaction using this package, you need to initiate the payment first to generate the form link. Then you can visit the generated page or embed it in your app to finalize the payment. The process to do that and the options available are described in the following sections.\n\n#### Set the customer details\nTo initiate a payment, you need to specify the user model using setCustomer method. The `$user` should be an instance of `Illuminate\\Database\\Eloquent\\Model` and the used fields are: name, email and phone. The phone is optional.\nA value of type `LaravelPaytabsFacade` will be returned.\n```php\nuse Devinweb\\LaravelPaytabs\\Facades\\LaravelPaytabsFacade;\n$paytabs = LaravelPaytabsFacade::setCustomer($user);\n\n```\n#### Set cart details\nYou need also to set  the shopping cart details using the `setCart` function. A three-key array with the keys **id**, **amount**, and **description** should form `$cart`. \nA value of type `LaravelPaytabsFacade` will be returned.\n```php\nuse Devinweb\\LaravelPaytabs\\Facades\\LaravelPaytabsFacade;\n\n$cart = [\n    'id' =\u003e \"123\",\n    'amount' =\u003e 10,\n    'description' =\u003e 'cart description'\n];\n\n$paytabs = LaravelPaytabsFacade::setCart($cart);\n```\n#### Set redirect url\nThe redirect url must be included in your request. The user will be sent back to this URL after the payment has been processed. \n\n```php\nuse Devinweb\\LaravelPaytabs\\Facades\\LaravelPaytabsFacade;\n$paytabs = LaravelPaytabsFacade::setRedirectUrl($url);\n\n```\n⚠️ If you use one redirect url for all the payments inside your project, you can add it to the .env as explained [above](#paytabs-keys).\n\n\n#### Framed Hosted Payment Page\nTo display the hosted payment page in an embed frame within the merchant website, you can call `framedPage`. \nA value of type `LaravelPaytabsFacade` will be returned.\n```php\nuse Devinweb\\LaravelPaytabs\\Facades\\LaravelPaytabsFacade;\n\n$paytabs = LaravelPaytabsFacade::framedPage($user);\n\n```\n\n#### Billing\n\nIf you want to display the billing section prefilled on the payment page, you can set the billing details by creating the billing class using this command. You can find all the billing files in app/Billing the folder.\n```bash\nphp artisan make:billing PaytabsBilling\n```\nthen use\n```php\nuse Devinweb\\LaravelPaytabs\\Facades\\LaravelPaytabsFacade;\nuse App\\Billing\\PaytabsBilling;\n\nLaravelPaytabsFacade::addBilling(new PaytabsBilling);\n```\nThe getData method of the created class should return an array with keys: `street1`, `city`, `state`, `country`, `zip` and `ip`.\nIf you added all this values, you can hide the billing section from the hosted payment page using hideBilling function.\n```php\nuse Devinweb\\LaravelPaytabs\\Facades\\LaravelPaytabsFacade;\nuse App\\Billing\\PaytabsBilling;\n\nLaravelPaytabsFacade::addBilling(new PaytabsBilling)-\u003ehideBilling();\n```\n#### Shipping\nThe same way as billing, you can use display the shipping section prefilled on the payment page.\nCreate the shipping class and then add the shipping details.\n```bash\nphp artisan make:billing PaytabsShipping\n```\n```php\nuse Devinweb\\LaravelPaytabs\\Facades\\LaravelPaytabsFacade;\nuse App\\Billing\\PaytabsShipping;\n\nLaravelPaytabsFacade::addShipping(new PaytabsShipping);\n```\nYou may occasionally include digital products among the services you offer to customers, in which case you won't require their shipping information. You can use `hideShipping` option to hide shipping details section from the generated Hosted payment page. \nA value of type `LaravelPaytabsFacade` will be returned.\n```php\nuse Devinweb\\LaravelPaytabs\\Facades\\LaravelPaytabsFacade;\n\n$paytabs = LaravelPaytabsFacade::hideShipping();\n```\n\n⚠️️ If the billing details are already added, this function will hide the billing section as well.\n\n\n#### Generate the hosted payment page\nAfter setting all the payment page details and parameters, you need to use the `initiate` function to call the Paytabs Transactions Api and initiate your payment. The transaction type can be sale or auth.\n```php\nuse Devinweb\\LaravelPaytabs\\Facades\\LaravelPaytabsFacade;\nuse Devinweb\\LaravelPaytabs\\Enums\\TransactionClass;\nuse Devinweb\\LaravelPaytabs\\Enums\\TransactionType;\n\nLaravelPaytabsFacade::setCustomer($user)\n            -\u003esetCart($cart_data)\n            -\u003esetRedirectUrl($url)\n            -\u003ehideShipping()\n            -\u003einitiate(TransactionType::SALE, TransactionClass::ECOM);\n```\nIf the payment page is created successfully, you will receive a response such as shown below including the payment page URL (**redirect_url**). \nA row with `status=pending` will be added to the transactions table and a `TransactionInitiated` event will be fired.\n```json\n{\n  \"tran_ref\": \"TST2110300142699\",\n  \"tran_type\": \"Sale\",\n  \"cart_id\": \"cart_11111\",\n  \"cart_description\": \"Description of the items/services\",\n  \"cart_currency\": \"EGP\",\n  \"cart_amount\": \"100.00\",\n  \"return\": \"https://devinweb.com/4b3af623-085f-4b82-ab22-cb6cedeba218\",\n  \"redirect_url\": \"https://secure.paytabs.sa/payment/page/3F76B62E82E417E6AB2104212437A16EA53E657E75232A6C4C544962\",\n   \"customer_details\": {\n    \"name\": \"first last\",\n    \"email\": \"email@domain.com\",\n    \"phone\": \"0522222222\",\n    \"street1\": \"address street\",\n    \"city\": \"dubai\",\n    \"state\": \"du\",\n    \"country\": \"AE\",\n    \"zip\": \"12345\",\n    \"ip\": \"1.1.1.1\"\n  },\n\n}\n```\nAfter visiting the generated URL and finalizing your payment, the transaction status will be changed to `paid` or `failed` and you will be redirected to your return url. A `TransactionSucceed` or a `TransactionFail` event will be fired.\nThe payment result details will be posted to the redirect URL, as the example shown below:\n\n```\n// Successful transaction response example\nacquirerMessage= \n\u0026acquirerRRN= \n\u0026cartId=cart_11111 \n\u0026customerEmail=imane%devinweb.com \n\u0026respCode=G96376 \n\u0026respMessage=Authorised \n\u0026respStatus=A \n\u0026token= \n\u0026tranRef=TST2110400143785 \n\u0026signature=db333934b8bd8d5f94d90ab28c72831d563dc10bb196ebd78a300af7df8fad7\nGeneric\n```\nYou can visit the paytabs [official documentation](https://support.paytabs.com/en/support/solutions/articles/60000711358-what-is-response-code-vs-the-response-status-) to learn more about other paytabs Response Code/Status.\n\n\n### Follow up a transaction\nAfter initiating or finalizing your payment, you may need to do some operations on it. \n#### Get a transaction by reference\nYou can use this function to retrieve the details of a transaction such as its status, type, etc.\nThe `transactionRef` represents the reference of the transaction returned in the responses as `tran_ref` and stored in transactions table as `transaction_ref`.\n```php\nuse Devinweb\\LaravelPaytabs\\Facades\\LaravelPaytabsFacade;\n$transactionRef = \"TST2105900091468\";\n$transaction = LaravelPaytabsFacade::setTransactionRef($transactionRef)\n            -\u003egetTransaction();\n```\n* Response\n```json\n{\n  \"tran_ref\": \"TST2105900091468\",\n  \"tran_type\": \"Sale\",\n  \"cart_id\": \"Sample Payment\",\n  \"cart_description\": \"Sample Payment\",\n  \"cart_currency\": \"EGP\",\n  \"cart_amount\": \"1\",\n  \"customer_details\": {\n    \"name\": \"Imane Acherrat\",\n    \"email\": \"imane@devinweb.com\",\n    \"phone\": \"01005417901\",\n    \"street1\": \"Alexandria\",\n    \"city\": \"Alexandria\",\n    \"state\": \"ALX\",\n    \"country\": \"EG\",\n    \"ip\": \"40.123.210.168\"\n  },\n  \"payment_result\": {\n    \"response_status\": \"A\",\n    \"response_code\": \"G15046\",\n    \"response_message\": \"Authorised\",\n    \"transaction_time\": \"2021-02-28T12:24:06Z\"\n  },\n  \"payment_info\": {\n    \"card_type\": \"Credit\",\n    \"card_scheme\": \"Visa\",\n    \"payment_description\": \"4111 11## #### 1111\"\n  }\n}\n```\n⚠️ You can visit the paytabs [official documentation ](https://support.paytabs.com/en/support/solutions/articles/60000711358-what-is-response-code-vs-the-response-status) to learn more about payment_result section.\n\n#### Refund, Capture or Void transaction\n\u003e Refund request is available for those Authenticated Sale transactions or Authenticated Capture transactions.\n\n\u003e Capture request is available for successfully Authenticated Authorize Transactions\n\n\u003e Void requests are available for Authenticated Authorize transactions that are not fully captured yet. \n\nTo perform a refund, void or capture action on transaction using LaravelPaytabs, you need to set the user model (`setCustomer`), the transaction reference (`setTransactionRef`) and the cart details (`setCart`) as shown below, and pass the action type and class to the `followUpTransaction`.\n\n```php\nuse Devinweb\\LaravelPaytabs\\Facades\\LaravelPaytabsFacade;\nuse Devinweb\\LaravelPaytabs\\Enums\\TransactionClass;\nuse Devinweb\\LaravelPaytabs\\Enums\\TransactionType;\n\nLaravelPaytabsFacade::setCart($cart_data)\n        -\u003esetTransactionRef($payment-\u003etran_ref)\n        -\u003esetCustomer(Auth::user())\n        -\u003efollowUpTransaction(TransactionType::REFUND, TransactionClass::ECOM);\n```\nA `TransactionSucceed` or `TransactionFail` event will be fired.\n### Events handlers\nThis package fires three events during the process of transaction: `TransactionInitiated`, `TransactionSucceed` and `TransactionFail`.\n| Event                                               | Description            |\n| --------------------------------------------------- | ---------------------- |\n| Devinweb\\LaravelPaytabs\\Events\\TransactionInitiated | Transaction initiated  |\n| Devinweb\\LaravelPaytabs\\Events\\TransactionSucceed   | Successful transaction |\n| Devinweb\\LaravelPaytabs\\Events\\TransactionFail      |  Transaction fail       |\n\nThe content of the events is the response returned by the transaction api.\n\n#### Listener exemple\n\nUse this laravel command to create a new listener\n```bash\nphp artisan make:listener TransactionInitiatedListener\n```\nThen register the event with your listener in app/Providers/EventServiceProvider.\n```php\nclass EventServiceProvider extends ServiceProvider\n{\n    /**\n     * The event listener mappings for the application.\n     *\n     * @var array\n     */\n    protected $listen = [\n         'Devinweb\\LaravelPaytabs\\Events\\TransactionInitiated' =\u003e [\n            'App\\Listeners\\TransactionInitiatedListener',\n        ],\n    ];\n\n}\n```\n\n\n### Testing\n\n```bash\ncomposer test\n```\n\n### Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n### Security\n\nIf you discover any security related issues, please email imane@devinweb.com instead of using the issue tracker.\n\n## Credits\n\n-   [Imane Acherrat](https://github.com/devinweb)\n-   [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n## Laravel Paytabs Boilerplate\n\nYou can use this repository to check the integration of the package [laravel-paytabs-boilerplate](https://github.com/devinweb/laravel-paytabs-boilerplate).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevinweb%2Flaravel-paytabs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevinweb%2Flaravel-paytabs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevinweb%2Flaravel-paytabs/lists"}