Skip to content

Commit fc047a0

Browse files
committed
Merge branch 'YP-1933__platezhi-po-svobodnym-rekvizitam' into 'main'
YP-1933__platezhi-po-svobodnym-rekvizitam See merge request ypmn-public/php-api-client!38
2 parents 531f940 + bd31e4b commit fc047a0

4 files changed

Lines changed: 130 additions & 0 deletions

File tree

src/Details.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,29 @@ public function setReceipts($receipts): self
102102
return $this;
103103
}
104104

105+
/**
106+
* Получить массив объектов получателей по свободным реквизитам
107+
*
108+
* @return Receiver[]|null
109+
*/
110+
public function getReceivers(): ?array
111+
{
112+
return $this->valuesContainer['receivers'] ?? null;
113+
}
114+
115+
/**
116+
* Установить получателей для оплаты по свободным реквизитам
117+
*
118+
* @param Receiver[] $receivers
119+
* @return self
120+
*/
121+
public function setReceivers(?array $receivers): self
122+
{
123+
$this->valuesContainer['receivers'] = $receivers;
124+
125+
return $this;
126+
}
127+
105128

106129

107130
/**

src/Examples/authorize.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,35 @@
144144
'utm_content' => @$_REQUEST['utm_content'], //'Идентификатор конкретного рекламного экземпляра'
145145
]));
146146
}
147+
//Пример добавления получателей для оплаты по свободным реквизитам
148+
if (!empty(@$_REQUEST['receivers'])) {
149+
$details->setReceivers([
150+
new \Ypmn\Receiver(
151+
'sku123-1',
152+
'044525225',
153+
'30101810400000000225',
154+
'40702810121340952493',
155+
'Иванов Иван Иванович',
156+
'1234567890',
157+
'123456789',
158+
'Оплата за товар {{persAcc}} {{period}}',
159+
'1234567890',
160+
'01/2023'
161+
),
162+
new \Ypmn\Receiver(
163+
'sku123-2',
164+
'044030785',
165+
'30101810300000000785',
166+
'40702810410849746412',
167+
'Петров Петр Петрович',
168+
'123456789012',
169+
'123456788',
170+
'Оплата за услугу {{persAcc}}',
171+
'0987654321',
172+
'02/2023'
173+
),
174+
]);
175+
}
147176

148177
// Новая оплата с токенизацией (необязательно), или оплата токеном
149178
if (@$_REQUEST['section'] === 'new_payment_and_tokenization') {

src/Examples/authorize_form.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ class='form-control mb-3 w-100'
113113
Сплитование (разделение платежа между получателями)
114114
</label>
115115
</div>
116+
117+
<div class='form-check mb-3'>
118+
<input name='receivers' value='yes' class='form-check-input' type='checkbox' id='receivers'>
119+
<label class='form-check-label' for='receivers'>
120+
Оплата по свободным реквизитам
121+
</label>
122+
</div>
116123
</div>
117124
</div>
118125

src/Receiver.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Ypmn;
6+
7+
use DateTimeZone;
8+
9+
class Receiver implements \JsonSerializable
10+
{
11+
private string $sku;
12+
private string $bic;
13+
private string $correspondentAccount;
14+
private string $account;
15+
private string $name;
16+
private string $inn;
17+
private string $kpp;
18+
private string $purpose;
19+
private string $personalAccount;
20+
private string $period;
21+
22+
public function __construct(
23+
string $sku,
24+
string $bic,
25+
string $correspondentAccount,
26+
string $account,
27+
string $name,
28+
string $inn,
29+
string $kpp,
30+
string $purpose,
31+
string $personalAccount,
32+
string $period
33+
) {
34+
$this->sku = $sku;
35+
$this->bic = $bic;
36+
$this->correspondentAccount = $correspondentAccount;
37+
$this->account = $account;
38+
$this->name = $name;
39+
$this->inn = $inn;
40+
$this->kpp = $kpp;
41+
$this->purpose = $purpose;
42+
$this->personalAccount = $personalAccount;
43+
44+
if (preg_match('~^(0[1-9]|1[0-2])\/\d{4}$~', $period)) {
45+
throw new PaymentException('Аргумент period имеет неверный формат');
46+
}
47+
48+
$this->period = $period;
49+
}
50+
51+
public function toArray(): array
52+
{
53+
return [
54+
'sku' => $this->sku,
55+
'bic' => $this->bic,
56+
'correspondentAccount' => $this->correspondentAccount,
57+
'account' => $this->account,
58+
'name' => $this->name,
59+
'inn' => $this->inn,
60+
'kpp' => $this->kpp,
61+
'purpose' => $this->purpose,
62+
'personalAccount' => $this->personalAccount,
63+
'period' => $this->period
64+
];
65+
}
66+
67+
public function jsonSerialize()
68+
{
69+
return $this->toArray();
70+
}
71+
}

0 commit comments

Comments
 (0)