Skip to content

Commit 169ab5b

Browse files
author
Ruslan Plotnikov
committed
YP-1357 Add storedCredentials block to webhook object
1 parent 4a448b8 commit 169ab5b

6 files changed

Lines changed: 150 additions & 1 deletion

src/Webhook.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class Webhook implements WebhookInterface
1414
/** @var OrderDataInterface Информация о Заказе */
1515
private OrderDataInterface $orderData;
1616

17+
/** @var WebhookAuthorizationInterface Информация об авторизации */
18+
private WebhookAuthorizationInterface $authorization;
19+
1720
/** @inheritDoc */
1821
public function catchJsonRequest(): self
1922
{
@@ -32,7 +35,7 @@ public function catchJsonRequest(): self
3235
$this->orderData->setCurrency($request['orderData']['currency']);
3336
$this->orderData->setAmount($request['orderData']['amount']);
3437
$this->orderData->setCommission((float) $request['orderData']['commission']);
35-
$this->orderData->setLoyaltyPointsAmount((string) $request['orderData']['loyaltyPointsAmount']);
38+
$this->orderData->setLoyaltyPointsAmount((int) $request['orderData']['loyaltyPointsAmount']);
3639
$this->orderData->setLoyaltyPointsDetails((array) $request['orderData']['loyaltyPointsDetails']);
3740

3841
$cardDetails = new CardDetails;
@@ -95,6 +98,23 @@ public function catchJsonRequest(): self
9598
$client->setDelivery($delivery);
9699
}
97100

101+
if (isset($request['authorization']['storedCredentials'])) {
102+
$storedCredentialsArray = $request['authorization']['storedCredentials'];
103+
104+
$storedCredentials = new WebhookStoredCredentials;
105+
106+
if (isset($storedCredentialsArray['ypmnBindingId'])) {
107+
$storedCredentials->setYpmnBindingId($storedCredentialsArray['ypmnBindingId']);
108+
}
109+
110+
if (isset($storedCredentialsArray['useId'])) {
111+
$storedCredentials->setUseId($storedCredentialsArray['useId']);
112+
}
113+
114+
$this->authorization = new WebhookAuthorization;
115+
$this->authorization->setStoredCredentials($storedCredentials);
116+
}
117+
98118
return $this;
99119
}
100120

@@ -123,4 +143,17 @@ public function setOrderData(OrderDataInterface $orderData): self
123143
$this->orderData = $orderData;
124144
return $this;
125145
}
146+
147+
/** @inheritDoc */
148+
public function setAuthorization(WebhookAuthorizationInterface $authorization): self
149+
{
150+
$this->authorization = $authorization;
151+
return $this;
152+
}
153+
154+
/** @inheritDoc */
155+
public function getAuthorization(): WebhookAuthorizationInterface
156+
{
157+
return $this->authorization;
158+
}
126159
}

src/WebhookAuthorization.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Ypmn;
4+
5+
class WebhookAuthorization implements WebhookAuthorizationInterface
6+
{
7+
private WebhookStoredCredentialsInterface $storedCredentials;
8+
9+
/** @inheritDoc */
10+
public function setStoredCredentials(WebhookStoredCredentialsInterface $storedCredentials): self
11+
{
12+
$this->storedCredentials = $storedCredentials;
13+
return $this;
14+
}
15+
16+
/** @inheritDoc */
17+
public function getStoredCredentials(): WebhookStoredCredentialsInterface
18+
{
19+
return $this->storedCredentials;
20+
}
21+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Ypmn;
4+
5+
interface WebhookAuthorizationInterface
6+
{
7+
/**
8+
* Установить объект с учетными данными
9+
* @param WebhookStoredCredentialsInterface $storedCredentials
10+
* @return self
11+
*/
12+
public function setStoredCredentials(WebhookStoredCredentialsInterface $storedCredentials): self;
13+
14+
/**
15+
* Получить объект с учетными данными
16+
* @return WebhookStoredCredentialsInterface
17+
*/
18+
public function getStoredCredentials(): WebhookStoredCredentialsInterface;
19+
}

src/WebhookInterface.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,17 @@ public function getOrderData(): OrderDataInterface;
3636
* @return Webhook
3737
*/
3838
public function setOrderData(OrderDataInterface $orderData): self;
39+
40+
/**
41+
* Установить информацию об авторизации
42+
* @param WebhookAuthorizationInterface $authorization
43+
* @return $this
44+
*/
45+
public function setAuthorization(WebhookAuthorizationInterface $authorization): self;
46+
47+
/**
48+
* Получить информацию об авторизации
49+
* @return WebhookAuthorizationInterface
50+
*/
51+
public function getAuthorization(): WebhookAuthorizationInterface;
3952
}

src/WebhookStoredCredentials.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Ypmn;
4+
5+
class WebhookStoredCredentials implements WebhookStoredCredentialsInterface
6+
{
7+
private string $ypmnBindingId;
8+
private string $useId;
9+
10+
public function setYpmnBindingId(string $ypmnBindingId): self
11+
{
12+
$this->ypmnBindingId = $ypmnBindingId;
13+
return $this;
14+
}
15+
16+
public function getYpmnBindingId(): string
17+
{
18+
return $this->ypmnBindingId;
19+
}
20+
21+
public function setUseId(string $useId): self
22+
{
23+
$this->useId = $useId;
24+
return $this;
25+
}
26+
27+
public function getUseId(): string
28+
{
29+
return $this->useId;
30+
}
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Ypmn;
4+
5+
interface WebhookStoredCredentialsInterface
6+
{
7+
/**
8+
* Установить токен подписки SberPay
9+
* @return $this
10+
* @throws PaymentException Ошибка оплаты
11+
*/
12+
public function setYpmnBindingId(string $ypmnBindingId): self;
13+
14+
/**
15+
* Получить токен подписки SberPay
16+
* @return string
17+
*/
18+
public function getYpmnBindingId(): string;
19+
20+
/**
21+
* Установить идентификатор первоначальной операции
22+
* @param string $useId
23+
* @return self
24+
*/
25+
public function setUseId(string $useId): self;
26+
27+
/**
28+
* Получить идентификатор первоначальной операции
29+
* @return string
30+
*/
31+
public function getUseId(): string;
32+
}

0 commit comments

Comments
 (0)