Skip to content

Commit f2b8043

Browse files
committed
Merge branch 'examples_interface_fix' into 'main'
card details full bank name fix See merge request ypmn-public/php-api-client!39
2 parents fc047a0 + d400728 commit f2b8043

7 files changed

Lines changed: 72 additions & 24 deletions

File tree

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,41 +33,41 @@
3333

3434
Пример быстрого старта для приёма платежей:
3535
```php
36-
$merchant = new Merchant('MERCHANT_CODE', 'SECRET_KEY');
36+
$merchant = new Merchant('MERCHANT_CODE', 'SECRET_KEY'); // Коды подключения API
37+
$merchantPaymentReference = 123; // Номер заказа в вашей системе
3738
$billing = (new Billing)
38-
->setCountryCode('RU')
39-
->setFirstName('Иван')
40-
->setLastName('Петров')
41-
->setEmail('test1@ypmn.ru')
42-
->setPhone('+74996492009')
43-
->setCity('Москва');
39+
->setCountryCode('RU') // Страна Плательщика
40+
->setFirstName('Иван') // Имя Плательщика
41+
->setLastName('Петров') // Фамилия Плательщика
42+
->setEmail('test1@ypmn.ru') // Почта Плательщика
43+
->setPhone('+74996492009') // Телефон Плательщика
44+
->setCity('Москва'); // Город Плательщика
4445

45-
$client = (new Client)
46-
->setBilling($billing);
47-
46+
$client = (new Client)->setBilling($billing);
4847
$payment = (new Payment)
4948
->addProduct(new Product([
50-
'name' => 'Заказ №' . $merchantPaymentReference,
51-
'sku' => $merchantPaymentReference,
52-
'unitPrice' => 20.42,
53-
'quantity' => 1,
49+
'name' => 'Заказ №' . $merchantPaymentReference, // Наименование товарной позиции
50+
'sku' => 'test_artikul', // Артикул
51+
'unitPrice' => 20.42, // Стоимость единицы
52+
'quantity' => 1, // Количество
5453
]));
5554
$payment_method = $_GET['method'] ?? PaymentMethods::CCVISAMC; // Определим платёжный метод
5655
$authorization = new Authorization($payment_method, true);
5756
$payment->setAuthorization($authorization);
5857
$payment->setMerchantPaymentReference($merchantPaymentReference);
59-
$payment->setReturnUrl('https://' . @$_SERVER['HTTP_HOST'] . '/php-api-client/?function=returnPage');
58+
$payment->setSuccessUrl('https://' . $_SERVER['HTTP_HOST'] . '/?status=success'); // Редирект после успешной оплаты
59+
$payment->setFailUrl('https://' . $_SERVER['HTTP_HOST'] . '/?status=success'); // Редирект в случае неоплаты
6060
$payment->setClient($client);
61+
6162
$apiRequest = new ApiRequest($merchant);
6263
$responseData = $apiRequest->sendAuthRequest($payment, $merchant);
63-
$responseData = json_decode((string) $responseData["response"], true);
64-
64+
$responseData = json_decode((string) $responseData["response"], true); // Отправка запроса и обработка ответа
6565
if (isset($responseData["paymentResult"])) {
6666
if (!empty($responseData['paymentResult']['bankResponseDetails']['customBankNode']['qr'])) {
6767
$qr = $responseData['paymentResult']['bankResponseDetails']['customBankNode']['qr'];
6868
}
6969

70-
// Выведем кнопку оплаты, рекомендуется
70+
// Выведем кнопку оплаты (рекомендуется)
7171
echo Std::drawYpmnButton([
7272
'qr' => ($qr ?? null),
7373
'url' => $responseData['paymentResult']['url'] ?? '',
@@ -87,7 +87,7 @@ if (isset($responseData["paymentResult"])) {
8787
- безопасность и точность расчётов
8888

8989
Библиотека содержит:
90-
- Клиент API
90+
- Клиент для работы с API платежей, выплат, отчётов
9191
- Простой встроенный сервер с примерами
9292
- Описание контейнера для запуска в Docker
9393

src/ApiRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ private function sendPostPutRequest(
368368
$curl = curl_init();
369369
$date = (new DateTime())->format(DateTimeInterface::ATOM);
370370

371-
$useragent = "SDK_" . @PHP_VERSION;
371+
$useragent = "SDK_PHP_" . @PHP_VERSION;
372372
$referer = @$_SERVER['HTTP_HOST'] ?? @$_SERVER['SERVER_NAME'] ?? "" . @$_SERVER['REQUEST_URI'] ?? "";
373373

374374
$setOptArray = [

src/CardDetails.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class CardDetails implements CardDetailsInterface
4141
/** @var string Банк, выпустивший карту */
4242
private string $cardIssuerBank;
4343

44+
/** @var string Банк, выпустивший карту (полное наименование) */
45+
private string $cardIssuerBankFullName;
46+
4447
/** Protobuf generation Trait */
4548
use ProtobufSerializable;
4649

@@ -69,6 +72,7 @@ public function getExpiryMonth(): ?int
6972
public function setExpiryMonth(int $expiryMonth): self
7073
{
7174
$this->expiryMonth = $expiryMonth;
75+
7276
return $this;
7377
}
7478

@@ -84,8 +88,8 @@ public function setYear(int $year): self
8488
if ( $year< 1900) {
8589
throw new PaymentException('Проверьте год выпуска карты');
8690
}
87-
8891
$this->year = $year;
92+
8993
return $this;
9094
}
9195

@@ -99,6 +103,7 @@ public function getExpiryYear(): ?int
99103
public function setExpiryYear(int $expiryYear): self
100104
{
101105
$this->expiryYear = $expiryYear;
106+
102107
return $this;
103108
}
104109

@@ -112,6 +117,7 @@ public function getCvv(): ?string
112117
public function setCvv(string $cvv): self
113118
{
114119
$this->cvv = $cvv;
120+
115121
return $this;
116122
}
117123

@@ -125,6 +131,7 @@ public function getOwner(): ?string
125131
public function setOwner(string $owner): self
126132
{
127133
$this->owner = $owner;
134+
128135
return $this;
129136
}
130137

@@ -138,6 +145,7 @@ public function getTimeSpentTypingNumber(): ?int
138145
public function setTimeSpentTypingNumber(int $timeSpentTypingNumber): self
139146
{
140147
$this->timeSpentTypingNumber = $timeSpentTypingNumber;
148+
141149
return $this;
142150
}
143151

@@ -151,6 +159,7 @@ public function getTimeSpentTypingOwner(): ?int
151159
public function setTimeSpentTypingOwner(int $timeSpentTypingOwner): self
152160
{
153161
$this->timeSpentTypingOwner = $timeSpentTypingOwner;
162+
154163
return $this;
155164
}
156165

@@ -164,6 +173,7 @@ public function getBin(): ?int
164173
public function setBin(int $bin): self
165174
{
166175
$this->bin = $bin;
176+
167177
return $this;
168178
}
169179

@@ -177,6 +187,7 @@ public function getPan(): ?string
177187
public function setPan(string $pan): self
178188
{
179189
$this->pan = $pan;
190+
180191
return $this;
181192
}
182193

@@ -190,6 +201,7 @@ public function getType(): ?string
190201
public function setType(string $type): self
191202
{
192203
$this->type = $type;
204+
193205
return $this;
194206
}
195207

@@ -203,6 +215,21 @@ public function getCardIssuerBank(): ?string
203215
public function setCardIssuerBank(string $cardIssuerBank): self
204216
{
205217
$this->cardIssuerBank = $cardIssuerBank;
218+
219+
return $this;
220+
}
221+
222+
/** @inheritDoc */
223+
public function getCardIssuerBankFullName(): ?string
224+
{
225+
return $this->cardIssuerBankFullName ?? null;
226+
}
227+
228+
/** @inheritDoc */
229+
public function setCardIssuerBankFullName(string $cardIssuerBankFullName): CardDetails
230+
{
231+
$this->cardIssuerBankFullName = $cardIssuerBankFullName;
232+
206233
return $this;
207234
}
208235

src/CardDetailsInterface.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,19 @@ public function setCardIssuerBank(string $cardIssuerBank) : self;
138138
*/
139139
public function getCardIssuerBank() : ?string;
140140

141+
/**
142+
* Установить Полное наименование Банка, выпустившего карту
143+
* @param string $cardIssuerBankFullName
144+
* @return CardDetails
145+
*/
146+
public function setCardIssuerBankFullName(string $cardIssuerBankFullName): CardDetails;
147+
148+
/**
149+
* Получить Полное наименование Банка, выпустившего карту
150+
* @return string|null Полное наименование Банка, выпустившего карту
151+
*/
152+
public function getCardIssuerBankFullName(): ?string;
153+
141154
/**
142155
* Получить Год Карты
143156
* @return int|null Год Карты

src/Examples/returnPage.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
<?php
22
/**
3-
* Страница после оплаты.
4-
* Параметры передаются в $_GET или $_POST, в зависимости от настройки мерчанта в YPMN:
3+
* @deprecated Используйте новые параметры
4+
* `successUrl` после успешной оплаты
5+
* и `failUrl` после неудачной оплаты
6+
* https://ypmn.ru/doc/#tag/payment-api-return-url
7+
*
8+
* Ниже старая (единая) страница после оплаты.
9+
* В ней параметры передаются в $_GET или $_POST, в зависимости от настройки мерчанта в YPMN
510
*/
611
$statusResponseFromServer = (json_decode($_POST['body'] ?? '{}', true))['status'] ?? null;
712

src/Examples/start.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@
1616
* Убедитесь, что эти адреса разрешены в Firewall вашего приложения
1717
*/
1818
$merchant = new Merchant('gitttest', 'vk0!K4(~9)1d69@0p4&N');
19-
//$merchant = new Merchant('CLD_FUL', 'SECRET_KEY');

src/Webhook.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ public function catchJsonRequest(): self
9090
$cardDetails->setCardIssuerBank($request['paymentResult']['cardDetails']['cardIssuerBank']);
9191
}
9292

93+
if (!empty($request['paymentResult']['cardDetails']['cardIssuerBankFullName'])) {
94+
$cardDetails->setCardIssuerBankFullName($request['paymentResult']['cardDetails']['cardIssuerBankFullName']);
95+
}
96+
9397
$this->paymentResult = new PaymentResult;
9498
$this->paymentResult->setCardDetails($cardDetails);
9599

0 commit comments

Comments
 (0)