Skip to content

Commit ff3b7a4

Browse files
author
Ivan Tagil
authored
Merge pull request #32 from Itonomy/feature/CMP-65_configuration-of-order-expiry-time
CMP-65 - Configuration of order expiry time (CM.com)
2 parents e109f73 + bac46e4 commit ff3b7a4

30 files changed

+410
-28
lines changed

Api/Config/ConfigInterface.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,22 @@ public function getBanContactPaymentProfile(): ?string;
116116
* @throws NoSuchEntityException
117117
*/
118118
public function getCmPaymentsMenuPaymentProfile(): ?string;
119+
120+
/**
121+
* Get Order Expiry Unit
122+
*
123+
* @param string $paymentMethodCode
124+
* @return ?string
125+
* @throws NoSuchEntityException
126+
*/
127+
public function getOrderExpiryUnit(string $paymentMethodCode): ?string;
128+
129+
/**
130+
* Get Order Expiry Duration
131+
*
132+
* @param string $paymentMethodCode
133+
* @return ?string
134+
* @throws NoSuchEntityException
135+
*/
136+
public function getOrderExpiryDuration(string $paymentMethodCode): ?string;
119137
}

Api/Service/Order/Request/RequestPartByOrderInterface.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
<?php
2+
/**
3+
* Copyright © CM.com. All rights reserved.
4+
* See LICENSE.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
28

39
namespace CM\Payments\Api\Service\Order\Request;
410

@@ -10,7 +16,6 @@ interface RequestPartByOrderInterface
1016
/**
1117
* @param OrderInterface $order
1218
* @param OrderCreate $orderCreate
13-
*
1419
* @return OrderCreate
1520
*/
1621
public function process(OrderInterface $order, OrderCreate $orderCreate): OrderCreate;

Api/Service/Order/Request/RequestPartByQuoteInterface.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
<?php
2+
/**
3+
* Copyright © CM.com. All rights reserved.
4+
* See LICENSE.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
28

39
namespace CM\Payments\Api\Service\Order\Request;
410

@@ -10,7 +16,6 @@ interface RequestPartByQuoteInterface
1016
/**
1117
* @param CartInterface $quote
1218
* @param OrderCreate $orderCreate
13-
*
1419
* @return OrderCreate
1520
*/
1621
public function process(CartInterface $quote, OrderCreate $orderCreate): OrderCreate;

Client/Model/Request/OrderCreate.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ class OrderCreate
5858
*/
5959
private $returnUrls;
6060

61+
/**
62+
* @var array
63+
*/
64+
private $expiry;
65+
6166
/**
6267
* Order constructor
6368
*
@@ -69,6 +74,7 @@ class OrderCreate
6974
* @param ?string $country
7075
* @param ?string $paymentProfile
7176
* @param ?array $returnUrls
77+
* @param ?array $expiry
7278
*/
7379
public function __construct(
7480
?string $orderId = null,
@@ -78,7 +84,8 @@ public function __construct(
7884
?string $language = null,
7985
?string $country = null,
8086
?string $paymentProfile = null,
81-
?array $returnUrls = null
87+
?array $returnUrls = null,
88+
?array $expiry = null
8289
) {
8390
$this->orderId = $orderId;
8491
$this->amount = $amount;
@@ -88,6 +95,7 @@ public function __construct(
8895
$this->country = $country;
8996
$this->paymentProfile = $paymentProfile;
9097
$this->returnUrls = $returnUrls;
98+
$this->expiry = $expiry;
9199
}
92100

93101
/**
@@ -106,7 +114,8 @@ public function toArray(): array
106114
'language' => $this->language,
107115
'country' => $this->country,
108116
'profile' => $this->paymentProfile,
109-
'return_urls' => $this->returnUrls
117+
'return_urls' => $this->returnUrls,
118+
'expiry' => $this->expiry
110119
]);
111120
}
112121

@@ -237,4 +246,20 @@ public function setReturnUrls(array $returnUrls): void
237246
{
238247
$this->returnUrls = $returnUrls;
239248
}
249+
250+
/**
251+
* @return array
252+
*/
253+
public function getExpiry(): ?array
254+
{
255+
return $this->expiry;
256+
}
257+
258+
/**
259+
* @param array $expiry
260+
*/
261+
public function setExpiry(array $expiry): void
262+
{
263+
$this->expiry = $expiry;
264+
}
240265
}

Config/Config.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,32 @@ public function getCmPaymentsMenuPaymentProfile(): ?string
206206
);
207207
}
208208

209+
/**
210+
* @inheritDoc
211+
*/
212+
public function getOrderExpiryUnit(string $paymentMethodCode): ?string
213+
{
214+
$configPath = "payment/{$paymentMethodCode}/order_expiry_unit";
215+
return $this->getConfig(
216+
$configPath,
217+
ScopeInterface::SCOPE_STORES,
218+
(string)$this->storeManager->getStore()->getId()
219+
);
220+
}
221+
222+
/**
223+
* @inheritDoc
224+
*/
225+
public function getOrderExpiryDuration(string $paymentMethodCode): ?string
226+
{
227+
$configPath = "payment/{$paymentMethodCode}/order_expiry_duration";
228+
return $this->getConfig(
229+
$configPath,
230+
ScopeInterface::SCOPE_STORES,
231+
(string)$this->storeManager->getStore()->getId()
232+
);
233+
}
234+
209235
/**
210236
* Get config value by path
211237
*
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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\Model\Adminhtml\Source;
10+
11+
use Magento\Framework\Data\OptionSourceInterface;
12+
13+
class OrderExpiryUnit implements OptionSourceInterface
14+
{
15+
/**
16+
* Units
17+
*/
18+
public const MINUTES = 'MINUTES';
19+
public const HOURS = 'HOURS';
20+
public const DAYS = 'DAYS';
21+
22+
/**
23+
* Options array
24+
*
25+
* @var array
26+
*/
27+
public $options = null;
28+
29+
/**
30+
* Test/Live Key Array
31+
*
32+
* @return array
33+
*/
34+
public function toOptionArray()
35+
{
36+
if (!$this->options) {
37+
$this->options = [
38+
['value' => self::MINUTES, 'label' => __('Minutes')],
39+
['value' => self::HOURS, 'label' => __('Hours')],
40+
['value' => self::DAYS, 'label' => __('Days')]
41+
];
42+
43+
array_unshift($this->options, ['value' => '', 'label' => __('None')]);
44+
}
45+
46+
return $this->options;
47+
}
48+
}

Service/Order/Request/Part/Amount.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See LICENSE.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace CM\Payments\Service\Order\Request\Part;
810

911
use CM\Payments\Api\Service\Order\Request\RequestPartByOrderInterface;

Service/Order/Request/Part/Country.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See LICENSE.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace CM\Payments\Service\Order\Request\Part;
810

911
use CM\Payments\Api\Service\Order\Request\RequestPartByOrderInterface;

Service/Order/Request/Part/Currency.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See LICENSE.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace CM\Payments\Service\Order\Request\Part;
810

911
use CM\Payments\Api\Service\Order\Request\RequestPartByOrderInterface;

Service/Order/Request/Part/Email.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See LICENSE.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace CM\Payments\Service\Order\Request\Part;
810

911
use CM\Payments\Api\Service\Order\Request\RequestPartByOrderInterface;

Service/Order/Request/Part/Expiry.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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\Service\Order\Request\Part;
10+
11+
use CM\Payments\Api\Config\ConfigInterface;
12+
use CM\Payments\Api\Service\Order\Request\RequestPartByOrderInterface;
13+
use CM\Payments\Client\Model\Request\OrderCreate;
14+
use Magento\Framework\Exception\NoSuchEntityException;
15+
use Magento\Sales\Api\Data\OrderInterface;
16+
17+
class Expiry implements RequestPartByOrderInterface
18+
{
19+
/**
20+
* @var ConfigInterface
21+
*/
22+
private $config;
23+
24+
/**
25+
* Expiry constructor
26+
*
27+
* @param ConfigInterface $config
28+
*/
29+
public function __construct(ConfigInterface $config)
30+
{
31+
$this->config = $config;
32+
}
33+
34+
/**
35+
* @inheritDoc
36+
*/
37+
public function process(OrderInterface $order, OrderCreate $orderCreate): OrderCreate
38+
{
39+
try {
40+
$method = $order->getPayment()->getMethod();
41+
$orderExpiryUnit = $this->config->getOrderExpiryUnit($method);
42+
$orderExpiryDuration = $this->config->getOrderExpiryDuration($method);
43+
44+
$expiry = [];
45+
if ($orderExpiryUnit && $orderExpiryDuration) {
46+
$expiry = [
47+
'expire_after' => [
48+
'unit' => $orderExpiryUnit,
49+
'duration' => $orderExpiryDuration
50+
]
51+
];
52+
}
53+
54+
$orderCreate->setExpiry($expiry);
55+
} catch (NoSuchEntityException $e) {
56+
$orderCreate->setExpiry([]);
57+
}
58+
59+
return $orderCreate;
60+
}
61+
}

Service/Order/Request/Part/Language.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class Language implements RequestPartByOrderInterface
1919
private $localeResolver;
2020

2121
/**
22-
* Language constructor.
22+
* Language constructor
23+
*
2324
* @param ResolverInterface $localeResolver
2425
*/
2526
public function __construct(ResolverInterface $localeResolver)

Service/Order/Request/Part/OrderId.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See LICENSE.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace CM\Payments\Service\Order\Request\Part;
810

911
use CM\Payments\Api\Service\Order\Request\RequestPartByOrderInterface;

Service/Order/Request/Part/PaymentProfile.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See LICENSE.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace CM\Payments\Service\Order\Request\Part;
810

911
use CM\Payments\Api\Config\ConfigInterface;
@@ -19,7 +21,8 @@ class PaymentProfile implements RequestPartByOrderInterface
1921
private $config;
2022

2123
/**
22-
* Currency constructor.
24+
* PaymentProfile constructor
25+
*
2326
* @param ConfigInterface $config
2427
*/
2528
public function __construct(ConfigInterface $config)

Service/Order/Request/Part/ReturnUrls.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See LICENSE.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace CM\Payments\Service\Order\Request\Part;
810

911
use CM\Payments\Api\Service\Order\Request\RequestPartByOrderInterface;
@@ -20,7 +22,8 @@ class ReturnUrls implements RequestPartByOrderInterface
2022
private $urlBuilder;
2123

2224
/**
23-
* ReturnUrls constructor.
25+
* ReturnUrls constructor
26+
*
2427
* @param UrlInterface $urlBuilder
2528
*/
2629
public function __construct(UrlInterface $urlBuilder)

Service/Quote/Request/Part/Amount.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See LICENSE.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace CM\Payments\Service\Quote\Request\Part;
810

911
use CM\Payments\Api\Service\Order\Request\RequestPartByQuoteInterface;

Service/Quote/Request/Part/Country.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See LICENSE.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace CM\Payments\Service\Quote\Request\Part;
810

911
use CM\Payments\Api\Service\Order\Request\RequestPartByQuoteInterface;

Service/Quote/Request/Part/Currency.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See LICENSE.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace CM\Payments\Service\Quote\Request\Part;
810

911
use CM\Payments\Api\Service\Order\Request\RequestPartByQuoteInterface;

0 commit comments

Comments
 (0)