Skip to content

Commit

Permalink
Prevent display of token when save for later is not selected
Browse files Browse the repository at this point in the history
This sets the token `isVisible` value to faluse if
`VaultConfigProvider::IS_ACTIVE_CODE` is not set in the payment's
`additionalInformation` property. The value is not set when placing orders
through the admin panel, unless the save for later checkbox is selected. This
caused all admin order payment to be visible in the stored payment method
section in the storefront.

Fixes magento#19515

Testing on 2.3 depends on magento#19764
  • Loading branch information
pmclain committed Dec 14, 2018
1 parent b8892f0 commit bbb386b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
8 changes: 3 additions & 5 deletions app/code/Magento/Vault/Observer/AfterPaymentSaveObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,9 @@ public function execute(Observer $observer)
$paymentToken->setPaymentMethodCode($payment->getMethod());

$additionalInformation = $payment->getAdditionalInformation();
if (isset($additionalInformation[VaultConfigProvider::IS_ACTIVE_CODE])) {
$paymentToken->setIsVisible(
(bool) (int) $additionalInformation[VaultConfigProvider::IS_ACTIVE_CODE]
);
}
$paymentToken->setIsVisible(
(bool) (int) ($additionalInformation[VaultConfigProvider::IS_ACTIVE_CODE] ?? 0)
);

$paymentToken->setPublicHash($this->generatePublicHash($paymentToken));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Magento\Sales\Model\Order\Payment;
use Magento\Vault\Model\PaymentToken;
use Magento\Vault\Model\PaymentTokenManagement;
use Magento\Vault\Model\Ui\VaultConfigProvider;
use Magento\Vault\Observer\AfterPaymentSaveObserver;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

Expand Down Expand Up @@ -93,7 +94,7 @@ protected function setUp()

// Sales Order Payment Model
$this->salesOrderPaymentMock = $this->getMockBuilder(Payment::class)
->setMethods(null)
->setMethods(['getAdditionalInformation'])
->disableOriginalConstructor()
->getMock();
$this->salesOrderPaymentMock->setOrder($this->salesOrderMock);
Expand Down Expand Up @@ -122,9 +123,10 @@ protected function setUp()
* @param string $token
* @param bool $isActive
* @param string $method
* @param array $additionalInformation
* @dataProvider positiveCaseDataProvider
*/
public function testPositiveCase($customerId, $createdAt, $token, $isActive, $method)
public function testPositiveCase($customerId, $createdAt, $token, $isActive, $method, $additionalInformation)
{
$this->paymentTokenMock->setGatewayToken($token);
$this->paymentTokenMock->setCustomerId($customerId);
Expand All @@ -136,6 +138,8 @@ public function testPositiveCase($customerId, $createdAt, $token, $isActive, $me
->method('getVaultPaymentToken')
->willReturn($this->paymentTokenMock);

$this->salesOrderPaymentMock->method('getAdditionalInformation')->willReturn($additionalInformation);

if (!empty($token)) {
$this->paymentTokenManagementMock->expects($this->once())
->method('saveTokenWithPaymentLink')
Expand All @@ -158,6 +162,7 @@ public function testPositiveCase($customerId, $createdAt, $token, $isActive, $me
static::assertEquals($token, $paymentToken->getGatewayToken());
static::assertEquals($isActive, $paymentToken->getIsActive());
static::assertEquals($createdAt, $paymentToken->getCreatedAt());
static::assertEquals($additionalInformation[VaultConfigProvider::IS_ACTIVE_CODE] ?? false, $paymentToken->getIsVisible());
}

/**
Expand All @@ -171,14 +176,32 @@ public function positiveCaseDataProvider()
'10\20\2015',
'asdfg',
true,
'paypal'
'paypal',
[],
],
[
1,
'10\20\2015',
'asdfg',
true,
'paypal',
[VaultConfigProvider::IS_ACTIVE_CODE => true],
],
[
1,
'10\20\2015',
'asdfg',
true,
'paypal',
[VaultConfigProvider::IS_ACTIVE_CODE => false],
],
[
null,
null,
null,
false,
null
null,
[],
],
];
}
Expand Down

0 comments on commit bbb386b

Please sign in to comment.