shop.balmet.com

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

securetrading_pp.php (5419B)


      1 <?php
      2 class ModelExtensionPaymentSecureTradingPp extends Model {
      3 	public function getMethod($address, $total) {
      4 		$this->load->language('extension/payment/securetrading_pp');
      5 
      6 		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('payment_securetrading_pp_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_securetrading_pp_total') > $total) {
      9 			$status = false;
     10 		} elseif (!$this->config->get('payment_securetrading_pp_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'       => 'securetrading_pp',
     23 				'title'      => $this->language->get('text_title'),
     24 				'terms'      => '',
     25 				'sort_order' => $this->config->get('payment_securetrading_pp_sort_order')
     26 			);
     27 		}
     28 
     29 		return $method_data;
     30 	}
     31 
     32 	public function getOrder($order_id) {
     33 		$qry = $this->db->query("SELECT * FROM `" . DB_PREFIX . "securetrading_pp_order` WHERE `order_id` = '" . (int)$order_id . "' LIMIT 1");
     34 
     35 		return $qry->row;
     36 	}
     37 
     38 	public function editOrder($order_id, $order) {
     39 		$this->db->query("UPDATE `" . DB_PREFIX . "order` SET shipping_firstname = '" . $this->db->escape($order['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($order['shipping_lastname']) . "', shipping_address_1 = '" . $this->db->escape($order['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($order['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($order['shipping_city']) . "', shipping_zone = '" . $this->db->escape($order['shipping_zone']) . "', shipping_zone_id = " . (int)$order['shipping_zone_id'] . ", shipping_country = '" . $this->db->escape($order['shipping_country']) . "', shipping_country_id = " . (int)$order['shipping_country_id'] . ", shipping_postcode = '" . $this->db->escape($order['shipping_postcode']) . "',  payment_firstname = '" . $this->db->escape($order['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($order['payment_lastname']) . "', payment_address_1 = '" . $this->db->escape($order['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($order['payment_address_2']) . "', payment_city = '" . $this->db->escape($order['payment_city']) . "', payment_zone = '" . $this->db->escape($order['payment_zone']) . "', payment_zone_id = " . (int)$order['payment_zone_id'] . ", payment_country = '" . $this->db->escape($order['payment_country']) . "', payment_country_id = " . (int)$order['payment_country_id'] . ", payment_postcode = '" . $this->db->escape($order['payment_postcode']) . "' WHERE order_id = " . (int)$order_id);
     40 	}
     41 
     42 	public function addReference($order_id, $reference) {
     43 		$this->db->query("REPLACE INTO " . DB_PREFIX . "securetrading_pp_order SET order_id = " . (int)$order_id . ", transaction_reference = '" . $this->db->escape($reference) . "', `created` = now()");
     44 	}
     45 
     46 	public function confirmOrder($order_id, $order_status_id, $comment = '', $notify = false) {
     47 
     48 		$this->logger('confirmOrder');
     49 
     50 		$this->load->model('checkout/order');
     51 
     52 		$this->db->query("UPDATE `" . DB_PREFIX . "order` SET order_status_id = 0 WHERE order_id = "  . (int)$order_id);
     53 
     54 		$this->model_checkout_order->addOrderHistory($order_id, $order_status_id, $comment, $notify);
     55 
     56 		$order_info = $this->model_checkout_order->getOrder($order_id);
     57 
     58 		$securetrading_pp_order = $this->getOrder($order_id);
     59 
     60 		$amount = $this->currency->format($order_info['total'], $order_info['currency_code'], false, false);
     61 
     62 		switch($this->config->get('payment_securetrading_pp_settle_status')){
     63 			case 0:
     64 				$trans_type = 'auth';
     65 				break;
     66 			case 1:
     67 				$trans_type = 'auth';
     68 				break;
     69 			case 2:
     70 				$trans_type = 'suspended';
     71 				break;
     72 			case 100:
     73 				$trans_type = 'payment';
     74 				break;
     75 			default :
     76 				$trans_type = 'default';
     77 		}
     78 
     79 		$this->db->query("UPDATE `" . DB_PREFIX . "securetrading_pp_order` SET `settle_type` = '" . $this->config->get('payment_securetrading_pp_settle_status') . "', `modified` = now(), `currency_code` = '" . $this->db->escape($order_info['currency_code']) . "', `total` = '" . $amount . "' WHERE order_id = " . (int)$order_info['order_id']);
     80 
     81 		$this->db->query("INSERT INTO `" . DB_PREFIX . "securetrading_pp_order_transaction` SET `securetrading_pp_order_id` = '" . (int)$securetrading_pp_order['securetrading_pp_order_id'] . "', `amount` = '" . $amount . "', type = '" . $trans_type . "',  `created` = now()");
     82 
     83 	}
     84 
     85 	public function updateOrder($order_id, $order_status_id, $comment = '', $notify = false) {
     86 		$this->load->model('checkout/order');
     87 
     88 		$this->db->query("UPDATE `" . DB_PREFIX . "order` SET order_status_id = " . (int)$order_status_id . " WHERE order_id = " . (int)$order_id);
     89 
     90 		$this->model_checkout_order->addOrderHistory($order_id, $order_status_id, $comment, $notify);
     91 	}
     92 
     93 	public function getCountry($iso_code_2) {
     94 		return $this->db->query("SELECT * FROM " . DB_PREFIX . "country WHERE LOWER(iso_code_2) = '" . $this->db->escape($iso_code_2) . "'")->row;
     95 	}
     96 
     97 	public function logger($message) {
     98 		$log = new Log('secure.log');
     99 		$log->write($message);
    100 	}
    101 }