Coder Social home page Coder Social logo

cardpay's Introduction

PaySys\CardPay

Build Status Code Quality Code Coverage Packagist MIT

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

Event Parameters Description
$onBeforePayRequest \PaySys\PaySys\IPayment $payment Occurs before pay request
$onPayRequest \PaySys\PaySys\IPayment $payment Occurs on pay request

Service PaySys\CardPay\Security\Response

Event Parameters Description
$onResponse array $parameters Occurs on response from bank
$onSuccess array $parameters Occurs on success payment response from bank
$onFail array $parameters Occurs on fail payment response from bank
$onError array $parameters, \PaySys\PaySys\Exception $e Occurs on damaged response from bank

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 {}

cardpay's People

Contributors

romanmatyus avatar scrutinizer-auto-fixer avatar lawbrence007 avatar

Stargazers

Ján Bočínec avatar Dmitrijs Čornobiļs avatar triblax avatar

Watchers

James Cloos avatar  avatar  avatar  avatar

cardpay's Issues

StatusChecker

Support for checking of transactions (spec. 5. chapter), only by variable symbol.

API:

$configuration = new PaySys\CardPay\Configuration(/** ... */);

$checker = new PaySys\CardPay\StatusChecker\Selection($configuration);
$checker->vs('123444'); // @return self

// Create query, call bank server, check response, parse XML, return array of Transaction
$checker->getAll(); // @return array of PaySys\CardPay\Transaction

Test/Sandbox URL fails

Hello.

Excuse me for possible not related question, but I hope that you can help me.

During testing TatraBanka CardPay logic, I found that test env doesn't work...

Using test values:

mid: 9999

secret: 31323334353637383930313233343536373839303132333435363738393031323132333435363738393031323334353637383930313233343536373839303132

I received such URL:

https://moja.tatrabanka.sk/cgi-bin/e-commerce/start/example?MID=9999&AMT=12345.67&CURR=978&VS=123456720&RURL=http%3A%2F%2Fcp.local%2Fcart%2Fpayment%2Fconfirm%2Ftatrabanka&IPC=172.30.0.1&NAME=John+Doe&REM=serhii%40realpadsoftware.com&TIMESTAMP=24092019092851&HMAC=1b06f4919e995a1993661ce9797689d71dafcf0f29626f1c5110c01e4726161b&AREDIR=1&LANG=en

But if fails with 500 error.

If I use prod endpoint: https://moja.tatrabanka.sk/cgi-bin/e-commerce/start/cardpay with same data it returns me an error: "Payment can not be made because of an invalid security signature.", although HMAC tester (https://moja.tatrabanka.sk/cgi-bin/e-commerce/start/example) provides me same HMAC value as I sent to it...

Maybe you saw such behavior before and have any information?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.