backbone/chaching
Composer 安装命令:
composer require backbone/chaching
包简介
Universal payment library for banking services in Slovakia
关键字:
README 文档
README
Simple and unified object-oriented library written in PHP for e-commerce services offered by Slovak banks and financial institutions.
-
CardPay with optional addition for ComfortPay service -- Tatra banka, a.s.
-
TatraPay -- Tatra banka, a.s.
-
ePlatby VÚB -- VÚB, a.s.
-
VÚB eCard -- VÚB, a.s.
-
SporoPay -- Slovenská sporiteľna, a.s.
-
iTerminal -- Poštová banka, a.s.
-
GP webpay -- Global Payments Europe, s.r.o.
-
TrustCard -- TrustPay, a.s.
-
PayPal -- PayPal (Europe) S.à r.l. et Cie, S.C.A.
-
BenefitPlus -- Benefit Management s.r.o.
The current version of the library is v0.23.0 and requires PHP 5.4 or PHP 7+ to work. Even though there are things to make better, it is already being used in production without any sort of problems.
Chaching library is open-sourced software licensed under the MIT license.
Setup and installation
The recommended way to install the library is to use composer and add it as a dependency to your project's composer.json file.
{
"require": {
"backbone/chaching": "0.23.1"
}
}
After that, run the following command to perform the installation:
$ composer install
Usage
The library follows the PSR-0 convention of naming classes and after installing is available under its own namespace \Chaching. Basic setup includes the following:
use Chaching\Chaching;
$driver = Chaching::CARDPAY;
$authorization = [ 'merchant_id', 'password' ];
$options = [];
$chaching = new Chaching($driver, $authorization, $options);
As already mentioned in the introduction, currently there are eight different payment methods that are supported with each having it's own driver constant: Chaching::CARDPAY, Chaching::TATRAPAY, Chaching::TRUSTPAY, Chaching::EPLATBY, Chaching::ECARD, Chaching::PAYPAL, Chaching::GPWEBPAY, Chaching::ITERMINAL, Chaching::ITERMINAL2 and Chaching::BENEFITPLUS.
In case of Chaching::GPWEBPAY use an associated array instead of password, so authentication information would look like this:
$authorization = [
'merchant_id', [
'key' => '...../gpwebpay.crt',
'passphrase' => 'passphrase',
'certificate' => '...../gpwebpay.key'
]
];
Public and private key needs to be created according to GP webpay's documentation.
And in case of Chaching::ITERMINAL or Chaching::ITERMINAL2 use an associated array as well:
$authorization = [
NULL, [
'keystore' => '...../iterminal.pem',
'password' => 'password'
]
];
Beforementioned empty $options array may at the moment contain these keys:
ecdsa_keys_file- Absolute file path to file with Tatra banka's ECDSA keys (used only with HMAC message signing in CardPay and TatraPay)sandbox- Would you like to use sandbox or production URLs when communicating with the bank or financial institution? Default value isFALSE. Due to their limitations, sandbox is available only forChaching::TRUSTPAY,Chaching::ECARD,Chaching::PAYPAL,Chaching::GPWEBPAY,Chaching::ITERMINAL,Chaching::ITERMINAL2andChaching::BENEFITPLUS(if not listed here, production URLs will be used even in sandbox mode).
Afterwards, we need to create a request for the external service with specific information about the payment.
$payment = $chaching->request([
'currency' => \Chaching\Currencies::EUR,
'variable_symbol' => 70000000,
'amount' => 9.99,
'description' => 'My wonderful product',
'constant_symbol' => '0308',
'return_email' => '...',
'callback' => 'http://...'
]);
By running the process method in the next code block, we are getting back (when $auto_redirect is set to FALSE) the URL to redirect the user to, where the user will make the payment.
(Note that with Chaching::ITERMINAL or Chaching::ITERMINAL2 the $auto_redirect will not ever work as the transaction identifier that is provided for you is strictly needed for thereafter. Only after you succesfully create the transaction you can use the redirection URL. For more information read bank's documentation.)
try
{
$redirect_url = $payment->process($auto_redirect = FALSE);
}
catch (\Chaching\Exceptions\InvalidOptionsException $e)
{
// Missing or incorrect value of some configuration option.
}
catch (\Chaching\Exceptions\InvalidRequestException $e)
{
// General error with authentication or the request itself.
}
Remember the callback key in the request options? It is an absolute URL that the banking service will redirect to upon completion of the payment. Chaching also has methods to help with handling the response, checking it's validity, etc. However, if you are running with Chaching::ITERMINAL's (or Chaching::ITERMINAL2's) driver, you do not need to provide a callback as it is set in the merchant's centre provided by the bank.
try
{
$payment = $chaching->response($_REQUEST);
if ($payment->status === \Chaching\TransactionStatuses::SUCCESS)
{
// Wohoo, we've got the money!
}
elseif ($payment->status === \Chaching\TransactionStatuses::TIMEOUT)
{
// Special type that is only returned by TatraPay service. In general
// it's a good idea to check for it nonetheless.
}
else
{
// Failure, the user cancelled, the payment got rejected or the payment pending.
}
}
catch (\Chaching\Exceptions\InvalidResponseException $e)
{
// General error with authentication or the response itself.
}
TrustPay is a special case with response handling as they use notification mechanism similar to PayPal's IPN to let you know the status of the payment. In that case, in similar fashion to handling responses we use the notification method.
try
{
$payment = $chaching->notification($_GET);
// And now we can check the $payment->status and do what's appropriate.
}
catch (\Chaching\Exceptions\InvalidResponseException $e)
{
// General error with authentication or the response/notification itself.
}
You can also use a notification method with SporoPay and their mail notifications to the account own They come not at the same time as regular responses when user redirects their browser from SporoPay's interface, it is just another redundant way of checking payment status in case not everything goes according to the plan. (The same use case true for Tatra banka's services CardPay and TatraPay, but in those cases you can just use the response.)
When using Poštová banka's iTerminal service, Tatra banka's CardPay service or Benefit Plus service, there is an option of refunding part or full payment that has been successfully completed before. Poštová banka and Benefit Plus supports only one refund per transaction, in case of CardPay you may refund in as many steps as you'd like until sum of all refunds reaches the amount of original transaction.
try
{
$payment = $chaching->refund([
'transaction_id' => '...',
'amount' => 1.00,
'currency' => \Chaching\Currencies::EUR
]);
// Check $payment->status and do what's appropriate.
}
catch (\Chaching\Exceptions\ChachingException $e)
{
// General error with authentication, request or bank's response.
}
Payment status can be one of TransactionStatuses::REVERSED, TransactionStatuses::SUCCESS or TransactionStatuses::FAILURE. First two mean that the payment has been successfully refunded.
Newest addition to the different services provided by supported payment institutions is the ability to check whether Tatra banka's TatraPay service is available and accepting requests.
use \Chaching\Chaching;
use \Chaching\ServiceStatuses;
$authorization = [ 'merchant_id', 'password' ];
$chaching = new Chaching(Chaching::TATRAPAY, $authorization);
try
{
$status = $chaching->status();
if ($status->status === ServiceStatuses::ONLINE)
{
// TatraPay is alive and well!
}
}
catch (\Chaching\Exceptions\ChachingException $e)
{
// General error with authentication, request or bank's response.
}
PayPal deserves an honourable mention here: Please, set the instant payment notification's (IPNs) character encoding to UTF-8. Go to your Paypal profile, click "My selling tools" in the sidebar, scroll to the bottom and click "PayPal button language encoding", click "More options" and set the encoding to UTF-8. It will save you so much pain.
Contributing
- Check for open issues or open a new issue for a feature request or a bug.
- Fork the repository and make your changes to the master branch (or branch off of it).
- Send a pull request
TODO
To release a proper v1.0 code of the library needs to have a more thorough tutorial to explain it's usage as well as complete tests.
© 2025 BACKBONE, s.r.o. © 2022 Global Payments s.r.o. (Drivers/GPWebPay/GPwebpayAdditionalInfoRequest_v.5.xsd)
backbone/chaching 适用场景与选型建议
backbone/chaching 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.79k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2014 年 09 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payment」 「money」 「paypal」 「trustpay」 「tatrapay」 「cardpay」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 backbone/chaching 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 backbone/chaching 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 backbone/chaching 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PayPal SDK for ExpressCheckout and AdaptivePayments. Supports recurring payments, simple payments, parallel payments and chained payments.
Beyonic PHP Library
A PayPal IPN (Instant Payment Notification) listener for PHP
Librería para la gestión sencilla de pagos mediante TPV Redsys y Paypal
Rich payment solutions for Laravel framework. Paypal, payex, authorize.net, be2bill, omnipay, recurring paymens, instant notifications and many more
The Payum Yandex Money gateway
统计信息
- 总下载量: 4.79k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-09-29