Skip to content

Commit 3f7506f

Browse files
author
Alexey Babak
committed
merchant tokens added
1 parent 0d5576e commit 3f7506f

File tree

4 files changed

+188
-16
lines changed

4 files changed

+188
-16
lines changed

src/Authorization.php

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class Authorization implements AuthorizationInterface
1919
/** @var CardDetailsInterface|null Данные карты */
2020
private ?CardDetailsInterface $cardDetails = null;
2121

22+
/** @var MerchantTokenInterface|null Данные карты (в виде токена) */
23+
private ?MerchantTokenInterface $merchantToken = null;
24+
2225
/**
2326
* Создать Платёжную Авторизацию
2427
* @param string $paymentMethodType Метод оплаты (из справочника)
@@ -33,7 +36,7 @@ public function __constructor(string $paymentMethodType, bool $isUsed) {
3336

3437
/**
3538
* @inheritDoc
36-
* @throws PaymentException Ощибка оплаты
39+
* @throws PaymentException Ошибка оплаты
3740
*/
3841
public function setPaymentMethod(string $paymentMethodType) : self
3942
{
@@ -51,27 +54,29 @@ public function setPaymentMethod(string $paymentMethodType) : self
5154
return $this;
5255
}
5356

54-
/**
55-
* @param bool $isUsed
56-
* @return $this
57-
*/
57+
/** @inheritDoc */
5858
public function setUsePaymentPage(bool $isUsed) : self
5959
{
60-
$this->usePaymentPage = $isUsed;
60+
if ($isUsed === true) {
61+
if (is_null($this->merchantToken) && is_null($this->cardDetails)) {
62+
$this->usePaymentPage = $isUsed;
63+
} else {
64+
throw new PaymentException('For using PaymentPage need to make MerchantToken = NULL and CardDetails = NULL');
65+
}
66+
} else {
67+
$this->usePaymentPage = $isUsed;
68+
}
69+
6170
return $this;
6271
}
6372

64-
/**
65-
* @inheritDoc
66-
*/
73+
/** @inheritDoc */
6774
public function getUsePaymentPage(): bool
6875
{
6976
return $this->usePaymentPage;
7077
}
7178

72-
/**
73-
* @return string
74-
*/
79+
/** @inheritDoc */
7580
public function getPaymentMethod(): string
7681
{
7782
return $this->paymentMethod;
@@ -84,10 +89,36 @@ public function getCardDetails(): CardDetailsInterface
8489
}
8590

8691
/** @inheritDoc */
87-
public function setCardDetails(CardDetailsInterface $cardDetails): Authorization
92+
public function setCardDetails(CardDetailsInterface $cardDetails): self
8893
{
89-
$this->cardDetails = $cardDetails;
90-
return $this;
94+
if (is_null($this->merchantToken) && $this->usePaymentPage === false) {
95+
$this->cardDetails = $cardDetails;
96+
97+
return $this;
98+
} else {
99+
throw new PaymentException('For using CardDetails need to make MerchantToken = NULL and usePaymentPage = false');
100+
}
101+
}
102+
103+
/** @inheritDoc */
104+
public function getMerchantToken(): ?MerchantTokenInterface
105+
{
106+
return $this->merchantToken;
107+
}
108+
109+
/**
110+
* @inheritDoc
111+
* @throws PaymentException
112+
*/
113+
public function setMerchantToken(?MerchantTokenInterface $merchantToken): self
114+
{
115+
if (is_null($this->getCardDetails()) && $this->getUsePaymentPage() === false) {
116+
$this->merchantToken = $merchantToken;
117+
118+
return $this;
119+
} else {
120+
throw new PaymentException('For using MerchantToken need to make CardDetails = NULL and usePaymentPage = false');
121+
}
91122
}
92123

93124
/**
@@ -104,6 +135,10 @@ public function arraySerialize(): array
104135
$resultArray['cardDetails'] = $this->cardDetails->toArray();
105136
}
106137

138+
if (!is_null($this->merchantToken)) {
139+
$resultArray['merchantToken'] = $this->merchantToken->toArray();
140+
}
141+
107142
return $resultArray;
108143
}
109144
}

src/AuthorizationInterface.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,24 @@ public function getCardDetails(): CardDetailsInterface;
3535
* @param CardDetailsInterface $cardDetails
3636
* @return Authorization
3737
*/
38-
public function setCardDetails(CardDetailsInterface $cardDetails): Authorization;
38+
public function setCardDetails(CardDetailsInterface $cardDetails): self;
3939

4040
/**
4141
* Получить Использование платёжной страницы
4242
* @return bool Использование платёжной страницы
4343
*/
4444
public function getUsePaymentPage() : bool;
45+
46+
/**
47+
* Получить Токен мерчанта
48+
* @return MerchantTokenInterface|null Токен мерчанта
49+
*/
50+
public function getMerchantToken(): ?MerchantTokenInterface;
51+
52+
/**
53+
* Установить Токен мерчанта
54+
* @param MerchantTokenInterface|null $merchantToken Токен мерчанта
55+
* @return $this
56+
*/
57+
public function setMerchantToken(?MerchantTokenInterface $merchantToken): self;
4558
}

src/MerchantToken.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace payuru\phpPayu4;
4+
5+
class MerchantToken implements MerchantTokenInterface
6+
{
7+
/** @var string Хэш Токен карты */
8+
private string $tokenHash;
9+
10+
/** @var int CVV Карты */
11+
private int $cvv;
12+
13+
/** @var string Имя Владельца Карты */
14+
private string $owner;
15+
16+
/** @inheritDoc */
17+
public function getTokenHash(): string
18+
{
19+
return $this->tokenHash;
20+
}
21+
22+
/** @inheritDoc */
23+
public function setTokenHash(string $tokenHash): MerchantToken
24+
{
25+
$this->tokenHash = $tokenHash;
26+
return $this;
27+
}
28+
29+
/** @inheritDoc */
30+
public function getCvv(): int
31+
{
32+
return $this->cvv;
33+
}
34+
35+
/** @inheritDoc */
36+
public function setCvv(int $cvv): MerchantToken
37+
{
38+
$this->cvv = $cvv;
39+
return $this;
40+
}
41+
42+
/** @inheritDoc */
43+
public function getOwner(): string
44+
{
45+
return $this->owner;
46+
}
47+
48+
/** @inheritDoc */
49+
public function setOwner(string $owner): MerchantToken
50+
{
51+
$this->owner = $owner;
52+
return $this;
53+
}
54+
55+
/** @inheritDoc */
56+
public function toArray() : array
57+
{
58+
$resultArray = get_object_vars($this);
59+
60+
foreach ($resultArray as &$value) {
61+
if (is_object($value) && method_exists($value, 'toArray')) {
62+
63+
$value = $value->toArray();
64+
65+
} else {
66+
if (is_array($value)) {
67+
foreach ($value as &$arrayValue) {
68+
if (is_object($arrayValue) && method_exists($arrayValue, 'toArray')) {
69+
70+
$arrayValue = $arrayValue->toArray();
71+
}
72+
}
73+
}
74+
}
75+
}
76+
77+
return $resultArray;
78+
}
79+
}

src/MerchantTokenInterface.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace payuru\phpPayu4;
4+
5+
interface MerchantTokenInterface
6+
{
7+
/**
8+
* Установить Хэш Токен карты
9+
* @param string $tokenHash Хэш Токен карты
10+
* @return $this
11+
*/
12+
public function setTokenHash(string $tokenHash) : self;
13+
14+
/**
15+
* Получить Хэш Токен карты
16+
* @return string $tokenHash Хэш Токен карты
17+
*/
18+
public function getTokenHash() : string;
19+
20+
/**
21+
* Установить CVV Карты
22+
* @param int $cvv CVV Карты
23+
* @return $this
24+
*/
25+
public function setCvv(int $cvv) : self;
26+
27+
/**
28+
* Получить CVV Карты
29+
* @return int CVV Карты
30+
*/
31+
public function getCvv() : int;
32+
33+
/**
34+
* Установить Имя Владельца Карты
35+
* @param string $owner Имя Владельца Карты
36+
* @return $this
37+
*/
38+
public function setOwner(string $owner) : self;
39+
40+
/**
41+
* Получить Имя Владельца Карты
42+
* @return string Имя Владельца Карты
43+
*/
44+
public function getOwner() : string;
45+
}

0 commit comments

Comments
 (0)