Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class fortumo {
- public function fortumo() {
- global $db;
- global $config_table_prefix;
- $arr = fetchAssoc("select `processor_table`, `processor_ret_table` from " . TABLE_PAYMENT_PROCESSORS . " where `processor_code` like 'fortumo'");
- $this->table = $config_table_prefix . $arr['processor_table'];
- $this->ret_table = $config_table_prefix . $arr['processor_ret_table'];
- $this->name = "fortumo";
- }
- public function gettable() {
- global $db;
- global $config_table_prefix;
- $table = $config_table_prefix . fetchRow("select `processor_table` from " . TABLE_PAYMENT_PROCESSORS . " where `processor_code` like 'fortumo'");
- return $table;
- }
- public function settable($table) {
- $this->table = $table;
- }
- public function setamount($str) {
- $amount = number_format($str, 2, ".", "");
- $this->post['amount'] = $amount;
- $this->amount = $amount;
- }
- public function init($key = "") {
- global $config_live_site;
- $this->pending = 0;
- if ($key) {
- $this->user_key = $key;
- } else if (isset($_GET['ukey']) && $_GET['ukey']) {
- $this->user_key = $_GET['ukey'];
- } else if (isset($_GET['message']) && $_GET['message']) {
- $this->user_key = getKey();
- } else {
- $this->user_key = randCode();
- }
- $this->postback_url = $config_live_site . "/payment_return/fortumo.php";
- $this->pay_settings = getSettings();
- setTest($this->pay_settings['test']);
- $this->fortumo_keys = array("message", "sender", "country", "price", "currency", "service_id", "message_id", "keyword", "shortcode", "operator", "billing_type", "status", "test", "sig");
- }
- public function randcode() {
- return random_string(6);
- }
- public function random_string($len = 5, $str = "") {
- $i = 1;
- while ($i <= $len) {
- $ord = rand(49, 104);
- if (49 <= $ord && $ord <= 57 || 97 <= $ord && $ord <= 104) {
- $str.= chr($ord);
- } else {
- $str.= random_string(1);
- }
- ++$i;
- }
- return $str;
- }
- public function getkey() {
- if (!$_GET['message'] || !$_GET['keyword']) {
- return "";
- }
- $msg = urldecode($_GET['message']);
- $keyword = urldecode($_GET['keyword']);
- return trim(substr($msg, strlen($keyword)));
- }
- public function getuserkey() {
- return $this->user_key;
- }
- public function getpost() {
- }
- public function setdebug($val) {
- $this->debug = $val;
- }
- public function setformtitle($val) {
- $this->formTitle = $val;
- }
- public function setinvoiceno($val) {
- $this->invoice_no = $val;
- }
- public function settest($value) {
- if ($value == 1) {
- $this->test = "true";
- return 1;
- }
- $this->test = "false";
- return 1;
- }
- public function getsettings() {
- global $db;
- $result = fetchAssoc("select * from " . $this->table);
- return $result;
- }
- public function getform() {
- $form = "<form method=\"post\" name=\"payment_form\" id=\"payment_form\" action=\"/payment_return/fortumo.php?ukey=%s\">\n<input type=\"submit\" name=\"submit_payment\" value=\"%s\">\n</form>";
- $str = sprintf($form, $this->user_key, $this->formTitle);
- return $str;
- }
- public function info() {
- $i = $this->info();
- $str = getVal("fortumo_info");
- $key = $this->pay_settings['keyword'] . " " . $this->user_key;
- $str = str_replace("::KEY::", $key, $str);
- $str = str_replace("::SHORT_CODE::", $this->pay_settings['short_code'], $str);
- global $db;
- $amount = fetchRow("select `amount` from " . TABLE_PAYMENT_ACTIONS . " where ukey='" . $this->user_key . "'");
- $str = str_replace("::AMOUNT::", $amount, $str);
- return $str;
- }
- public function process() {
- $i = $this->info();
- $failed_info = getVal("fortumo_failed");
- $success_info = getVal("fortumo_success");
- if (!in_array($_SERVER['REMOTE_ADDR'], array("81.20.151.38", "81.20.148.122", "209.20.83.207"))) {
- log("validateData: ERROR: Invalid IP:" . $_SERVER['REMOTE_ADDR']);
- echo $failed_info;
- return 0;
- }
- $secret = $this->pay_settings['secret'];
- if (!empty($secret) && !check_signature($_GET, $secret)) {
- log("validateData: ERROR: Invalid signature!");
- echo $failed_info;
- return 0;
- }
- echo $success_info;
- $success = 0;
- $success = saveToDB();
- if (!$success) {
- log("saveToDB: ERROR: Cannot save to db!");
- }
- logIt($success);
- return 1;
- }
- public function check_signature($params_array, $secret) {
- ksort($params_array);
- $str = "";
- foreach($params_array as $k => $v) {
- if ($k != "sig" && $k != "mode") {
- $str.= "{$k}={$v}";
- }
- }
- $str.= $secret;
- $signature = md5($str);
- return $params_array['sig'] == $signature;
- }
- public function savetodb() {
- global $db;
- $addtosql = "";
- $entirepost = "";
- foreach($_GET as $key => $val) {
- if (in_array($key, $this->fortumo_keys)) {
- $addtosql.= $key . "='" . $val . "',";
- }
- $entirepost.= "[" . $key . "]=\\'" . $val . "\\',";
- }
- $addtosql = rtrim($addtosql, ",");
- $res_upd = query("update " . TABLE_PAYMENT_ACTIONS . " SET completed='1' where ukey='" . $this->user_key . "'");
- $timestamp = date("Y-m-d H:i:s");
- $res = query("INSERT INTO " . $this->ret_table . " SET date='{$timestamp}', entirepost='" . $entirepost . "', " . $addtosql . ",ukey='" . $this->user_key . "'");
- return 1;
- }
- public function logit($success) {
- if (!$this->debug) {
- } else {
- $content = "-----------------------------------\n" . date("r") . "\n";
- $content.= "RECEIVED values:\n";
- foreach($_GET as $key => $val) {
- $content.= escape($key) . "=" . escape($val) . "\n";
- }
- $content.= "-----------------------------------\n";
- global $config_abs_path;
- $file = $config_abs_path . "/log/fortumo_transaction";
- if (!$success) {
- $file = $config_abs_path . "/log/fortumo_error";
- }
- $handle = fopen($file, "a");
- fwrite($handle, $content);
- fclose($handle);
- }
- }
- public function log($msg) {
- if (!$this->debug) {
- } else {
- $content = "-----------------------------------\n" . date("r") . "\n";
- $content.= $msg . "\n";
- $content.= "-----------------------------------\n";
- global $config_abs_path;
- $file = $config_abs_path . "/log/fortumo_debug";
- $handle = fopen($file, "a");
- fwrite($handle, $content);
- fclose($handle);
- }
- }
- public function geterror() {
- return $this->error;
- }
- public function adderror($str) {
- $this->error.= $str;
- }
- public function seterror($str) {
- $this->error = $str;
- }
- public function gettmp() {
- return $this->tmp;
- }
- public function check_form() {
- global $lng;
- $array_required = array("paypal_email", "paypal_currency");
- foreach($array_required as $field) {
- if (!isset($_POST[$field])) {
- addError($lng['settings']['errors']["required_" . $field] . "<br />");
- }
- }
- if (getError() != "") {
- if ($_POST['paypal_demo'] == "on") {
- $this->tmp['paypal_demo'] = 1;
- } else {
- $this->tmp['paypal_demo'] = 0;
- }
- $array_fields = array("paypal_email", "paypal_currency", "paypal_pay_title");
- foreach($array_fields as $field) {
- if (isset($_POST[$field])) {
- $this->tmp[$field] = clean($_POST[$field]);
- }
- }
- }
- }
- public function savesettings() {
- global $lng;
- $this->error = "";
- $this->tmp = array();
- $this->clean = array();
- check_form();
- if (getError() != "") {
- return 0;
- }
- global $config_demo;
- if ($config_demo == 1) {
- addError($lng['general']['errors']['demo'] . "<br />");
- }
- global $db;
- $this->clean['test'] = checkbox_value("test");
- $sql = "update " . $this->table . " set test = " . $this->clean['test'];
- $array_fields = array("keyword", "short_code", "secret", "currency");
- foreach($array_fields as $field) {
- if (isset($_POST[$field])) {
- $this->clean[$field] = escape($_POST[$field]);
- } else {
- $this->clean[$field] = "";
- }
- $sql.= ", `{$field}` = '" . $this->clean[$field] . "'";
- }
- query($sql);
- return 1;
- }
- public function correctsettings() {
- return 1;
- }
- public function getpending() {
- return $this->pending;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement