paysys / cardpay
Library for Tatra bank CardPay gateway in Nette framework.
Installs: 2 402
Dependents: 0
Suggesters: 1
Security: 0
Stars: 3
Watchers: 4
Forks: 5
Open Issues: 3
Requires
- php: >=7.1
- nette/application: >=2.3
- nette/di: >=2.4
- nette/http: >=2.3
- nette/utils: >=2.4
- paysys/paysys: ^0.1
Requires (Dev)
- ext-mbstring: *
- jakub-onderka/php-parallel-lint: ~1.0
- nette/tester: ~2.1
- phpstan/phpstan: ~0.10.6
- phpstan/phpstan-nette: ~0.6
This package is not auto-updated.
Last update: 2024-11-09 21:12:01 UTC
README
Library for implement CardPay gateway (v1.5 with HMAC & ECDSA) from Tatra Banka in Nette framework.
Requirements
Requires PHP 7.1 or later.
Use universal libraty PaySys\PaySys.
Installation
The best way to install Unique is use Composer package PaySys/CardPay
.
$ composer require paysys/cardpay
Configuration
extensions: cardPay: PaySys\CardPay\DI\CardPayExtension cardPay: mid: '1234' key: '64-bit hexadecimal string'
Events
Object PaySys\PaySys\Button
Service PaySys\CardPay\Security\Response
Example
Generating payment button
Set PaySys\CardPay\Payment
.
Button need PaySys\PaySys\IConfiguration
service. Use DI generated factory PaySys\PaySys\IButtonFactory
for getting configured PaySys\PaySys\Button
component.
Now set $onPayRequest
event on PaySys\PaySys\Button
for redirect to CardPay gateway. Signed redirect URL is genereated by service PaySys\CardPay\Security\Request->getUrl(PaySys\CardPay\Payment $payment)
.
class OrderPresenter extends Presenter { /** @var \PaySys\PaySys\IButtonFactory @inject */ public $cardPayButtonFactory; /** @var \PaySys\CardPay\Security\Request @inject */ public $cardPayRequest; protected function createComponentCardPayButton() { $payment = new \PaySys\CardPay\Payment("12.34", "00456", "John Doe"); $button = $this->cardPayButtonFactory->create($payment); $button->onPayRequest[] = function ($payment) { $this->redirectUrl($this->cardPayRequest->getUrl($payment)); }; return $button; } }
Process payment response
Event-driven processing
Default is Bank response routed to included presenter CardPay:CardPay:process
. In this case are automatic called events on service PaySys\CardPay\Security\Response
.
For processing payment by events use for example Kdyby\Events.
Own presenter
Too it's possible write own Nette\Application\UI\Presenter
for hnadling payment. In this case are events called same as before example.
class OrderPresenter extends Presenter { /** @var Nette\Http\IRequest @inject */ public $httpRequest; /** @var \PaySys\CardPay\Security\Response @inject */ public $bankResponse; public function actionProcessCardPay() { try { $this->bankResponse->paid($this->httpRequest->getQuery()); // store info about payment $this->flashMessage('Thanks for payment.', 'success'); } catch (\PaySys\PaySys\Exception $e) { // log $this->flashMessage('Payment failed. Please try it later.', 'danger'); } $this->redirect('finish'); } }
Now just add route to configuration:
cardPay: rurl: Order:processCardPay
Exceptions
class \PaySys\PaySys\Exception extends \Exception {} class \PaySys\PaySys\SignatureException extends \PaySys\PaySys\Exception {} class \PaySys\PaySys\ServerException extends \PaySys\PaySys\Exception {} class \PaySys\PaySys\InvalidArgumentException extends \PaySys\PaySys\Exception {} class \PaySys\PaySys\ConfigurationException extends \PaySys\PaySys\Exception {}