payment_webhook.php

main 63 lines · 1.8 KB Raw
Alex Alex Commit Initial commit 01/10/2026 09:20
1<?php
2if (PHP_VERSION_ID < 80100) {
3 http_response_code(500);
4 exit('PHP 8.1 or higher is required.');
5}
6
7$version = '2.0.1';
8$time = time();
9$aacQueries = 0;
10$accQueriesData = [];
11
12require 'config.php';
13require 'engine/database/connect.php';
14require 'engine/function/general.php';
15require 'engine/function/settings.php';
16znote_apply_settings();
17require 'engine/function/payments.php';
18
19if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'POST') {
20 http_response_code(405);
21 header('Allow: POST');
22 header('Content-Type: application/json');
23 echo json_encode(['received' => false, 'status' => 'method_not_allowed']);
24 exit;
25}
26
27$contentLength = (int)($_SERVER['CONTENT_LENGTH'] ?? 0);
28if ($contentLength > 1048576) {
29 http_response_code(413);
30 header('Content-Type: application/json');
31 echo json_encode(['received' => false, 'status' => 'payload_too_large']);
32 exit;
33}
34
35$provider = strtolower(trim((string)($_GET['provider'] ?? $_POST['provider'] ?? '')));
36$payload = file_get_contents('php://input') ?: '';
37if (strlen($payload) > 1048576) {
38 http_response_code(413);
39 header('Content-Type: application/json');
40 echo json_encode(['received' => false, 'status' => 'payload_too_large']);
41 exit;
42}
43
44payment_gateway_ensure_schema();
45
46try {
47 if ($provider === 'stripe') {
48 $result = payment_gateway_handle_stripe_webhook($payload);
49 } elseif ($provider === 'mercadopago') {
50 $result = payment_gateway_handle_mercadopago_webhook($payload);
51 } else {
52 $result = ['code' => 404, 'status' => 'unknown_provider'];
53 }
54} catch (Throwable $e) {
55 error_log('Payment webhook error: ' . $e->getMessage());
56 $result = ['code' => 500, 'status' => 'server_error'];
57}
58
59http_response_code((int)$result['code']);
60header('Content-Type: application/json');
61echo json_encode(['received' => $result['code'] < 500, 'status' => $result['status']]);
62?>
63
Top