shop.balmet.com

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

pilibaba.php (4137B)


      1 <?php
      2 class ModelExtensionPaymentPilibaba extends Model {
      3 	public function getMethod($address, $total) {
      4 		$this->load->language('extension/payment/pilibaba');
      5 
      6 		$status = true;
      7 
      8 		if (!isset($this->session->data['shipping_method']['code']) || $this->session->data['shipping_method']['code'] != 'pilibaba.pilibaba') {
      9 			$status = false;
     10 		}
     11 
     12 		$method_data = array();
     13 
     14 		if ($status) {
     15 			$method_data = array(
     16 				'code'			=> 'pilibaba',
     17 				'title'			=> $this->language->get('text_title'),
     18 				'terms'			=> '',
     19 				'sort_order'	=> $this->config->get('payment_pilibaba_sort_order')
     20 			);
     21 		}
     22 
     23 		return $method_data;
     24 	}
     25 
     26 	public function getOrderTaxAmount($order_id) {
     27 		$query = $this->db->query("SELECT SUM(`value`) AS `value` FROM `" . DB_PREFIX . "order_total` WHERE `order_id` = '" . (int)$order_id . "' AND `code` = 'tax'");
     28 
     29 		if ($query->num_rows) {
     30 			return intval(round($query->row['value'], 2) * 100);
     31 		} else {
     32 			return 0;
     33 		}
     34 	}
     35 
     36 	public function addPilibabaOrder($response_data) {
     37 		$this->db->query("INSERT INTO `" . DB_PREFIX . "pilibaba_order` SET `order_id` = '" . (int)$response_data['orderNo'] . "', `amount` = '" . (float)$response_data['orderAmount'] . "', `fee` = '" . (float)$response_data['fee'] . "', `tracking` = '', `date_added` = NOW()");
     38 	}
     39 
     40 	public function getConsumerInfo($order_id) {
     41 		$sign_msg = strtoupper(md5($this->config->get('payment_pilibaba_merchant_number') . $order_id . 'MD5' . $this->config->get('payment_pilibaba_secret_key')));
     42 
     43 		if ($this->config->get('payment_pilibaba_environment') == 'live') {
     44 			$url = 'https://www.pilibaba.com/pilipay/consumerInfo';
     45 		} else {
     46 			$url = 'http://pre.pilibaba.com/pilipay/consumerInfo';
     47 		}
     48 
     49 		$url .= '?merchantNo=' . $this->config->get('payment_pilibaba_merchant_number') . '&orderNo=' . $order_id . '&signType=' . 'MD5' . '&signMsg=' . $sign_msg;
     50 
     51 		$this->log('URL: ' . $url);
     52 
     53 		$ch = curl_init();
     54 		curl_setopt($ch, CURLOPT_URL, $url);
     55 		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
     56 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     57 		curl_setopt($ch, CURLOPT_HEADER, false);
     58 		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
     59 		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     60 		$response = curl_exec($ch);
     61 		if (curl_errno($ch)) {
     62 			$this->log('cURL error: ' . curl_errno($ch));
     63 		}
     64 		curl_close($ch);
     65 
     66 		$this->log('Response: ' . print_r($response, true));
     67 
     68 		return json_decode($response, true);
     69 	}
     70 
     71 	public function updateOrderInfo($data, $order_id) {
     72 		$parts = explode(' ', $data['name']);
     73 
     74 		$data['lastname'] = array_pop($parts);
     75 
     76 		$data['firstname'] = implode(' ', $parts);
     77 
     78 		$this->db->query("UPDATE `" . DB_PREFIX . "order` SET `firstname` = '" . $this->db->escape($data['firstname']) . "', `lastname` = '" . $this->db->escape($data['lastname']) . "', `email` = '" . $this->db->escape($data['email']) . "', `telephone` = '" . $this->db->escape($data['mobile']) . "', `payment_firstname` = '" . $this->db->escape($data['firstname']) . "', `payment_lastname` = '" . $this->db->escape($data['lastname']) . "', `payment_address_1` = '" . $this->db->escape($data['address']) . "', `payment_city` = '" . $this->db->escape($data['city']) . "', `payment_postcode` = '" . $this->db->escape($data['zipcode']) . "', `payment_country` = '" . $this->db->escape($data['country']) . "', `payment_zone` = '" . $this->db->escape($data['district']) . "', `shipping_firstname` = '" . $this->db->escape($data['firstname']) . "', `shipping_lastname` = '" . $this->db->escape($data['lastname']) . "', `shipping_address_1` = '" . $this->db->escape($data['address']) . "', `shipping_city` = '" . $this->db->escape($data['city']) . "', `shipping_postcode` = '" . $this->db->escape($data['zipcode']) . "', `shipping_country` = '" . $this->db->escape($data['country']) . "', `shipping_zone` = '" . $this->db->escape($data['district']) . "', `date_modified` = NOW() WHERE `order_id` = '" . (int)$order_id . "'");
     79 	}
     80 
     81 	public function log($data) {
     82 		if ($this->config->get('payment_pilibaba_logging')) {
     83 			$log = new Log('pilibaba.log');
     84 
     85 			$log->write($data);
     86 		}
     87 	}
     88 }