PageRenderTime 75ms CodeModel.GetById 41ms app.highlight 12ms RepoModel.GetById 18ms app.codeStats 0ms

/includes/modules/payment/smscoin.php

https://bitbucket.org/smscoin/zen_cart_bank
PHP | 253 lines | 132 code | 29 blank | 92 comment | 14 complexity | 3ea175f06bb9effd505e4b319dd9cd94 MD5 | raw file
  1<?php
  2/*
  3=====================================================
  4 OSCommerce plugin - by SmsCoin
  5-----------------------------------------------------
  6 http://smscoin.com
  7-----------------------------------------------------
  8 Copyright (c) 2008 SmsCoin
  9=====================================================
 10 Файл: smscoin.php
 11-----------------------------------------------------
 12 Purpose: payment module via SMS message
 13=====================================================
 14*/
 15
 16include_once(dirname(__FILE__)."/../../languages/$_SESSION[language]/modules/payment/smscoin.php");
 17
 18###
 19#  MD5 sign
 20#  Функция генерации md5 подписи
 21###
 22function ref_sign() {
 23	$params = func_get_args();
 24	$prehash = implode("::", $params);
 25	return md5($prehash);
 26}
 27
 28class smscoin extends base {
 29
 30	var $code, $title, $description, $enabled;
 31	###
 32	#  Constructor
 33	#  Функция конструктор
 34	###
 35	function smscoin() {
 36		global $order;
 37		$this->code = 'smscoin';
 38		$this->title = MODULE_PAYMENT_SMSCOIN_TEXT_TITLE;
 39		$this->description = MODULE_PAYMENT_SMSCOIN_TEXT_DESCRIPTION;
 40		$this->sort_order = MODULE_PAYMENT_SMSCOIN_SORT_ORDER;
 41		$this->enabled = ((MODULE_PAYMENT_SMSCOIN_STATUS == 'True') ? true : false);
 42
 43		if (is_object($order)) $this->update_status();
 44
 45		$this->form_action_url = MODULE_PAYMENT_SMSCOIN_HTTP_ADDR;
 46	}
 47	###
 48	#  Update status
 49	#  Функция обновления статуса
 50	###
 51	function update_status() {
 52		global $order, $db;
 53
 54		if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_SMSCOIN_ZONE > 0) ) {
 55			$check_flag = false;
 56			$check_query = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_SMSCOIN_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
 57			while (!$check_query->EOF) {
 58				if ($check_query->fields['zone_id'] < 1) {
 59					$check_flag = true;
 60					break;
 61				} elseif ($check_query->fields['zone_id'] == $order->billing['zone_id']) {
 62					$check_flag = true;
 63					break;
 64				}
 65				$check_query->MoveNext();
 66			}
 67
 68			if ($check_flag == false) {
 69				$this->enabled = false;
 70			}
 71		}
 72	}
 73	###
 74	#  Validation
 75	#  Функция валидации
 76	###
 77	function javascript_validation() {
 78		return false;
 79	}
 80	###
 81	#  Select
 82	#  Функция выделения
 83	###
 84	function selection() {
 85		return array('id' => $this->code,
 86			   'module' => $this->title);
 87	}
 88	###
 89	#  Pre confirmation
 90	#  Функция проверки подтверждения
 91	###
 92	function pre_confirmation_check() {
 93		return false;
 94	}
 95	###
 96	#  Confirmation
 97	#  Функция подтверждения
 98	###
 99	function confirmation() {
100		global $_POST;
101		return array('title' => MODULE_PAYMENT_SMSCOIN_TEXT_DESCRIPTION);
102	}
103	###
104	#  Show payment button
105	#  Функция генерации кнопки
106	###
107	function process_button() {
108		global $order, $currencies, $currency, $db;
109
110		$products = '';
111		foreach($order->products as $key => $product) {
112			$products .= $product['name'];
113			if (@$product['attributes'] !='') {
114				foreach($product['attributes'] as $key => $attribut) {
115					$products .= ' (' . $attribut['option'].': ' . $attribut['value'] . ')';
116				}
117			}
118		}
119
120		$currency = $_SESSION['currency'];
121		$amount = number_format($order->info['total'] * $currencies->get_value($currency), 2);
122
123		$clear_amount = '0';
124
125		$crc = ref_sign(MODULE_PAYMENT_SMSCOIN_ID,$_SESSION['customer_id'],$amount,$clear_amount,$products,MODULE_PAYMENT_SMSCOIN_SECRET_KEY);
126
127		$process_button_string = zen_draw_hidden_field('s_purse', MODULE_PAYMENT_SMSCOIN_ID) ."\n".
128								zen_draw_hidden_field('s_order_id', $_SESSION['customer_id']) ."\n" .
129								zen_draw_hidden_field('s_amount', $amount)  ."\n".
130								zen_draw_hidden_field('s_clear_amount', $clear_amount) ."\n" .
131								zen_draw_hidden_field('s_description', $products) ."\n" .
132								zen_draw_hidden_field('s_sign', $crc) ."\n";
133		$order->info['payment_module_code'] = $_SESSION['payment'];
134		$order->info['payment_method'] = $_SESSION['payment'];
135		$order_total_modules = new order_total;
136		$order_totals = $order_total_modules->pre_confirmation_check();
137		$order_totals = $order_total_modules->process();
138		$insert_id = $order->create($order_totals, 2);
139		$order->create_add_products($insert_id);
140		$_SESSION['cart']->reset(true);
141		return $process_button_string;
142	}
143
144	###
145	#  Payment proccess
146	#  Функция препроцесса
147	###
148	function before_process() {
149		global $_POST;
150
151		$purse	  = $_POST["s_purse"];		// sms:bank id	  идентификатор смс:банка
152		$order_id	= $_POST["s_order_id"];	 // operation id	   идентификатор операции
153		$amount	= $_POST["s_amount"];	   // transaction sum   сумма транзакции
154		$clear_amount = $_POST["s_clear_amount"]; // billing algorithm  алгоритм подсчета стоимости
155		$s_status	= $_POST["s_status"];	 // Status 1 - delivered, 0 - Panding   статус платежа: 1 - прошел, 0 - не прошел.
156		$s_sign	= $_POST["s_sign"];	   // MD5-хэш строки, MD5 - hash
157
158		// Check proccess
159		// если проверка платежа неудачна - вернуться к выбору оплаты
160		if ($s_sign != ref_sign(MODULE_PAYMENT_SMSCOIN_SECRET_KEY,$purse,$order_id,$amount,$clear_amount,$s_status)) {
161			zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . MODULE_PAYMENT_SMSCOIN_TEXT_ERROR_MESSAGE, 'SSL', true, false));
162		}
163
164		// Allow
165		// проверка платежа удачна
166		return false;
167	}
168	###
169	#  After proccess
170	#  Функция вызова после процесса
171	###
172	function after_process() {
173		global $insert_id, $db;
174	}
175	###
176	#  Get error
177	#  Функция ошибки
178	###
179	function get_error() {
180		return false;
181	}
182	###
183	#  Check
184	#  Функция проверки
185	###
186	function check() {
187		global $db;
188		if (!isset($this->_check)) {
189			$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_SMSCOIN_STATUS'");
190			$this->_check = $check_query->RecordCount();
191		}
192		return $this->_check;
193	}
194
195	###
196	#  installation of module payment method in the system
197	#  Функция для инсталляции модуля оплаты в систему
198	###
199	function install() {
200		global $db;
201		// following payment method switched on or off
202		// включен или выключен данный модуль оплаты
203		$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('".MODULE_PAYMENT_SMSCOIN_STATUS_TITLE."', 'MODULE_PAYMENT_SMSCOIN_STATUS', 'True', '".MODULE_PAYMENT_SMSCOIN_STATUS_DESC."', '6', '1', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
204
205		// allowed countries where the following module is accessible
206		// разрешённые страны, для которых будет доступен данный модуль оплаты
207		$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('".MODULE_PAYMENT_SMSCOIN_ALLOWED_TITLE."', 'MODULE_PAYMENT_SMSCOIN_ALLOWED', 'RU', '".MODULE_PAYMENT_SMSCOIN_ALLOWED_DESC."', '6', '2', now())");
208
209		// your sms bank identification in the system
210		// идентификатор вашего смс:банка в системе
211		$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('".MODULE_PAYMENT_SMSCOIN_ID_TITLE."', 'MODULE_PAYMENT_SMSCOIN_ID', '123', '".MODULE_PAYMENT_SMSCOIN_ID_DESC."', '6', '3', now())");
212
213		// your sms bank secret key
214		// секретный ключ вашего смс:банка
215		$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('".MODULE_PAYMENT_SMSCOIN_SECRET_KEY_TITLE."', 'MODULE_PAYMENT_SMSCOIN_SECRET_KEY', '', '".MODULE_PAYMENT_SMSCOIN_SECRET_KEY_DESC."', '6', '4', now())");
216
217		// payment zones; enables access to payment method from that specific zone only
218		// зоны оплаты; данный модуль оплаты доступен только для выбранной зоны
219		$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title,configuration_key, configuration_value,  configuration_group_id, sort_order, use_function, set_function, date_added) values ('".MODULE_PAYMENT_SMSCOIN_ZONE_TITLE."', 'MODULE_PAYMENT_SMSCOIN_ZONE', '0', '6', '4', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())");
220
221
222		// order status, which will be specified after the payment
223		// cтатус заказа, который будет установлен после оплаты
224		$db->Execute("insert into " . TABLE_CONFIGURATION . " ( configuration_title, configuration_key, configuration_value,  configuration_description ,configuration_group_id, sort_order, set_function, use_function, date_added) values ('".MODULE_PAYMENT_SMSCOIN_ORDER_STATUS_ID_TITLE."','MODULE_PAYMENT_SMSCOIN_ORDER_STATUS_ID', '0','".MODULE_PAYMENT_SMSCOIN_ORDER_STATUS_ID_DESC."' ,'6', '5', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
225
226		// cтатус заказа, который будет установлен до оплаты
227		$db->Execute("insert into " . TABLE_CONFIGURATION . " ( configuration_title, configuration_key, configuration_value,  configuration_description ,configuration_group_id, sort_order, set_function, use_function, date_added) values ('".MODULE_PAYMENT_SMSCOIN_ORDER_STATUS_BEFORE_ID_TITLE."','MODULE_PAYMENT_SMSCOIN_ORDER_STATUS_BEFORE_ID', '0','".MODULE_PAYMENT_SMSCOIN_ORDER_STATUS_BEFORE_ID_DESC."' ,'6', '5', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
228
229		// payment module sort order (under which number in the payment module list will following module be accessible)
230		// порядок сортировки модуля оплаты (под каким номером в списке модулей оплаты будет доступен данный модуль)
231		$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description , configuration_group_id, sort_order, date_added) values ('".MODULE_PAYMENT_SMSCOIN_SORT_ORDER_TITLE."','MODULE_PAYMENT_SMSCOIN_SORT_ORDER', '0', '".MODULE_PAYMENT_SMSCOIN_ORDER_STATUS_ID_DESC."', '6', '6', now())");
232
233		// payment module sort order (under which number in the payment module list will following module be accessible)
234		// порядок сортировки модуля оплаты (под каким номером в списке модулей оплаты будет доступен данный модуль)
235		$db->Execute("insert into " . TABLE_CONFIGURATION . " ( configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('".MODULE_PAYMENT_SMSCOIN_HTTP_ADDR_TITLE."','MODULE_PAYMENT_SMSCOIN_HTTP_ADDR', 'http://bank.smscoin.com/bank/', '".MODULE_PAYMENT_SMSCOIN_HTTP_ADDR_DESC."' ,'6', '7', now())");
236
237	}
238	###
239	#  Функция удаления
240	###
241	function remove() {
242		global $db;
243		$db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
244	}
245	###
246	#  Функция ключей
247	###
248	function keys() {
249		return array('MODULE_PAYMENT_SMSCOIN_STATUS','MODULE_PAYMENT_SMSCOIN_ALLOWED', 'MODULE_PAYMENT_SMSCOIN_ZONE', 'MODULE_PAYMENT_SMSCOIN_ORDER_STATUS_ID', 'MODULE_PAYMENT_SMSCOIN_ORDER_STATUS_BEFORE_ID', 'MODULE_PAYMENT_SMSCOIN_SORT_ORDER', 'MODULE_PAYMENT_SMSCOIN_ID', 'MODULE_PAYMENT_SMSCOIN_SECRET_KEY', 'MODULE_PAYMENT_SMSCOIN_HTTP_ADDR');
250	}
251
252}
253?>