Skip to content

Commit

Permalink
Merge pull request #6 from bileto/pln-and-hu-from-apiv16
Browse files Browse the repository at this point in the history
Support for PLN and HUF
  • Loading branch information
Michal Kočárek authored Aug 2, 2016
2 parents b025d77 + 2f39385 commit e4e40d2
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.idea
vendor
vendor/
composer.lock
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,8 @@ try {
dump((string)$e);
}
```

## Settings


If you would like to use `PLN` and `HUF` currencies, you need to send email to `[email protected]` with your MerchantIds (sandbox and production). This functionality will be available September 2016.
14 changes: 9 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@
"authors": [
{
"name": "Michal Sänger",
"email": "[email protected]"
"email": "[email protected]"
},
{
"name": "Jan Machala",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": { "Omnipay\\Csob\\" : "src/" }
},
"require": {
"omnipay/common": "2.3.*"
"omnipay/common": "2.5.*"
},
"require-dev": {
"omnipay/tests": "^2.0",
"symfony/var-dumper": "^2.7",
"mockery/mockery": "^0.9.4"
"omnipay/tests": "2.0.*",
"symfony/var-dumper": "3.1.*",
"mockery/mockery": "0.9.*"
}
}
16 changes: 6 additions & 10 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/3.7/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
bootstrap="./vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
stopOnFailure="false">
<testsuites>
<testsuite name="Application Test Suite">
<testsuite name="Unit Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<ini name="date.timezone" value="UTC" />
</php>
</phpunit>
6 changes: 3 additions & 3 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
* ČSOB payment gateway
*
* @package Omnipay\Csob
* @see https://github.com/csob/paymentgateway/wiki/eAPI-1.5-EN
* @see https://github.com/csob/paymentgateway/wiki/eAPI-v1.6-EN
*/
class Gateway extends AbstractGateway
{
const URL_SANDBOX = 'https://iapi.iplatebnibrana.csob.cz/api/v1.5';
const URL_PRODUCTION = 'https://api.platebnibrana.csob.cz/api/v1.5';
const URL_SANDBOX = 'https://iapi.iplatebnibrana.csob.cz/api/v1.6';
const URL_PRODUCTION = 'https://api.platebnibrana.csob.cz/api/v1.6';

/** @var DataSignator */
private $signator;
Expand Down
3 changes: 2 additions & 1 deletion src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace Omnipay\Csob\Message;

use Omnipay\Common\Message\AbstractRequest as OmnipayAbstractRequest;
use Omnipay\Csob\Sign\DataSignator;
use Omnipay\Csob\Sign\DataVerifier;

abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
abstract class AbstractRequest extends OmnipayAbstractRequest
{
/** @var DataSignator */
private $signator;
Expand Down
3 changes: 2 additions & 1 deletion src/Message/AbstractResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace Omnipay\Csob\Message;

use Omnipay\Common\Message\AbstractResponse as OmnipayAbstractResponse;
use Omnipay\Csob\Sign\DataVerifier;

class AbstractResponse extends \Omnipay\Common\Message\AbstractResponse
class AbstractResponse extends OmnipayAbstractResponse
{
/** @var DataVerifier */
private $verifier;
Expand Down
5 changes: 1 addition & 4 deletions src/Message/EchoRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ public function setDttm($value)
*/
public function getData()
{
$data = [
"merchantId" => $this->getParameter('merchantId'),
"dttm" => $this->getParameter('dttm'),
];
$data = $this->getParameters();
$data['signature'] = $this->signData($data);
return $data;
}
Expand Down
18 changes: 1 addition & 17 deletions src/Message/InitPaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,7 @@ public function setLanguage($value)
*/
public function getData()
{
$data = [
"merchantId" => $this->getParameter('merchantId'),
"orderNo" => $this->getParameter('orderNo'),
"dttm" => $this->getParameter('dttm'),
"payOperation" => $this->getParameter('payOperation'),
"payMethod" => $this->getParameter('payMethod'),
"totalAmount" => $this->getParameter('totalAmount'),
"currency" => $this->getParameter('currency'),
"closePayment" => $this->getParameter('closePayment'),
"returnUrl" => $this->getParameter('returnUrl'),
"returnMethod" => $this->getParameter('returnMethod'),
"cart" => $this->getParameter('cart'),
"description" => $this->getParameter('description'),
"merchantData" => $this->getParameter('merchantData'),
"customerId" => $this->getParameter('customerId'),
"language" => $this->getParameter('language'),
];
$data = $this->getParameters();
$data['signature'] = $this->signData($data);
return $data;
}
Expand Down
6 changes: 0 additions & 6 deletions src/Message/ProcessPaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ public function setMerchantId($value)
public function getData()
{
return $this->getParameters();
$data = [
"merchantId" => $this->getParameter('merchantId'),
"payId" => $this->getParameter('payId'),
"dttm" => $this->getParameter('dttm'),
];
return $data;
}

/**
Expand Down
16 changes: 9 additions & 7 deletions src/Purchase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
*/
class Purchase
{
const CURENCY_CZK = 'CZK';
const CURENCY_EUR = 'EUR';
const CURENCY_USD = 'USD';
const CURENCY_GBP = 'GBP';
const CURRENCY_CZK = 'CZK';
const CURRENCY_EUR = 'EUR';
const CURRENCY_USD = 'USD';
const CURRENCY_GBP = 'GBP';
const CURRENCY_HUF = 'HUF';
const CURRENCY_PLN = 'PLN';

const LANG_CZ = 'CZ';
const LANG_EN = 'EN';
Expand Down Expand Up @@ -71,11 +73,11 @@ class Purchase

/**
* Currency code.
* Approved values: CZK, EUR, USD, GBP
* Approved values: CZK, EUR, USD, GBP, HUF, PLN
*
* @var string
*/
private $currency = self::CURENCY_CZK;
private $currency = self::CURRENCY_CZK;

/**
* It indicates whether the payment should automatically be put in the queue
Expand Down Expand Up @@ -143,7 +145,7 @@ class Purchase
/**
* Preferred language mutation to be displayed on the payment gateway.
* Czech mutation is by default.
* Approved values: CZ, EN, DE, SK
* Approved values: CZ, EN, DE, FR, HU, IT, JP, PL, PT, RO, RU, SK, ES, TR, VN
*
* @var string
*/
Expand Down
5 changes: 0 additions & 5 deletions tests/bootstrap.php

This file was deleted.

3 changes: 2 additions & 1 deletion tests/unit/PurchaseTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

use Omnipay\Csob\CartItem;
use Omnipay\Csob\Purchase;

class PurchaseTest extends PHPUnit_Framework_TestCase
{
public function testToArray()
{
$purchase = new Purchase('merch123', '00456', 'http://eshop.com', 'Some desc');
$item = new \Omnipay\Csob\CartItem("Some item", 2, 150.50, "Some cart item");
$item = new CartItem("Some item", 2, 150.50, "Some cart item");
$purchase->addCartItem($item);
$purchase->setDttm('xyz');
$expected = [
Expand Down
13 changes: 9 additions & 4 deletions tests/unit/Sign/DataSignatorTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
<?php

use Omnipay\Csob\Sign\DataSignator;
use Omnipay\Csob\Sign\Preparer;
use Omnipay\Csob\Sign\Signator;
use Omnipay\Csob\Sign\Verifier;

class DataSignatorTest extends PHPUnit_Framework_TestCase {

public function testSign()
{
$privateKey = file_get_contents(__DIR__ . '/assets/rsa_A1029DTmM7.key');
$publicKey = file_get_contents(__DIR__ . '/assets/rsa_A1029DTmM7.pub');
$preparer = new \Omnipay\Csob\Sign\Preparer();
$signator = new \Omnipay\Csob\Sign\Signator($privateKey);
$verifier = new \Omnipay\Csob\Sign\Verifier($publicKey);
$signator = new \Omnipay\Csob\Sign\DataSignator($preparer, $signator);
$preparer = new Preparer();
$signator = new Signator($privateKey);
$verifier = new Verifier($publicKey);
$signator = new DataSignator($preparer, $signator);

$data = [
"merchantId" => "A1029DTmM7",
Expand Down
10 changes: 7 additions & 3 deletions tests/unit/Sign/DataVerifierTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<?php

use Omnipay\Csob\Sign\DataVerifier;
use Omnipay\Csob\Sign\Preparer;
use Omnipay\Csob\Sign\Verifier;

class DataVerifierTest extends PHPUnit_Framework_TestCase
{
public function testVerify()
{
$publicKey = file_get_contents(__DIR__ . '/assets/mips_iplatebnibrana.csob.cz.pub');
$preparer = new \Omnipay\Csob\Sign\Preparer();
$verifier = new \Omnipay\Csob\Sign\Verifier($publicKey);
$dataVerifier = new \Omnipay\Csob\Sign\DataVerifier($preparer, $verifier);
$preparer = new Preparer();
$verifier = new Verifier($publicKey);
$dataVerifier = new DataVerifier($preparer, $verifier);

$data = [
"authCode" => "518778",
Expand Down
7 changes: 5 additions & 2 deletions tests/unit/Sign/SignatorTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<?php

use Omnipay\Csob\Sign\Signator;
use Omnipay\Csob\Sign\Verifier;

class SignatorTest extends PHPUnit_Framework_TestCase
{
public function testSign()
{
$privateKey = file_get_contents(__DIR__ . '/assets/rsa_A1029DTmM7.key');
$publicKey = file_get_contents(__DIR__ . '/assets/rsa_A1029DTmM7.pub');
$signator = new \Omnipay\Csob\Sign\Signator($privateKey);
$verifier = new \Omnipay\Csob\Sign\Verifier($publicKey);
$signator = new Signator($privateKey);
$verifier = new Verifier($publicKey);
$text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec malesuada porta orci, eget vehicula tortor eleifend in.';

$signed = $signator->sign($text);
Expand Down
7 changes: 5 additions & 2 deletions tests/unit/Sign/VerifierTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<?php

use Omnipay\Csob\Sign\Signator;
use Omnipay\Csob\Sign\Verifier;

class VerifierTest extends PHPUnit_Framework_TestCase
{
public function testVerify()
{
$privateKey = file_get_contents(__DIR__ . '/assets/rsa_A1029DTmM7.key');
$publicKey = file_get_contents(__DIR__ . '/assets/rsa_A1029DTmM7.pub');
$signator = new \Omnipay\Csob\Sign\Signator($privateKey);
$verifier = new \Omnipay\Csob\Sign\Verifier($publicKey);
$signator = new Signator($privateKey);
$verifier = new Verifier($publicKey);
$text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas metus arcu, accumsan in massa non';
$signed = $signator->sign($text);

Expand Down

0 comments on commit e4e40d2

Please sign in to comment.