paysera/notification-php-client
Composer 安装命令:
composer require paysera/notification-php-client
包简介
Notification API PHP client
README 文档
README
#NotificationPhpClient
##What is NotificationPhpClient?
This is a library for webtopay.com Notification API. It allows you to easily check sign and parse the callback request from webtopay.com about funds in your account. You have to set-up notifications in "Account settings" page on webtopay.com to get the notifications.
##Installation
###Manual
- Use
git clone https://github.com/evp/NotificationPhpClient.gitto copy the NotificationPhpClient directory to your project directory. - Add the following code to your PHP file where you intend to check notification callbacks:
require_once '/path/to/NotificationPhpClient/src/Evp/Notification/Autoloader.php'; Evp_Notification_Autoloader::register();
This will ensure that all of the library's classes are properly loaded. Make sure you change the 'path/to' to the actual path of the NotificationPhpClient.
###Composer
- Add
"paysera/notification-php-client": "dev-master"dependency to composer.json file. - Execute
composer update paysera/notification-php-clientin your project directory.
##Using the library
$notification = Evp_Notification_Container::create()->getRequestParser()->parseRequest($_POST);
Evp_Notification_Container::create method is used for fluent interface, you can create container by using new keyword.
Evp_Notification_RequestParser::parseRequest method returns instance of Evp_Notification_Entity_OperationNotification,
which provides interface for getting the data from callback.
You can use method Evp_Notification_RequestParser::parseRequestToArray to get all passed parameters as an array
if you prefer.
You can customize the parameters and services by providing optional array parameter when creating Evp_Notification_Container.
Each time when callback is parsed and signature is checked, public key is requested from webtopay.com server. To cache
public key, provide parameter cache.filePath to container. For example:
$container = new Evp_Notification_Container(array( 'cache.filePath' => '/tmp/evp.notifications.public-key.php', ));
Be aware that this file must be in a safe place that no other script or third party could overwrite it. Otherwise security can be breached by replacing the public key. If there is no cache available, file is not readable or sign is invalid with cached key, public key will be downloaded from webtopay.com and saved to cache.
Notification API requires that response code would be 200 and content would start with "OK". Library does not provide any method to give this kind of response.
If signature check does not pass or some other issue occurs, library throws an exception. You can process those exceptions by catching them:
try { $notification = Evp_Notification_Container::create()->getRequestParser()->parseRequest($_POST); // process $notification somehow echo 'OK'; } catch (Evp_Notification_Exception $exception) { // log $exception somehow // do not respond 'OK' if you want that callback would be repeated after some time echo 'Error: ' . $exception; }
##Running tests
Run phpunit in the base directory.
paysera/notification-php-client 适用场景与选型建议
paysera/notification-php-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 42.28k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2013 年 04 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 paysera/notification-php-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 paysera/notification-php-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 42.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2013-04-03