Skip to content

Commit 667eacf

Browse files
committed
ACP2E-4270: Vaulted Card issue when placing order on Admin
- Add test coverage
1 parent e4a14e0 commit 667eacf

File tree

6 files changed

+291
-21
lines changed

6 files changed

+291
-21
lines changed

app/code/Magento/Paypal/Model/Payflowpro.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\Paypal\Model;
@@ -604,6 +604,18 @@ public function getConfig()
604604
return $this->config;
605605
}
606606

607+
/**
608+
* @inheritdoc
609+
*/
610+
public function setStore($storeId)
611+
{
612+
parent::setStore($storeId);
613+
if ($this->config) {
614+
$storeId = $this->storeManager->getStore($this->getStore())->getId();
615+
$this->config->setStoreId($storeId);
616+
}
617+
}
618+
607619
/**
608620
* @inheritdoc
609621
*

app/code/Magento/Paypal/Test/Unit/Model/PayflowproTest.php

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -15,6 +15,7 @@
1515
use Magento\Framework\HTTP\LaminasClient;
1616
use Magento\Framework\HTTP\LaminasClientFactory;
1717
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
18+
use Magento\Framework\TestFramework\Unit\Matcher\MethodInvokedAtIndex;
1819
use Magento\Payment\Model\Info;
1920
use Magento\Payment\Model\InfoInterface;
2021
use Magento\Payment\Model\Method\ConfigInterface;
@@ -481,16 +482,17 @@ public function testRefund(): void
481482
*/
482483
protected function initStoreMock(): void
483484
{
484-
$storeId = 27;
485-
$storeMock = $this->getMockBuilder(Store::class)->disableOriginalConstructor()
486-
->onlyMethods(['getId'])
487-
->getMock();
488-
$this->storeManagerMock->expects(static::once())
485+
$this->storeManagerMock->expects(static::any())
489486
->method('getStore')
490-
->willReturn($storeMock);
491-
$storeMock->expects(static::once())
492-
->method('getId')
493-
->willReturn($storeId);
487+
->willReturnCallback(
488+
function ($storeId) {
489+
$storeMock = $this->createPartialMock(Store::class, ['getId']);
490+
$storeMock->expects(static::once())
491+
->method('getId')
492+
->willReturn($storeId === null ? 1 : $storeId);
493+
return $storeMock;
494+
}
495+
);
494496
}
495497

496498
/**
@@ -806,4 +808,20 @@ public static function dataProviderMapGatewayResponse(): array
806808
]
807809
];
808810
}
811+
812+
public function testSetStore(): void
813+
{
814+
$storeId = 2;
815+
$this->initStoreMock();
816+
$this->configMock->expects($this->exactly(2))
817+
->method('setStoreId');
818+
$this->configMock->expects(new MethodInvokedAtIndex(0))
819+
->method('setStoreId')
820+
->with(1);
821+
$this->configMock->expects(new MethodInvokedAtIndex(1))
822+
->method('setStoreId')
823+
->with($storeId);
824+
$this->payflowpro->getConfig();
825+
$this->payflowpro->setStore($storeId);
826+
}
809827
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Vault\Model\Method;
77

@@ -25,7 +25,7 @@
2525
use Magento\Framework\Serialize\Serializer\Json;
2626

2727
/**
28-
* Class Vault
28+
* Vault payment method
2929
*
3030
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
3131
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -38,7 +38,7 @@ class Vault implements VaultPaymentInterface
3838
/**
3939
* @deprecated
4040
*/
41-
const TOKEN_METADATA_KEY = 'token_metadata';
41+
public const TOKEN_METADATA_KEY = 'token_metadata';
4242

4343
/**
4444
* @var string
@@ -202,6 +202,7 @@ public function getTitle()
202202
public function setStore($storeId)
203203
{
204204
$this->storeId = (int)$storeId;
205+
$this->vaultProvider->setStore($storeId);
205206
}
206207

207208
/**
@@ -488,6 +489,7 @@ public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
488489
);
489490

490491
$payment->setMethod($this->vaultProvider->getCode());
492+
return $this;
491493
}
492494

493495
/**
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Vault\Test\Fixture;
10+
11+
use Magento\Framework\DataObject;
12+
use Magento\Framework\Encryption\EncryptorInterface;
13+
use Magento\TestFramework\Fixture\DataFixtureInterface;
14+
use Magento\Vault\Api\Data\PaymentTokenFactoryInterface;
15+
use Magento\Vault\Api\PaymentTokenRepositoryInterface;
16+
use Magento\Vault\Model\PaymentTokenFactory;
17+
18+
/**
19+
* Create a payment token for a customer
20+
*
21+
* Example: Basic usage. This will create a payment token for a customer
22+
* ```php
23+
* #[
24+
* DataFixture(CustomerFixture::class, as: 'customer'),
25+
* DataFixture(PaymentTokenFixture::class, ['customer_id' => '$customer.id$'], as: 'token'),
26+
* DataFixture(
27+
* SetPaymentMethodFixture::class,
28+
* [
29+
* 'cart_id' => '$cart.id$',
30+
* 'method' => [
31+
* 'method' => 'payflowpro_cc_vault',
32+
* 'additional_data' => [
33+
* 'public_hash' => '$token.public_hash$',
34+
* 'customer_id' => '$customer.id$',
35+
* ]
36+
* ]
37+
* ]
38+
* )
39+
* ]
40+
* ```
41+
*/
42+
class PaymentToken implements DataFixtureInterface
43+
{
44+
private const DEFAULT_DATA = [
45+
'entity_id' => null,
46+
'customer_id' => null,
47+
'website_id' => null,
48+
'public_hash' => null,
49+
'payment_method_code' => null,
50+
'type' => PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD,
51+
'expires_at' => null,
52+
'created_at' => null,
53+
'gateway_token' => null,
54+
'token_details' => null,
55+
'is_visible' => true,
56+
'is_active' => true,
57+
];
58+
59+
/**
60+
* @param PaymentTokenRepositoryInterface $paymentTokenRepository
61+
* @param PaymentTokenFactory $paymentTokenFactory
62+
* @param EncryptorInterface $encryptor
63+
*/
64+
public function __construct(
65+
private readonly PaymentTokenRepositoryInterface $paymentTokenRepository,
66+
private readonly PaymentTokenFactory $paymentTokenFactory,
67+
private readonly EncryptorInterface $encryptor
68+
) {
69+
}
70+
71+
/**
72+
* @inheritDoc
73+
*/
74+
public function apply(array $data = []): ?DataObject
75+
{
76+
$data = array_merge(
77+
self::DEFAULT_DATA,
78+
[
79+
'expires_at' => strtotime('+1 year'),
80+
'public_hash' => $this->encryptor->hash(uniqid((string) $data['customer_id']))
81+
],
82+
$data
83+
);
84+
$token = $this->paymentTokenFactory->create($data['type']);
85+
$token->addData($data);
86+
$this->paymentTokenRepository->save($token);
87+
return $token;
88+
}
89+
}

app/code/Magento/Vault/Test/Unit/Model/Method/VaultTest.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -393,4 +393,20 @@ public static function internalUsageDataProvider()
393393
['configValue' => null, 'paymentValue' => null, 'expected' => false],
394394
];
395395
}
396+
397+
public function testSetStore(): void
398+
{
399+
$storeId = 2;
400+
/** @var Vault $model */
401+
$model = $this->objectManager->getObject(
402+
Vault::class,
403+
[
404+
'vaultProvider' => $this->vaultProvider,
405+
]
406+
);
407+
$this->vaultProvider->expects($this->once())
408+
->method('setStore')
409+
->willReturn($storeId);
410+
$model->setStore($storeId);
411+
}
396412
}

0 commit comments

Comments
 (0)