omidgfx/payir-gateway
Composer 安装命令:
composer require omidgfx/payir-gateway
包简介
Makes your (pay.ir) payments easy and implements reliable interfaces for payment gateway.
README 文档
README
Makes your (pay.ir) payments easy and implements reliable interfaces for payment gateway.
Payir Gateway is a composer library to help working with pay.ir payment gateway.
- Secure
- Reliable
- Easy-to-use
Tutorial
▷ Watch tutorial video in aparat
Basic scenario
For a healthy payment, first of all you need to send the order information to pay.ir and get a token and store it in your database (uniquely), then pass your client to an address that's involved with the token you just got. The client pays and passes back to your website again.
Now the client is in your website, you should verify his payment and sell your stuff.
How to use?
-
Step 1
Add Payir Gateway to your project.
$ composer require omidgfx/payir-gateway
-
Step 2
Create an instance of
Omidgfx\Payirclass using by yourAPI-KEY.$payir = new Omidgfx\Payir( # api key 'API-KEY-STRING', # language Payir::LANGUAGE_FARSI // or Payir::LANGUAGE_ENGLISH );
-
Step 3
Get a new
tokenfrom pay.ir bysendmethod and use it for opening payment gateway.$response = $payir->send( # total amount of the order 1000, # callback url to your website 'https://myshop.com/verify?order=123', # mobile number [optional] '09121111111', # factor number '123', # description of the order 'Some description', # valid card number '6219861012345678' );
> Use `try-catch` to catch the exceptions. -
Step 4
Check for
$responseto be an instance ofOmidgfx\Payir\SendResponseclass.- if
$responsewas an instance ofOmidgfx\Payir\SendResponseclass then save the token in your database and then redirect your client to Pay Link by$response->redirectToPayLink()or get Pay Link by$response->getPayLink()as a string. - if
$responsewas an instance ofOmidgfx\Payir\ErrorResponseclass then show the error message to your client by$response->error()or track it down to fix it.
if ($response instanceof Omidgfx\Payir\SendResponse) { $response->redirectToPayLink(); # redirection } elseif ($response instanceof Omidgfx\Payir\ErrorResponse) { echo 'ERR ' . $response->errorCode . ': ' . $response->error(); }
- if
-
Step 5
After payment action performed, the client will be passed to your website, now you need to verify the transaction. Payir Gateway will do this for you with a cool callback listener like following:
Imagine
https://site.com/verify.php?invoice=123is your callback (redirect), following code must written in your callback listener controller for exampleverify.php.Do Step 2 in
verify.phpagain.$payir = new Omidgfx\Payir( # api key 'API-KEY-STRING', # language Payir::LANGUAGE_FARSI // or Payir::LANGUAGE_ENGLISH );
Create your callback listener:
$cb = $payir->makeCallbackListener();
Setup events on your callback listener:
- setOnError
- setOnSuccess
- setOnException
$cb->setOnError(function (Payir\ErrorResponse $errorResponse) { echo 'ERR ' . $errorResponse->errorCode . ': ' . $errorResponse->error(); })->setOnSuccess(function (Payir\VerifyResponse $verifyResponse) { // $verifyResponse->status is always 1 here /* // Save these data or use them to check if transId is in your database already. $status = $verifyResponse->status; $amount = $verifyResponse->amount; $transId = $verifyResponse->transId; $factorNumber = $verifyResponse->factorNumber; $mobile = $verifyResponse->mobile; $factorNumber = $verifyResponse->factorNumber; $description = $verifyResponse->description; $message = $verifyResponse->message; */ if(DB::getInstance()->exists('orders', ['trans_id' => $verifyResponse->transId]) == false){ // SELL YOUR STUFF HERE }else{ echo 'ERR: Security reason'; } })->setOnException(function (Exception $exception) { //throw $exception; echo 'ERR: ' . $exception->getMessage(); });
Now turn on your callback listener like following:
$cb->listen();
Created with ❤ by Pejman Chatrrouz (Omidgfx)
🎁 Donate me
omidgfx/payir-gateway 适用场景与选型建议
omidgfx/payir-gateway 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 631 次下载、GitHub Stars 达 6, 最近一次更新时间为 2019 年 09 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「plugin」 「gateway」 「payment-gateway」 「pay.ir」 「pejman chatrrouz」 「omidgfx」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 omidgfx/payir-gateway 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 omidgfx/payir-gateway 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 omidgfx/payir-gateway 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CakePHP 4.x AdminLTE Theme.
repository php library
Payyo Gateway for the Omnipay payment processing library
Client SDK for CyberSource REST APIs
Plugin for YOURLS. Default tools to use in some laemmi plugins
Client library to send SMS using Comilio SMS Gateway API (https://www.comilio.it)
统计信息
- 总下载量: 631
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-2.1-only
- 更新时间: 2019-09-20