From 4a9b160957adde6cd450697f5ff8f3e3c9b53afa Mon Sep 17 00:00:00 2001 From: dpfaffenbauer Date: Mon, 21 Aug 2017 15:39:48 +0200 Subject: [PATCH 1/5] remove deprecated Direct/Offsite Gateway Factory --- src/OmnipayDirectGatewayFactory.php | 19 --- src/OmnipayOffsiteGatewayFactory.php | 19 --- tests/OmnipayDirectGatewayFactoryTest.php | 130 --------------------- tests/OmnipayOffsiteGatewayFactoryTest.php | 129 -------------------- 4 files changed, 297 deletions(-) delete mode 100644 src/OmnipayDirectGatewayFactory.php delete mode 100644 src/OmnipayOffsiteGatewayFactory.php delete mode 100644 tests/OmnipayDirectGatewayFactoryTest.php delete mode 100644 tests/OmnipayOffsiteGatewayFactoryTest.php diff --git a/src/OmnipayDirectGatewayFactory.php b/src/OmnipayDirectGatewayFactory.php deleted file mode 100644 index 42c3644..0000000 --- a/src/OmnipayDirectGatewayFactory.php +++ /dev/null @@ -1,19 +0,0 @@ -assertTrue($rc->implementsInterface(GatewayFactoryInterface::class)); - } - - /** - * @test - */ - public function couldBeConstructedWithoutAnyArguments() - { - new OmnipayDirectGatewayFactory(); - } - - /** - * @test - */ - public function shouldAllowCreateGateway() - { - $factory = new OmnipayDirectGatewayFactory(); - - $gateway = $factory->create(array('type' => 'Dummy', 'options' => array( - 'testMode' => true, - ))); - - $this->assertInstanceOf(Gateway::class, $gateway); - - $this->assertAttributeNotEmpty('apis', $gateway); - $this->assertAttributeNotEmpty('actions', $gateway); - - $extensions = $this->readAttribute($gateway, 'extensions'); - $this->assertAttributeNotEmpty('extensions', $extensions); - } - - /** - * @test - */ - public function shouldAllowCreateGatewayWithCustomGateway() - { - $factory = new OmnipayDirectGatewayFactory(); - - $gateway = $factory->create(array( - 'payum.api' => $this->createGatewayMock(), - )); - - $this->assertInstanceOf('Payum\Core\Gateway', $gateway); - - $this->assertAttributeNotEmpty('apis', $gateway); - $this->assertAttributeNotEmpty('actions', $gateway); - - $extensions = $this->readAttribute($gateway, 'extensions'); - $this->assertAttributeNotEmpty('extensions', $extensions); - } - - /** - * @test - */ - public function shouldAllowCreateGatewayConfig() - { - $factory = new OmnipayDirectGatewayFactory(); - - $config = $factory->createConfig(['type' => 'Dummy']); - - $this->assertInternalType('array', $config); - $this->assertNotEmpty($config); - } - - /** - * @test - */ - public function shouldContainCaptureActionAndMissCaptureOffsiteAction() - { - $factory = new OmnipayDirectGatewayFactory(); - - $config = $factory->createConfig(['type' => 'Dummy']); - - $this->assertInternalType('array', $config); - - $this->assertArrayHasKey('payum.action.capture', $config); - $this->assertArrayNotHasKey('payum.action.capture_offsite', $config); - } - - /** - * @test - * - * @expectedException \Payum\Core\Exception\LogicException - * @expectedExceptionMessage The type fields are required. - */ - public function shouldThrowIfRequiredOptionsNotPassed() - { - $factory = new OmnipayDirectGatewayFactory(); - - $factory->create(); - } - - /** - * @test - * - * @expectedException \Payum\Core\Exception\LogicException - * @expectedExceptionMessage Given omnipay gateway type Invalid or class is not supported. Supported: - */ - public function shouldThrowIfTypeNotValid() - { - $factory = new OmnipayDirectGatewayFactory(); - - $factory->create(array('type' => 'Invalid')); - } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject|GatewayInterface - */ - protected function createGatewayMock() - { - return $this->getMock('Omnipay\Common\GatewayInterface'); - } -} \ No newline at end of file diff --git a/tests/OmnipayOffsiteGatewayFactoryTest.php b/tests/OmnipayOffsiteGatewayFactoryTest.php deleted file mode 100644 index e252c4f..0000000 --- a/tests/OmnipayOffsiteGatewayFactoryTest.php +++ /dev/null @@ -1,129 +0,0 @@ -assertTrue($rc->implementsInterface(GatewayFactoryInterface::class)); - } - - /** - * @test - */ - public function couldBeConstructedWithoutAnyArguments() - { - new OmnipayOffsiteGatewayFactory(); - } - - /** - * @test - */ - public function shouldAllowCreateGateway() - { - $factory = new OmnipayOffsiteGatewayFactory(); - - $gateway = $factory->create(array('type' => 'Dummy', 'options' => array( - 'testMode' => true, - ))); - - $this->assertInstanceOf('Payum\Core\Gateway', $gateway); - - $this->assertAttributeNotEmpty('apis', $gateway); - $this->assertAttributeNotEmpty('actions', $gateway); - - $extensions = $this->readAttribute($gateway, 'extensions'); - $this->assertAttributeNotEmpty('extensions', $extensions); - } - - /** - * @test - */ - public function shouldAllowCreateGatewayWithCustomGateway() - { - $factory = new OmnipayOffsiteGatewayFactory(); - - $gateway = $factory->create(array( - 'payum.api' => $this->createGatewayMock(), - )); - - $this->assertInstanceOf('Payum\Core\Gateway', $gateway); - - $this->assertAttributeNotEmpty('apis', $gateway); - $this->assertAttributeNotEmpty('actions', $gateway); - - $extensions = $this->readAttribute($gateway, 'extensions'); - $this->assertAttributeNotEmpty('extensions', $extensions); - } - - /** - * @test - * - * @expectedException \Payum\Core\Exception\LogicException - * @expectedExceptionMessage The type fields are required. - */ - public function shouldThrowIfRequiredOptionsNotPassed() - { - $factory = new OmnipayOffsiteGatewayFactory(); - - $factory->create(); - } - - /** - * @test - */ - public function shouldAllowCreateGatewayConfig() - { - $factory = new OmnipayOffsiteGatewayFactory(); - - $config = $factory->createConfig(); - - $this->assertInternalType('array', $config); - $this->assertNotEmpty($config); - } - - /** - * @test - */ - public function shouldContainCaptureOffsiteActionAndMissCaptureAction() - { - $factory = new OmnipayOffsiteGatewayFactory(); - - $config = $factory->createConfig(['type' => 'Dummy']); - - $this->assertInternalType('array', $config); - - $this->assertArrayHasKey('payum.action.capture_offsite', $config); - $this->assertArrayNotHasKey('payum.action.capture', $config); - } - - /** - * @test - * - * @expectedException \Payum\Core\Exception\LogicException - * @expectedExceptionMessage Given omnipay gateway type Invalid or class is not supported. Supported: - */ - public function shouldThrowIfTypeNotValid() - { - $factory = new OmnipayOffsiteGatewayFactory(); - - $factory->create(array('type' => 'Invalid')); - } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject|OmnipayGatewayInterface - */ - protected function createGatewayMock() - { - return $this->getMock(OmnipayGatewayInterface::class); - } -} \ No newline at end of file From 8e7c59912de73b19a70c7f913756b9995363294a Mon Sep 17 00:00:00 2001 From: dpfaffenbauer Date: Mon, 21 Aug 2017 16:59:39 +0200 Subject: [PATCH 2/5] Fixes and changes for omnipay/common:^3.0 --- composer.json | 13 +++++++----- src/OmnipayGatewayFactory.php | 18 +++-------------- src/Resources/docs/get-it-started.md | 6 ++++-- .../docs/why-should-you-use-this-bridge.md | 2 +- tests/Functional/PaymentTest.php | 8 ++++---- tests/OmnipayGatewayFactoryTest.php | 20 +------------------ 6 files changed, 21 insertions(+), 46 deletions(-) mode change 100644 => 100755 composer.json mode change 100644 => 100755 src/OmnipayGatewayFactory.php mode change 100644 => 100755 src/Resources/docs/get-it-started.md mode change 100644 => 100755 src/Resources/docs/why-should-you-use-this-bridge.md diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 index 18a1192..5134076 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "payum/omnipay-bridge", "type": "library", - "description": "This bridge allows you to use omnipay gateways but in payum like way.", + "description": "This bridge allows you to use omnipay gateways but in payum like way.", "keywords": ["payment", "omnipay"], "homepage": "https://github.com/Payum/OmnipayBridge", "license": "MIT", @@ -22,11 +22,12 @@ "require": { "php": ">=5.5.0", "payum/core": "^1.3", - "omnipay/common": "^2.3" + "omnipay/common": "^3.0", + "php-http/guzzle6-adapter": "^1.1" }, "require-dev": { "phpunit/phpunit": "^4", - "omnipay/dummy": "^2" + "omnipay/dummy": "^3.0" }, "config": { "bin-dir": "bin" @@ -39,7 +40,9 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "2.0-dev" } - } + }, + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/src/OmnipayGatewayFactory.php b/src/OmnipayGatewayFactory.php old mode 100644 new mode 100755 index f7dcdf9..a987352 --- a/src/OmnipayGatewayFactory.php +++ b/src/OmnipayGatewayFactory.php @@ -17,11 +17,6 @@ class OmnipayGatewayFactory extends GatewayFactory { - /** - * @var string - */ - private $omnipayGatewayTypeOrClass; - /** * @var OmnipayOmnipayGatewayFactory|null */ @@ -30,14 +25,12 @@ class OmnipayGatewayFactory extends GatewayFactory /** * {@inheritDoc} * - * @param string $omnipayGatewayTypeOrClass * @param OmnipayOmnipayGatewayFactory|null $omnipayGatewayFactory */ - public function __construct($omnipayGatewayTypeOrClass = null, OmnipayOmnipayGatewayFactory $omnipayGatewayFactory = null, array $defaultConfig = array(), GatewayFactoryInterface $coreGatewayFactory = null) + public function __construct(OmnipayOmnipayGatewayFactory $omnipayGatewayFactory = null, array $defaultConfig = array(), GatewayFactoryInterface $coreGatewayFactory = null) { parent::__construct($defaultConfig, $coreGatewayFactory); - $this->omnipayGatewayTypeOrClass = $omnipayGatewayTypeOrClass; $this->omnipayGatewayFactory = $omnipayGatewayFactory ?: Omnipay::getFactory(); } @@ -60,10 +53,6 @@ protected function populateConfig(ArrayObject $config) $config->defaults($config['options']); } - $config->defaults([ - 'type' => $this->omnipayGatewayTypeOrClass, - ]); - // omnipay does not provide required options. $config['payum.required_options'] = ['type']; @@ -74,9 +63,8 @@ protected function populateConfig(ArrayObject $config) $gateway = $this->omnipayGatewayFactory->create($config['type']); } catch (OmnipayException $e) { throw new LogicException(sprintf( - 'Given omnipay gateway type %s or class is not supported. Supported: %s', - $config['type'], - implode(', ', $this->omnipayGatewayFactory->getSupportedGateways()) + 'Given omnipay gateway type %s or class is not supported.', + $config['type'] ), 0, $e); } diff --git a/src/Resources/docs/get-it-started.md b/src/Resources/docs/get-it-started.md old mode 100644 new mode 100755 index 6dd6d16..dbe3f52 --- a/src/Resources/docs/get-it-started.md +++ b/src/Resources/docs/get-it-started.md @@ -33,7 +33,8 @@ $payum = (new PayumBuilder()) // direct payment like Stripe or Authorize.Net ->addGateway('gatewayName', [ - 'factory' => 'omnipay_stripe', + 'factory' => 'omnipay', + 'type' => 'stripe', 'username' => 'REPLACE IT', 'password' => 'REPLACE IT', 'signature' => 'REPLACE IT', @@ -43,7 +44,8 @@ $payum = (new PayumBuilder()) // or offsite payment like Paypal ExpressCheckout ->addGateway('gatewayName', [ - 'factory' => 'omnipay_paypal_express', + 'factory' => 'omnipay', + 'type' => 'paypal_express' 'username' => 'REPLACE IT', 'password' => 'REPLACE IT', 'signature' => 'REPLACE IT', diff --git a/src/Resources/docs/why-should-you-use-this-bridge.md b/src/Resources/docs/why-should-you-use-this-bridge.md old mode 100644 new mode 100755 index 8565a6f..fb4f8b5 --- a/src/Resources/docs/why-should-you-use-this-bridge.md +++ b/src/Resources/docs/why-should-you-use-this-bridge.md @@ -35,7 +35,7 @@ use Payum\Core\Model\ArrayObject; $payum = (new PayumBuilder()) ->addDefaultStorages() - ->addGateway('stripe', ['factory' => 'omnipay_stripe', 'apiKey' => 'abc123']) + ->addGateway('stripe', ['factory' => 'omnipay', 'type' => 'stripe', 'apiKey' => 'abc123']) ->getPayum() ; diff --git a/tests/Functional/PaymentTest.php b/tests/Functional/PaymentTest.php index 6289528..a1a5f36 100644 --- a/tests/Functional/PaymentTest.php +++ b/tests/Functional/PaymentTest.php @@ -13,9 +13,9 @@ class PaymentTest extends \PHPUnit_Framework_TestCase */ public function shouldFinishSuccessfully() { - $factory = new OmnipayGatewayFactory('Dummy'); + $factory = new OmnipayGatewayFactory(); - $gateway = $factory->create([]); + $gateway = $factory->create(['type' => 'Dummy']); $date = new \DateTime('now + 2 year'); @@ -44,9 +44,9 @@ public function shouldFinishSuccessfully() */ public function shouldFinishWithFailed() { - $factory = new OmnipayGatewayFactory('Dummy'); + $factory = new OmnipayGatewayFactory(); - $gateway = $factory->create([]); + $gateway = $factory->create(['type' => 'Dummy']); $date = new \DateTime('now + 2 year'); diff --git a/tests/OmnipayGatewayFactoryTest.php b/tests/OmnipayGatewayFactoryTest.php index 880f3fb..275d8a7 100644 --- a/tests/OmnipayGatewayFactoryTest.php +++ b/tests/OmnipayGatewayFactoryTest.php @@ -26,24 +26,6 @@ public function couldBeConstructedWithoutAnyArguments() new OmnipayGatewayFactory(); } - /** - * @test - */ - public function shouldAllowCreateGatewayWithTypeGivenInConstructor() - { - $factory = new OmnipayGatewayFactory('Dummy'); - - $gateway = $factory->create([]); - - $this->assertInstanceOf(Gateway::class, $gateway); - - $this->assertAttributeNotEmpty('apis', $gateway); - $this->assertAttributeNotEmpty('actions', $gateway); - - $extensions = $this->readAttribute($gateway, 'extensions'); - $this->assertAttributeNotEmpty('extensions', $extensions); - } - /** * @test */ @@ -112,7 +94,7 @@ public function shouldAllowCreateGatewayConfig() * @test * * @expectedException \Payum\Core\Exception\LogicException - * @expectedExceptionMessage Given omnipay gateway type Invalid or class is not supported. Supported: + * @expectedExceptionMessage Given omnipay gateway type Invalid or class is not supported. */ public function shouldThrowIfTypeNotValid() { From b766d127f6d0210230113b32d8584ea29a901735 Mon Sep 17 00:00:00 2001 From: dpfaffenbauer Date: Fri, 1 Sep 2017 08:32:01 +0100 Subject: [PATCH 3/5] drop travis suport for 5.5 and add 7.0, 7.1 --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 658be0a..54436ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,9 @@ language: php php: - - 5.5 - 5.6 + - 7.0 + - 7.1 - hhvm - nightly From 20829cf6f9032e4df388af34c660b5d319509371 Mon Sep 17 00:00:00 2001 From: dpfaffenbauer Date: Fri, 1 Sep 2017 08:47:18 +0100 Subject: [PATCH 4/5] rename namespace from OmnipayBridge to OmnipayV3Bridge --- composer.json | 10 +++++----- src/Action/BaseApiAwareAction.php | 2 +- src/Action/CaptureAction.php | 2 +- src/Action/ConvertPaymentAction.php | 2 +- src/Action/NotifyAction.php | 2 +- src/Action/OffsiteCaptureAction.php | 2 +- src/Action/StatusAction.php | 2 +- src/OmnipayGatewayFactory.php | 12 ++++++------ tests/Action/BaseApiAwareActionTest.php | 12 ++++++------ tests/Action/CaptureActionTest.php | 10 +++++----- tests/Action/ConvertPaymentActionTest.php | 6 +++--- tests/Action/NotifyActionTest.php | 6 +++--- tests/Action/OffsiteCaptureActionTest.php | 10 +++++----- tests/Action/StatusActionTest.php | 6 +++--- tests/CreditCardGateway.php | 2 +- tests/Functional/PaymentTest.php | 5 ++--- tests/OffsiteGateway.php | 2 +- tests/OmnipayGatewayFactoryTest.php | 4 ++-- tests/bootstrap.php | 2 +- 19 files changed, 49 insertions(+), 50 deletions(-) diff --git a/composer.json b/composer.json index 5134076..c48c85c 100755 --- a/composer.json +++ b/composer.json @@ -1,9 +1,9 @@ { - "name": "payum/omnipay-bridge", + "name": "payum/omnipay-v3-bridge", "type": "library", "description": "This bridge allows you to use omnipay gateways but in payum like way.", "keywords": ["payment", "omnipay"], - "homepage": "https://github.com/Payum/OmnipayBridge", + "homepage": "https://github.com/Payum/OmnipayV3Bridge", "license": "MIT", "authors": [ { @@ -33,14 +33,14 @@ "bin-dir": "bin" }, "autoload": { - "psr-4": { "Payum\\OmnipayBridge\\": "src" } + "psr-4": { "Payum\\OmnipayV3Bridge\\": "src" } }, "autoload-dev": { - "psr-4": { "Payum\\OmnipayBridge\\Tests\\": "tests" } + "psr-4": { "Payum\\OmnipayV3Bridge\\Tests\\": "tests" } }, "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "1.0-dev" } }, "minimum-stability": "dev", diff --git a/src/Action/BaseApiAwareAction.php b/src/Action/BaseApiAwareAction.php index 23e5852..b53915e 100644 --- a/src/Action/BaseApiAwareAction.php +++ b/src/Action/BaseApiAwareAction.php @@ -1,5 +1,5 @@ assertTrue($rc->isSubclassOf('Payum\Core\Action\ActionInterface')); } @@ -18,7 +18,7 @@ public function shouldImplementActionInterface() */ public function shouldImplementApiAwareInterface() { - $rc = new \ReflectionClass('Payum\OmnipayBridge\Action\BaseApiAwareAction'); + $rc = new \ReflectionClass('Payum\OmnipayV3Bridge\Action\BaseApiAwareAction'); $this->assertTrue($rc->isSubclassOf('Payum\Core\ApiAwareInterface')); } @@ -28,7 +28,7 @@ public function shouldImplementApiAwareInterface() */ public function shouldBeAbstract() { - $rc = new \ReflectionClass('Payum\OmnipayBridge\Action\BaseApiAwareAction'); + $rc = new \ReflectionClass('Payum\OmnipayV3Bridge\Action\BaseApiAwareAction'); $this->assertTrue($rc->isAbstract()); } @@ -40,7 +40,7 @@ public function shouldAllowSetApi() { $expectedApi = $this->createGatewayMock(); - $action = $this->getMockForAbstractClass('Payum\OmnipayBridge\Action\BaseApiAwareAction'); + $action = $this->getMockForAbstractClass('Payum\OmnipayV3Bridge\Action\BaseApiAwareAction'); $action->setApi($expectedApi); @@ -54,7 +54,7 @@ public function shouldAllowSetApi() */ public function throwIfUnsupportedApiGiven() { - $action = $this->getMockForAbstractClass('Payum\OmnipayBridge\Action\BaseApiAwareAction'); + $action = $this->getMockForAbstractClass('Payum\OmnipayV3Bridge\Action\BaseApiAwareAction'); $action->setApi(new \stdClass); } diff --git a/tests/Action/CaptureActionTest.php b/tests/Action/CaptureActionTest.php index b8f0059..5fb04c1 100644 --- a/tests/Action/CaptureActionTest.php +++ b/tests/Action/CaptureActionTest.php @@ -1,5 +1,5 @@ diff --git a/tests/Action/OffsiteCaptureActionTest.php b/tests/Action/OffsiteCaptureActionTest.php index dce3df0..01a44ee 100644 --- a/tests/Action/OffsiteCaptureActionTest.php +++ b/tests/Action/OffsiteCaptureActionTest.php @@ -1,5 +1,5 @@ getFileName()).'/Tests'; $loader->add('Payum\Core\Tests', $coreDir); -$loader->add('Payum\OmnipayBridge\Tests', __DIR__); \ No newline at end of file +$loader->add('Payum\OmnipayV3Bridge\Tests', __DIR__); \ No newline at end of file From 33934fa9484521e9bda14f271bc3c4f7d699f385 Mon Sep 17 00:00:00 2001 From: dpfaffenbauer Date: Fri, 1 Sep 2017 08:59:12 +0100 Subject: [PATCH 5/5] use omnipay alpha version constraint --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index c48c85c..5ec447a 100755 --- a/composer.json +++ b/composer.json @@ -22,12 +22,12 @@ "require": { "php": ">=5.5.0", "payum/core": "^1.3", - "omnipay/common": "^3.0", + "omnipay/common": "^3.0@alpha", "php-http/guzzle6-adapter": "^1.1" }, "require-dev": { "phpunit/phpunit": "^4", - "omnipay/dummy": "^3.0" + "omnipay/dummy": "^3.0@alpha" }, "config": { "bin-dir": "bin"