Skip to content

Commit 3806190

Browse files
author
Ivan Tagil
committed
Merge remote-tracking branch 'remotes/origin/feature/direct-flow' into feature/CMP-41_42_configure-api-credentials-and-connectivity
Resolving of conflicts
2 parents bde8a63 + e702ee1 commit 3806190

File tree

20 files changed

+1000
-92
lines changed

20 files changed

+1000
-92
lines changed

Api/Config/ConfigInterface.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface ConfigInterface
1616
* XML Paths of configuration settings
1717
*/
1818
public const XML_PATH_GENERAL_ENABLED = 'cm_payments/general/enabled';
19+
public const XML_PATH_GENERAL_CURRENT_VERSION = 'cm_payments/general/current_version';
1920
public const XML_PATH_GENERAL_TEST_MERCHANT_NAME = 'cm_payments/general/test_merchant_name';
2021
public const XML_PATH_GENERAL_TEST_MERCHANT_PASSWORD = 'cm_payments/general/test_merchant_password';
2122
public const XML_PATH_GENERAL_TEST_MERCHANT_KEY = 'cm_payments/general/test_merchant_key';
@@ -26,6 +27,7 @@ interface ConfigInterface
2627
public const XML_PATH_PAYMENT_PROFILE = 'payment/cm_payments_methods/profile';
2728
public const XML_PATH_PAYMENT_CREDIT_CARD_PROFILE = 'payment/cm_payments_creditcard/profile';
2829
public const XML_PATH_PAYMENT_BANCONTACT_PROFILE = 'payment/cm_payments_bancontact/profile';
30+
public const XML_PATH_PAYMENT_CM_PAYMENTS_PROFILE = 'payment/cm_payments/profile';
2931

3032
/**
3133
* Checks that extension is enabled
@@ -36,30 +38,47 @@ interface ConfigInterface
3638
public function isEnabled(): ?bool;
3739

3840
/**
41+
* Get Current Version
42+
*
43+
* @return string|null
44+
* @throws NoSuchEntityException
45+
*/
46+
public function getCurrentVersion(): ?string;
47+
48+
/**
49+
* Get Merchant Key
50+
*
3951
* @return string|null
4052
* @throws NoSuchEntityException
4153
*/
4254
public function getMerchantKey(): ?string;
4355

4456
/**
57+
* Get Merchant Name
58+
*
4559
* @return string|null
4660
* @throws NoSuchEntityException
4761
*/
4862
public function getMerchantName(): ?string;
4963

5064
/**
65+
* Get Merchant Password
66+
*
5167
* @return string|null
5268
* @throws NoSuchEntityException
5369
*/
5470
public function getMerchantPassword(): ?string;
5571

5672
/**
73+
* @param string $paymentMethod
5774
* @return string|null
5875
* @throws NoSuchEntityException
5976
*/
60-
public function getPaymentProfile(): ?string;
77+
public function getPaymentProfile(string $paymentMethod): ?string;
6178

6279
/**
80+
* Get mode
81+
*
6382
* @return string|null
6483
* @throws NoSuchEntityException
6584
*/
@@ -89,4 +108,12 @@ public function getCreditCardPaymentProfile(): ?string;
89108
* @throws NoSuchEntityException
90109
*/
91110
public function getBanContactPaymentProfile(): ?string;
111+
112+
/**
113+
* Get Payment Profile for CM Payments Menu Method
114+
*
115+
* @return ?string
116+
* @throws NoSuchEntityException
117+
*/
118+
public function getCmPaymentsMenuPaymentProfile(): ?string;
92119
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © CM.com. All rights reserved.
4+
* See LICENSE.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace CM\Payments\Api\Service;
10+
11+
interface VersionServiceInterface
12+
{
13+
/**
14+
* Repository Vendor Name
15+
*/
16+
public const REPOSITORY_VENDOR_NAME = 'cmdotcom';
17+
18+
/**
19+
* Repository Extension Name
20+
*/
21+
public const REPOSITORY_EXTENSION_NAME = 'pay-ext-magento2';
22+
23+
/**
24+
*/
25+
public function getLatestVersion();
26+
27+
/**
28+
* Get Repository Url
29+
*
30+
* @return string
31+
*/
32+
public function getRepositoryUrl(): string;
33+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
/**
3+
* Copyright © CM.com. All rights reserved.
4+
* See LICENSE.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace CM\Payments\Block\Adminhtml\System\Config\Button;
10+
11+
use CM\Payments\Api\Config\ConfigInterface;
12+
use Exception;
13+
use Magento\Backend\Block\Template\Context;
14+
use Magento\Backend\Block\Widget\Button;
15+
use Magento\Config\Block\System\Config\Form\Field;
16+
use Magento\Framework\Data\Form\Element\AbstractElement;
17+
use Magento\Framework\Exception\NoSuchEntityException;
18+
19+
class CheckLatestVersion extends Field
20+
{
21+
/**
22+
* @var string
23+
*/
24+
protected $_template = 'CM_Payments::system/config/button/check_latest_version.phtml';
25+
26+
/**
27+
* @var ConfigInterface
28+
*/
29+
private $config;
30+
31+
/**
32+
* CheckLatestVersion constructor
33+
*
34+
* @param Context $context
35+
* @param ConfigInterface $config
36+
* @param array $data
37+
*/
38+
public function __construct(
39+
Context $context,
40+
ConfigInterface $config,
41+
array $data = []
42+
) {
43+
parent::__construct($context, $data);
44+
45+
$this->config = $config;
46+
}
47+
48+
/**
49+
* @return ?string
50+
* @throws NoSuchEntityException
51+
*/
52+
public function getCurrentVersion(): ?string
53+
{
54+
return $this->config->getCurrentVersion();
55+
}
56+
57+
/**
58+
* @param AbstractElement $element
59+
* @return string
60+
*/
61+
public function render(AbstractElement $element): string
62+
{
63+
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
64+
65+
return parent::render($element);
66+
}
67+
68+
/**
69+
* @param AbstractElement $element
70+
* @return string
71+
*/
72+
public function _getElementHtml(AbstractElement $element): string
73+
{
74+
return $this->_toHtml();
75+
}
76+
77+
/**
78+
* @return string
79+
*/
80+
public function getCheckLatestVersionUrl(): string
81+
{
82+
return $this->getUrl('cmpayments/action/checkLatestVersion');
83+
}
84+
85+
/**
86+
* @return string
87+
*/
88+
public function getButtonHtml(): string
89+
{
90+
$buttonData = [
91+
'class' => 'cmpayments_button_version',
92+
'label' => __('Check the Latest Version'),
93+
'data_attribute' => ['bind' => 'click: checkLatestVersion']
94+
];
95+
try {
96+
$button = $this->getLayout()->createBlock(
97+
Button::class
98+
)->setData($buttonData);
99+
100+
return $button->toHtml();
101+
} catch (Exception $e) {
102+
return '';
103+
}
104+
}
105+
}

Config/Config.php

Lines changed: 70 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use CM\Payments\Api\Config\ConfigInterface;
1212
use CM\Payments\Model\Adminhtml\Source\Mode;
13+
use CM\Payments\Model\ConfigProvider;
1314
use Magento\Framework\App\Config\ScopeConfigInterface;
1415
use Magento\Store\Model\ScopeInterface;
1516
use Magento\Store\Model\StoreManagerInterface;
@@ -54,35 +55,27 @@ public function isEnabled(): ?bool
5455
}
5556

5657
/**
57-
* Get config value by path
58-
*
59-
* @param string $path
60-
* @param string $scopeType
61-
* @param string|null $scopeCode
62-
* @param bool $isFlag
63-
* @return mixed
58+
* @inheritDoc
6459
*/
65-
private function getConfig(
66-
string $path,
67-
string $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
68-
?string $scopeCode = null,
69-
bool $isFlag = false
70-
) {
71-
return $isFlag ?
72-
$this->scopeConfig->isSetFlag($path, $scopeType, $scopeCode) :
73-
$this->scopeConfig->getValue($path, $scopeType, $scopeCode);
60+
public function getCurrentVersion(): ?string
61+
{
62+
return $this->getConfig(
63+
self::XML_PATH_GENERAL_CURRENT_VERSION,
64+
ScopeInterface::SCOPE_STORES,
65+
(string)$this->storeManager->getStore()->getId()
66+
);
7467
}
7568

7669
/**
7770
* @inheritDoc
7871
*/
79-
public function getMerchantKey(): ?string
72+
public function getMerchantName(): ?string
8073
{
8174
$mode = $this->getMode();
82-
$configPath = self::XML_PATH_GENERAL_TEST_MERCHANT_KEY;
75+
$configPath = self::XML_PATH_GENERAL_TEST_MERCHANT_NAME;
8376

8477
if ($mode == Mode::LIVE) {
85-
$configPath = self::XML_PATH_GENERAL_LIVE_MERCHANT_KEY;
78+
$configPath = self::XML_PATH_GENERAL_LIVE_MERCHANT_NAME;
8679
}
8780

8881
return $this->getConfig(
@@ -95,10 +88,17 @@ public function getMerchantKey(): ?string
9588
/**
9689
* @inheritDoc
9790
*/
98-
public function getMode(): ?string
91+
public function getMerchantPassword(): ?string
9992
{
93+
$mode = $this->getMode();
94+
$configPath = self::XML_PATH_GENERAL_TEST_MERCHANT_PASSWORD;
95+
96+
if ($mode == Mode::LIVE) {
97+
$configPath = self::XML_PATH_GENERAL_LIVE_MERCHANT_PASSWORD;
98+
}
99+
100100
return $this->getConfig(
101-
self::XML_PATH_GENERAL_MODE,
101+
$configPath,
102102
ScopeInterface::SCOPE_STORES,
103103
(string)$this->storeManager->getStore()->getId()
104104
);
@@ -107,13 +107,13 @@ public function getMode(): ?string
107107
/**
108108
* @inheritDoc
109109
*/
110-
public function getMerchantName(): ?string
110+
public function getMerchantKey(): ?string
111111
{
112112
$mode = $this->getMode();
113-
$configPath = self::XML_PATH_GENERAL_TEST_MERCHANT_NAME;
113+
$configPath = self::XML_PATH_GENERAL_TEST_MERCHANT_KEY;
114114

115115
if ($mode == Mode::LIVE) {
116-
$configPath = self::XML_PATH_GENERAL_LIVE_MERCHANT_NAME;
116+
$configPath = self::XML_PATH_GENERAL_LIVE_MERCHANT_KEY;
117117
}
118118

119119
return $this->getConfig(
@@ -126,17 +126,10 @@ public function getMerchantName(): ?string
126126
/**
127127
* @inheritDoc
128128
*/
129-
public function getMerchantPassword(): ?string
129+
public function getMode(): ?string
130130
{
131-
$mode = $this->getMode();
132-
$configPath = self::XML_PATH_GENERAL_TEST_MERCHANT_PASSWORD;
133-
134-
if ($mode == Mode::LIVE) {
135-
$configPath = self::XML_PATH_GENERAL_LIVE_MERCHANT_PASSWORD;
136-
}
137-
138131
return $this->getConfig(
139-
$configPath,
132+
self::XML_PATH_GENERAL_MODE,
140133
ScopeInterface::SCOPE_STORES,
141134
(string)$this->storeManager->getStore()->getId()
142135
);
@@ -145,13 +138,23 @@ public function getMerchantPassword(): ?string
145138
/**
146139
* @inheritDoc
147140
*/
148-
public function getPaymentProfile(): ?string
141+
public function getPaymentProfile(string $paymentMethod): ?string
149142
{
150-
return $this->getConfig(
143+
$defaultPaymentMethod = $this->getConfig(
151144
self::XML_PATH_PAYMENT_PROFILE,
152145
ScopeInterface::SCOPE_STORES,
153146
(string)$this->storeManager->getStore()->getId()
154147
);
148+
149+
if ($paymentMethod == ConfigProvider::CODE_CREDIT_CARD) {
150+
return $this->getCreditCardPaymentProfile() ?? $defaultPaymentMethod;
151+
} elseif ($paymentMethod == ConfigProvider::CODE_BANCONTACT) {
152+
return $this->getBanContactPaymentProfile() ?? $defaultPaymentMethod;
153+
} elseif ($paymentMethod == ConfigProvider::CODE_CM_PAYMENTS_MENU) {
154+
return $this->getCmPaymentsMenuPaymentProfile() ?? $defaultPaymentMethod;
155+
}
156+
157+
return $defaultPaymentMethod;
155158
}
156159

157160
/**
@@ -190,4 +193,36 @@ public function getBanContactPaymentProfile(): ?string
190193
(string)$this->storeManager->getStore()->getId()
191194
);
192195
}
196+
197+
/**
198+
* @inheritDoc
199+
*/
200+
public function getCmPaymentsMenuPaymentProfile(): ?string
201+
{
202+
return $this->getConfig(
203+
ConfigInterface::XML_PATH_PAYMENT_CM_PAYMENTS_PROFILE,
204+
ScopeInterface::SCOPE_STORES,
205+
(string)$this->storeManager->getStore()->getId()
206+
);
207+
}
208+
209+
/**
210+
* Get config value by path
211+
*
212+
* @param string $path
213+
* @param string $scopeType
214+
* @param string|null $scopeCode
215+
* @param bool $isFlag
216+
* @return mixed
217+
*/
218+
private function getConfig(
219+
string $path,
220+
string $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
221+
?string $scopeCode = null,
222+
bool $isFlag = false
223+
) {
224+
return $isFlag ?
225+
$this->scopeConfig->isSetFlag($path, $scopeType, $scopeCode) :
226+
$this->scopeConfig->getValue($path, $scopeType, $scopeCode);
227+
}
193228
}

0 commit comments

Comments
 (0)