Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PaymentTokenFactory interface to have the "Interface" at the end of the name. #9306

Merged
merged 23 commits into from
Jun 15, 2017
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c35f3b8
Fixed coding standard violation for an interface which was not ending…
dverkade Apr 19, 2017
d2ea4c1
Added the old interface name with a @deprecated message, which extend…
dverkade Apr 19, 2017
71468a3
- Added @codingStandardsIgnoreFile to the old interface file
dverkade Apr 19, 2017
1ec515c
- Added @codingStandardsIgnoreFile to the old interface file
dverkade Apr 19, 2017
4f55988
Added new PaymentTokenFactory logic
dverkade May 13, 2017
dfe690c
- Reverted PaymentTokenInterfaceFactory to original class.
dverkade May 13, 2017
f0711c2
Changed to use the correct namespace for the PaymentTokenInterfaceaFa…
dverkade May 13, 2017
84e668a
- Reverted changes in other modules so it will use the old PaymentTok…
dverkade May 13, 2017
716b7f8
Added constructor to the PaymentToken class to set the type.
dverkade May 13, 2017
e3f2800
Fixed code review items.
dverkade May 13, 2017
0760010
Fixed coding standards for PaymentToken class
dverkade May 13, 2017
f1c42fd
Added using the PaymentTokenFactoryInterface
dverkade May 13, 2017
3ef7f92
Added checking token types to the factory. Will throw a error when th…
dverkade May 13, 2017
94fc33e
Changed constructor
dverkade May 13, 2017
c036be8
Changed constructor
dverkade May 13, 2017
7f4dbe0
Changed variable to correct one in PaymentTokenFactory
dverkade May 13, 2017
85a6c71
- Fixed Unit tests
dverkade May 13, 2017
bea1a3c
Fixed coding standard violations
dverkade May 13, 2017
e6dea5b
Added code to the PaymentTokenFactory class for backwards compatibili…
dverkade Jun 9, 2017
cdf43f3
When an array is supplied, should go straight to the objectmanager cr…
dverkade Jun 12, 2017
f5eaf7a
Fixed coding standard violation
dverkade Jun 12, 2017
57c8974
- Removed abstract method
dverkade Jun 14, 2017
eaf3b04
Added specific type hint for the tokenTypes parameter
dverkade Jun 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions app/code/Magento/Vault/Api/Data/PaymentTokenFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Vault\Api\Data;

/**
* Interface PaymentTokenFactoryInterface
* @api
*/
interface PaymentTokenFactoryInterface
{
/**
* Payment Token types
* @var string
*/
const TOKEN_TYPE_ACCOUNT = 'account';
const TOKEN_TYPE_CREDIT_CARD = 'card';

/**
* Create payment token entity
* @param $type string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please specify Null as a possible input value

* @return PaymentTokenInterface
*/
public function create($type = null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

/**
* Interface PaymentTokenInterfaceFactory
* @api
* @deprecated
* @see PaymentTokenFactoryInterface
*/
interface PaymentTokenInterfaceFactory
{
Expand Down
31 changes: 24 additions & 7 deletions app/code/Magento/Vault/Model/AbstractPaymentTokenFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
use Magento\Framework\ObjectManagerInterface;
use Magento\Vault\Api\Data\PaymentTokenInterface;
use Magento\Vault\Api\Data\PaymentTokenInterfaceFactory;
use Magento\Vault\Api\Data\PaymentTokenFactoryInterface;

/**
* Class AbstractPaymentTokenFactory
* @api
* @deprecated
* @see PaymentTokenFactoryInterface
*/
abstract class AbstractPaymentTokenFactory implements PaymentTokenInterfaceFactory
{
Expand All @@ -20,13 +22,26 @@ abstract class AbstractPaymentTokenFactory implements PaymentTokenInterfaceFacto
*/
private $objectManager;

/**
* @var PaymentTokenFactoryInterface
*/
private $paymentTokenFactory;

/**
* AccountPaymentTokenFactory constructor.
* @param ObjectManagerInterface $objectManager
* @param PaymentTokenFactoryInterface $paymentTokenFactory
*/
public function __construct(ObjectManagerInterface $objectManager)
{
public function __construct(
ObjectManagerInterface $objectManager,
PaymentTokenFactoryInterface $paymentTokenFactory = null
) {
if (!$paymentTokenFactory) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use === null instead

$paymentTokenFactory = $objectManager->get(PaymentTokenFactoryInterface::class);
}

$this->objectManager = $objectManager;
$this->paymentTokenFactory = $paymentTokenFactory;
}

/**
Expand All @@ -35,9 +50,11 @@ public function __construct(ObjectManagerInterface $objectManager)
*/
public function create()
{
/** @var PaymentTokenInterface $paymentToken */
$paymentToken = $this->objectManager->create(PaymentTokenInterface::class);
$paymentToken->setType($this->getType());
return $paymentToken;
return $this->paymentTokenFactory->create($this->getType());
}

/**
* @return string
*/
abstract public function getType();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to specify abstract public getType method here
we get it from PaymentTokenInterfaceFactory

interface PaymentTokenInterfaceFactory
{
    /**
     * Create payment token entity
     * @return PaymentTokenInterface
     */
    public function create();

    /**
     * Return type of payment token
     * @return string
     */
    public function getType();
}

}
3 changes: 2 additions & 1 deletion app/code/Magento/Vault/Model/AccountPaymentTokenFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

/**
* Class AccountPaymentTokenFactory
* @api
* @deprecated
* @see PaymentTokenFactoryInterface
*/
class AccountPaymentTokenFactory extends AbstractPaymentTokenFactory
{
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Vault/Model/CreditCardTokenFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

/**
* Class CreditCardTokenFactory
* @api
* @deprecated
* @see PaymentTokenFactoryInterface
*/
class CreditCardTokenFactory extends AbstractPaymentTokenFactory
{
Expand Down
62 changes: 62 additions & 0 deletions app/code/Magento/Vault/Model/PaymentTokenFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Vault\Model;

use Magento\Framework\ObjectManagerInterface;
use Magento\Vault\Api\Data\PaymentTokenFactoryInterface;
use Magento\Vault\Api\Data\PaymentTokenInterface;

/**
* PaymentTokenFactory class
* @api
*/
class PaymentTokenFactory implements PaymentTokenFactoryInterface
{
/**
* @var array
*/
private $tokenTypes = [];

/**
* PaymentTokenFactory constructor.
* @param ObjectManagerInterface $objectManager
* @param array $tokenTypes
*/
public function __construct(ObjectManagerInterface $objectManager, $tokenTypes = [])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please specify
array for $tokenTypes

Copy link
Member Author

@dverkade dverkade Jun 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what you mean here. array has been definied in the doc comments and is specified in the param as default value was well. What and how do you want it to be described?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean explicitly specify type hint for $tokenTypes
like
array $tokenTypes = []

{
$this->objectManager = $objectManager;
$this->tokenTypes = $tokenTypes;
}

/**
* Create payment token entity
* @param $type string
* @return PaymentTokenInterface
*/
public function create($type = null)
{
/**
* This code added for Backward Compatibility reasons only, as previous implementation of Code Generated factory
* accepted an array as any other code generated factory
*/
if (is_array($type)) {
return $this->objectManager->create(
PaymentTokenInterface::class,
$type
);
}

if ($type !== null && !in_array($type, $this->tokenTypes, true)) {
throw new \LogicException('There is no such payment token type: ' . $type);
}

return $this->objectManager->create(
PaymentTokenInterface::class,
['data' => [PaymentTokenInterface::TYPE => $type]]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Vault\Api\Data\PaymentTokenInterface;
use Magento\Vault\Model\PaymentTokenFactory;
use Magento\Vault\Model\AccountPaymentTokenFactory;
use Magento\Vault\Model\PaymentToken;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
Expand Down Expand Up @@ -36,10 +37,16 @@ protected function setUp()
{
$objectManager = new ObjectManager($this);

$this->paymentToken = $objectManager->getObject(PaymentToken::class);
$tokenTypes = [
'account' => \Magento\Vault\Api\Data\PaymentTokenFactoryInterface::TOKEN_TYPE_ACCOUNT,
'credit_card' => \Magento\Vault\Api\Data\PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD
];

$this->paymentToken = $objectManager->getObject(PaymentToken::class);
$this->objectManager = $this->getMock(ObjectManagerInterface::class);
$this->factory = new AccountPaymentTokenFactory($this->objectManager);

$this->paymentTokenFactory = new PaymentTokenFactory($this->objectManager, $tokenTypes);
$this->factory = new AccountPaymentTokenFactory($this->objectManager, $this->paymentTokenFactory);
}

/**
Expand All @@ -51,6 +58,8 @@ public function testCreate()
->method('create')
->willReturn($this->paymentToken);

$this->paymentToken->setType(\Magento\Vault\Api\Data\PaymentTokenFactoryInterface::TOKEN_TYPE_ACCOUNT);

/** @var PaymentTokenInterface $paymentToken */
$paymentToken = $this->factory->create();
static::assertInstanceOf(PaymentTokenInterface::class, $paymentToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Vault\Api\Data\PaymentTokenInterface;
use Magento\Vault\Model\PaymentTokenFactory;
use Magento\Vault\Model\CreditCardTokenFactory;
use Magento\Vault\Model\PaymentToken;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
Expand Down Expand Up @@ -36,10 +37,16 @@ protected function setUp()
{
$objectManager = new ObjectManager($this);

$this->paymentToken = $objectManager->getObject(PaymentToken::class);
$tokenTypes = [
'account' => \Magento\Vault\Api\Data\PaymentTokenFactoryInterface::TOKEN_TYPE_ACCOUNT,
'credit_card' => \Magento\Vault\Api\Data\PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD
];

$this->paymentToken = $objectManager->getObject(PaymentToken::class);
$this->objectManager = $this->getMock(ObjectManagerInterface::class);
$this->factory = new CreditCardTokenFactory($this->objectManager);

$this->paymentTokenFactory = new PaymentTokenFactory($this->objectManager, $tokenTypes);
$this->factory = new CreditCardTokenFactory($this->objectManager, $this->paymentTokenFactory);
}

/**
Expand All @@ -51,6 +58,8 @@ public function testCreate()
->method('create')
->willReturn($this->paymentToken);

$this->paymentToken->setType(\Magento\Vault\Api\Data\PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD);

/** @var PaymentTokenInterface $paymentToken */
$paymentToken = $this->factory->create();
static::assertInstanceOf(PaymentTokenInterface::class, $paymentToken);
Expand Down
10 changes: 10 additions & 0 deletions app/code/Magento/Vault/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Vault\Model\VaultPaymentInterface" type="Magento\Vault\Model\Method\Vault"/>
<preference for="Magento\Vault\Api\Data\PaymentTokenInterface" type="Magento\Vault\Model\PaymentToken"/>
<preference for="Magento\Vault\Api\Data\PaymentTokenFactoryInterface" type="Magento\Vault\Model\PaymentTokenFactory"/>
<preference for="Magento\Vault\Api\PaymentTokenRepositoryInterface" type="Magento\Vault\Model\PaymentTokenRepository" />
<preference for="Magento\Vault\Api\PaymentTokenManagementInterface" type="Magento\Vault\Model\PaymentTokenManagement" />
<preference for="Magento\Vault\Api\PaymentMethodListInterface" type="Magento\Vault\Model\PaymentMethodList" />
Expand Down Expand Up @@ -43,4 +44,13 @@
</argument>
</arguments>
</virtualType>

<type name="Magento\Vault\Model\PaymentTokenFactory">
<arguments>
<argument name="tokenTypes" xsi:type="array">
<item name="account" xsi:type="const">Magento\Vault\Api\Data\PaymentTokenFactoryInterface::TOKEN_TYPE_ACCOUNT</item>
<item name="credit_card" xsi:type="const">Magento\Vault\Api\Data\PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD</item>
</argument>
</arguments>
</type>
</config>