Skip to content

Commit 56a8872

Browse files
authored
Merge pull request #6 from yourpayments/YP-317_v4
YP-317 new behavior for sbp
2 parents 6eb6285 + 22d5c66 commit 56a8872

9 files changed

+252
-54
lines changed

src/CardDetailsInterface.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,8 @@
22

33
namespace Ypmn;
44

5-
interface CardDetailsInterface
5+
interface CardDetailsInterface extends DetailsInterface
66
{
7-
/**
8-
* Установить Номер карты
9-
* @param string $number Номер карты
10-
* @return $this
11-
*/
12-
public function setNumber(string $number) : self;
13-
14-
/**
15-
* Получить Номер карты
16-
* @return string Номер карты
17-
*/
18-
public function getNumber() : string;
19-
207
/**
218
* Установить Месяц прекращения действия Карты
229
* @param int $expiryMonth Месяц прекращения действия Карты

src/DestinationInterface.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Ypmn;
4+
5+
interface DestinationInterface
6+
{
7+
/**
8+
* Получить Тип направления платежа
9+
* @return string
10+
*/
11+
public function getType(): string;
12+
13+
/**
14+
* Установить Тип направления платежа
15+
* @param string $type
16+
* @return PayoutDestination
17+
* @throws PaymentException
18+
*/
19+
public function setType(string $type): self;
20+
21+
public function arraySerialize() : array;
22+
23+
public function getDetails(): ?DetailsInterface;
24+
25+
public function setDetails(?DetailsInterface $details): self;
26+
27+
/**
28+
* Получить биллинговую информацию о Получателе платежа
29+
* @return Billing|null
30+
*/
31+
public function getRecipient(): ?Billing;
32+
33+
/**
34+
* Установить биллинговую информацию о Получателе платежа
35+
* @param Billing|null $recipient
36+
* @return PayoutDestination
37+
*/
38+
public function setRecipient(?Billing $recipient): self;
39+
}

src/DetailsInterface.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Ypmn;
4+
5+
interface DetailsInterface
6+
{
7+
/**
8+
* Установить Номер карты
9+
* @param string $number Номер карты
10+
* @return $this
11+
*/
12+
public function setNumber(string $number) : self;
13+
14+
/**
15+
* Получить Номер карты
16+
* @return string Номер карты
17+
*/
18+
public function getNumber() : string;
19+
}

src/Payout.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Payout implements PayoutInterface, \JsonSerializable
1010
private ?string $merchantPayoutReference;
1111
private ?Amount $amount = null;
1212
private ?string $description;
13-
private ?PayoutDestination $destination;
13+
private ?DestinationInterface $destination;
1414
private ?PayoutSource $source;
1515

1616
public function __construct(string $merchantPayoutReference = null)
@@ -58,13 +58,13 @@ public function setDescription(?string $description): self
5858
}
5959

6060
/** @inheritdoc */
61-
public function getDestination(): ?PayoutDestination
61+
public function getDestination(): ?DestinationInterface
6262
{
6363
return $this->destination;
6464
}
6565

6666
/** @inheritdoc */
67-
public function setDestination(?PayoutDestination $destination): self
67+
public function setDestination(?DestinationInterface $destination): self
6868
{
6969
$this->destination = $destination;
7070
return $this;

src/PayoutDestination.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ public function setCard(?CardDetails $card): self
5757
return $this;
5858
}
5959

60+
/** @inheritdoc */
61+
public function getDetails(): ?DetailsInterface
62+
{
63+
return $this->card;
64+
}
65+
66+
/** @inheritdoc */
67+
public function setDetails(?DetailsInterface $details): self
68+
{
69+
$this->card = $details;
70+
71+
return $this;
72+
}
73+
6074
/** @inheritdoc */
6175
public function getRecipient(): ?Billing
6276
{

src/PayoutDestinationInterface.php

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,8 @@
22

33
namespace Ypmn;
44

5-
interface PayoutDestinationInterface
5+
interface PayoutDestinationInterface extends DestinationInterface
66
{
7-
8-
/**
9-
* Получить Тип направления платежа
10-
* @return string
11-
*/
12-
public function getType(): string;
13-
14-
/**
15-
* Установить Тип направления платежа
16-
* @param string $type
17-
* @return PayoutDestination
18-
* @throws PaymentException
19-
*/
20-
public function setType(string $type): self;
21-
227
/**
238
* Получить Информацию о карте
249
* @return CardDetails|null
@@ -32,26 +17,10 @@ public function getCard(): ?CardDetails;
3217
*/
3318
public function setCard(?CardDetails $card): self;
3419

35-
/**
36-
* Получить биллинговую информацию о Получателе платежа
37-
* @return Billing|null
38-
*/
39-
public function getRecipient(): ?Billing;
40-
41-
/**
42-
* Установить биллинговую информацию о Получателе платежа
43-
* @param Billing|null $recipient
44-
* @return PayoutDestination
45-
*/
46-
public function setRecipient(?Billing $recipient): self;
47-
48-
4920
/**
5021
* Установить номер карты
5122
* @param string $cardNumber
5223
* @return PayoutDestination
5324
*/
5425
public function setCardNumber(string $cardNumber): self;
55-
56-
public function arraySerialize() : array;
5726
}

src/PayoutInterface.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ public function getDescription(): ?string;
3838
public function setDescription(?string $description): self;
3939

4040
/**
41-
* @return PayoutDestination|null
41+
* @return DestinationInterface|null
4242
*/
43-
public function getDestination(): ?PayoutDestination;
43+
public function getDestination(): ?DestinationInterface;
4444

4545
/**
46-
* @param PayoutDestination|null $destination
46+
* @param DestinationInterface|null $destination
4747
* @return Payout
4848
*/
49-
public function setDestination(?PayoutDestination $destination): self;
49+
public function setDestination(?DestinationInterface $destination): self;
5050

5151
/**
5252
* @return PayoutSource|null
@@ -58,5 +58,4 @@ public function getSource(): ?PayoutSource;
5858
* @return Payout
5959
*/
6060
public function setSource(?PayoutSource $source): self;
61-
6261
}

src/PayoutMobileDestination.php

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Ypmn;
6+
7+
/**
8+
* Это класс для описания направления платежа по сбп
9+
**/
10+
class PayoutMobileDestination implements DestinationInterface
11+
{
12+
private const AVAILABLE_TYPES = [
13+
'sbp',
14+
];
15+
16+
private string $type;
17+
private ?DetailsInterface $details = null;
18+
private ?Billing $recipient = null;
19+
20+
/**
21+
* @throws PaymentException
22+
*/
23+
public function __construct(string $type = 'sbp')
24+
{
25+
$this->setType($type);
26+
}
27+
28+
/** @inheritdoc */
29+
public function getType(): string
30+
{
31+
return $this->type;
32+
}
33+
34+
/** @inheritdoc */
35+
public function setType(string $type): self
36+
{
37+
if (!in_array($type, self::AVAILABLE_TYPES)) {
38+
throw new PaymentException('Недопустимый тип выплаты');
39+
}
40+
41+
$this->type = $type;
42+
43+
return $this;
44+
}
45+
46+
/** @inheritdoc */
47+
public function getDetails(): ?DetailsInterface
48+
{
49+
return $this->details;
50+
}
51+
52+
/** @inheritdoc */
53+
public function setDetails(?DetailsInterface $details): self
54+
{
55+
$this->details = $details;
56+
57+
return $this;
58+
}
59+
60+
/** @inheritdoc */
61+
public function getRecipient(): ?Billing
62+
{
63+
return $this->recipient;
64+
}
65+
66+
/** @inheritdoc */
67+
public function setRecipient(?Billing $recipient): self
68+
{
69+
$this->recipient = $recipient;
70+
return $this;
71+
}
72+
73+
/** @inheritdoc */
74+
public function setPhoneNumber(string $phoneNumber): self
75+
{
76+
if ($this->getDetails() === null) {
77+
$this->setDetails(new PhoneDetails());
78+
}
79+
80+
$this->getDetails()->setNumber($phoneNumber);
81+
82+
return $this;
83+
}
84+
85+
/** @inheritdoc */
86+
public function setBankInformation(int $bankId, string $bankName): self
87+
{
88+
if ($this->getDetails() === null) {
89+
$this->setDetails(new PhoneDetails());
90+
}
91+
92+
$this->getDetails()->setBankId($bankId);
93+
$this->getDetails()->setBankName($bankName);
94+
95+
return $this;
96+
}
97+
98+
/**
99+
* @return array
100+
*/
101+
public function arraySerialize() : array
102+
{
103+
$address = $this->getRecipient()->getAddressLine1()
104+
. ( $this->getRecipient()->getAddressLine2() ? '' . $this->getRecipient()->getAddressLine2() : null);
105+
106+
return [
107+
'type' => $this->getType(),
108+
'sbp' => [
109+
'phoneNumber' => $this->getDetails()->getNumber(),
110+
"bankId" => $this->getDetails()->getBankId(),
111+
"bankName" => $this->getDetails()->getBankName()
112+
],
113+
'recipient' => [
114+
'type' => $this->getRecipient()->getType(),
115+
'email' => $this->getRecipient()->getEmail(),
116+
'city' => $this->getRecipient()->getCity(),
117+
'address' => $address,
118+
'postalCode' => $this->getRecipient()->getZipCode(),
119+
'countryCode' => $this->getRecipient()->getCountryCode(),
120+
'firstName' => $this->getRecipient()->getFirstName(),
121+
'lastName' => $this->getRecipient()->getLastName()
122+
],
123+
];
124+
}
125+
}

src/PhoneDetails.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Ypmn;
4+
5+
class PhoneDetails implements DetailsInterface
6+
{
7+
private string $number;
8+
private int $bankId;
9+
private string $bankName;
10+
11+
public function getNumber(): string
12+
{
13+
return $this->number;
14+
}
15+
16+
public function setNumber(string $number): self
17+
{
18+
$this->number = $number;
19+
20+
return $this;
21+
}
22+
23+
public function getBankId(): int
24+
{
25+
return $this->bankId;
26+
}
27+
28+
public function setBankId(int $bankId): self
29+
{
30+
$this->bankId = $bankId;
31+
32+
return $this;
33+
}
34+
35+
public function getBankName(): string
36+
{
37+
return $this->bankName;
38+
}
39+
40+
public function setBankName(string $bankName): self
41+
{
42+
$this->bankName = $bankName;
43+
44+
return $this;
45+
}
46+
}

0 commit comments

Comments
 (0)