zfr/zfr-paymill
Composer 安装命令:
composer require zfr/zfr-paymill
包简介
PHP library for interacting with the Paymill REST API
README 文档
README
ZfrPaymill is a modern PHP library based on Guzzle for Paymill payment system.
Note : this library does not contain tests, mainly because I'm not sure about how to write tests for an API wrapper. Don't hesitate to help on this ;-).
Dependencies
- Guzzle: >= 3.5
Installation
Installation of ZfrPaymill is only officially supported using Composer:
php composer.phar require zfr/zfr-paymill:1.*
Tutorial
First, you need to instantiate the Paymill client, passing your private API key (you can find it in your Paymill settings):
$client = new PaymillClient('my-api-key');
The currently supported version of the API is version 2.0.
How to use it?
Using the client is easy. For instance, here is how you'd create a new offer:
$details = $client->createOffer(array( 'name' => 'MyOffer', 'amount' => 500, 'currency' => 'EUR', 'interval' => '1 MONTH' ));
The parameters have a direct one-to-one mapping with the official documentation (for any reference, you can also
check the ZfrPaymill\Client\ServiceDescription\Paymill-2.0.php file). To know what the responses look like, please
refer to the official API reference.
For most get methods, you must pass an id parameter, as follows:
$details = $client->getClient(array('id' => 'my-client-id'));
Exceptions
ZfrPaymill tries its best to throw useful exceptions. Two kinds of exceptions can occur:
- Guzzle exceptions: by default, Guzzle automatically validate parameters according to rules defined in the service description before sending the actual request. If you encounter those exceptions, you likely have broken code.
- ZfrPaymill exceptions: those exceptions are thrown if an error occurred on Paymill side. Each exception implement
ZfrPaymill\Exception\ExceptionInterface.
Here are all the exceptions:
ZfrPaymill\Exception\UnauthorizedException: your API key is likely to be wrong...ZfrPaymill\Exception\TransactionErrorException: transaction couldn't be completed.ZfrPaymill\Exception\NotFoundException: is thrown whenever client receives a 404 exception.ZfrPaymill\Exception\ValidationErrorException: some errors on your sent data.ZfrPaymill\Exception\ServerErrorException: any errors where Paymill is likely to be doing something wrong...
Usage:
try { $client->createTransaction(array( 'amount' => 4000, 'currency' => 'EUR', 'token' => '1234' )); } catch (\ZfrPaymill\Exception\TransactionErrorException $exception) { // Seems the transaction failed, let's see why: $why = $exception->getMessage(); // Let's also get the response to have more info: $response = $exception->getResponse(); } catch (\Exception $exception) { // Catch any other exception... }
For transaction/refund/preauthorization methods, Paymill may return status code 200 even if an error occured. Paymill stores this error in a
response_codeproperty in the reponse. However, ZfrPaymill will automatically checks if this is set, and throw aTransactionErrorException, so that you don't need to check for this yourself, but only catch the exception.
Advanced usage
Listeners
Because ZfrPaymill is based on Guzzle, you can take advantage of all its feature. For instance, you can add
listeners to various events by calling the addSubscriber method on the client.
Complete reference
Here is a complete list of all methods, with a link to the official documentation for parameters names:
PAYMENT RELATED METHODS:
- array createPayment(array $args = array()) doc
- array deletePayment(array $args = array()) doc
- array getPayment(array $args = array()) doc
- array getPayments(array $args = array()) doc
PREAUTHORIZATION RELATED METHODS:
- array createPreauthorization(array $args = array()) doc
- array deletePreauthorization(array $args = array()) doc
- array getPreauthorization(array $args = array()) doc
- array getPreauthorizations(array $args = array()) doc
TRANSACTION RELATED METHODS:
- array createTransaction(array $args = array()) doc
- array getTransaction(array $args = array()) doc
- array getTransactions(array $args = array()) doc
- array updateTransaction(array $args = array()) doc
REFUND RELATED METHODS:
- array getRefund(array $args = array()) doc
- array getRefunds(array $args = array()) doc
- array refundTransaction(array $args = array()) doc
CLIENT RELATED METHODS:
- array createClient(array $args = array()) doc
- array deleteClient(array $args = array()) doc
- array getClient(array $args = array()) doc
- array getClients(array $args = array()) doc
- array updateClient(array $args = array()) doc
OFFER RELATED METHODS:
- array createOffer(array $args = array()) doc
- array deleteOffer(array $args = array()) doc
- array getOffer(array $args = array()) doc
- array getOffers(array $args = array()) doc
- array updateOffer(array $args = array()) doc
SUBSCRIPTION RELATED METHODS:
- array createSubscription(array $args = array()) doc
- array deleteSubscription(array $args = array()) doc
- array getSubscription(array $args = array()) doc
- array getSubscriptions(array $args = array()) doc
- array updateSubscription(array $args = array()) doc
WEBHOOK RELATED METHODS:
zfr/zfr-paymill 适用场景与选型建议
zfr/zfr-paymill 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 1, 最近一次更新时间为 2013 年 11 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payment」 「paymill」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 zfr/zfr-paymill 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zfr/zfr-paymill 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zfr/zfr-paymill 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Paymill driver for the Omnipay payment processing library
Paymill gateway for Payum
Laravel wrapper for the Paymill API
Paymill payments for Symfony apps
Laravel wrapper for the Paymill API
Paymill integration with Magento 2
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-11-23