-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Changes from 21 commits
c35f3b8
d2ea4c1
71468a3
1ec515c
4f55988
dfe690c
f0711c2
84e668a
716b7f8
e3f2800
0760010
f1c42fd
3ef7f92
94fc33e
c036be8
7f4dbe0
85a6c71
bea1a3c
e6dea5b
cdf43f3
f5eaf7a
57c8974
eaf3b04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
* @return PaymentTokenInterface | ||
*/ | ||
public function create($type = null); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
{ | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
||
/** | ||
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to specify abstract public getType method here interface PaymentTokenInterfaceFactory
{
/**
* Create payment token entity
* @return PaymentTokenInterface
*/
public function create();
/**
* Return type of payment token
* @return string
*/
public function getType();
} |
||
} |
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 = []) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please specify There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean explicitly specify type hint for $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]] | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
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