-
Notifications
You must be signed in to change notification settings - Fork 53
/
picpay_notification.php
115 lines (95 loc) · 3.31 KB
/
picpay_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/* Simple integration with PicPay
* Notification file
* @author: World Script
* /
/ * This file must be configured in your callback url
* for PicPay I can send requests here.
* Picpay will expect an HTTP 200 response from your site
* Access the PicPay documentation to see more details.
* https://ecommerce.picpay.com/doc/
*/
require 'config/config.php';
// comment to show E_NOTICE [undefinied variable etc.], comment if you want make script and see all errors
error_reporting(E_ALL ^ E_STRICT ^ E_NOTICE);
// true = show sent queries and SQL queries status/status code/error message
define('DEBUG_DATABASE', false);
define('INITIALIZED', true);
if (!defined('ONLY_PAGE'))
define('ONLY_PAGE', true);
$navegador = filter_input(INPUT_SERVER, "HTTP_USER_AGENT", FILTER_DEFAULT);
if ($navegador !== "Mozilla/5.0") {
header("Location: ./?subtopic=accountmanagement");
}
// check if site is disabled/requires installation
include_once('./system/load.loadCheck.php');
// fix user data, load config, enable class auto loader
include_once('./system/load.init.php');
// DATABASE
include_once('./system/load.database.php');
if (DEBUG_DATABASE)
Website::getDBHandle()->setPrintQueries(true);
$picpay = new PicPay;
/*
- "created": registro criado
- "expired": prazo para pagamento expirado
- "analysis": pago e em processo de análise anti-fraude
- "paid": pago
- "completed": pago e saldo disponível
- "refunded": pago e devolvido
- "chargeback": pago e com chargeback
*/
// função que verifica a requisição
$notification = $picpay->notificationPayment();
if($notification){
$status = $notification->status;
$authorizationId = $notification->authorizationId;
$referenceId = $notification->referenceId;
$picpayPayment = new PicPayPayment();
$picpayPayment->loadById((int) $referenceId);
if ($picpayPayment->isLoaded()) {
$picpayPayment->setAuthorizationid($authorizationId);
$picpayPayment->setStatus($status);
$picpayPayment->save();
if ($status == "completed") {
$doubleStatus = function () use ($SQL) {
$q = $SQL->prepare("SELECT value FROM server_config WHERE config = 'double'");
$q->execute([]);
$q = $q->fetchAll();
if ($q[0]['value'] == "active") {
return true;
} else {
return false;
}
};
$verify_transaction = function () use ($SQL, $id) {
$v = $SQL->prepare("SELECT * FROM picpay_payment where id = :id AND status = 'DELIVERED'");
$v->execute(['id' => $id]);
if ($v->rowCount() == 0) {
return true;
} else {
return false;
}
};
if ($verify_transaction()) {
try {
$conn = $SQLPDO;
$entregarCoins = ($doubleStatus() ? ($picpayPayment->getCoins() * 2) : $picpayPayment->getCoins());
$stmt = $conn->prepare('UPDATE accounts SET coins = coins + :item_count WHERE id = :id');
$stmt->execute(array('item_count' => $entregarCoins, 'id' => $picpayPayment->getAccount() ));
$stmt = $conn->prepare("UPDATE picpay_payment SET status = 'DELIVERED' WHERE id = :id");
$stmt->execute(array('id' => $picpayPayment->getID()));
} catch (PDOException $e) {
die('ERROR: ' . $e->getMessage());
}
$pay_method = "PicPay";
$acc = new Account();
$acc->loadByName(strtolower($name));
include_once "send_payment_voucher.php";
echo 'wow';
}
}
}
}
}
?>