Skip to content

Commit 0d5576e

Browse files
author
Alexey Babak
committed
card details update
1 parent c0dcb10 commit 0d5576e

4 files changed

Lines changed: 93 additions & 15 deletions

File tree

src/Authorization.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class Authorization implements AuthorizationInterface
1616
private bool $usePaymentPage = true;
1717
private string $paymentMethod = self::TYPE_CCVISAMC;
1818

19+
/** @var CardDetailsInterface|null Данные карты */
20+
private ?CardDetailsInterface $cardDetails = null;
21+
1922
/**
2023
* Создать Платёжную Авторизацию
2124
* @param string $paymentMethodType Метод оплаты (из справочника)
@@ -74,14 +77,33 @@ public function getPaymentMethod(): string
7477
return $this->paymentMethod;
7578
}
7679

80+
/** @inheritDoc */
81+
public function getCardDetails(): CardDetailsInterface
82+
{
83+
return $this->cardDetails;
84+
}
85+
86+
/** @inheritDoc */
87+
public function setCardDetails(CardDetailsInterface $cardDetails): Authorization
88+
{
89+
$this->cardDetails = $cardDetails;
90+
return $this;
91+
}
92+
7793
/**
7894
* @return array
7995
*/
8096
public function arraySerialize(): array
8197
{
82-
return [
98+
$resultArray = [
8399
'usePaymentPage' => ($this->usePaymentPage ? 'YES' : 'NO'),
84-
'paymentMethod' => $this->paymentMethod,
100+
'paymentMethod' => $this->paymentMethod,
85101
];
102+
103+
if (!is_null($this->cardDetails)) {
104+
$resultArray['cardDetails'] = $this->cardDetails->toArray();
105+
}
106+
107+
return $resultArray;
86108
}
87109
}

src/AuthorizationInterface.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ public function getPaymentMethod(): string;
2424
*/
2525
public function setUsePaymentPage(bool $isUsed) : self;
2626

27+
/**
28+
* Получить Данные Карты
29+
* @return CardDetailsInterface Данные Карты
30+
*/
31+
public function getCardDetails(): CardDetailsInterface;
32+
33+
/**
34+
* Установить Данные Карты
35+
* @param CardDetailsInterface $cardDetails
36+
* @return Authorization
37+
*/
38+
public function setCardDetails(CardDetailsInterface $cardDetails): Authorization;
39+
2740
/**
2841
* Получить Использование платёжной страницы
2942
* @return bool Использование платёжной страницы

src/CardDetails.php

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function getNumber(): string
4444
}
4545

4646
/** @inheritDoc */
47-
public function setNumber(string $number): CardDetails
47+
public function setNumber(string $number): self
4848
{
4949
$this->number = $number;
5050
return $this;
@@ -57,7 +57,7 @@ public function getExpiryMonth(): int
5757
}
5858

5959
/** @inheritDoc */
60-
public function setExpiryMonth(int $expiryMonth): CardDetails
60+
public function setExpiryMonth(int $expiryMonth): self
6161
{
6262
$this->expiryMonth = $expiryMonth;
6363
return $this;
@@ -70,8 +70,12 @@ public function getYear(): int
7070
}
7171

7272
/** @inheritDoc */
73-
public function setYear(int $year): CardDetails
73+
public function setYear(int $year): self
7474
{
75+
if ( $year< 1900) {
76+
throw new PaymentException('Проверьте год выпуска карты');
77+
}
78+
7579
$this->year = $year;
7680
return $this;
7781
}
@@ -83,7 +87,7 @@ public function getExpiryYear(): int
8387
}
8488

8589
/** @inheritDoc */
86-
public function setExpiryYear(int $expiryYear): CardDetails
90+
public function setExpiryYear(int $expiryYear): self
8791
{
8892
$this->expiryYear = $expiryYear;
8993
return $this;
@@ -96,7 +100,7 @@ public function getCvv(): int
96100
}
97101

98102
/** @inheritDoc */
99-
public function setCvv(int $cvv): CardDetails
103+
public function setCvv(int $cvv): self
100104
{
101105
$this->cvv = $cvv;
102106
return $this;
@@ -109,7 +113,7 @@ public function getOwner(): string
109113
}
110114

111115
/** @inheritDoc */
112-
public function setOwner(string $owner): CardDetails
116+
public function setOwner(string $owner): self
113117
{
114118
$this->owner = $owner;
115119
return $this;
@@ -122,7 +126,7 @@ public function getTimeSpentTypingNumber(): int
122126
}
123127

124128
/** @inheritDoc */
125-
public function setTimeSpentTypingNumber(int $timeSpentTypingNumber): CardDetails
129+
public function setTimeSpentTypingNumber(int $timeSpentTypingNumber): self
126130
{
127131
$this->timeSpentTypingNumber = $timeSpentTypingNumber;
128132
return $this;
@@ -135,7 +139,7 @@ public function getTimeSpentTypingOwner(): int
135139
}
136140

137141
/** @inheritDoc */
138-
public function setTimeSpentTypingOwner(int $timeSpentTypingOwner): CardDetails
142+
public function setTimeSpentTypingOwner(int $timeSpentTypingOwner): self
139143
{
140144
$this->timeSpentTypingOwner = $timeSpentTypingOwner;
141145
return $this;
@@ -148,7 +152,7 @@ public function getBin(): int
148152
}
149153

150154
/** @inheritDoc */
151-
public function setBin(int $bin): CardDetails
155+
public function setBin(int $bin): self
152156
{
153157
$this->bin = $bin;
154158
return $this;
@@ -161,7 +165,7 @@ public function getPan(): string
161165
}
162166

163167
/** @inheritDoc */
164-
public function setPan(string $pan): CardDetails
168+
public function setPan(string $pan): self
165169
{
166170
$this->pan = $pan;
167171
return $this;
@@ -174,7 +178,7 @@ public function getType(): string
174178
}
175179

176180
/** @inheritDoc */
177-
public function setType(string $type): CardDetails
181+
public function setType(string $type): self
178182
{
179183
$this->type = $type;
180184
return $this;
@@ -187,9 +191,34 @@ public function getCardIssuerBank(): string
187191
}
188192

189193
/** @inheritDoc */
190-
public function setCardIssuerBank(string $cardIssuerBank): CardDetails
194+
public function setCardIssuerBank(string $cardIssuerBank): self
191195
{
192196
$this->cardIssuerBank = $cardIssuerBank;
193197
return $this;
194198
}
195-
}
199+
200+
/** @inheritDoc */
201+
public function toArray() : array
202+
{
203+
$resultArray = get_object_vars($this);
204+
205+
foreach ($resultArray as &$value) {
206+
if (is_object($value) && method_exists($value, 'toArray')) {
207+
208+
$value = $value->toArray();
209+
210+
} else {
211+
if (is_array($value)) {
212+
foreach ($value as &$arrayValue) {
213+
if (is_object($arrayValue) && method_exists($arrayValue, 'toArray')) {
214+
215+
$arrayValue = $arrayValue->toArray();
216+
}
217+
}
218+
}
219+
}
220+
}
221+
222+
return $resultArray;
223+
}
224+
}

src/CardDetailsInterface.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,18 @@ public function setCardIssuerBank(string $cardIssuerBank) : self;
148148
* @return string Банк, выпустивший карту
149149
*/
150150
public function getCardIssuerBank() : string;
151+
152+
/**
153+
* Получить Год Карты
154+
* @return int Год Карты
155+
*/
156+
public function getYear(): int;
157+
158+
/**
159+
*
160+
* Установить Год Карты
161+
* @param int $year Год Карты
162+
* @return $this Детали Карты
163+
*/
164+
public function setYear(int $year): self;
151165
}

0 commit comments

Comments
 (0)