-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbtcipn_ipn.php
More file actions
93 lines (60 loc) · 2.42 KB
/
btcipn_ipn.php
File metadata and controls
93 lines (60 loc) · 2.42 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
require_once("config.php");
if (!isset($_POST['payment'])){exit;}
if ($_POST['payment'] != 'VALID'){
error_log ('BTCIPN : Invalid payment type EXPECTED VALID. please contact btcipn.com');
exit;
}
$requeired_minimum_confirmation = 1;
$seller_wallet_address = $addresswallet;
if ($_POST['seller_address'] != $seller_wallet_address){
error_log ('BTCIPN : Wrong seller_address');
exit;
}
if ($_POST['confirmations'] >= '0'){
}
if ($_POST['confirmations'] == $requeired_minimum_confirmation){
if (!is_payment_processed($_POST['packet_id'])){
$encoded_data = urlencode(base64_encode(json_encode($_POST)));
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query(array('data'=>$encoded_data)),
//'content' => http_build_query(array('data'=>$encoded_data, 'testnet'=>'true')), // for testnet
),
);
$context = stream_context_create($options);
$IPN_VERIFICATION = file_get_contents('https://btcipn.com/api/verifyipn/', false, $context);
if ($IPN_VERIFICATION == "OK"){
set_payment_processed($_POST['packet_id']);
//$_POST['custom_data']
$ex = explode("|",$_POST['custom_data']);
$cred = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$cred->bindValue(":username",$ex[1],PDO::PARAM_STR);
$cred->execute();
$cred = $cred->fetchAll();
$crediti = $cred[0]['credits'];
$crediti = $crediti + $ex[0];
$upd = $pdo->prepare("UPDATE users SET credits = :credits WHERE username = :username");
$upd->bindValue(":credits",$crediti,PDO::PARAM_STR);
$upd->bindValue(":username",$ex[1],PDO::PARAM_STR);
$upd->execute();
}else{
error_log ('BTCIPN : INVALID IPN REQUEST');
exit;
}
}else{
exit;
}
}
function is_payment_processed($packet_id){
if (file_exists('packets/'.$packet_id.'.dat')){
return true;
}
return false;
}
function set_payment_processed($packet_id){
file_put_contents('packets/'.$packet_id.'.dat',time());
}
?>