Skip to content

Commit 72978fe

Browse files
authored
ENGCOM-4839: Prevent display of token when save for later is not selected #19767
2 parents b202e67 + 5f4103e commit 72978fe

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

app/code/Magento/Vault/Observer/AfterPaymentSaveObserver.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,9 @@ public function execute(Observer $observer)
7777
$paymentToken->setPaymentMethodCode($payment->getMethod());
7878

7979
$additionalInformation = $payment->getAdditionalInformation();
80-
if (isset($additionalInformation[VaultConfigProvider::IS_ACTIVE_CODE])) {
81-
$paymentToken->setIsVisible(
82-
(bool) (int) $additionalInformation[VaultConfigProvider::IS_ACTIVE_CODE]
83-
);
84-
}
80+
$paymentToken->setIsVisible(
81+
(bool) (int) ($additionalInformation[VaultConfigProvider::IS_ACTIVE_CODE] ?? 0)
82+
);
8583

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

@@ -115,7 +113,7 @@ protected function generatePublicHash(PaymentTokenInterface $paymentToken)
115113
/**
116114
* Reads Payment token from Order Payment
117115
*
118-
* @param OrderPaymentExtensionInterface | null $extensionAttributes
116+
* @param OrderPaymentExtensionInterface|null $extensionAttributes
119117
* @return PaymentTokenInterface | null
120118
*/
121119
protected function getPaymentToken(OrderPaymentExtensionInterface $extensionAttributes = null)

app/code/Magento/Vault/Test/Unit/Observer/AfterPaymentSaveObserverTest.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Vault\Test\Unit\Observer;
78

89
use Magento\Framework\App\DeploymentConfig;
@@ -15,9 +16,13 @@
1516
use Magento\Sales\Model\Order\Payment;
1617
use Magento\Vault\Model\PaymentToken;
1718
use Magento\Vault\Model\PaymentTokenManagement;
19+
use Magento\Vault\Model\Ui\VaultConfigProvider;
1820
use Magento\Vault\Observer\AfterPaymentSaveObserver;
1921
use PHPUnit_Framework_MockObject_MockObject as MockObject;
2022

23+
/**
24+
* Tests for AfterPaymentSaveObserver.
25+
*/
2126
class AfterPaymentSaveObserverTest extends \PHPUnit\Framework\TestCase
2227
{
2328
/**
@@ -93,7 +98,7 @@ protected function setUp()
9398

9499
// Sales Order Payment Model
95100
$this->salesOrderPaymentMock = $this->getMockBuilder(Payment::class)
96-
->setMethods(null)
101+
->setMethods(['getAdditionalInformation'])
97102
->disableOriginalConstructor()
98103
->getMock();
99104
$this->salesOrderPaymentMock->setOrder($this->salesOrderMock);
@@ -122,9 +127,10 @@ protected function setUp()
122127
* @param string $token
123128
* @param bool $isActive
124129
* @param string $method
130+
* @param array $additionalInfo
125131
* @dataProvider positiveCaseDataProvider
126132
*/
127-
public function testPositiveCase($customerId, $createdAt, $token, $isActive, $method)
133+
public function testPositiveCase($customerId, $createdAt, $token, $isActive, $method, $additionalInfo)
128134
{
129135
$this->paymentTokenMock->setGatewayToken($token);
130136
$this->paymentTokenMock->setCustomerId($customerId);
@@ -136,6 +142,8 @@ public function testPositiveCase($customerId, $createdAt, $token, $isActive, $me
136142
->method('getVaultPaymentToken')
137143
->willReturn($this->paymentTokenMock);
138144

145+
$this->salesOrderPaymentMock->method('getAdditionalInformation')->willReturn($additionalInfo);
146+
139147
if (!empty($token)) {
140148
$this->paymentTokenManagementMock->expects($this->once())
141149
->method('saveTokenWithPaymentLink')
@@ -158,6 +166,10 @@ public function testPositiveCase($customerId, $createdAt, $token, $isActive, $me
158166
static::assertEquals($token, $paymentToken->getGatewayToken());
159167
static::assertEquals($isActive, $paymentToken->getIsActive());
160168
static::assertEquals($createdAt, $paymentToken->getCreatedAt());
169+
static::assertEquals(
170+
$additionalInfo[VaultConfigProvider::IS_ACTIVE_CODE] ?? false,
171+
$paymentToken->getIsVisible()
172+
);
161173
}
162174

163175
/**
@@ -171,14 +183,32 @@ public function positiveCaseDataProvider()
171183
'10\20\2015',
172184
'asdfg',
173185
true,
174-
'paypal'
186+
'paypal',
187+
[],
188+
],
189+
[
190+
1,
191+
'10\20\2015',
192+
'asdfg',
193+
true,
194+
'paypal',
195+
[VaultConfigProvider::IS_ACTIVE_CODE => true],
196+
],
197+
[
198+
1,
199+
'10\20\2015',
200+
'asdfg',
201+
true,
202+
'paypal',
203+
[VaultConfigProvider::IS_ACTIVE_CODE => false],
175204
],
176205
[
177206
null,
178207
null,
179208
null,
180209
false,
181-
null
210+
null,
211+
[],
182212
],
183213
];
184214
}

0 commit comments

Comments
 (0)