diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7d8c231..b4b7c2f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,11 +19,14 @@ jobs: strategy: fail-fast: false matrix: - php: [7.1, 7.2, 7.3, 7.4] - symfony: [^3.4, ^4.4, ^5.2] + php: [7.1, 7.2, 7.3, 7.4, 8.0] + symfony: [^3.4, ^4.4, ^5.2, ^6.0] exclude: - - php: 7.1 - symfony: ^5.2 + - { php: 7.1, symfony: ^5.2 } + - { php: 7.1, symfony: ^6.0 } + - { php: 7.2, symfony: ^6.0 } + - { php: 7.3, symfony: ^6.0 } + - { php: 7.4, symfony: ^6.0 } env: APP_ENV: test diff --git a/README.md b/README.md index fb2d781..c658b51 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ PayumPayzen =========== -PayZen Payum Gateway (Systempay, Scellius) +PayZen Payum Gateway (Systempay, Scellius, CLIC&PAY, OSB, SOGE_COMMERCE) [](https://github.com/ekyna/PayumPayzen/actions/workflows/build.yml) @@ -21,7 +21,10 @@ $gateway = $factory->create([ 'site_id' => '132456', 'certificate' => '132456', 'ctx_mode' => Api::MODE_PRODUCTION, + 'hash_mode' => Api::HASH_MODE_SHA256, 'directory' => __DIR__ . '/payzen-cache', + 'endpoint' => Api::ENDPOINT_SYSTEMPAY, // default value, see `Api::ENDPOINT_*` constants for more + 'endpoint_url' => // null default value, add custom endpoint not in `Api::ENDPOINT_*` constants ]); // Register your convert payment action diff --git a/composer.json b/composer.json index 9755cb0..8b3a90b 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "authors": [ { "name": "Etienne Dauvergne", - "homepage": "http://ekyna.com" + "homepage": "https://ekyna.com" } ], "keywords": [ @@ -20,15 +20,15 @@ "MIT" ], "require": { - "php": "^7.1", + "php": "^7.1|^8.0", "payum/core": "^1.5", - "php-http/guzzle6-adapter": "^1.1", - "symfony/options-resolver": "^3.0|^4.0|^5.0", - "symfony/process": "^3.0|^4.0|^5.0", - "psr/log": "^1.0" + "symfony/options-resolver": ">3.4,<7.0", + "symfony/process": ">3.4,<7.0", + "psr/log": "^1.0|^2.0" }, "require-dev": { - "phpunit/phpunit": "^7.0|^8.0" + "phpunit/phpunit": "^7.0|^8.0", + "php-http/guzzle6-adapter": "^2.0" }, "autoload": { "psr-4": { diff --git a/src/Api/Api.php b/src/Api/Api.php index 8b91f74..4e01666 100644 --- a/src/Api/Api.php +++ b/src/Api/Api.php @@ -21,7 +21,10 @@ class Api const HASH_MODE_SHA256 = 'SHA256'; const ENDPOINT_SYSTEMPAY = 'SYSTEMPAY'; + const ENDPOINT_SOGECOMMERCE = 'SOGECOMMERCE'; const ENDPOINT_SCELLIUS = 'SCELLIUS'; + const ENDPOINT_CLICANDPAY = 'CLICANDPAY'; + const ENDPOINT_OSB = 'OSB'; /** * @var OptionsResolver @@ -204,6 +207,7 @@ private function getDirectoryPath(): string { $path = $this->config['directory']; + // Create directory if not exists if (!is_dir($path)) { if (!mkdir($path, 0755, true)) { @@ -247,6 +251,7 @@ private function getConfigResolver(): OptionsResolver ]) ->setDefaults([ 'endpoint' => null, + 'endpoint_url' => null, 'hash_mode' => self::HASH_MODE_SHA256, 'debug' => false, ]) @@ -254,6 +259,7 @@ private function getConfigResolver(): OptionsResolver ->setAllowedTypes('certificate', 'string') ->setAllowedValues('ctx_mode', $this->getModes()) ->setAllowedTypes('directory', 'string') + ->setAllowedTypes('endpoint_url', ['null', 'string']) ->setAllowedValues('endpoint', $this->getEndPoints()) ->setAllowedValues('hash_mode', $this->getHashModes()) ->setAllowedTypes('debug', 'bool') @@ -466,7 +472,7 @@ private function getModes(): array private function getEndPoints(): array { - return [null, self::ENDPOINT_SYSTEMPAY, self::ENDPOINT_SCELLIUS]; + return [null, self::ENDPOINT_SYSTEMPAY, self::ENDPOINT_SOGECOMMERCE, self::ENDPOINT_SCELLIUS, self::ENDPOINT_CLICANDPAY, self::ENDPOINT_OSB]; } private function getHashModes(): array @@ -476,6 +482,9 @@ private function getHashModes(): array private function getUrl(): string { + if ($this->config['endpoint_url'] !== null) { + return $this->config['endpoint_url']; + } if (self::ENDPOINT_SYSTEMPAY === $this->config['endpoint']) { return 'https://paiement.systempay.fr/vads-payment/'; } @@ -484,6 +493,17 @@ private function getUrl(): string return 'https://scelliuspaiement.labanquepostale.fr/vads-payment/'; } + if (self::ENDPOINT_CLICANDPAY === $this->config['endpoint']) { + return 'https://clicandpay.groupecdn.fr/vads-payment/'; + } + + if (self::ENDPOINT_OSB === $this->config['endpoint']) { + return 'https://secure.osb.pf/vads-payment/'; + } + if (self::ENDPOINT_SOGECOMMERCE === $this->config['endpoint']) { + return 'https://sogecommerce.societegenerale.eu/vads-payment/'; + } + return 'https://secure.payzen.eu/vads-payment/'; } diff --git a/src/PayzenGatewayFactory.php b/src/PayzenGatewayFactory.php index b06f2a0..534cb0e 100644 --- a/src/PayzenGatewayFactory.php +++ b/src/PayzenGatewayFactory.php @@ -16,7 +16,7 @@ class PayzenGatewayFactory extends GatewayFactory /** * Builds a new factory. * - * @param array $defaultConfig + * @param array $defaultConfig * @param GatewayFactoryInterface|null $coreGatewayFactory * * @return PayzenGatewayFactory @@ -48,12 +48,14 @@ protected function populateConfig(ArrayObject $config) if (false == $config['payum.api']) { $config['payum.default_options'] = [ - 'site_id' => null, - 'certificate' => null, - 'ctx_mode' => null, - 'directory' => null, - 'endpoint' => null, - 'debug' => false, + 'site_id' => null, + 'certificate' => null, + 'ctx_mode' => null, + 'directory' => null, + 'endpoint' => null, + 'endpoint_url' => null, + 'hash_mode' => Api\Api::HASH_MODE_SHA256, + 'debug' => false, ]; $config->defaults($config['payum.default_options']); @@ -64,12 +66,14 @@ protected function populateConfig(ArrayObject $config) $config->validateNotEmpty($config['payum.required_options']); $payzenConfig = [ - 'endpoint' => $config['endpoint'], - 'site_id' => $config['site_id'], - 'certificate' => $config['certificate'], - 'ctx_mode' => $config['ctx_mode'], - 'directory' => $config['directory'], - 'debug' => $config['debug'], + 'endpoint' => $config['endpoint'], + 'endpoint_url' => $config['endpoint_url'], + 'site_id' => $config['site_id'], + 'certificate' => $config['certificate'], + 'ctx_mode' => $config['ctx_mode'], + 'directory' => $config['directory'], + 'hash_mode' => $config['hash_mode'], + 'debug' => $config['debug'], ]; $api = new Api\Api(); diff --git a/tests/Action/AbstractActionTest.php b/tests/Action/AbstractActionTest.php index 7f13f13..7d28f2d 100644 --- a/tests/Action/AbstractActionTest.php +++ b/tests/Action/AbstractActionTest.php @@ -16,16 +16,6 @@ */ abstract class AbstractActionTest extends GenericActionTest { - /** - * @test - */ - public function couldBeConstructedWithoutAnyArguments() - { - parent::couldBeConstructedWithoutAnyArguments(); - - $this->assertTrue(true); - } - /** * @return MockObject|GatewayInterface */ diff --git a/tests/Api/ApiTest.php b/tests/Api/ApiTest.php index c274a5d..6a9f01a 100644 --- a/tests/Api/ApiTest.php +++ b/tests/Api/ApiTest.php @@ -172,6 +172,20 @@ public function provideCreateRequestUrl(): Generator 'https://paiement.systempay.fr/vads-payment/?vads_action_mode=INTERACTIVE&vads_page_action=PAYMENT&vads_payment_config=SINGLE&vads_return_mode=POST&vads_version=V2&vads_amount=1234&vads_currency=978&vads_trans_date=20200101120000&vads_trans_id=000001&vads_site_id=123456789&vads_ctx_mode=PRODUCTION&signature=p9TbeohlOZVPAmhEwfAlGxRJxFAKpNg5wYBSN9emuqs%3D', ]; + yield [ + [ + 'endpoint_url' => 'https://custom-url.fr/vads-payment/', + ], + [ + 'vads_amount' => '1234', + 'vads_currency' => '978', + 'vads_trans_date' => '20200101120000', + 'vads_trans_id' => '000001', + ], + 'https://custom-url.fr/vads-payment/?vads_action_mode=INTERACTIVE&vads_page_action=PAYMENT&vads_payment_config=SINGLE&vads_return_mode=POST&vads_version=V2&vads_amount=1234&vads_currency=978&vads_trans_date=20200101120000&vads_trans_id=000001&vads_site_id=123456789&vads_ctx_mode=PRODUCTION&signature=p9TbeohlOZVPAmhEwfAlGxRJxFAKpNg5wYBSN9emuqs%3D', + ]; + + yield [ [ 'endpoint' => Api::ENDPOINT_SCELLIUS, @@ -184,6 +198,32 @@ public function provideCreateRequestUrl(): Generator ], 'https://scelliuspaiement.labanquepostale.fr/vads-payment/?vads_action_mode=INTERACTIVE&vads_page_action=PAYMENT&vads_payment_config=SINGLE&vads_return_mode=POST&vads_version=V2&vads_amount=1234&vads_currency=978&vads_trans_date=20200101120000&vads_trans_id=000001&vads_site_id=123456789&vads_ctx_mode=PRODUCTION&signature=p9TbeohlOZVPAmhEwfAlGxRJxFAKpNg5wYBSN9emuqs%3D', ]; + + yield [ + [ + 'endpoint' => Api::ENDPOINT_OSB, + ], + [ + 'vads_amount' => '1234', + 'vads_currency' => '978', + 'vads_trans_date' => '20200101120000', + 'vads_trans_id' => '000001', + ], + 'https://secure.osb.pf/vads-payment/?vads_action_mode=INTERACTIVE&vads_page_action=PAYMENT&vads_payment_config=SINGLE&vads_return_mode=POST&vads_version=V2&vads_amount=1234&vads_currency=978&vads_trans_date=20200101120000&vads_trans_id=000001&vads_site_id=123456789&vads_ctx_mode=PRODUCTION&signature=p9TbeohlOZVPAmhEwfAlGxRJxFAKpNg5wYBSN9emuqs%3D', + ]; + + yield [ + [ + 'endpoint' => Api::ENDPOINT_SOGECOMMERCE, + ], + [ + 'vads_amount' => '1234', + 'vads_currency' => '978', + 'vads_trans_date' => '20200101120000', + 'vads_trans_id' => '000001', + ], + 'https://sogecommerce.societegenerale.eu/vads-payment/?vads_action_mode=INTERACTIVE&vads_page_action=PAYMENT&vads_payment_config=SINGLE&vads_return_mode=POST&vads_version=V2&vads_amount=1234&vads_currency=978&vads_trans_date=20200101120000&vads_trans_id=000001&vads_site_id=123456789&vads_ctx_mode=PRODUCTION&signature=p9TbeohlOZVPAmhEwfAlGxRJxFAKpNg5wYBSN9emuqs%3D', + ]; } /**