-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipn.php
60 lines (54 loc) · 2.71 KB
/
ipn.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
<?php
// AYAPAY IPN EXAMPLE
include 'config.php';
$address = $_POST['address'];
$txn_id = $_POST['txn_id'];
$label = intval($_POST['label']);
$confirms = intval($_POST['confirms']);
$currency = $_POST['currency'];
$amount = floatval($_POST['amount']);
$status = intval($_POST['status']);
$hash = $_POST['hash'];
$hash_compare = md5($txn_id.'YOUR API KEY'); // your api key
if($hash_compare =! $hash){
exit;
}
$con = db_connection();
$find_transaction = mysqli_query($con, "SELECT * FROM ipn_notify WHERE coin_type = '" . $currency . "' AND status = '0' AND txid = '" . $txn_id . "' AND user_id = " . $label);
// check database to find transaction if notify not new and try to update confirms.
if ($find_transaction->num_rows > 0) {
while ($row = $find_transaction->fetch_assoc()) {
if (($status >= 100 || $status == 2 )) {
//here you can accept payment and finish the progress.
$status_text = "Deposit confirmed";
$update_transaction = "UPDATE ipn_notify SET confirm = '" . $confirms . "', status = '" . $status . "', status_text = '" . $status_text . "' WHERE id = " . $row["id"];
if ($con->query($update_transaction) === TRUE) {
die('IPN OK');
}
} else if ($status < 0) {
$update_transaction = "UPDATE ipn_notify SET confirm = '" . $confirms . "', status = '" . $status . "', status_text = '" . $status_text . "' WHERE id = " . $row["id"];
if ($con->query($update_transaction) === TRUE) {
die('IPN OK');
}
}
}
} else {
$find_txid = mysqli_query($con, "SELECT * FROM ipn_notify WHERE coin_type = '" . $currency . "' AND txid = '" . $txn_id . "' AND user_id = " . $label);
//extra check for some wallet apps they are fast so with 1 confirms may comes
if ($find_txid->num_rows > 0) {
die('IPN OK');
}
if($confirms >= 1 && $status == 0){
$status = 100;
$status_text = "Deposit confirmed";
//here you can accept payment and finish the progress.
}else{
$status_text = "Deposit detected";
}
//if non of all founded so it's new transaction, here will inserted with 0 confirms to check for next confirms and waiting for acception.
$insert_transaction = "INSERT INTO ipn_notify (user_id, address, txid, coin_type, amount, confirm, status, status_text) VALUES ('" . $label . "', '" . $address . "', '" . $txn_id . "', '" . $currency . "', '" . $amount . "', '" . $confirms . "', '" . $status . "', '" . $status_text . "')";
if ($con->query($insert_transaction) === TRUE) {
die('IPN OK');
}
}
?>