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