Skip to content

Commit

Permalink
Merge ec5efa7 into 084d804
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalkowski83 committed Aug 1, 2019
2 parents 084d804 + ec5efa7 commit 55e6d97
Show file tree
Hide file tree
Showing 70 changed files with 415 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@

/behat.yml
/phpspec.yml
/bin/*
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,26 @@ $ bin/console debug:container bitbag_sylius_przelewy24_plugin
```bash
$ composer install
$ cd tests/Application
$ cp .env .env.local #edit .env.local file and setup configuration
$ yarn install
$ yarn run gulp
$ bin/console assets:install -e test
$ bin/console doctrine:database:create -e test
$ bin/console doctrine:schema:create -e test
$ bin/console server:run 127.0.0.1:8080 -e test
$ open http://localhost:8080
$ bin/behat
$ bin/phpspec run
$ bin/console sylius:fixture:load -e test #install fixtures
open http://localhost:8080
```
For admin panel:
```
open http://localhost:8080/admin
sylius:sylius
```
From root catalog
```bash
$ vendor/bin/behat
$ vendor/bin/phpspec run
```

## Contribution

Learn more about our contribution workflow on http://docs.sylius.org/en/latest/contributing/.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"license": "MIT",
"require": {
"php": "^7.2",

"sylius/sylius": "~1.4.0"
"sylius/sylius": "^1.5"
},
"require-dev": {
"behat/behat": "^3.4",
Expand Down
6 changes: 4 additions & 2 deletions src/Action/CaptureAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use BitBag\SyliusPrzelewy24Plugin\Bridge\Przelewy24BridgeInterface;
use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\Exception\UnsupportedApiException;
use Payum\Core\GatewayAwareInterface;
Expand Down Expand Up @@ -58,6 +59,7 @@ public function execute($request): void
{
RequestNotSupportedException::assertSupports($this, $request);

/** @var ArrayObject $details */
$details = $request->getModel();

if (isset($details['p24_status'])) {
Expand All @@ -66,14 +68,14 @@ public function execute($request): void

/** @var TokenInterface $token */
$token = $request->getToken();
$details['p24_session_id'] = uniqid();
$details['p24_session_id'] = uniqid('p24_', true);
$notifyToken = $this->tokenFactory->createNotifyToken($token->getGatewayName(), $token->getDetails());
$details['p24_url_return'] = $token->getAfterUrl();
$details['p24_url_cancel'] = $token->getAfterUrl() . '&' . http_build_query(['status' => Przelewy24BridgeInterface::CANCELLED_STATUS]);
$details['p24_wait_for_result'] = '1';
$details['p24_url_status'] = $notifyToken->getTargetUrl();
$details['token'] = $this->przelewy24Bridge->trnRegister($details->toUnsafeArray());
$details['p24_status'] = Przelewy24BridgeInterface::CREATED_STATUS;
$details['token'] = $this->przelewy24Bridge->trnRegister($details->toUnsafeArray());

throw new HttpPostRedirect(
$this->przelewy24Bridge->getTrnRequestUrl($details['token'])
Expand Down
44 changes: 24 additions & 20 deletions src/Bridge/Przelewy24Bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace BitBag\SyliusPrzelewy24Plugin\Bridge;

use Exception;
use GuzzleHttp\ClientInterface;

final class Przelewy24Bridge implements Przelewy24BridgeInterface
Expand Down Expand Up @@ -45,24 +46,23 @@ public function setAuthorizationData(

public function getTrnRegisterUrl(): string
{
return $this->getHostForEnvironment() . 'trnRegister';
return sprintf('%strnRegister', $this->getHostForEnvironment());
}

public function getTrnRequestUrl(string $token): string
{
return $this->getHostForEnvironment() . 'trnRequest/' . $token;
return sprintf('%strnRequest/%s', $this->getHostForEnvironment(), $token);
}

public function getTrnVerifyUrl(): string
{
return $this->getHostForEnvironment() . 'trnVerify';
return sprintf('%strnVerify', $this->getHostForEnvironment());
}

public function getHostForEnvironment(): string
{
return self::SANDBOX_ENVIRONMENT === $this->environment ?
self::SANDBOX_HOST : self::PRODUCTION_HOST
;
self::SANDBOX_HOST : self::PRODUCTION_HOST;
}

public function createSign(array $parameters): string
Expand All @@ -76,12 +76,14 @@ public function trnRegister(array $posData): string
$posData['p24_pos_id'] = $this->merchantId;
$posData['p24_api_version'] = self::P24_API_VERSION;

$sign = $this->createSign([
$posData['p24_session_id'],
$posData['p24_merchant_id'],
$posData['p24_amount'],
$posData['p24_currency'],
]);
$sign = $this->createSign(
[
$posData['p24_session_id'],
$posData['p24_merchant_id'],
$posData['p24_amount'],
$posData['p24_currency'],
]
);

$posData['p24_sign'] = $sign;

Expand All @@ -94,21 +96,23 @@ public function trnVerify(array $posData): bool
$posData['p24_pos_id'] = $this->merchantId;
$posData['p24_api_version'] = self::P24_API_VERSION;

$sign = $this->createSign([
$posData['p24_session_id'],
$posData['p24_order_id'],
$posData['p24_amount'],
$posData['p24_currency'],
]);
$sign = $this->createSign(
[
$posData['p24_session_id'],
$posData['p24_order_id'],
$posData['p24_amount'],
$posData['p24_currency'],
]
);

$posData['p24_sign'] = $sign;

return (int) $this->request($posData, $this->getTrnVerifyUrl())['error'] === 0;
return (int)$this->request($posData, $this->getTrnVerifyUrl())['error'] === 0;
}

public function request(array $posData, string $url): array
{
$response = (string) $this->client->request('POST', $url, ['form_params' => $posData])->getBody();
$response = (string)$this->client->request('POST', $url, ['form_params' => $posData])->getBody();

$result = [];

Expand All @@ -119,7 +123,7 @@ public function request(array $posData, string $url): array
}

if (!isset($result['error']) || $result['error'] > 0) {
throw new \Exception($response);
throw new \RuntimeException($response);
}

return $result;
Expand Down
18 changes: 9 additions & 9 deletions src/Bridge/Przelewy24BridgeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@

interface Przelewy24BridgeInterface
{
const SANDBOX_ENVIRONMENT = 'sandbox';
const PRODUCTION_ENVIRONMENT = 'production';
const SANDBOX_HOST = 'https://sandbox.przelewy24.pl/';
const PRODUCTION_HOST = 'https://secure.przelewy24.pl/';
const P24_API_VERSION = '3.2';
const COMPLETED_STATUS = 'completed';
const FAILED_STATUS = 'failed';
const CANCELLED_STATUS = 'cancelled';
const CREATED_STATUS = 'created';
public const SANDBOX_ENVIRONMENT = 'sandbox';
public const PRODUCTION_ENVIRONMENT = 'production';
public const SANDBOX_HOST = 'https://sandbox.przelewy24.pl/';
public const PRODUCTION_HOST = 'https://secure.przelewy24.pl/';
public const P24_API_VERSION = '3.2';
public const COMPLETED_STATUS = 'completed';
public const FAILED_STATUS = 'failed';
public const CANCELLED_STATUS = 'cancelled';
public const CREATED_STATUS = 'created';

public function getTrnRegisterUrl(): string;

Expand Down
Empty file modified tests/Application/Kernel.php
100755 → 100644
Empty file.
Empty file modified tests/Application/composer.json
100755 → 100644
Empty file.
Empty file modified tests/Application/config/bootstrap.php
100755 → 100644
Empty file.
Empty file modified tests/Application/config/bundles.php
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/_sylius.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/dev/framework.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/dev/jms_serializer.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/dev/monolog.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/dev/routing.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/dev/swiftmailer.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/dev/web_profiler.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/doctrine.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/doctrine_migrations.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/fos_rest.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/framework.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/jms_serializer.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/liip_imagine.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/prod/doctrine.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/prod/jms_serializer.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/prod/monolog.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/routing.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/security.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/security_checker.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/sonata_core.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/staging/monolog.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/staging/swiftmailer.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/stof_doctrine_extensions.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/swiftmailer.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/test/framework.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/test/monolog.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/test/swiftmailer.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/test/sylius_theme.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/test/web_profiler.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/test_cached/doctrine.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/test_cached/fos_rest.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/test_cached/framework.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/test_cached/monolog.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/test_cached/swiftmailer.yaml
100755 → 100644
Empty file.
Empty file.
Empty file modified tests/Application/config/packages/test_cached/sylius_theme.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/test_cached/twig.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/translation.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/twig.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/twig_extensions.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/packages/validator.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/routes.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/routes/dev/twig.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/routes/dev/web_profiler.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/routes/liip_imagine.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/routes/sylius_admin.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/routes/sylius_admin_api.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/routes/sylius_shop.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/services.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/config/services_test.yaml
100755 → 100644
Empty file.
Empty file modified tests/Application/gulpfile.babel.js
100755 → 100644
Empty file.
Empty file modified tests/Application/package.json
100755 → 100644
Empty file.
Empty file modified tests/Application/public/.htaccess
100755 → 100644
Empty file.
Empty file modified tests/Application/public/favicon.ico
100755 → 100644
Empty file.
Empty file modified tests/Application/public/index.php
100755 → 100644
Empty file.
Empty file modified tests/Application/public/media/image/.gitignore
100755 → 100644
Empty file.
Empty file modified tests/Application/public/robots.txt
100755 → 100644
Empty file.
Loading

0 comments on commit 55e6d97

Please sign in to comment.