private function check_payment_live() { $ip = $this->ip_address(); $hash = md5($this->boxID . $this->private_key . $this->userID . $this->orderID . $this->language . $this->period . $ip); $box_status = ""; $data = array("r" => $this->private_key, "b" => $this->boxID, "o" => $this->orderID, "u" => $this->userID, "l" => $this->language, "e" => $this->period, "i" => $ip, "h" => $hash); $ch = curl_init("https://coins.gourl.io/result.php"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 20); $res = curl_exec($ch); if ($res) { $res = json_decode($res, true); } if ($res) { foreach ($res as $k => $v) { if (is_string($v)) { $res[$k] = trim($v); } } } if (isset($res["status"]) && in_array($res["status"], array("payment_received")) && $res["box"] && is_numeric($res["box"]) && $res["box"] > 0 && $res["amount"] && is_numeric($res["amount"]) && $res["amount"] > 0 && $res["private_key"] && preg_replace('/[^A-Za-z0-9]/', '', $res["private_key"]) == $res["private_key"] && $res["private_key"] == $this->private_key) { foreach ($res as $k => $v) { if ($k == "datetime") { $mask = '/[^0-9\\ \\-\\:]/'; } elseif (in_array($k, array("err", "date"))) { $mask = '/[^A-Za-z0-9\\.\\_\\-\\@\\ ]/'; } else { $mask = '/[^A-Za-z0-9\\.\\_\\-\\@]/'; } if ($v && preg_replace($mask, '', $v) != $v) { $res[$k] = ""; } } if (!$res["amountusd"] || !is_numeric($res["amountusd"])) { $res["amountusd"] = 0; } if (!$res["confirmed"] || !is_numeric($res["confirmed"])) { $res["confirmed"] = 0; } $dt = gmdate('Y-m-d H:i:s'); $obj = run_sql("select paymentID, processed, txConfirmed from crypto_payments where boxID = " . $res["box"] . " && orderID = '" . $res["order"] . "' && userID = '" . $res["user"] . "' && txID = '" . $res["tx"] . "' limit 1"); if ($obj) { $this->paymentID = $obj->paymentID; $this->processed = $obj->processed ? true : false; $this->confirmed = $obj->txConfirmed; // refresh $sql = "UPDATE \t\tcrypto_payments \n\t\t\t\t\t\tSET \t\tboxType \t\t\t= '" . $res["boxtype"] . "',\n\t\t\t\t\t\t\t\t\tamount \t\t\t\t= " . $res["amount"] . ",\n\t\t\t\t\t\t\t\t\tamountUSD\t\t\t= " . $res["amountusd"] . ",\n\t\t\t\t\t\t\t\t\tcoinLabel\t\t\t= '" . $res["coinlabel"] . "',\n\t\t\t\t\t\t \t\t\tunrecognised\t\t= 0,\n\t\t\t\t\t\t \t\t\taddr\t\t\t\t= '" . $res["addr"] . "',\n\t\t\t\t\t\t \t\t\ttxDate\t\t\t\t= '" . $res["datetime"] . "',\n\t\t\t\t\t\t \t\t\ttxConfirmed\t\t\t= " . $res["confirmed"] . ",\n\t\t\t\t\t\t \t\t\ttxCheckDate\t\t\t= '" . $dt . "'\n\t\t\t\t\t\tWHERE \t\tpaymentID \t\t\t= {$this->paymentID} \n\t\t\t\t\t\tLIMIT \t\t1"; run_sql($sql); if ($res["confirmed"] && !$this->confirmed) { $box_status = "cryptobox_updated"; } } else { // Save new payment details in local database $sql = "INSERT INTO crypto_payments (boxID, boxType, orderID, userID, countryID, coinLabel, amount, amountUSD, unrecognised, addr, txID, txDate, txConfirmed, txCheckDate, recordCreated)\n\t\t\t\t\t\tVALUES (" . $res["box"] . ", '" . $res["boxtype"] . "', '" . $res["order"] . "', '" . $res["user"] . "', '" . $res["usercountry"] . "', '" . $res["coinlabel"] . "', " . $res["amount"] . ", " . $res["amountusd"] . ", 0, '" . $res["addr"] . "', '" . $res["tx"] . "', '" . $res["datetime"] . "', " . $res["confirmed"] . ", '{$dt}', '{$dt}')"; $this->paymentID = run_sql($sql); $box_status = "cryptobox_newrecord"; } $this->paymentDate = $res["datetime"]; $this->amountPaid = $res["amount"]; $this->amountPaidUSD = $res["amountusd"]; $this->paid = true; $this->boxType = $res["boxtype"]; $this->confirmed = $res["confirmed"]; /** * User-defined function for new payment - cryptobox_new_payment($paymentID = 0, $payment_details = array(), $box_status = ""). * You can add function to the bottom of this file cryptobox.class.php or create in a separate file. * For example, send confirmation email, update user membership, etc. * * The function will automatically appear for each new payment usually two times : * a) when a new payment is received, with values: $box_status = cryptobox_newrecord, $payment_details[confirmed] = 0 * b) and a second time when existing payment is confirmed (6+ confirmations) with values: $box_status = cryptobox_updated, $payment_details[confirmed] = 1. * * But sometimes if the payment notification is delayed for 20-30min, the payment/transaction will already be confirmed and the function will * appear once with values: $box_status = cryptobox_newrecord, $payment_details[confirmed] = 1 * * If payment received with correct amount, function receive: $payment_details[status] = 'payment_received' and $payment_details[user] = 11, 12, etc (user_id who has made payment) * If incorrectly paid amount, the system can not recognize user; function receive: $payment_details[status] = 'payment_received_unrecognised' and $payment_details[user] = '' */ if (in_array($box_status, array("cryptobox_newrecord", "cryptobox_updated")) && function_exists('cryptobox_new_payment')) { cryptobox_new_payment($this->paymentID, $res, $box_status); } return true; } return false; }
* { * "status":"payment_received_unrecognised" * "err":"An incorrect bitcoin amount has been received" * "private_key":"1206lO6HX76cw9Bitcoin77DOGED82Y8eyBExZ9kZpX" * "box":"120" * "boxtype":"paymentbox" * "order":"" * "user":"" * "usercountry":"" * "amount":"12.26" * "amountusd":"0.05" * "coinlabel":"BTC" * "coinname":"bitcoin" * "addr":"14dt2cSbvwghDcETJDuvFGHe5bCsCPR9jW" * "tx":"6f1c6f34189a27446d18e25b9c79db78be55b0bb775b1768b5aa4520f27d71a8" * "confirmed":0 * "timestamp":"1422623712" * "date":"30 January 2015" * "datetime":"2015-01-30 13:15:12" * } * * See more - https://gourl.io/api-php.html#ipn */ if (in_array($box_status, array("cryptobox_newrecord", "cryptobox_updated")) && function_exists('cryptobox_new_payment')) { cryptobox_new_payment($paymentID, $_POST, $box_status); } } else { $box_status = "Only POST Data Allowed"; } echo $box_status; // don't delete it