atbox / zarinpal
zarinpal 的交易请求系统
v1.1.3
2016-09-10 10:45 UTC
Requires
- guzzlehttp/guzzle: ^6.2
Requires (Dev)
- phpunit/phpunit: 5.3.*
This package is not auto-updated.
Last update: 2024-09-23 13:42:07 UTC
README
zarinpal 交易请求库
##Laravel 兼容 此包适用于各种项目,但为了方便 Laravel 用户,我添加了提供者。只需将以下内容添加到 "config/app.php" 文件中的 providers 列表:
'providers' => array( ... 'Zarinpal\Laravel\ZarinpalServiceProvider' ... )
然后运行 'php artisan vendor:publish --provider="Zarinpal\Laravel\ZarinpalServiceProvider"
' 以将配置文件添加到 Laravel 配置目录,配置后即可使用。现在您可以像这样访问 zarinpal 库:
Zarinpal::request("example.com/testVerify.php",1000,'testing'); Zarinpal::verify('OK',1000,$answer['Authority']);
##使用 ###安装 composer require atbox/zarinpal
或
"require": { ... "atbox/zarinpal" : "1.*", ... },
###请求
use Zarinpal\Drivers\Soap; use Zarinpal\Zarinpal; $test = new Zarinpal('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',new soap()); echo json_encode($answer = $test->request("example.com/testVerify.php",1000,'testing')); if(isset($answer['Authority'])) { file_put_contents('Authority',$answer['Authority']); $test->redirect(); } //it will redirect to zarinpal to do the transaction or fail and just echo the errors. //$answer['Authority'] must save somewhere to do the verification
###验证
use Zarinpal\Drivers\Soap; use Zarinpal\Zarinpal; $test = new Zarinpal('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',new soap()); $answer['Authority'] = file_get_contents('Authority'); echo json_encode($test->verify('OK',1000,$answer['Authority'])); //'Status'(index) going to be 'success', 'error' or 'canceled'
##更换驱动器 驱动器可以使用 restAPI、soap 和 NuSoap 之间进行切换,使用以下方式:
restAPI(推荐)
$test = new Zarinpal('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX');
或 soap
use Zarinpal\Drivers\Soap; $test = new Zarinpal('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',new soap());
或 nuSoap
use Zarinpal\Drivers\NuSoap; $test = new Zarinpal('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',new NuSoap());
##Zaringate 为了将用户重定向到 Zaringate 而不是 Zarinpal 网关,请将 true 作为重定向方法的第一个参数传递(默认情况下,使用此方法将用户重定向到 Zarinpal 网关)
Zarinpal::redirect(true);