<?php
define('MODULE_PAYMENT_PAYGOL_ID_TITLE' , 'Your service id at PayGol');
define('MODULE_PAYMENT_PAYGOL_ID_DESC' , 'See please the <b>pg_serviceid</b> parameter on your service, for more information go to <a href="http://www.paygol.com">paygol.com</a> an see the implementation of your services.');
define('MODULE_PAYMENT_PAYGOL_STATUS_TITLE' , 'Switch on payment by sms and phone call module.');
define('MODULE_PAYMENT_PAYGOL_STATUS_DESC' , 'Do you wish to receive sms payments?');
define('MODULE_PAYMENT_PAYGOL_SORT_ORDER_TITLE' , 'Sort order');
define('MODULE_PAYMENT_PAYGOL_SORT_ORDER_DESC' , 'Module sort order.');
define('MODULE_PAYMENT_PAYGOL_ZONE_TITLE' , 'Payment zones');
define('MODULE_PAYMENT_PAYGOL_ZONE_DESC' , 'Already chosen zone enables access to payment method for customers of that specific zone only.');
define('MODULE_PAYMENT_PAYGOL_ORDER_STATUS_ID_TITLE' , 'Default order status');
define('MODULE_PAYMENT_PAYGOL_ORDER_STATUS_ID_DESC' , 'When using this option set up status order. It is recommended to set status order as <b>Delivered</b>.');
define('MODULE_PAYMENT_PAYGOL_TEXT_ERROR_MESSAGE', 'An error occurred while attempting to transfer money, please try again or choose a different payment method.');
class paygol
{
var $code, $title, $description, $enabled;
function paygol() {
global $order;
$this->code = 'paygol';
$this->title = MODULE_PAYMENT_PAYGOL_TEXT_TITLE;
$this->description = MODULE_PAYMENT_PAYGOL_TEXT_DESCRIPTION;
$this->sort_order = MODULE_PAYMENT_PAYGOL_SORT_ORDER;
$this->enabled = ((MODULE_PAYMENT_PAYGOL_STATUS == 'True') ? true : false);
if ((int)MODULE_PAYMENT_PAYGOL_ORDER_STATUS_ID > 0)
{
$this->order_status = MODULE_PAYMENT_PAYGOL_ORDER_STATUS_ID;
}
if (is_object($order)) $this->update_status();
$this->form_action_url = MODULE_PAYMENT_PAYGOL_HTTP_ADDR;
}
function update_status()
{
global $order;
if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_PAYGOL_ZONE > 0) )
{
$check_flag = false;
$check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_PAYGOL_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
while ($check = tep_db_fetch_array($check_query))
{
if ($check['zone_id'] < 1)
{
$check_flag = true;
break;
}
elseif ($check['zone_id'] == $order->billing['zone_id'])
{
$check_flag = true;
break;
}
}
if ($check_flag == false)
{
$this->enabled = false;
}
}
}
function before_process() {
return false;
}
function javascript_validation()
{
return false;
}
function selection()
{
return array('id' => $this->code,
'module' => $this->title);
}
function pre_confirmation_check()
{
return false;
}
function confirmation()
{
global $_POST;
return array('title' => MODULE_PAYMENT_PAYGOL_TEXT_DESCRIPTION);
}
function process_button()
{
global $order, $currencies, $currency;
$products = '';
foreach($order->products as $key => $product) {
$products .= $product['name'];
if (@$product['attributes'] !='') {
foreach($product['attributes'] as $key => $attribut)
{
$products .= ' (' . $attribut['option'].': ' . $attribut['value'] . ')';
}
}
}
$order_query = tep_db_query("select MAX(orders_id) AS orders_id FROM " . TABLE_ORDERS_TOTAL);
$order_id = tep_db_fetch_array($order_query);
$currency = $_SESSION['currency'];
$num = $order_id['orders_id'] + 1;
$amount = number_format($order->info['total'] * $currencies->get_value($currency), 2);
$clear_amount = '0';
$process_button_string = tep_draw_hidden_field('pg_serviceid', MODULE_PAYMENT_PAYGOL_ID) .
tep_draw_hidden_field('pg_price', $amount) .
tep_draw_hidden_field('pg_currency', $currency) .
tep_draw_hidden_field('pg_return_url', tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL')) .
tep_draw_hidden_field('pg_cancel_url', tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL')) .
tep_draw_hidden_field('pg_notify_url', '');
return $process_button_string;
}
function after_process()
{
global $insert_id;
if ($this->order_status) tep_db_query("UPDATE ". TABLE_ORDERS ." SET orders_status='".$this->order_status."' WHERE orders_id='".$insert_id."'");
}
function get_error()
{
return false;
}
function check()
{
if (!isset($this->_check))
{
$check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_PAYGOL_STATUS'");
$this->_check = tep_db_num_rows($check_query);
}
return $this->_check;
}
// installation of module payment method in the system
function install()
{
// following payment method switched on or off
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('".MODULE_PAYMENT_PAYGOL_STATUS_TITLE."', 'MODULE_PAYMENT_PAYGOL_STATUS', 'True', '".MODULE_PAYMENT_PAYGOL_STATUS_DESC."', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
// your sms bank identification in the system
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('".MODULE_PAYMENT_PAYGOL_ID_TITLE."', 'MODULE_PAYMENT_PAYGOL_ID', '', '".MODULE_PAYMENT_PAYGOL_ID_DESC."', '6', '3', now())");
// payment zones; enables access to payment method from that specific zone only
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title,configuration_key, configuration_value, configuration_group_id, sort_order, use_function, set_function, date_added) values ('".MODULE_PAYMENT_PAYGOL_ZONE_TITLE."', 'MODULE_PAYMENT_PAYGOL_ZONE', '0', '6', '4', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");
// order status, which will be specified after the payment
tep_db_query("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_PAYGOL_ORDER_STATUS_ID_TITLE."','MODULE_PAYMENT_PAYGOL_ORDER_STATUS_ID', '0','".MODULE_PAYMENT_PAYGOL_ORDER_STATUS_ID_DESC."' ,'6', '5', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");
// payment module sort order (under which number in the payment module list will following module be accessible)
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description , configuration_group_id, sort_order, date_added) values ('".MODULE_PAYMENT_PAYGOL_SORT_ORDER_TITLE."','MODULE_PAYMENT_PAYGOL_SORT_ORDER', '0', '".MODULE_PAYMENT_PAYGOL_ORDER_STATUS_ID_DESC."', '6', '6', now())");
}
function remove()
{
tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}
function keys()
{
return array('MODULE_PAYMENT_PAYGOL_STATUS', 'MODULE_PAYMENT_PAYGOL_ZONE', 'MODULE_PAYMENT_PAYGOL_ORDER_STATUS_ID', 'MODULE_PAYMENT_PAYGOL_SORT_ORDER', 'MODULE_PAYMENT_PAYGOL_ID');
}
}
?>