Files
ms1inscription-v5/webhooks/paypalold/paypal.php
2026-05-13 09:43:32 -04:00

92 lines
2.7 KiB
PHP

<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/php/inc_fonctions.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/paypal_advanced/PaypalWebhook.class.php');
// affaire trouver une solution pour tout les environements
$strDatabaseHost = 'localhost';
$strDatabaseUser = 'devinscription_bd';
$strDatabasePass = 'x$@_v0-l_I((';
$strDatabaseMain = 'devinscription_preprod';
$strDatabaseProd = 'devinscription_prod';
$strDatabasePreProd = 'devinscription_preprod';
$arrConDatabaseMain = array(
'host' => $strDatabaseHost,
'user' => $strDatabaseUser,
'pass' => $strDatabasePass,
'db' => $strDatabaseMain
);
$objDatabase = new clsMysql($arrConDatabaseMain);
$__raw = file_get_contents('php://input');
$__hdr = function_exists('getallheaders') ? getallheaders() : [];
file_put_contents(__DIR__ . '/paypal_incoming.json', ($__raw ?: "{}") . "\n", FILE_APPEND);
file_put_contents(__DIR__ . '/paypal_incoming_headers.log', print_r($__hdr, true) . "\n", FILE_APPEND);
$data = json_decode($__raw, true);
file_put_contents(__DIR__ . '/paypal_decoded.log', print_r($data, true) . "\n", FILE_APPEND);
$eventType = $data['event_type'] ?? '';
$captureId = null;
$refundId = $data['resource']['id'] ?? '';
if (isset($data['resource']['links']) && is_array($data['resource']['links'])) {
foreach ($data['resource']['links'] as $lnk) {
if (($lnk['rel'] ?? '') === 'up' && strpos($lnk['href'], '/captures/') !== false) {
$captureId = basename($lnk['href']);
break;
}
}
}
file_put_contents(__DIR__ . '/paypal_event_detected.log',
"[".date('c')."] Event={$eventType} Refund={$refundId} Capture={$captureId}\n",
FILE_APPEND
);
$refundId = $data['resource']['id'] ?? null;
$status = $data['resource']['status'] ?? null;
$eventType = $data['event_type'] ?? null;
/* $captureId est déjà construit plus haut dans ton script */
$Q = function($v){ return $v === null ? "NULL" : "'" . addslashes($v) . "'"; };
if ($refundId && $status) {
$sql = "
INSERT INTO inscriptions_panier_remboursement (
refund_id,
status,
status_interne,
create_time,
update_time
) VALUES (
{$Q($refundId)},
{$Q($status)},
'WEBHOOK',
NOW(),
NOW()
)
ON DUPLICATE KEY UPDATE
status = VALUES(status),
status_interne = 'WEBHOOK',
update_time = NOW()
";
$ok = $objDatabase->fxQuery($sql);
file_put_contents(__DIR__.'/paypal_db_update.log',
"[".date('c')."] UPSERT refund_id={$refundId} cap={$captureId} ok=".$ok."\n",
FILE_APPEND
);
} else {
file_put_contents(__DIR__.'/paypal_db_update.log',
"[".date('c')."] SKIP UPSERT: refundId/status manquants (refundId="
.var_export($refundId,true).", status=".var_export($status,true).")\n",
FILE_APPEND
);
}
exit;