Skip to content

Commit a700584

Browse files
committed
Merge branch 'ADD__webhook_example' into 'main'
FIX: Webhook.php See merge request ypmn-public/php-api-client!21
2 parents c4f6e5e + 3fd4d84 commit a700584

File tree

5 files changed

+86
-4
lines changed

5 files changed

+86
-4
lines changed

example.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
case 'qstPrint':
5151
case 'SOMGetPaymentLink':
5252
case 'qstList':
53+
case 'webhookProcessing':
5354
require './src/Examples/start.php';
5455
@include './src/Examples/'.$_GET['function'] . '__prepend.php';
5556
require './src/Examples/'.$_GET['function'] . '.php';

example_list.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,10 @@
202202
'docLink' => 'https://ypmn.ru/ru/documentation/#tag/widget-integration',
203203
'link' => '',
204204
],
205+
'webhookProcessing' => [
206+
'name' => 'Обработка вебхука',
207+
'about' => 'В этом примере показана обработка вебхука IPN',
208+
'docLink' => 'https://ypmn.ru/ru/documentation/#tag/webhooks',
209+
'link' => '',
210+
]
205211
];

src/Examples/webhookProcessing.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
/**
4+
* webhookProcessing.php
5+
*
6+
* На адрес этого файла будет приходить вебхук IPN
7+
* Чтобы изменить адрес, отредактируйте параметр URL на странице
8+
* https://secure.ypmn.ru/cpanel/ipn_settings.php
9+
*
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
// Подключим файл, в котором заданы параметры мерчанта
15+
include_once 'start.php';
16+
17+
use Ypmn\Webhook;
18+
19+
// Обрабатываем только POST запросы
20+
if (empty($_POST)) {
21+
die();
22+
}
23+
24+
// Создадим обработчик вебхука
25+
$webhookHandler = new Webhook();
26+
27+
// Обработаем вебхук
28+
try {
29+
$webhookHandler->catchJsonRequest();
30+
31+
$paymentResult = $webhookHandler->getPaymentResult();
32+
$orderData = $webhookHandler->getOrderData();
33+
$authorization = $webhookHandler->getAuthorization();
34+
35+
36+
// Обозначим путь до папки и запишем вебхук в лог
37+
$folder = __DIR__ . "/../../webhooks_log/";
38+
$filename = $folder . "ypmn" . date("Y-m-d H:i:s") ."_" . uniqid() . ".log";
39+
40+
if (!file_exists($folder)) {
41+
mkdir($folder, 0777, true);
42+
}
43+
44+
file_put_contents($filename, json_encode([
45+
"orderData" => [
46+
"orderDate" => $orderData->getOrderDate(),
47+
"payuPaymentReference" => $orderData->getPayuPaymentReference(),
48+
"merchantPaymentReference" => $orderData->getMerchantPaymentReference(),
49+
"status" => $orderData->getStatus(),
50+
"currency" => $orderData->getCurrency(),
51+
"amount" => $orderData->getAmount() ?? "null",
52+
"commission" => $orderData->getCommission() ?? "null",
53+
"loyaltyPointsAmount" => $orderData->getLoyaltyPointsAmount() ?? "null",
54+
"loyaltyPointsDetails" => $orderData->getLoyaltyPointsDetails() ?? "null",
55+
],
56+
57+
"paymentResult" => [
58+
"cardDetails" => [
59+
"bin" => $paymentResult->getCardDetails()->getBin(),
60+
"owner" => $paymentResult->getCardDetails()->getOwner(),
61+
"pan" => $paymentResult->getCardDetails()->getPan(),
62+
"type" => $paymentResult->getCardDetails()->getType(),
63+
"cardIssuerBank" => $paymentResult->getCardDetails()->getCardIssuerBank(),
64+
],
65+
"paymentMethod" => $paymentResult->getPaymentMethod(),
66+
"paymentDate" => $paymentResult->getPaymentDate(),
67+
"authCode" => $paymentResult->getAuthCode(),
68+
"merchantId" => $paymentResult->getMerchantId(),
69+
],
70+
]));
71+
72+
73+
} catch (\Ypmn\PaymentException $e) {
74+
// YourLogger::log(...);
75+
}
76+

src/PaymentResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function setCardDetails(CardDetailsInterface $cardDetails): self
152152
}
153153

154154
/** @inheritDoc */
155-
public function getCardDetails($cardDetails) : CardDetailsInterface
155+
public function getCardDetails() : CardDetailsInterface
156156
{
157157
return $this->cardDetails;
158158
}

src/PaymentResultInterface.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,10 @@ public function setInstallmentsNumber(string $installmentsNumber): self;
110110
public function setCardDetails(CardDetailsInterface $cardDetails): self;
111111

112112
/**
113-
* Установить Информацию о Карте
114-
* @param $cardDetails
113+
* Получить информацию о Карте
115114
* @return CardDetailsInterface
116115
*/
117-
public function getCardDetails($cardDetails) : CardDetailsInterface;
116+
public function getCardDetails() : CardDetailsInterface;
118117

119118

120119
/**

0 commit comments

Comments
 (0)