Skip to content

Commit 95ff2ed

Browse files
committed
Merge remote-tracking branch 'origin/BUG#AC-2901' into Hammer_Platform_Health_Scope_21082023
2 parents 7c379dd + 8aa810a commit 95ff2ed

File tree

8 files changed

+153
-22
lines changed

8 files changed

+153
-22
lines changed

app/code/Magento/Vault/Api/Data/PaymentTokenInterface.php

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,52 @@ interface PaymentTokenInterface
1919
/*
2020
* Entity ID.
2121
*/
22-
const ENTITY_ID = 'entity_id';
22+
public const ENTITY_ID = 'entity_id';
2323
/*
2424
* Customer ID.
2525
*/
26-
const CUSTOMER_ID = 'customer_id';
26+
public const CUSTOMER_ID = 'customer_id';
2727
/*
2828
* Unique hash for frontend.
2929
*/
30-
const PUBLIC_HASH = 'public_hash';
30+
public const PUBLIC_HASH = 'public_hash';
3131
/*
3232
* Payment method code.
3333
*/
34-
const PAYMENT_METHOD_CODE = 'payment_method_code';
34+
public const PAYMENT_METHOD_CODE = 'payment_method_code';
3535
/*
3636
* Token type.
3737
*/
38-
const TYPE = 'type';
38+
public const TYPE = 'type';
3939
/*
4040
* Token creation timestamp.
4141
*/
42-
const CREATED_AT = 'created_at';
42+
public const CREATED_AT = 'created_at';
4343
/*
4444
* Token expiration timestamp.
4545
*/
46-
const EXPIRES_AT = 'expires_at';
46+
public const EXPIRES_AT = 'expires_at';
4747
/*
4848
* Gateway token ID.
4949
*/
50-
const GATEWAY_TOKEN = 'gateway_token';
50+
public const GATEWAY_TOKEN = 'gateway_token';
5151
/*
5252
* Additional details.
5353
*/
54-
const DETAILS = 'details';
54+
public const DETAILS = 'details';
5555
/*
5656
* Is vault payment record active.
5757
*/
58-
const IS_ACTIVE = 'is_active';
58+
public const IS_ACTIVE = 'is_active';
5959
/*
6060
* Is vault payment token visible.
6161
*/
62-
const IS_VISIBLE = 'is_visible';
62+
public const IS_VISIBLE = 'is_visible';
63+
64+
/*
65+
* Vault website id
66+
*/
67+
public const WEBSITE_ID = 'website_id';
6368

6469
/**
6570
* Gets the entity ID.
@@ -249,4 +254,20 @@ public function getIsVisible();
249254
* @since 100.1.0
250255
*/
251256
public function setIsVisible($isVisible);
257+
258+
/**
259+
* Gets vault payment website id.
260+
*
261+
* @return int website id.
262+
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
263+
*/
264+
public function getWebsiteId();
265+
266+
/**
267+
* Sets vault payment website id.
268+
*
269+
* @param int $websiteId
270+
* @return $this
271+
*/
272+
public function setWebsiteId(int $websiteId);
252273
}

app/code/Magento/Vault/Model/PaymentToken.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,22 @@ public function setIsVisible($isVisible)
214214
$this->setData(PaymentTokenInterface::IS_VISIBLE, (bool) $isVisible);
215215
return $this;
216216
}
217+
218+
/**
219+
* @inheritdoc
220+
*/
221+
public function getWebsiteId()
222+
{
223+
return $this->getData(PaymentTokenInterface::WEBSITE_ID);
224+
}
225+
226+
/**
227+
* @inheritdoc
228+
*/
229+
public function setWebsiteId(int $websiteId)
230+
{
231+
$this->setData(PaymentTokenInterface::WEBSITE_ID, $websiteId);
232+
233+
return $this;
234+
}
217235
}

app/code/Magento/Vault/Model/Ui/Adminhtml/TokensConfigProvider.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,21 @@ public function getTokensComponents($vaultPaymentCode)
194194
]
195195
);
196196

197+
//Load stored cards based on website id @see AC-2901
198+
$websiteId = $this->storeManager->getWebsite()->getId();
199+
$quote = $this->session->getQuote() ?? null;
200+
if ($quote) {
201+
$websiteId = $quote->getStore()->getWebsite()->getId();
202+
}
203+
204+
$this->searchCriteriaBuilder->addFilters(
205+
[
206+
$this->filterBuilder->setField(PaymentTokenInterface::WEBSITE_ID)
207+
->setValue($websiteId)
208+
->create(),
209+
]
210+
);
211+
197212
$searchCriteria = $this->searchCriteriaBuilder->create();
198213

199214
foreach ($this->paymentTokenRepository->getList($searchCriteria)->getItems() as $token) {
@@ -267,6 +282,7 @@ private function getOrderPaymentEntityId()
267282
*
268283
* @return Data
269284
* @deprecated 100.1.0
285+
* @see MAGETWO-71174
270286
*/
271287
private function getPaymentDataHelper()
272288
{
@@ -281,6 +297,7 @@ private function getPaymentDataHelper()
281297
*
282298
* @return OrderRepositoryInterface
283299
* @deprecated 100.2.0
300+
* @see MAGETWO-71174
284301
*/
285302
private function getOrderRepository()
286303
{
@@ -297,6 +314,7 @@ private function getOrderRepository()
297314
*
298315
* @return PaymentTokenManagementInterface
299316
* @deprecated 100.2.0
317+
* @see MAGETWO-71174
300318
*/
301319
private function getPaymentTokenManagement()
302320
{

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
class AfterPaymentSaveObserver implements ObserverInterface
2222
{
23-
const PAYMENT_OBJECT_DATA_KEY = 'payment';
23+
public const PAYMENT_OBJECT_DATA_KEY = 'payment';
2424

2525
/**
2626
* @var PaymentTokenManagementInterface
@@ -75,6 +75,7 @@ public function execute(Observer $observer)
7575
$paymentToken->setCustomerId($order->getCustomerId());
7676
$paymentToken->setIsActive(true);
7777
$paymentToken->setPaymentMethodCode($payment->getMethod());
78+
$paymentToken->setWebsiteId($order->getStore()->getWebsiteId());
7879

7980
$additionalInformation = $payment->getAdditionalInformation();
8081
$paymentToken->setIsVisible(

app/code/Magento/Vault/Test/Unit/Model/Ui/Adminhtml/TokensConfigProviderTest.php

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Magento\Sales\Api\Data\OrderPaymentInterface;
2323
use Magento\Sales\Api\OrderRepositoryInterface;
2424
use Magento\Store\Api\Data\StoreInterface;
25+
use Magento\Store\Api\Data\WebsiteInterface;
2526
use Magento\Store\Model\StoreManagerInterface;
2627
use Magento\Vault\Api\Data\PaymentTokenInterface;
2728
use Magento\Vault\Api\Data\PaymentTokenSearchResultsInterface;
@@ -44,12 +45,12 @@ class TokensConfigProviderTest extends TestCase
4445
/**#@+
4546
* Global values
4647
*/
47-
const STORE_ID = 1;
48-
const ORDER_ID = 2;
49-
const ORDER_PAYMENT_ENTITY_ID = 3;
50-
const ENTITY_ID = 4;
51-
const VAULT_PAYMENT_CODE = 'vault_payment';
52-
const VAULT_PROVIDER_CODE = 'payment';
48+
public const STORE_ID = 1;
49+
public const ORDER_ID = 2;
50+
public const ORDER_PAYMENT_ENTITY_ID = 3;
51+
public const ENTITY_ID = 4;
52+
public const VAULT_PAYMENT_CODE = 'vault_payment';
53+
public const VAULT_PROVIDER_CODE = 'payment';
5354
/**#@-*/
5455

5556
/**
@@ -77,6 +78,11 @@ class TokensConfigProviderTest extends TestCase
7778
*/
7879
private $storeManager;
7980

81+
/**
82+
* @var WebsiteInterface|MockObject
83+
*/
84+
private $websiteMock;
85+
8086
/**
8187
* @var StoreInterface|MockObject
8288
*/
@@ -134,7 +140,7 @@ protected function setUp(): void
134140
->getMock();
135141
$this->session = $this->getMockBuilder(Quote::class)
136142
->disableOriginalConstructor()
137-
->setMethods(['getCustomerId', 'getReordered', 'getStoreId'])
143+
->setMethods(['getCustomerId', 'getReordered', 'getStoreId','getQuote'])
138144
->getMock();
139145
$this->dateTimeFactory = $this->getMockBuilder(DateTimeFactory::class)
140146
->disableOriginalConstructor()
@@ -217,6 +223,19 @@ public function testGetTokensComponentsRegisteredCustomer()
217223
->method('getProviderCode')
218224
->willReturn(self::VAULT_PROVIDER_CODE);
219225

226+
$this->websiteMock = $this->getMockForAbstractClass(WebsiteInterface::class);
227+
$this->storeManager->expects(static::once())
228+
->method('getWebsite')
229+
->willReturn($this->websiteMock);
230+
231+
$this->websiteMock->expects(static::once())
232+
->method('getId')
233+
->willReturn(1);
234+
235+
$this->session->expects(static::once())
236+
->method('getQuote')
237+
->willReturn(null);
238+
220239
/** @var PaymentTokenInterface|MockObject $token */
221240
$token = $this->getMockBuilder(PaymentTokenInterface::class)
222241
->getMockForAbstractClass();
@@ -281,6 +300,14 @@ public function testGetTokensComponentsGuestCustomer()
281300
$this->vaultPayment->expects(static::once())
282301
->method('getProviderCode')
283302
->willReturn(self::VAULT_PROVIDER_CODE);
303+
$this->websiteMock = $this->getMockForAbstractClass(WebsiteInterface::class);
304+
$this->storeManager->expects(static::once())
305+
->method('getWebsite')
306+
->willReturn($this->websiteMock);
307+
308+
$this->websiteMock->expects(static::once())
309+
->method('getId')
310+
->willReturn(1);
284311

285312
/** @var PaymentTokenInterface|MockObject $token */
286313
$token = $this->getMockBuilder(PaymentTokenInterface::class)
@@ -595,13 +622,14 @@ private function getSearchCriteria($customerId, $entityId, $vaultProviderCode)
595622
);
596623

597624
$isVisibleFilter = $this->createExpectedFilter(PaymentTokenInterface::IS_VISIBLE, 1, 4);
625+
$websiteFilter = $this->createExpectedFilter(PaymentTokenInterface::WEBSITE_ID, 1, 5);
598626

599627
$this->filterBuilder->expects(static::once())
600628
->method('setConditionType')
601629
->with('gt')
602630
->willReturnSelf();
603631

604-
$this->searchCriteriaBuilder->expects(self::exactly(5))
632+
$this->searchCriteriaBuilder->expects(self::exactly(6))
605633
->method('addFilters')
606634
->willReturnMap(
607635
[
@@ -610,6 +638,7 @@ private function getSearchCriteria($customerId, $entityId, $vaultProviderCode)
610638
[$expiresAtFilter, $this->searchCriteriaBuilder],
611639
[$isActiveFilter, $this->searchCriteriaBuilder],
612640
[$isVisibleFilter, $this->searchCriteriaBuilder],
641+
[$websiteFilter, $this->searchCriteriaBuilder],
613642
]
614643
);
615644

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Sales\Api\Data\OrderPaymentExtension;
1515
use Magento\Sales\Model\Order;
1616
use Magento\Sales\Model\Order\Payment;
17+
use Magento\Store\Model\Store;
1718
use Magento\Vault\Model\PaymentToken;
1819
use Magento\Vault\Model\PaymentTokenManagement;
1920
use Magento\Vault\Model\Ui\VaultConfigProvider;
@@ -66,6 +67,11 @@ class AfterPaymentSaveObserverTest extends TestCase
6667
*/
6768
protected $salesOrderPaymentMock;
6869

70+
/**
71+
* @var Store|MockObject
72+
*/
73+
protected $storeMock;
74+
6975
/**
7076
* @inheritdoc
7177
*/
@@ -101,6 +107,11 @@ protected function setUp(): void
101107
// Sales Order Model
102108
$this->salesOrderMock = $this->createMock(Order::class);
103109

110+
$this->storeMock = $this->getMockBuilder(Store::class)
111+
->setMethods(['getWebsiteId'])
112+
->disableOriginalConstructor()
113+
->getMock();
114+
104115
// Sales Order Payment Model
105116
$this->salesOrderPaymentMock = $this->getMockBuilder(Payment::class)
106117
->setMethods(['getAdditionalInformation'])
@@ -137,18 +148,27 @@ protected function setUp(): void
137148
* @param array $additionalInfo
138149
* @dataProvider positiveCaseDataProvider
139150
*/
140-
public function testPositiveCase($customerId, $createdAt, $token, $isActive, $method, $additionalInfo)
151+
public function testPositiveCase($customerId, $createdAt, $token, $isActive, $method, $websiteId, $additionalInfo)
141152
{
142153
$this->paymentTokenMock->setGatewayToken($token);
143154
$this->paymentTokenMock->setCustomerId($customerId);
144155
$this->paymentTokenMock->setCreatedAt($createdAt);
145156
$this->paymentTokenMock->setPaymentMethodCode($method);
146157
$this->paymentTokenMock->setIsActive($isActive);
158+
$this->paymentTokenMock->setWebsiteId($websiteId);
147159

148160
$this->paymentExtension->expects($this->exactly(2))
149161
->method('getVaultPaymentToken')
150162
->willReturn($this->paymentTokenMock);
151163

164+
$this->salesOrderMock->expects($this->any())
165+
->method('getStore')
166+
->willReturn($this->storeMock);
167+
168+
$this->storeMock->expects($this->any())
169+
->method('getWebsiteId')
170+
->willReturn($websiteId);
171+
152172
$this->salesOrderPaymentMock->method('getAdditionalInformation')->willReturn($additionalInfo);
153173

154174
if (!empty($token)) {
@@ -193,6 +213,7 @@ public function positiveCaseDataProvider()
193213
'asdfg',
194214
true,
195215
'paypal',
216+
1,
196217
[],
197218
],
198219
[
@@ -201,6 +222,7 @@ public function positiveCaseDataProvider()
201222
'asdfg',
202223
true,
203224
'paypal',
225+
1,
204226
[VaultConfigProvider::IS_ACTIVE_CODE => true],
205227
],
206228
[
@@ -209,14 +231,34 @@ public function positiveCaseDataProvider()
209231
'asdfg',
210232
true,
211233
'paypal',
234+
1,
212235
[VaultConfigProvider::IS_ACTIVE_CODE => false],
213236
],
237+
[
238+
1,
239+
'10\20\2015',
240+
'asdfg',
241+
true,
242+
'braintree_cc_vault',
243+
2,
244+
[VaultConfigProvider::IS_ACTIVE_CODE => true],
245+
],
246+
[
247+
1,
248+
'10\20\2015',
249+
'asdfg',
250+
true,
251+
'braintree_cc_vault',
252+
1,
253+
[VaultConfigProvider::IS_ACTIVE_CODE => true],
254+
],
214255
[
215256
null,
216257
null,
217258
null,
218259
false,
219260
null,
261+
1,
220262
[],
221263
],
222264
];

app/code/Magento/Vault/etc/db_schema.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
comment="Entity ID"/>
1313
<column xsi:type="int" name="customer_id" unsigned="true" nullable="true" identity="false"
1414
comment="Customer ID"/>
15+
<column xsi:type="int" name="website_id" unsigned="true" nullable="true" identity="false" comment="Website ID"/>
1516
<column xsi:type="varchar" name="public_hash" nullable="false" length="128"
1617
comment="Hash code for using on frontend"/>
1718
<column xsi:type="varchar" name="payment_method_code" nullable="false" length="128"

0 commit comments

Comments
 (0)