Skip to content

Commit 60c0dbb

Browse files
MC-39109: Vault throw The requested Payment Method is not available. error
1 parent a75033b commit 60c0dbb

File tree

2 files changed

+134
-4
lines changed

2 files changed

+134
-4
lines changed

app/code/Magento/Vault/Plugin/PaymentVaultInformationManagement.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\Checkout\Api\PaymentInformationManagementInterface;
1111
use Magento\Quote\Api\Data\AddressInterface;
1212
use Magento\Quote\Api\Data\PaymentInterface;
13-
use Magento\Vault\Model\PaymentMethodList;
13+
use Magento\Vault\Api\PaymentMethodListInterface;
1414
use Magento\Store\Model\StoreManagerInterface;
1515

1616
/**
@@ -19,7 +19,7 @@
1919
class PaymentVaultInformationManagement
2020
{
2121
/**
22-
* @var PaymentMethodList
22+
* @var PaymentMethodListInterface
2323
*/
2424
private $vaultPaymentMethodList;
2525

@@ -31,11 +31,11 @@ class PaymentVaultInformationManagement
3131
/**
3232
* PaymentVaultInformationManagement constructor.
3333
*
34-
* @param PaymentMethodList $vaultPaymentMethodList
34+
* @param PaymentMethodListInterface $vaultPaymentMethodList
3535
* @param StoreManagerInterface $storeManager
3636
*/
3737
public function __construct(
38-
PaymentMethodList $vaultPaymentMethodList,
38+
PaymentMethodListInterface $vaultPaymentMethodList,
3939
StoreManagerInterface $storeManager
4040
) {
4141
$this->vaultPaymentMethodList = $vaultPaymentMethodList;
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Vault\Test\Unit\Plugin;
9+
10+
use Magento\Checkout\Api\PaymentInformationManagementInterface;
11+
use Magento\Store\Api\Data\StoreInterface;
12+
use Magento\Store\Model\StoreManagerInterface;
13+
use Magento\Vault\Api\PaymentMethodListInterface;
14+
use Magento\Vault\Plugin\PaymentVaultInformationManagement;
15+
use Magento\Quote\Api\Data\PaymentInterface;
16+
use PHPUnit\Framework\MockObject\MockObject;
17+
use PHPUnit\Framework\TestCase;
18+
19+
/**
20+
* Test for payment vault information management plugin
21+
*/
22+
class PaymentVaultInformationManagementTest extends TestCase
23+
{
24+
/**
25+
* @var StoreManagerInterface|MockObject
26+
*/
27+
private $storeManager;
28+
29+
/**
30+
* @var StoreInterface|MockObject
31+
*/
32+
private $store;
33+
34+
/**
35+
* @var PaymentMethodListInterface|MockObject
36+
*/
37+
private $paymentMethodList;
38+
39+
/**
40+
* @var PaymentVaultInformationManagement
41+
*/
42+
private $plugin;
43+
44+
/**
45+
* @var PaymentInformationManagementInterface|MockObject
46+
*/
47+
private $paymentInformationManagement;
48+
49+
/**
50+
* @var PaymentInterface|MockObject
51+
*/
52+
private $payment;
53+
54+
/**
55+
* @inheritDoc
56+
*/
57+
protected function setUp(): void
58+
{
59+
$this->storeManager = $this->getMockBuilder(StoreManagerInterface::class)
60+
->disableOriginalConstructor()
61+
->onlyMethods(['getStore'])
62+
->getMockForAbstractClass();
63+
$this->store = $this->getMockBuilder(StoreInterface::class)
64+
->disableOriginalConstructor()
65+
->onlyMethods(['getId'])
66+
->getMockForAbstractClass();
67+
$this->paymentMethodList = $this->getMockBuilder(PaymentMethodListInterface::class)
68+
->disableOriginalConstructor()
69+
->onlyMethods(['getActiveList'])
70+
->getMockForAbstractClass();
71+
$this->paymentInformationManagement = $this
72+
->getMockBuilder(PaymentInformationManagementInterface::class)
73+
->disableOriginalConstructor()
74+
->getMockForAbstractClass();
75+
$this->payment = $this->getMockBuilder(PaymentInterface::class)
76+
->onlyMethods(['setMethod'])
77+
->disableOriginalConstructor()
78+
->getMockForAbstractClass();
79+
$this->plugin = new PaymentVaultInformationManagement($this->paymentMethodList, $this->storeManager);
80+
}
81+
82+
/**
83+
* Test payment method for vault before saving payment information
84+
*
85+
* @param string $requestPaymentMethodCode
86+
* @param string $methodCode
87+
* @dataProvider vaultPaymentMethodDataProvider
88+
*
89+
* @return void
90+
*/
91+
public function testBeforeSavePaymentInformation($requestPaymentMethodCode, $methodCode): void
92+
{
93+
$this->store->method('getId')
94+
->willReturn(1);
95+
$this->storeManager->method('getStore')
96+
->willReturn($this->store);
97+
$activeVaultMethod = $this->getMockBuilder(PaymentInterface::class)
98+
->disableOriginalConstructor()
99+
->addMethods(['getCode', 'getProviderCode'])
100+
->getMockForAbstractClass();
101+
$activeVaultMethod->method('getCode')
102+
->willReturn($methodCode);
103+
$this->paymentMethodList->method('getActiveList')
104+
->willReturn([$activeVaultMethod]);
105+
$this->payment->method('getMethod')
106+
->willReturn($requestPaymentMethodCode);
107+
$this->payment->expects($this->once())
108+
->method('setMethod')
109+
->with($methodCode);
110+
111+
$this->plugin->beforeSavePaymentInformation(
112+
$this->paymentInformationManagement,
113+
'1',
114+
$this->payment,
115+
null
116+
);
117+
}
118+
119+
/**
120+
* Data provider for BeforeSavePaymentInformation.
121+
*
122+
* @return array
123+
*/
124+
public function vaultPaymentMethodDataProvider(): array
125+
{
126+
return [
127+
['braintree_cc_vault_01', 'braintree_cc_vault'],
128+
];
129+
}
130+
}

0 commit comments

Comments
 (0)