shop.balmet.com

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

pp_payflow_iframe.php (4133B)


      1 <?php
      2 class ModelExtensionPaymentPPPayflowIframe extends Model {
      3 	public function getMethod($address, $total) {
      4 		$this->load->language('extension/payment/pp_payflow_iframe');
      5 
      6 		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('payment_pp_payflow_iframe_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_pp_payflow_iframe_total') > $total) {
      9 			$status = false;
     10 		} elseif (!$this->config->get('payment_pp_payflow_iframe_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' => 'pp_payflow_iframe',
     23 				'title' => $this->language->get('text_title'),
     24 				'terms'      => '',
     25 				'sort_order' => $this->config->get('payment_pp_payflow_iframe_sort_order')
     26 			);
     27 		}
     28 
     29 		return $method_data;
     30 	}
     31 
     32 	public function getOrderId($secure_token_id) {
     33 		$result = $this->db->query("SELECT `order_id` FROM `" . DB_PREFIX . "paypal_payflow_iframe_order` WHERE `secure_token_id` = '" . $this->db->escape($secure_token_id) . "'")->row;
     34 
     35 		if ($result) {
     36 			$order_id = $result['order_id'];
     37 		} else {
     38 			$order_id = false;
     39 		}
     40 
     41 		return $order_id;
     42 	}
     43 
     44 	public function addOrder($order_id, $secure_token_id) {
     45 		$this->db->query("INSERT INTO `" . DB_PREFIX . "paypal_payflow_iframe_order` SET `order_id` = '" . (int)$order_id . "', `secure_token_id` = '" . $this->db->escape($secure_token_id) . "'");
     46 	}
     47 
     48 	public function updateOrder($data) {
     49 		$this->db->query("
     50 			UPDATE `" . DB_PREFIX . "paypal_payflow_iframe_order`
     51 			SET `transaction_reference` = '" . $this->db->escape($data['transaction_reference']) . "',
     52 				`transaction_type` = '" . $this->db->escape($data['transaction_type']) . "',
     53 				`complete` = " . (int)$data['complete'] . "
     54 			WHERE `secure_token_id` = '" . $this->db->escape($data['secure_token_id']) . "'
     55 		");
     56 	}
     57 
     58 	public function call($data) {
     59 		$default_parameters = array(
     60 			'USER' => $this->config->get('payment_pp_payflow_iframe_user'),
     61 			'VENDOR' => $this->config->get('payment_pp_payflow_iframe_vendor'),
     62 			'PWD' => $this->config->get('payment_pp_payflow_iframe_password'),
     63 			'PARTNER' => $this->config->get('payment_pp_payflow_iframe_partner'),
     64 			'BUTTONSOURCE' => 'OpenCart_Cart_PFP',
     65 		);
     66 
     67 		$call_parameters = array_merge($data, $default_parameters);
     68 
     69 		if ($this->config->get('payment_pp_payflow_iframe_test')) {
     70 			$url = 'https://pilot-payflowpro.paypal.com';
     71 		} else {
     72 			$url = 'https://payflowpro.paypal.com';
     73 		}
     74 
     75 		$query_params = array();
     76 
     77 		foreach ($call_parameters as $key => $value) {
     78 			$query_params[] = $key . '=' . utf8_decode($value);
     79 		}
     80 
     81 		$this->log('Call data: ' . implode('&', $query_params));
     82 
     83 		$curl = curl_init($url);
     84 
     85 		curl_setopt($curl, CURLOPT_POST, true);
     86 		curl_setopt($curl, CURLOPT_POSTFIELDS, implode('&', $query_params));
     87 		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     88 		curl_setopt($curl, CURLOPT_HEADER, false);
     89 		curl_setopt($curl, CURLOPT_TIMEOUT, 30);
     90 		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     91 
     92 		$response = curl_exec($curl);
     93 
     94 		$this->log('Response data: ' . $response);
     95 
     96 		$response_params = array();
     97 		parse_str($response, $response_params);
     98 
     99 		return $response_params;
    100 	}
    101 
    102 	public function addTransaction($data) {
    103 		$this->db->query("
    104 			INSERT INTO " . DB_PREFIX . "paypal_payflow_iframe_order_transaction
    105 			SET order_id = " . (int)$data['order_id'] . ",
    106 				transaction_reference = '" . $this->db->escape($data['transaction_reference']) . "',
    107 				transaction_type = '" . $this->db->escape($data['type']) . "',
    108 				`time` = NOW(),
    109 				`amount` = '" . $this->db->escape($data['amount']) .  "'
    110 		");
    111 	}
    112 
    113 	public function log($message) {
    114 		if ($this->config->get('payment_pp_payflow_iframe_debug')) {
    115 			$log = new Log('payflow-iframe.log');
    116 			$log->write($message);
    117 		}
    118 	}
    119 }