-
Notifications
You must be signed in to change notification settings - Fork 7
/
notification.php
65 lines (54 loc) · 1.67 KB
/
notification.php
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
<?php
$data = json_decode(file_get_contents("config.json"), true);
const HOST = $data["host"];
const USER = $data["user"];
const PASSWORD = $data["password"];
const DB = $data["db"];
const ACCESS_TOKEN = $data["access_token"];
if ($_SERVER["REQUEST_METHOD"] != "POST") {
http_response_code(500);
return;
}
if (!(isset($_GET['id'])) && !(isset($_GET['topic']))) {
http_response_code(500);
return;
}
if ($_GET['topic'] != "payment") {
http_response_code(500);
return;
}
$id = $_GET['id'];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.mercadopago.com/v1/payments/' . $id,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer ' . ACCESS_TOKEN
)
));
$payment = json_decode(curl_exec($curl), true);
if ($payment["status"] === "approved") {
$conn = new mysqli(HOST, USER, PASSWORD, DB);
if ($conn->connect_error) {
http_response_code(500);
$conn->close();
return;
}
$player = $payment["external_reference"];
$insertSql = "INSERT INTO autopix_pendings (id, player) "
. "VALUES ('" . $id . "', '" . $player . "');";
if ($conn->query($insertSql)) {
$conn->close();
http_response_code(201);
} else {
http_response_code(500);
$conn->close();
}
}
?>