rasulian/laravel-zarinpal
Composer 安装命令:
composer require rasulian/laravel-zarinpal
包简介
A Laravel package to accept and verify payments from ZarinPal gateway based on REST
README 文档
README
A laravel package for ZarinPal gateway based on REST
This pacakge enables you to accept and verify payments from ZarinPal gateway which is based on REST.
Installation
The package can be installed through Composer:
composer require rasulian/laravel-zarinpal
You'll need to register the service provider:
// config/app.php
'providers' => [
// ...
Rasulian\ZarinPal\ZarinPalServiceProvider::class,
];
To publish the config file to config/zarinpal.php run:
php artisan vendor:publish --provider="Rasulian\ZarinPal\ZarinPalServiceProvider"
This is the default contents of the configuration:
// config/zarinpal.php
<?php
return [
'params' => [
'merchant-id' => '',
// Leave it empty if you're passing the callback url when doing the request
'callback-url' => '',
// A summary of your product or application, if needed
'description' => '',
],
// Set to true if you want to test the payment in sandbox mode
'testing' => false
];
Usage
1. Redirecting the customer to the Zarin Pal
Let's get technical. In the controller in which you will redirect the customer to the ZarinPal you must inject the payment gateway like so:
use Rasulian\ZarinPal\Payment;
class CheckoutConfirmOrderController extends Controller {
/**
* @param $zarinPal
*/
protected $zarinPal;
public function __construct(Payment $zarinPal)
{
...
$this->zarinPal = $zarinPal;
...
}
In the same controller in the method in which you redirect the customer to the ZarinPal you must set the $order that you've probably build up during the checkout-process.
public function doPayment(Request $request)
{
$invoice = $this->invoiceRepo->getCurrentInvoice();
// Doing the payment
$payment = $this->zarinPal->request(
// The total price for the order
$invoice->totalPrice,
// Pass any parameter you want when the customer successfully do the payment
// and gets back to your site
['paymentId' => $invoice->payment_id],
// Callback URL
route('checkout.payment.callback'),
// A summary of your product or application
'Good product'
);
// Throw an exception if the payment request result had any error
if ($payment->get('result') == 'warning')
throw new Exception($payment->get('error'));
// Redirect the customer to the ZarinPal gateway to do the payment
return redirect()->away($payment->get('url'));
}
2. Verifying the payment
So now we've redirected the customer to the payment provider. The customer did some actions there (hopefully he or she paid the order) and now gets redirected back to our shop site.
The payment provider will redirect the customer to the url of the route that is specified in the third parameter of therequest method or in the description option of the config file.
We must validate if the redirect to our site is a valid request.
In the controller that handles the request:
use Rasulian\ZarinPal\Payment;
class CheckoutPaymentVerificationController extends Controller {
/**
* @param $zarinPal
*/
protected $zarinPal;
public function __construct(Payment $zarinPal)
{
...
$this->zarinPal = $zarinPal;
...
}
...
Then, in the same controller, in the method you use to handle the request coming from the payment provider, use the verify method:
public function verifyPayment(Request $request)
{
$authority = $request->input('Authority');
$invoice = $this->invoiceRepo->getCurrentInvoice();
$verify = $this->zarinPal->verify($invoice->totalPrice, $authority);
if ($verify->get('result') == 'success') {
...
// Do the needed stuff If the verify was success
...
// If not, we can check which status code is given back to us from the ZarinPal gateway
// and show a message error correspond to the status code.
} else if (in_array($verify->get('code'), [-42, -54])) {
return view('shopping.payment')->with(['error' => $verify->get('error')]);
}
}
rasulian/laravel-zarinpal 适用场景与选型建议
rasulian/laravel-zarinpal 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 755 次下载、GitHub Stars 达 12, 最近一次更新时间为 2017 年 08 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「gateway」 「laravel」 「zarinpal」 「زر�」 「ن پال」 「لاراول」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rasulian/laravel-zarinpal 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rasulian/laravel-zarinpal 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rasulian/laravel-zarinpal 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Payyo Gateway for the Omnipay payment processing library
A Laravel package for connecting to all Iraninan payment gateways
PHP Wrapper of Zarinpal API.
Client library to send SMS using Comilio SMS Gateway API (https://www.comilio.it)
Alfabank REST API integration
统计信息
- 总下载量: 755
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-08-19