shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

firstdata.php (5232B)


      1 <?php
      2 class ModelExtensionPaymentFirstdata extends Model {
      3 	public function getMethod($address, $total) {
      4 		$this->load->language('extension/payment/firstdata');
      5 
      6 		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('payment_firstdata_geo_zone_id') . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");
      7 
      8 		if ($this->config->get('payment_firstdata_total') > 0 && $this->config->get('payment_firstdata_total') > $total) {
      9 			$status = false;
     10 		} elseif (!$this->config->get('payment_firstdata_geo_zone_id')) {
     11 			$status = true;
     12 		} elseif ($query->num_rows) {
     13 			$status = true;
     14 		} else {
     15 			$status = false;
     16 		}
     17 
     18 		$method_data = array();
     19 
     20 		if ($status) {
     21 			$method_data = array(
     22 				'code'       => 'firstdata',
     23 				'title'      => $this->language->get('text_title'),
     24 				'terms'      => '',
     25 				'sort_order' => $this->config->get('payment_firstdata_sort_order')
     26 			);
     27 		}
     28 
     29 		return $method_data;
     30 	}
     31 
     32 	public function addOrder($order_info, $order_ref, $transaction_date) {
     33 		if ($this->config->get('payment_firstdata_auto_settle') == 1) {
     34 			$settle_status = 1;
     35 		} else {
     36 			$settle_status = 0;
     37 		}
     38 
     39 		$this->db->query("INSERT INTO `" . DB_PREFIX . "firstdata_order` SET `order_id` = '" . (int)$order_info['order_id'] . "', `order_ref` = '" . $this->db->escape($order_ref) . "', `tdate` = '" . $this->db->escape($transaction_date) . "', `date_added` = now(), `date_modified` = now(), `capture_status` = '" . (int)$settle_status . "', `currency_code` = '" . $this->db->escape($order_info['currency_code']) . "', `total` = '" . $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false) . "'");
     40 
     41 		return $this->db->getLastId();
     42 	}
     43 
     44 	public function getOrder($order_id) {
     45 		$order = $this->db->query("SELECT * FROM `" . DB_PREFIX . "firstdata_order` WHERE `order_id` = '" . (int)$order_id . "' LIMIT 1");
     46 
     47 		return $order->row;
     48 	}
     49 
     50 	public function addTransaction($fd_order_id, $type, $order_info = array()) {
     51 		if (!empty($order_info)) {
     52 			$amount = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false);
     53 		} else {
     54 			$amount = 0.00;
     55 		}
     56 
     57 		$this->db->query("INSERT INTO `" . DB_PREFIX . "firstdata_order_transaction` SET `firstdata_order_id` = '" . (int)$fd_order_id . "', `date_added` = now(), `type` = '" . $this->db->escape($type) . "', `amount` = '" . (float)$amount . "'");
     58 	}
     59 
     60 	public function addHistory($order_id, $order_status_id, $comment) {
     61 		$this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int)$order_id . "', order_status_id = '" . (int)$order_status_id . "', notify = '0', comment = '" . $this->db->escape($comment) . "', date_added = NOW()");
     62 	}
     63 
     64 	public function logger($message) {
     65 		if ($this->config->get('payment_firstdata_debug') == 1) {
     66 			$log = new Log('firstdata.log');
     67 			$log->write($message);
     68 		}
     69 	}
     70 
     71 	public function mapCurrency($code) {
     72 		$currency = array(
     73 			'GBP' => 826,
     74 			'USD' => 840,
     75 			'EUR' => 978,
     76 		);
     77 
     78 		if (array_key_exists($code, $currency)) {
     79 			return $currency[$code];
     80 		} else {
     81 			return false;
     82 		}
     83 	}
     84 
     85 	public function getStoredCards() {
     86 		$customer_id = $this->customer->getId();
     87 
     88 		$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "firstdata_card` WHERE `customer_id` = '" . (int)$customer_id . "'");
     89 
     90 		return $query->rows;
     91 	}
     92 
     93 	public function storeCard($token, $customer_id, $month, $year, $digits) {
     94 		$existing_card = $this->db->query("SELECT * FROM `" . DB_PREFIX . "firstdata_card` WHERE `token` = '" . $this->db->escape($token) . "' AND `customer_id` = '" . (int)$customer_id . "' LIMIT 1");
     95 
     96 		if ($existing_card->num_rows > 0) {
     97 			$this->db->query("UPDATE `" . DB_PREFIX . "firstdata_card` SET `expire_month` = '" . $this->db->escape($month) . "', `expire_year` = '" . $this->db->escape($year) . "', `digits` = '" . $this->db->escape($digits) . "'");
     98 		} else {
     99 			$this->db->query("INSERT INTO `" . DB_PREFIX . "firstdata_card` SET `customer_id` = '" . (int)$customer_id . "', `date_added` = now(), `token` = '" . $this->db->escape($token) . "', `expire_month` = '" . $this->db->escape($month) . "', `expire_year` = '" . $this->db->escape($year) . "', `digits` = '" . $this->db->escape($digits) . "'");
    100 		}
    101 	}
    102 
    103 	public function responseHash($total, $currency, $txn_date, $approval_code) {
    104 		$tmp = $total . $this->config->get('payment_firstdata_secret') . $currency . $txn_date . $this->config->get('payment_firstdata_merchant_id') . $approval_code;
    105 
    106 		$ascii = bin2hex($tmp);
    107 
    108 		return sha1($ascii);
    109 	}
    110 
    111 	public function updateVoidStatus($order_id, $status) {
    112 		$this->db->query("UPDATE `" . DB_PREFIX . "firstdata_order` SET `void_status` = '" . (int)$status . "' WHERE `order_id` = '" . (int)$order_id . "'");
    113 	}
    114 
    115 	public function updateCaptureStatus($order_id, $status) {
    116 		$this->db->query("UPDATE `" . DB_PREFIX . "firstdata_order` SET `capture_status` = '" . (int)$status . "' WHERE `order_id` = '" . (int)$order_id . "'");
    117 	}
    118 }