Skip to content

Commit 3fd4d84

Browse files
author
Pavel Chugunov
committed
ADD: webhook example
1 parent 8ce8ff4 commit 3fd4d84

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
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';

src/Examples/webhookProcessing.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@
1111

1212
declare(strict_types=1);
1313

14+
// Подключим файл, в котором заданы параметры мерчанта
15+
include_once 'start.php';
16+
1417
use Ypmn\Webhook;
1518

19+
// Обрабатываем только POST запросы
20+
if (empty($_POST)) {
21+
die();
22+
}
23+
1624
// Создадим обработчик вебхука
1725
$webhookHandler = new Webhook();
1826

19-
2027
// Обработаем вебхук
2128
try {
2229
$webhookHandler->catchJsonRequest();
@@ -25,6 +32,44 @@
2532
$orderData = $webhookHandler->getOrderData();
2633
$authorization = $webhookHandler->getAuthorization();
2734

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+
2873
} catch (\Ypmn\PaymentException $e) {
2974
// YourLogger::log(...);
3075
}

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)