paysys / tatrapay
Library for Tatra bank TatraPay gateway in Nette framework.
Requires
- php: >=7.1
- ext-openssl: *
- nette/application: ~2.3@dev
- nette/di: ~2.4@dev
- nette/http: ~2.3@dev
- nette/utils: ~2.4@dev
- paysys/paysys: ^0.1@dev
Requires (Dev)
- ext-mbstring: *
- jakub-onderka/php-parallel-lint: ~0.8
- nette/tester: ~1.7@dev
- nikic/php-parser: ^3.0.2
- phpstan/phpstan: dev-master as 0.6.x-dev
- phpstan/phpstan-nette: ~0.6
Suggests
- paysys/cardpay: Allows use CardPay in Nette framework
This package is not auto-updated.
Last update: 2024-11-10 04:06:58 UTC
README
Library for implement TatraPay gateway (v4.0 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/TatraPay
.
$ composer require paysys/tatrapay
Configuration
extensions: TatraPay: PaySys\TatraPay\DI\TatraPayExtension TatraPay: mid: '1234' key: '64-bit hexadecimal string'
Events
Object PaySys\PaySys\Button
Service PaySys\TatraPay\Security\Response
Example
Generating payment button
Set PaySys\TatraPay\Payment
.
Button need PaySys\PaySys\IConfiguration
service. Use DI generated factory PaySys\TatraPay\IButtonFactory
for getting configured PaySys\PaySys\Button
component.
Now set $onPayRequest
event on PaySys\PaySys\Button
for redirect to TatraPay gateway. Signed redirect URL is genereated by service PaySys\TatraPay\Security\Request->getUrl(PaySys\TatraPay\Payment $payment)
.
class OrderPresenter extends Presenter { /** @var \PaySys\TatraPay\IButtonFactory @inject */ public $tatraPayButtonFactory; /** @var \PaySys\TatraPay\Security\Request @inject */ public $tatraPayRequest; protected function createComponentTatraPayButton() { $payment = new \PaySys\TatraPay\Payment("12.34", "00456", "John Doe"); $button = $this->tatraPayButtonFactory->create($payment); $button->onPayRequest[] = function ($payment) { $this->redirectUrl($this->TatraPayRequest->getUrl($payment)); }; return $button; } }
Process payment response
Event-driven processing
Default is Bank response routed to included presenter TatraPay:TatraPay:process
. In this case are automatic called events on service PaySys\TatraPay\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\TatraPay\Security\Response @inject */ public $bankResponse; public function actionProcessTatraPay() { 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:
tatraPay: rurl: Order:processTatraPay
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 {}