ffb128/zarinpal
Composer 安装命令:
composer require ffb128/zarinpal
包简介
PHP Wrapper of Zarinpal API.
README 文档
README
A PHP Full API Wrapper for Zarinpal.
This library allow you to work with zarinpal api as easy as possible.
Features
- Easy to use API
- Full API Methods
- Support both REST & Soap Client (Also you can add your driver)
- Full Documented
Installation
Using Composer
composer require ffb128/zarinpal
Quick Start
Request Authority (and Redirect user)
use ffb128\Zarinpal\Zarinpal; $zarinpal = new Zarinpal("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"); $zarinpal->setAmount(5500); $zarinpal->setDescription("Buying test product"); $zarinpal->setCallback("http://example.com/verify.php"); $result = $zarinpal->request(); if($result->ok == true){ echo $zarinpal->redirect(); } else{ echo "We have an error: ". $result->message; }
Verify Transaction (verify.php)
use ffb128\Zarinpal\Zarinpal; $zarinpal = new Zarinpal("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"); $zarinpal->setAmount(5500); $result = $zarinpal->verify(); if($result->ok == true){ echo "Successful Transaction!"; }
More!
Set uesr information
You can pass user information to Zarinpal, this is recommended to have more control on your transactions.
$zarinpal->setEmail("foo@bar.com"); $zarinpal->setMobile("09123456789");
Using Sandbox
You can use Sandbox mode when you want to do some testing transaction with custom result (succeeded or failed)
$zarinpal->enableSandbox();
Using Zaringate
By default, users will redirect to Zarinpal Webgate page, but you can transfer your users to payment gateway directly.
Notice that you need to activate some necessary service for using Zaringate (Call Zarinpal Supports)
$zarinpal->enableZaringate();
Shared Pay Off
This method is suitable for those sellers whose benefit from entered price must be distributed in a special way. For example you own a web site that presents ceremony services and you have some contributions with several contractors. In this way you would keep some money and settle the rest of it to the contractors' account.
// Means that 4500 Toman from the main transaction is sent // to ZP.199998.1 with this Description: Testing Profit $zarinpal->addSharedPay("ZP.199998.1", 4500, "Testing Profit");
You can also add multiple item for shared pay:
$zarinpal->addSharedPay("ZP.199996.1", 4500, "Testing Profit"); $zarinpal->addSharedPay("ZP.133476.2", 1200, "More Testing Profit"); $zarinpal->addSharedPay("ZP.197825.1", 6700, "More than More Testing Profit");
Long time Authority
By default, an Authority will expire at 15 minutes after generating.
But you can set your custom lifetime for your generated authority by using expireIn() method (between 1800 to 3888000 seconds)
You should use it before request()
// Will expire after 7200 seconds (2 hours) $zarinpal->expireIn(7200);
Notice that you need to activate some necessary service for using thins method (Call Zarinpal Supports)
Get redirect URL
Sometimes you need to have Gateway URL instead of redirect()
$zarinpal->getRedirectURL();
Pay attention to use this method after $zarinpal->request()
Look at to this more complete example:
$result = $zarinpal->request(); if($result->ok == true){ // Will return something like: // https://www.zarinpal.com/pg/StartPay/xxxxx/ $zarinpal->getRedirectURL(); }
Get Generated Authority
Normally you don't need this method, but it's possible to get pure generated authority.
It also need to run after request()
$result = $zarinpal->request(); if($result->ok == true){ $zarinpal->getAuthority(); }
Refresh Authority
If you want to refresh your authority lifetime, use refreshAuthority(). It does the same thing that expireIn() does. but refreshAuthority() can be used when you generated an authority in past and expireIn() will help you to set your authority life span before generating.
// This will refresh your authority (xxxxxxxxxx) for 3600 seconds (1 hour) $zarinpal->refreshAuthority("xxxxxxxxxx", 3600);
Get list of Unverified Transactions
This method return a list of transactions that you didn't verify() on them, so it sound that all transactions on this list should be uncompleted.
$result = $zarinpal->getUnverified(); if($result->ok == true){ // contain an array of array print_r($result->body->Authorities); } else{ echo $result->message; }
Http Drivers
This library allow you to use both REST and Soap Zarinpal Client as well.
By default the Curl driver will used for sending requests but you can change it by setHttpDriver() .
There are two ready to use driver (Curl and Soap) and also you can have your own (take a look at src/Http/Drivers)
// Switch to Soap Client (Need to install ext-soap) $zarinpal->setHttpDriver(new \ffb128\Zarinpal\Http\Drivers\Soap); // Swith to Curl Client (No Dependency!) $zarinpal->setHttpDriver(new \ffb128\Zarinpal\Http\Drivers\Curl);
It's recommended to use REST API (for better performance & speed)
Response
All response from API will return to you in Http\Response object.
this object contains these:
{
"ok": true|false,
"message": string,
"status": int,
"body": {
...
}
}
You can check if the request was successful or not using ok , get returned status in status and get translated status message in message
Also you can access to API result in body
License
Licensed under the terms of the MIT License
ffb128/zarinpal 适用场景与选型建议
ffb128/zarinpal 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 428 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 05 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「payment」 「zarinpal」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ffb128/zarinpal 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ffb128/zarinpal 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ffb128/zarinpal 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel package for connecting to all Iraninan payment gateways
Alfabank REST API integration
Connect to Iran payment gateways through PHP(laravel).
A Laravel package for connecting to all Iraninan payment gateways
a Laravel package to handle Internet Payment Gateways for Iran Banking System
A Laravel package for connecting to all Iraninan payment gateways
统计信息
- 总下载量: 428
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-05-23