blognevis/zarinpal
Composer 安装命令:
composer require blognevis/zarinpal
包简介
Zarinpal payment for Laravel Framework (with sandbox support)
README 文档
README
install it:
composer require saeedpooyanfar/zarinpal
laravel service provider should register automatically, if not, register Zarinpal\ZarinpalServiceProvider::class manually or run:
composer dump-autoload
set 36 chars "ZARINPAL_MERCHANTID" in .env file:
...
ZARINPAL_MERCHANTID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
...
Use it
request new payment:
<?php ... use GuzzleHttp\Exception\RequestException; use Zarinpal\Zarinpal; ... ... function request(Zarinpal $zarinpal) { $payment = [ 'callback_url' => route('payment.verify'), // Required 'amount' => 5000, // Required 'description' => 'a short description', // Required 'metadata' => [ 'mobile' => '0933xxx7694', // Optional 'email' => 'saeedp47@gmail.com' // Optional ] ]; try { $response = $zarinpal->request($payment); $code = $response['data']['code']; $message = $zarinpal->getCodeMessage($code); if($code === 100) { $authority = $response['data']['authority']; return $zarinpal->redirect($authority); } return 'Error, Code: ' . $code . ', Message: ' . $message; } catch (RequestException $exception) { // handle exception } } ...
If you have other redirection methods you can use:
... $url = $zarinpal->getRedirectUrl($authority); ...
to get the redirect url as a string.
verify the payment:
<?php ... use GuzzleHttp\Exception\RequestException; use Illuminate\Http\Request; use Zarinpal\Zarinpal; ... ... function verify(Request $request, Zarinpal $zarinpal) { $payment = [ 'authority' => $request->input('Authority'), // $_GET['Authority'] 'amount' => 5000 ]; if ($request->input('Status') !== 'OK') abort(406); try { $response = $zarinpal->verify($payment); $code = $response['data']['code']; $message = $zarinpal->getCodeMessage($code); if($code === 100) { $refId = $response['data']['ref_id']; return 'Payment was successful, RefID: ' . $refId . ', Message: ' . $message; } return 'Error, Code: ' . $code . ', Message: ' . $message; } catch (RequestException $exception) { // handle exception } } ...
Use this lib with other frameworks
<?php ... use Zarinpal\Zarinpal; use Zarinpal\Clients\GuzzleClient; // OR SoapClient ... ... $merchantID = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'; $sandbox = false; $zarinGate = false; // OR true $zarinGatePSP = 'Asan'; // Leave this parameter blank if you don't need a custom PSP zaringate. $client = new GuzzleClient($sandbox); $lang = 'fa'; // OR en $zarinpal = new Zarinpal($merchantID, $client, $lang, $sandbox, $zarinGate, $zarinGatePSP); // object is ready, call methods now! ...
Available configs
- ZARINPAL_LANG:
- messages language
- possible values: [fa, en]
- ZARINPAL_ZARINGATE:
- use zarringate for redirect urls
- possible values: [0, 1]
- ZARINPAL_ZARINGATE_PSP:
- use custom PSP for zaringate
- possible values: 'Asan', 'Sep', 'Sad', 'Pec', 'Fan', 'Emz'
Run test
# clone repo # cd zarinpal-laravel # composer install cd test php Request.php
Official documents
zarinpal
blognevis/zarinpal 适用场景与选型建议
blognevis/zarinpal 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 33 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 08 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「payment」 「laravel」 「zarinpal」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 blognevis/zarinpal 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 blognevis/zarinpal 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 blognevis/zarinpal 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Alfabank REST API integration
High-performance, opinionated PHP 8 web framework with O(1) routing, parallel async MySQL, type-safe asset bridge, and React-island frontend
Laravel package for Accurate Online API integration.
The skeleton application for the Geoffrey agent framework.
TrinkPOS Sanal POS (Virtual POS) API client for PHP
统计信息
- 总下载量: 33
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-19