g2apay.php (3167B)
1 <?php 2 class ModelExtensionPaymentG2APay extends Model { 3 4 public function getMethod($address, $total) { 5 $this->load->language('extension/payment/g2apay'); 6 7 $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('payment_g2apay_geo_zone_id') . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')"); 8 9 if ($this->config->get('payment_g2apay_total') > 0 && $this->config->get('payment_g2apay_total') > $total) { 10 $status = false; 11 } elseif (!$this->config->get('payment_g2apay_geo_zone_id')) { 12 $status = true; 13 } elseif ($query->num_rows) { 14 $status = true; 15 } else { 16 $status = false; 17 } 18 19 $method_data = array(); 20 21 if ($status) { 22 $method_data = array( 23 'code' => 'g2apay', 24 'title' => $this->language->get('text_title'), 25 'terms' => '', 26 'sort_order' => $this->config->get('payment_g2apay_sort_order') 27 ); 28 } 29 30 return $method_data; 31 } 32 33 public function addG2aOrder($order_info) { 34 $this->db->query("INSERT INTO `" . DB_PREFIX . "g2apay_order` SET `order_id` = '" . (int)$order_info['order_id'] . "', `date_added` = now(), `modified` = now(), `currency_code` = '" . $this->db->escape($order_info['currency_code']) . "', `total` = '" . $this->currency->format($order_info['total'], $order_info['currency_code'], false, false) . "'"); 35 } 36 37 public function updateOrder($g2apay_order_id, $g2apay_transaction_id, $type, $order_info) { 38 $this->db->query("UPDATE `" . DB_PREFIX . "g2apay_order` SET `g2apay_transaction_id` = '" . $this->db->escape($g2apay_transaction_id) . "', `modified` = now() WHERE `order_id` = '" . (int)$order_info['order_id'] . "'"); 39 40 $this->addTransaction($g2apay_order_id, $type, $order_info); 41 42 } 43 44 public function addTransaction($g2apay_order_id, $type, $order_info) { 45 $this->db->query("INSERT INTO `" . DB_PREFIX . "g2apay_order_transaction` SET `g2apay_order_id` = '" . (int)$g2apay_order_id . "', `date_added` = now(), `type` = '" . $this->db->escape($type) . "', `amount` = '" . $this->currency->format($order_info['total'], $order_info['currency_code'], false, false) . "'"); 46 } 47 48 public function getG2aOrder($order_id) { 49 $qry = $this->db->query("SELECT * FROM `" . DB_PREFIX . "g2apay_order` WHERE `order_id` = '" . (int)$order_id . "' LIMIT 1"); 50 51 if ($qry->num_rows) { 52 return $qry->row; 53 } else { 54 return false; 55 } 56 } 57 58 public function sendCurl($url, $fields) { 59 $curl = curl_init($url); 60 61 curl_setopt($curl, CURLOPT_URL, $url); 62 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 63 curl_setopt($curl, CURLOPT_POST, true); 64 curl_setopt($curl, CURLOPT_POSTFIELDS, $fields); 65 $response = curl_exec($curl); 66 67 curl_close($curl); 68 69 return json_decode($response); 70 } 71 72 public function logger($message) { 73 if ($this->config->get('payment_g2apay_debug') == 1) { 74 $log = new Log('g2apay.log'); 75 $backtrace = debug_backtrace(); 76 $log->write('Origin: ' . $backtrace[6]['class'] . '::' . $backtrace[6]['function']); 77 $log->write(print_r($message, 1)); 78 } 79 } 80 }