pp_payflow_iframe.php (4375B)
1 <?php 2 class ModelExtensionPaymentPPPayflowIFrame extends Model { 3 public function install() { 4 $this->db->query(" 5 CREATE TABLE `" . DB_PREFIX . "paypal_payflow_iframe_order` ( 6 `order_id` int(11) DEFAULT NULL, 7 `secure_token_id` varchar(255) NOT NULL, 8 `transaction_reference` varchar(255) DEFAULT NULL, 9 `transaction_type` varchar(1) DEFAULT NULL, 10 `complete` tinyint(4) NOT NULL DEFAULT '0', 11 PRIMARY KEY(`order_id`), 12 KEY `secure_token_id` (`secure_token_id`) 13 ) ENGINE=MyISAM DEFAULT COLLATE=utf8_general_ci"); 14 15 $this->db->query(" 16 CREATE TABLE `" . DB_PREFIX . "paypal_payflow_iframe_order_transaction` ( 17 `order_id` int(11) NOT NULL, 18 `transaction_reference` varchar(255) NOT NULL, 19 `transaction_type` char(1) NOT NULL, 20 `time` datetime NOT NULL, 21 `amount` decimal(10,4) DEFAULT NULL, 22 PRIMARY KEY (`transaction_reference`), 23 KEY `order_id` (`order_id`) 24 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); 25 } 26 27 public function uninstall() { 28 $this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "paypal_payflow_iframe_order`;"); 29 $this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "paypal_payflow_iframe_order_transaction`;"); 30 } 31 32 public function log($message) { 33 if ($this->config->get('payment_pp_payflow_iframe_debug')) { 34 $log = new Log('payflow-iframe.log'); 35 $log->write($message); 36 } 37 } 38 39 public function getOrder($order_id) { 40 $result = $this->db->query("SELECT * FROM " . DB_PREFIX . "paypal_payflow_iframe_order WHERE order_id = " . (int)$order_id); 41 42 if ($result->num_rows) { 43 $order = $result->row; 44 } else { 45 $order = false; 46 } 47 48 return $order; 49 } 50 51 public function updateOrderStatus($order_id, $status) { 52 $this->db->query(" 53 UPDATE " . DB_PREFIX . "paypal_payflow_iframe_order 54 SET `complete` = " . (int)$status . " 55 WHERE order_id = '" . (int)$order_id . "' 56 "); 57 } 58 59 public function addTransaction($data) { 60 $this->db->query(" 61 INSERT INTO " . DB_PREFIX . "paypal_payflow_iframe_order_transaction 62 SET order_id = " . (int)$data['order_id'] . ", 63 transaction_reference = '" . $this->db->escape($data['transaction_reference']) . "', 64 transaction_type = '" . $this->db->escape($data['type']) . "', 65 `time` = NOW(), 66 `amount` = '" . $this->db->escape($data['amount']) . "' 67 "); 68 } 69 70 public function getTransactions($order_id) { 71 return $this->db->query(" 72 SELECT * 73 FROM " . DB_PREFIX . "paypal_payflow_iframe_order_transaction 74 WHERE order_id = " . (int)$order_id . " 75 ORDER BY `time` ASC")->rows; 76 } 77 78 public function getTransaction($transaction_reference) { 79 $result = $this->db->query(" 80 SELECT * 81 FROM " . DB_PREFIX . "paypal_payflow_iframe_order_transaction 82 WHERE transaction_reference = '" . $this->db->escape($transaction_reference) . "'")->row; 83 84 if ($result) { 85 $transaction = $result; 86 } else { 87 $transaction = false; 88 } 89 90 return $transaction; 91 } 92 93 public function call($data) { 94 $default_parameters = array( 95 'USER' => $this->config->get('payment_pp_payflow_iframe_user'), 96 'VENDOR' => $this->config->get('payment_pp_payflow_iframe_vendor'), 97 'PWD' => $this->config->get('payment_pp_payflow_iframe_password'), 98 'PARTNER' => $this->config->get('payment_pp_payflow_iframe_partner'), 99 'BUTTONSOURCE' => 'OpenCart_Cart_PFP', 100 ); 101 102 $call_parameters = array_merge($data, $default_parameters); 103 104 if ($this->config->get('payment_pp_payflow_iframe_test')) { 105 $url = 'https://pilot-payflowpro.paypal.com'; 106 } else { 107 $url = 'https://payflowpro.paypal.com'; 108 } 109 110 $query_params = array(); 111 112 foreach ($call_parameters as $key => $value) { 113 $query_params[] = $key . '=' . utf8_decode($value); 114 } 115 116 $this->log('Call data: ' . implode('&', $query_params)); 117 118 $curl = curl_init($url); 119 120 curl_setopt($curl, CURLOPT_POST, true); 121 curl_setopt($curl, CURLOPT_POSTFIELDS, implode('&', $query_params)); 122 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 123 curl_setopt($curl, CURLOPT_HEADER, false); 124 curl_setopt($curl, CURLOPT_TIMEOUT, 30); 125 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 126 127 $response = curl_exec($curl); 128 129 $this->log('Response data: ' . $response); 130 131 $response_params = array(); 132 parse_str($response, $response_params); 133 134 return $response_params; 135 } 136 }