Skip to content

Commit 266bf84

Browse files
author
Alexey Babak
committed
added orderTimeout (in seconds)
1 parent 45e5a06 commit 266bf84

File tree

4 files changed

+110
-8
lines changed

4 files changed

+110
-8
lines changed

src/Authorization.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class Authorization implements AuthorizationInterface
2020
/** @var MerchantTokenInterface|null Данные карты (в виде токена) */
2121
private ?MerchantTokenInterface $merchantToken = null;
2222

23+
/** @var PaymentPageOptions|null */
24+
private ?PaymentPageOptions $paymentPageOptions = null;
25+
2326
/**
2427
* Создать Платёжную Авторизацию
2528
* @param string $paymentMethodType Метод оплаты (из справочника)
@@ -111,14 +114,6 @@ public function getMerchantToken(): ?MerchantTokenInterface
111114
*/
112115
public function setMerchantToken(?MerchantTokenInterface $merchantToken): self
113116
{
114-
if (!is_null($this->getCardDetails())){
115-
echo "Сработало 1 условие";
116-
var_dump($this->getCardDetails());
117-
}
118-
if ($this->getUsePaymentPage() !== false){
119-
echo "Сработало 2 условие";
120-
var_dump($this->getUsePaymentPage());
121-
}
122117
if (is_null($this->getCardDetails()) && $this->getUsePaymentPage() === false) {
123118
$this->merchantToken = $merchantToken;
124119

@@ -128,6 +123,20 @@ public function setMerchantToken(?MerchantTokenInterface $merchantToken): self
128123
}
129124
}
130125

126+
/** @inheritDoc */
127+
public function setPaymentPageOptions(PaymentPageOptionsInterface $paymentPageOptions): self
128+
{
129+
$this->paymentPageOptions = $paymentPageOptions;
130+
131+
return $this;
132+
}
133+
134+
/** @inheritDoc */
135+
public function getPaymentPageOptions(): PaymentPageOptionsInterface
136+
{
137+
return $this->paymentPageOptions;
138+
}
139+
131140
/**
132141
* @return array
133142
*/
@@ -146,6 +155,10 @@ public function arraySerialize(): array
146155
$resultArray['merchantToken'] = $this->merchantToken->toArray();
147156
}
148157

158+
if (!is_null($this->paymentPageOptions) && $this->paymentPageOptions->getOrderTimeout() > 0) {
159+
$resultArray['paymentPageOptions'] = $this->paymentPageOptions->toArray();
160+
}
161+
149162
return $resultArray;
150163
}
151164
}

src/AuthorizationInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,13 @@ public function getMerchantToken(): ?MerchantTokenInterface;
5555
* @return $this
5656
*/
5757
public function setMerchantToken(?MerchantTokenInterface $merchantToken): self;
58+
59+
/**
60+
* Установить настройки платёжной страницы
61+
* @param paymentPageOptionsInterface $paymentPageOptions
62+
* @return $this
63+
*/
64+
public function setPaymentPageOptions(PaymentPageOptionsInterface $paymentPageOptions): self;
65+
66+
public function getPaymentPageOptions(): PaymentPageOptionsInterface;
5867
}

src/PaymentPageOptions.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Ypmn;
6+
7+
/**
8+
* Это файл класса для настройки платёжной страницы
9+
**/
10+
class PaymentPageOptions implements PaymentPageOptionsInterface
11+
{
12+
/** @var int минимальное время на оплату заказа */
13+
const MIN_ORDER_TIMEOUT_SECONDS = 60;
14+
15+
/** @var int|null максимальное время оплаты товара (в сек) */
16+
protected ?int $timeoutSeconds = null;
17+
18+
/** @throws PaymentException */
19+
public function __construct($timeoutSeconds)
20+
{
21+
$this->setOrderTimeout($timeoutSeconds);
22+
}
23+
24+
/** @inheritDoc */
25+
public function setOrderTimeout(int $timeoutSeconds): paymentPageOptionsInterface
26+
{
27+
if ($timeoutSeconds < self::MIN_ORDER_TIMEOUT_SECONDS) {
28+
throw new PaymentException($timeoutSeconds . ' -- слишком маленькое время для оплаты заказа (в секундах)');
29+
}
30+
$this->timeoutSeconds = $timeoutSeconds;
31+
32+
return $this;
33+
}
34+
35+
/** @inheritDoc */
36+
public function getOrderTimeout(): int
37+
{
38+
return $this->timeoutSeconds;
39+
}
40+
41+
/** @inheritDoc */
42+
public function toArray(): array
43+
{
44+
return [
45+
'orderTimeout' => $this->getOrderTimeout(),
46+
];
47+
}
48+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Ypmn;
6+
7+
/**
8+
* Это файл интерфейса для настройки платёжной страницы
9+
**/
10+
interface PaymentPageOptionsInterface
11+
{
12+
/**
13+
* Установить максимальное время оплаты заказа
14+
* В секундах, со времени создания
15+
* @param int $timeoutSeconds
16+
* @return $this
17+
* @throws PaymentException
18+
*/
19+
public function setOrderTimeout(int $timeoutSeconds): self;
20+
21+
/**
22+
* Получить максимальное время оплаты заказа
23+
* В секундах, со времени создания
24+
* @return int
25+
*/
26+
public function getOrderTimeout(): int;
27+
28+
/**
29+
* @return array
30+
*/
31+
public function toArray(): array;
32+
}

0 commit comments

Comments
 (0)