Skip to content

Commit 62c7e0e

Browse files
ENGCOM-4839: Prevent display of token when save for later is not selected #19767
- Merge Pull Request #19767 from pmclain/magento2:issue/19515 - Merged commits: 1. bbb386b 2. d93a9b5
2 parents f7d4822 + d93a9b5 commit 62c7e0e

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

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

Lines changed: 3 additions & 5 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

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Sales\Model\Order\Payment;
1616
use Magento\Vault\Model\PaymentToken;
1717
use Magento\Vault\Model\PaymentTokenManagement;
18+
use Magento\Vault\Model\Ui\VaultConfigProvider;
1819
use Magento\Vault\Observer\AfterPaymentSaveObserver;
1920
use PHPUnit_Framework_MockObject_MockObject as MockObject;
2021

@@ -93,7 +94,7 @@ protected function setUp()
9394

9495
// Sales Order Payment Model
9596
$this->salesOrderPaymentMock = $this->getMockBuilder(Payment::class)
96-
->setMethods(null)
97+
->setMethods(['getAdditionalInformation'])
9798
->disableOriginalConstructor()
9899
->getMock();
99100
$this->salesOrderPaymentMock->setOrder($this->salesOrderMock);
@@ -122,9 +123,10 @@ protected function setUp()
122123
* @param string $token
123124
* @param bool $isActive
124125
* @param string $method
126+
* @param array $additionalInfo
125127
* @dataProvider positiveCaseDataProvider
126128
*/
127-
public function testPositiveCase($customerId, $createdAt, $token, $isActive, $method)
129+
public function testPositiveCase($customerId, $createdAt, $token, $isActive, $method, $additionalInfo)
128130
{
129131
$this->paymentTokenMock->setGatewayToken($token);
130132
$this->paymentTokenMock->setCustomerId($customerId);
@@ -136,6 +138,8 @@ public function testPositiveCase($customerId, $createdAt, $token, $isActive, $me
136138
->method('getVaultPaymentToken')
137139
->willReturn($this->paymentTokenMock);
138140

141+
$this->salesOrderPaymentMock->method('getAdditionalInformation')->willReturn($additionalInfo);
142+
139143
if (!empty($token)) {
140144
$this->paymentTokenManagementMock->expects($this->once())
141145
->method('saveTokenWithPaymentLink')
@@ -158,6 +162,7 @@ public function testPositiveCase($customerId, $createdAt, $token, $isActive, $me
158162
static::assertEquals($token, $paymentToken->getGatewayToken());
159163
static::assertEquals($isActive, $paymentToken->getIsActive());
160164
static::assertEquals($createdAt, $paymentToken->getCreatedAt());
165+
static::assertEquals($additionalInfo[VaultConfigProvider::IS_ACTIVE_CODE] ?? false, $paymentToken->getIsVisible());
161166
}
162167

163168
/**
@@ -171,14 +176,32 @@ public function positiveCaseDataProvider()
171176
'10\20\2015',
172177
'asdfg',
173178
true,
174-
'paypal'
179+
'paypal',
180+
[],
181+
],
182+
[
183+
1,
184+
'10\20\2015',
185+
'asdfg',
186+
true,
187+
'paypal',
188+
[VaultConfigProvider::IS_ACTIVE_CODE => true],
189+
],
190+
[
191+
1,
192+
'10\20\2015',
193+
'asdfg',
194+
true,
195+
'paypal',
196+
[VaultConfigProvider::IS_ACTIVE_CODE => false],
175197
],
176198
[
177199
null,
178200
null,
179201
null,
180202
false,
181-
null
203+
null,
204+
[],
182205
],
183206
];
184207
}

0 commit comments

Comments
 (0)