Skip to content

Commit 520f0ba

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 00d0619 + 1694879 commit 520f0ba

File tree

15 files changed

+840
-60
lines changed

15 files changed

+840
-60
lines changed

Api/Config/ConfigInterface.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ interface ConfigInterface
1515
/**
1616
* XML Paths of configuration settings
1717
*/
18-
public const XML_PATH_GENERAL_ENABLED = 'payment/cm_payments_general/enabled';
19-
public const XML_PATH_GENERAL_TEST_MERCHANT_KEY = 'payment/cm_payments_general/test_merchant_key';
20-
public const XML_PATH_GENERAL_TEST_MERCHANT_NAME = 'payment/cm_payments_general/test_merchant_name';
21-
public const XML_PATH_GENERAL_TEST_MERCHANT_PASSWORD = 'payment/cm_payments_general/test_merchant_password';
22-
public const XML_PATH_GENERAL_LIVE_MERCHANT_KEY = 'payment/cm_payments_general/live_merchant_key';
23-
public const XML_PATH_GENERAL_LIVE_MERCHANT_NAME = 'payment/cm_payments_general/live_merchant_name';
24-
public const XML_PATH_GENERAL_LIVE_MERCHANT_PASSWORD = 'payment/cm_payments_general/live_merchant_password';
25-
public const XML_PATH_GENERAL_MODE = 'payment/cm_payments_general/mode';
18+
public const XML_PATH_GENERAL_ENABLED = 'cm_payments/general/enabled';
19+
public const XML_PATH_GENERAL_TEST_MERCHANT_NAME = 'cm_payments/general/test_merchant_name';
20+
public const XML_PATH_GENERAL_TEST_MERCHANT_PASSWORD = 'cm_payments/general/test_merchant_password';
21+
public const XML_PATH_GENERAL_TEST_MERCHANT_KEY = 'cm_payments/general/test_merchant_key';
22+
public const XML_PATH_GENERAL_LIVE_MERCHANT_NAME = 'cm_payments/general/live_merchant_name';
23+
public const XML_PATH_GENERAL_LIVE_MERCHANT_PASSWORD = 'cm_payments/general/live_merchant_password';
24+
public const XML_PATH_GENERAL_LIVE_MERCHANT_KEY = 'cm_payments/general/live_merchant_key';
25+
public const XML_PATH_GENERAL_MODE = 'cm_payments/general/mode';
2626
public const XML_PATH_PAYMENT_PROFILE = 'payment/cm_payments_methods/profile';
2727
public const XML_PATH_PAYMENT_CREDIT_CARD_PROFILE = 'payment/cm_payments_creditcard/profile';
2828
public const XML_PATH_PAYMENT_BANCONTACT_PROFILE = 'payment/cm_payments_bancontact/profile';

Client/Api/OrderInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
use CM\Payments\Client\Model\Response\OrderCreate;
1212
use CM\Payments\Client\Model\Response\OrderDetail;
13+
use CM\Payments\Client\Model\Response\PaymentMethod;
1314
use CM\Payments\Client\Request\OrderCreateRequest;
15+
use CM\Payments\Client\Request\OrderGetMethodsRequest;
1416
use GuzzleHttp\Exception\RequestException;
1517

1618
interface OrderInterface
@@ -23,6 +25,14 @@ interface OrderInterface
2325
*/
2426
public function getDetail(string $orderKey): OrderDetail;
2527

28+
/**
29+
* @param string $orderKey
30+
* @return PaymentMethod[]
31+
*
32+
* @throws RequestException
33+
*/
34+
public function getMethods(string $orderKey): array;
35+
2636
/**
2737
* @param OrderCreateRequest $orderCreateRequest
2838
* @return OrderCreate
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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\Client\Model\Response\Method;
10+
11+
class IdealIssuer
12+
{
13+
/**
14+
* @var string
15+
*/
16+
private $id;
17+
18+
/**
19+
* @var string
20+
*/
21+
private $name;
22+
23+
/**
24+
* Authorization constructor.
25+
* @param array $authorization
26+
*/
27+
public function __construct(
28+
array $issuer
29+
) {
30+
$this->id = $issuer['id'];
31+
$this->name = $issuer['name'];
32+
}
33+
34+
/**
35+
* @return string
36+
*/
37+
public function getId(): string
38+
{
39+
return $this->id;
40+
}
41+
42+
/**
43+
* @return string
44+
*/
45+
public function getName(): string
46+
{
47+
return $this->name;
48+
}
49+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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\Client\Model\Response;
10+
11+
use CM\Payments\Client\Model\Response\Method\IdealIssuer;
12+
13+
class PaymentMethod
14+
{
15+
/**
16+
* @var string|null
17+
*/
18+
private $method;
19+
20+
/**
21+
* @var IdealIssuer[]
22+
*/
23+
private $idealIssuers;
24+
25+
/**
26+
* PaymentMethod constructor
27+
*
28+
* @param array $orderCreate
29+
*/
30+
public function __construct(
31+
array $method
32+
) {
33+
$this->method = $method['method'];
34+
$this->idealIssuers = isset($method['ideal_details']) ?
35+
$this->mapIssuers($method['ideal_details']['issuers']) : [];
36+
}
37+
38+
/**
39+
* @return string|null
40+
*/
41+
public function getMethod(): ?string
42+
{
43+
return $this->method;
44+
}
45+
46+
/**
47+
* @return IdealIssuer[]
48+
*/
49+
public function getIdealIssuers(): array
50+
{
51+
return $this->idealIssuers;
52+
}
53+
54+
/**
55+
* @param array $issuers
56+
* @return IdealIssuer[]
57+
*/
58+
private function mapIssuers(array $issuers): array
59+
{
60+
return array_map(function ($issuer) {
61+
return new IdealIssuer($issuer);
62+
}, $issuers);
63+
}
64+
}

Client/Order.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
use CM\Payments\Client\Api\OrderInterface;
1313
use CM\Payments\Client\Model\Response\OrderCreate;
1414
use CM\Payments\Client\Model\Response\OrderDetail;
15+
use CM\Payments\Client\Model\Response\PaymentMethod;
1516
use CM\Payments\Client\Request\OrderCreateRequest;
17+
use CM\Payments\Client\Request\OrderGetMethodsRequest;
1618
use CM\Payments\Client\Request\OrderGetRequest;
1719
use GuzzleHttp\Exception\RequestException;
1820

@@ -49,6 +51,22 @@ public function getDetail(string $orderKey): OrderDetail
4951
return new OrderDetail($response);
5052
}
5153

54+
/**
55+
* @inheritDoc
56+
*/
57+
public function getMethods(string $orderKey): array
58+
{
59+
$orderGetRequest = new OrderGetMethodsRequest($orderKey);
60+
61+
$response = $this->apiClient->execute(
62+
$orderGetRequest
63+
);
64+
65+
return array_map(function ($method) {
66+
return new PaymentMethod($method);
67+
}, $response);
68+
}
69+
5270
/**
5371
* @inheritDoc
5472
*/
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright © CM.com. All rights reserved.
4+
* See LICENSE.txt for license details.
5+
*/
6+
namespace CM\Payments\Gateway\Validator;
7+
8+
use Magento\Payment\Gateway\ConfigInterface;
9+
use Magento\Payment\Gateway\Validator\AbstractValidator;
10+
use Magento\Payment\Gateway\Validator\ResultInterface;
11+
use Magento\Payment\Gateway\Validator\ResultInterfaceFactory;
12+
13+
class CurrencyValidator extends AbstractValidator
14+
{
15+
/**
16+
* @var \Magento\Payment\Gateway\ConfigInterface
17+
*/
18+
private $config;
19+
20+
/**
21+
* @param ResultInterfaceFactory $resultFactory
22+
* @param \Magento\Payment\Gateway\ConfigInterface $config
23+
*/
24+
public function __construct(
25+
ResultInterfaceFactory $resultFactory,
26+
ConfigInterface $config
27+
) {
28+
$this->config = $config;
29+
parent::__construct($resultFactory);
30+
}
31+
32+
/**
33+
* @param array $validationSubject
34+
* @return ResultInterface
35+
*/
36+
public function validate(array $validationSubject)
37+
{
38+
$storeId = $validationSubject['storeId'];
39+
40+
if ((int)$this->config->getValue('allow_specific_currency', $storeId) !== 1) {
41+
return $this->createResult(true);
42+
}
43+
44+
$availableCurrencies = $this->getAvailableCurrencies($storeId);
45+
if (!empty($availableCurrencies) && !in_array($validationSubject['currency'], $availableCurrencies)) {
46+
return $this->createResult(false);
47+
}
48+
49+
return $this->createResult(true);
50+
}
51+
52+
/**
53+
* @param string $storeId
54+
*
55+
* @return string[]
56+
*/
57+
private function getAvailableCurrencies(string $storeId): array
58+
{
59+
$specificCurrency = $this->config->getValue('specific_currency', $storeId);
60+
if (empty($specificCurrency)) {
61+
return [];
62+
}
63+
64+
return explode(',', $specificCurrency);
65+
}
66+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Copyright © CM.com. All rights reserved.
4+
* See LICENSE.txt for license details.
5+
*/
6+
namespace CM\Payments\Model\AdminHtml\Source;
7+
8+
class AllSpecificCurrencies implements \Magento\Framework\Option\ArrayInterface
9+
{
10+
/**
11+
* {@inheritdoc}
12+
*/
13+
public function toOptionArray()
14+
{
15+
return [
16+
['value' => 0, 'label' => __('All Allowed Currencies')],
17+
['value' => 1, 'label' => __('Specific Currencies')]
18+
];
19+
}
20+
}

Model/Adminhtml/Source/Currency.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © CM.com. All rights reserved.
4+
* See LICENSE.txt for license details.
5+
*/
6+
namespace CM\Payments\Model\AdminHtml\Source;
7+
8+
class Currency implements \Magento\Framework\Option\ArrayInterface
9+
{
10+
/**
11+
* Countries
12+
*
13+
* @var \Magento\Directory\Model\Currency
14+
*/
15+
protected $currencyModel;
16+
17+
/**
18+
* Options array
19+
*
20+
* @var array
21+
*/
22+
protected $options;
23+
24+
/**
25+
* @param \Magento\Directory\Model\Currency $currency
26+
*/
27+
public function __construct(\Magento\Directory\Model\Currency $currency)
28+
{
29+
$this->currencyModel = $currency;
30+
}
31+
32+
/**
33+
* Return options array
34+
*
35+
* @param boolean $isMultiselect
36+
* @param string|array $foregroundCountries
37+
* @return array
38+
*/
39+
public function toOptionArray($isMultiselect = false, $foregroundCountries = '')
40+
{
41+
if (!$this->options) {
42+
$this->options = array_map(function ($currency) {
43+
return ['value' => $currency, 'label' => $currency];
44+
}, $this->currencyModel->getConfigAllowCurrencies());
45+
}
46+
47+
$options = $this->options;
48+
49+
if (!$isMultiselect) {
50+
array_unshift($options, ['value' => '', 'label' => __('--Please Select--')]);
51+
}
52+
53+
return $options;
54+
}
55+
}

0 commit comments

Comments
 (0)