{"id":21526482,"url":"https://github.com/saeeddev94/zarinpal-laravel","last_synced_at":"2025-04-09T23:33:28.928Z","repository":{"id":37548625,"uuid":"99886000","full_name":"SaeedDev94/zarinpal-laravel","owner":"SaeedDev94","description":"Zarinpal payment for Laravel Framework","archived":false,"fork":false,"pushed_at":"2023-07-23T16:14:52.000Z","size":107,"stargazers_count":46,"open_issues_count":6,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-18T09:56:53.411Z","etag":null,"topics":["framework","laravel","payment","zarinpal"],"latest_commit_sha":null,"homepage":"","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/SaeedDev94.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-08-10T05:47:00.000Z","updated_at":"2024-11-02T18:05:45.000Z","dependencies_parsed_at":"2022-08-02T02:20:06.604Z","dependency_job_id":"eb917703-4a05-4bed-a07a-e0e53375b730","html_url":"https://github.com/SaeedDev94/zarinpal-laravel","commit_stats":null,"previous_names":["saeed-pooyanfar/zarinpal-laravel"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaeedDev94%2Fzarinpal-laravel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaeedDev94%2Fzarinpal-laravel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaeedDev94%2Fzarinpal-laravel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaeedDev94%2Fzarinpal-laravel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SaeedDev94","download_url":"https://codeload.github.com/SaeedDev94/zarinpal-laravel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226116459,"owners_count":17575929,"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","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":["framework","laravel","payment","zarinpal"],"created_at":"2024-11-24T01:45:16.491Z","updated_at":"2024-11-24T01:45:17.158Z","avatar_url":"https://github.com/SaeedDev94.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **Zarinpal payment for Laravel Framework**\n\n- [Use this lib with other frameworks](#use-this-lib-with-other-frameworks)\u003cbr\u003e\n- [Available configs](#available-configs)\u003cbr\u003e\n\ninstall it:\n\n```shell\ncomposer require saeedpooyanfar/zarinpal\n```\n\nlaravel service provider should register automatically, if not, register `Zarinpal\\ZarinpalServiceProvider::class` manually or run:\n\n```shell\ncomposer dump-autoload\n``` \n\nset 36 chars \"ZARINPAL_MERCHANTID\" in `.env` file:\n\n```\n...\nZARINPAL_MERCHANTID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n...\n```\n\n# **Use it**\n\n**request new payment:**\n\n```php\n\u003c?php\n\n...\nuse GuzzleHttp\\Exception\\RequestException;\nuse Zarinpal\\Zarinpal;\n...\n\n...\nfunction request(Zarinpal $zarinpal) {\n    $payment = [\n        'callback_url' =\u003e route('payment.verify'), // Required\n        'amount'       =\u003e 5000,                    // Required\n        'description'  =\u003e 'a short description',   // Required\n        'metadata'     =\u003e [\n            'mobile' =\u003e '0933xxx7694',       // Optional\n            'email'  =\u003e 'saeedp47@gmail.com' // Optional\n        ]\n    ];\n    try {\n      $response = $zarinpal-\u003erequest($payment);\n      $code = $response['data']['code'];\n      $message = $zarinpal-\u003egetCodeMessage($code);\n      if($code === 100) {\n          $authority = $response['data']['authority'];\n          return $zarinpal-\u003eredirect($authority);\n      }\n      return \"Error, Code: ${code}, Message: ${message}\";\n    } catch (RequestException $exception) {\n        // handle exception\n    }\n}\n...\n```\n\nIf you have other redirection methods you can use:\n\n```php\n...\n$url = $zarinpal-\u003egetRedirectUrl($authority);\n...\n```\n\nto get the redirect url as a string.\n\n\n**verify the payment:**\n\n```php\n\u003c?php\n\n...\nuse GuzzleHttp\\Exception\\RequestException;\nuse Illuminate\\Http\\Request;\nuse Zarinpal\\Zarinpal;\n...\n\n...\nfunction verify(Request $request, Zarinpal $zarinpal) {\n    $payment = [\n        'authority' =\u003e $request-\u003einput('Authority'), // $_GET['Authority']\n        'amount'    =\u003e 5000\n    ];\n    if ($request-\u003einput('Status') !== 'OK') abort(406);\n    try {\n      $response = $zarinpal-\u003everify($payment);\n      $code = $response['data']['code'];\n      $message = $zarinpal-\u003egetCodeMessage($code);\n      if($code === 100) {\n          $refId = $response['data']['ref_id'];\n          return \"Payment was successful, RefID: ${refId}, Message: ${message}\";\n      }\n      return \"Error, Code: ${code}, Message: ${message}\";\n    } catch (RequestException $exception) {\n        // handle exception\n    }\n}\n...\n```\n\n# **Use this lib with other frameworks**\n\n```php\n\u003c?php\n\n...\nuse Zarinpal\\Zarinpal;\nuse Zarinpal\\Clients\\GuzzleClient; // OR SoapClient\n...\n\n...\n$merchantID = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX';\n$sandbox = false;\n$zarinGate = false; // OR true\n$zarinGatePSP = 'Asan'; // Leave this parameter blank if you don't need a custom PSP zaringate.\n$client = new GuzzleClient($sandbox);\n$lang = 'fa'; // OR en\n$zarinpal = new Zarinpal($merchantID, $client, $lang, $sandbox, $zarinGate, $zarinGatePSP);\n// object is ready, call methods now!\n...\n```\n\n# **Available configs**\n\n* ZARINPAL_LANG:\n    * messages language\n    * possible values: [fa, en]\n* ZARINPAL_ZARINGATE:\n    * use zarringate for redirect urls\n    * possible values: [0, 1]\n* ZARINPAL_ZARINGATE_PSP:\n    * use custom PSP for zaringate \n    * possible values: 'Asan', 'Sep', 'Sad', 'Pec', 'Fan', 'Emz'\n    \n# **Run test**\n\n```bash\n# clone repo\n# cd zarinpal-laravel\n# composer install\ncd test\nphp Request.php\n```\n\n# **Official documents**\n\n[Link](https://next.zarinpal.com/paymentGateway/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaeeddev94%2Fzarinpal-laravel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaeeddev94%2Fzarinpal-laravel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaeeddev94%2Fzarinpal-laravel/lists"}