Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Sisow iDeal not sending email order to customer and shop owner


Pinquin

Recommended Posts

I have the payment module Sisow ideal everything works but the customer and the shop owner don't get the order confirmation email.

I'm already 3 days busy trying to get it to work but without success.

 

here is the code from /includes/modules/payment/sisow/base.php

<?php 
if(!class_exists('Sisow'))
	require_once('sisow.cls5.php');

class SisowBase{
	public function start()
	{
		$this->configuration_group_id = 2000;
	}
		
	public function update_status()
	{
		global $order;
		
		$order_total = $order->info['total'];
		if(!empty($this->_minamount) && $this->_minamount > 0 && $this->_minamount > $order_total)
			$this->enabled = false;
		
		if(!empty($this->_maxamount) && $this->_maxamount > 0 && $this->_maxamount < $order_total)
			$this->enabled = false;		
		
		$query_zone = tep_db_query("select zone_country_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . $this->_geozone . "' and zone_country_id = '".$order->billing['country_id']."'");
		
		if(!empty($this->_geozone) && $this->_geozone > 0 && tep_db_num_rows($query_zone) == 0)
			$this->enabled = false;
	}
			
	public function selection()
	{
		if ($this->enabled) {
			return array('id' => $this->code,
				'module' => $this->public_title);
		}
	}
	
	public function javascript_validation() 
	{
	
	}
	
	/*
	Hieronder het order process (lege functies zijn verplicht voor OsCommerce)
	Deze staan ook in volgorde van benadering door OsCommerce
	*/
	public function pre_confirmation_check()
	{
	}
	
	public function confirmation()
	{
	
	}
	
	function process_button()
	{
	
	}
	
	public function before_process()
	{
		global $order;
		if($this->paymentcode == 'ideal')
		{
			$issuerid = $_POST['sisow_bank'];
		}
		
		$this->check_cart();
		$this->SaveOrder();
		$this->update_stock();
		$this->Prepare();
				
		$sisow = new Sisow($this->_merchantid, $this->_merchantkey, $this->_subid);
		$sisow->payment = $this->paymentcode;
		$sisow->purchaseId = $this->order_id;
		$sisow->entranceCode = $this->order_id;
		$sisow->description =  ($this->_prefix != '') ? $this->_prefix . ' ' . $this->order_id : STORE_NAME . ' ' . $this->order_id;
		$sisow->amount = round($order->info['total'], 2);
				
		$sisow->notifyUrl = HTTP_SERVER . DIR_WS_CATALOG . 'ext/modules/payment/sisow/notify.php?pmt=' . $this->code . '&billto='.$_SESSION['billto'].'&sendto='.$_SESSION['sendto'].'&language='.$_SESSION['language'].'&languageid='.$_SESSION['languages_id'];
		$sisow->returnUrl = $sisow->notifyUrl;

		$sisow->cancelUrl = $sisow->returnUrl;
		$sisow->callbackUrl = $sisow->notifyUrl;
		
		if($this->paymentcode)
			$sisow->issuerId = $issuerid;

		if(($ex = $sisow->TransactionRequest($this->arg)) < 0)
		{
			$this->UpdateOrderStatus($this->_status_failure, $this->order_id, 'TransactionRequest failed ('.$ex.', '.$sisow->errorCode.', '.$sisow->errorMessage.')');
			tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=Betaling niet geslaagd!', 'SSL'));
		}
		else
		{
			if($this->redirect)
			{
				$url = $sisow->issuerUrl;
			}
			else
			{
				require_once(DIR_WS_CLASSES . 'order.php');	
				$order = new Order($this->order_id);
			
				if($sisow->payment == 'overboeking' || $sisow->payment == 'ebill'){
					$status = $this->_status_pending;
					$desc = 'Response from Sisow: Pending';
				}
				else if ($sisow->payment == 'klarna'|| $sisow->payment == 'klarnaacc'){
					if($sisow->pendingKlarna){
						$status = $this->_status_pending;
						$desc = 'Response from Sisow: PendingKlarna';
					}
					else{
						$status = $this->_status_success;
						$desc = 'Response from Sisow: Reservation';
					}
				}
				
				$params = array('billto' => $_SESSION['billto'],
						'sendto'=> $_SESSION['sendto'],
						'language'=> $_SESSION['language'],
						'language_id'=> $_SESSION['languages_id']
						);
				
				$this->UpdateOrderStatus($status, $this->order_id, $desc, $params);
				$this->SendOrderMail($order, $this->order_id, $this, $params);
				
				if ($cart) {
					$cart->remove_all();
					$cart->reset(true);
				}
				
				tep_session_unregister('cart');
				$url = tep_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'SSL');
			}
			tep_redirect($url);
			exit;
		}
		
	}
	
	public function after_process() 
	{
	
	}
	
	public function notify($order_id, $trxid, $paymentclass, $params)
	{
		require_once(DIR_WS_CLASSES . 'order.php');	
		
		$this->order = new Order($order_id);
		$this->order_id = $order_id;
		
		$sisow = new Sisow($this->_merchantid, $this->_merchantkey, $this->_subid);
		
		if(($ex = $sisow->StatusRequest($trxid)) < 0)
		{
			echo 'StatusRequest error: ' . $ex . ' ' . $sisow->errorCode . ' ' . $sisow->errorMessage;
			exit;
		}
		
		$restock = false;
		switch ($sisow->status)
		{
			case "Success":
				$this->UpdateOrderStatus($this->_status_success, $this->order_id, 'Response from Sisow: ' . $sisow->status);
				$this->sendOrderMail($this->order, $this->order_id, $paymentclass, $params);
				break;
			case "Cancelled":
				$this->UpdateOrderStatus($this->_status_cancel, $this->order_id, 'Response from Sisow: ' . $sisow->status);
				$restock = true;
				break;
			case "Failure":
				$this->UpdateOrderStatus($this->_status_failure, $this->order_id, 'Response from Sisow: ' . $sisow->status);
				$restock = true;
				break;
			case "Expired":
				$this->UpdateOrderStatus($this->_status_cancel, $this->order_id, 'Response from Sisow: ' . $sisow->status);
				$restock = true;
				break;
		}
		
		if($this->_restock && $restock)
			$this->update_stock(false, $this->order_id);
		exit;
	}
	
	public function install()
	{
		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 ('Sisow ".$this->name."', 'MODULE_PAYMENT_".strtoupper($this->code)."_STATUS', 'True', 'Do you want to accept payments with Sisow ".$this->name."?', '".$this->configuration_group_id."', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
		
		tep_db_query("insert into " . TABLE_CONFIGURATION . " 
						(configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) 
						values ('Sort order of display.', 'MODULE_PAYMENT_".strtoupper($this->code)."_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '".$this->configuration_group_id."', '0' , now())");
						
		tep_db_query("insert into " . TABLE_CONFIGURATION . " 
						(configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order) 
						values ('Sisow merchant ID', 'MODULE_PAYMENT_".strtoupper($this->code)."_MERCHANTID', '', 'Set your Sisow merchant ID', '".$this->configuration_group_id."', '0')");
		
		tep_db_query("insert into " . TABLE_CONFIGURATION . " 
						(configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order) 
						values ('Sisow merchant Key', 'MODULE_PAYMENT_".strtoupper($this->code)."_MERCHANTKEY', '', 'Set your Sisow merchant Key', '".$this->configuration_group_id."', '0')");
						
		tep_db_query("insert into " . TABLE_CONFIGURATION . " 
						(configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order) 
						values ('Sisow SubID', 'MODULE_PAYMENT_".strtoupper($this->code)."_SUBID', '', 'Set your Sisow SubID', '".$this->configuration_group_id."', '0')");				
		
		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 ('Test mode', 'MODULE_PAYMENT_".strtoupper($this->code)."_TEST', 'False', 'Do you want to use Sisow ".$this->name." in test mode?', '".$this->configuration_group_id."', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");				
						
		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 ('Set default status', 'MODULE_PAYMENT_".strtoupper($this->code)."_ORDER_PENDING', '0', 'Default order status', '".$this->configuration_group_id."', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");
		
		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 ('Set success status', 'MODULE_PAYMENT_".strtoupper($this->code)."_ORDER_SUCCESS', '0', 'Set success order status', '".$this->configuration_group_id."', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");
		
		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 ('Set cancelled status', 'MODULE_PAYMENT_".strtoupper($this->code)."_ORDER_CANCELLED', '0', 'Set cancelled order status', '".$this->configuration_group_id."', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");		
		
		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 ('Set failed status', 'MODULE_PAYMENT_".strtoupper($this->code)."_ORDER_FAILED', '0', 'Set failed order status', '".$this->configuration_group_id."', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");
		
		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 ('Restock', 'MODULE_PAYMENT_".strtoupper($this->code)."_RESTOCK', 'True', 'Do you want Sisow ".$this->name." to restock?', '".$this->configuration_group_id."', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
		
		tep_db_query("insert into " . TABLE_CONFIGURATION . " 
						(configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order) 
						values ('Description prefix', 'MODULE_PAYMENT_".strtoupper($this->code)."_PREFIX', '', 'Description prefix', '".$this->configuration_group_id."', '0')");
			
		tep_db_query("insert into " . TABLE_CONFIGURATION . " 
						(configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order) 
						values ('Min Order Amount', 'MODULE_PAYMENT_".strtoupper($this->code)."_MINAMOUNT', '0', 'The min order amount', '".$this->configuration_group_id."', '0')");
		
		tep_db_query("insert into " . TABLE_CONFIGURATION . " 
						(configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order) 
						values ('Max Order Amount', 'MODULE_PAYMENT_".strtoupper($this->code)."_MAXAMOUNT', '0', 'The max order amount', '".$this->configuration_group_id."', '0')");
		
		tep_db_query("insert into " . TABLE_CONFIGURATION . " 
						(configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Payment Zone', 'MODULE_PAYMENT_".strtoupper($this->code)."_GEOZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '2', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");
		
		if($this->code == 'sisowoverboeking' || $this->code2 == 'sisowebill')
		{
			$desc = ($this->code == 'sisowoverboeking') ? 'Include paymentlink in mail' : 'Include bank account info in mail';
			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 ('Include', 'MODULE_PAYMENT_".strtoupper($this->code)."_INCLUDING', 'True', ".$desc.", '".$this->configuration_group_id."', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
			
			tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order) values ('Days', 'MODULE_PAYMENT_".strtoupper($this->code)."_DAYS', '', 'Days', '".$this->configuration_group_id."', '')");
		}
		
		
		
		
		/*
		if($this->code2 == 'SISOWKLARNA' || $this->code2 == 'SISOWKLARNAACC')
		{
			tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order) values ('Klarna ID', 'MODULE_PAYMENT_".$this->code2."_KLARNAID', '', 'Set the Klarna ID', '".$this->configuration_group_id."', '0')");
		}
		else
		*/
		
		tep_db_query("CREATE TABLE IF NOT EXISTS sisow(
			trxid varchar(20),
			orderid int,
			invoice varchar(32),
			invoicedate datetime,
			invoiceurl text,
			credit varchar(32),
			creditdate datetime,
			crediturl text,
			refund boolean,
			refundamount double,
			status varchar(20),
			method varchar(20),
			PRIMARY KEY(trxid))");
	}
	
	public function remove()
    {
        tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }
	
	public function keys()
    {
		$keys = array();
		
		$keys[] = 'MODULE_PAYMENT_'.strtoupper($this->code).'_STATUS';
        $keys[] = 'MODULE_PAYMENT_'.strtoupper($this->code).'_SORT_ORDER';
		$keys[] = 'MODULE_PAYMENT_'.strtoupper($this->code).'_MERCHANTID';
        $keys[] = 'MODULE_PAYMENT_'.strtoupper($this->code).'_MERCHANTKEY';
		$keys[] = 'MODULE_PAYMENT_'.strtoupper($this->code).'_SUBID';
		$keys[] = 'MODULE_PAYMENT_'.strtoupper($this->code).'_TEST';
		$keys[] = 'MODULE_PAYMENT_'.strtoupper($this->code).'_PREFIX';
        $keys[] = 'MODULE_PAYMENT_'.strtoupper($this->code).'_ORDER_PENDING';
        $keys[] = 'MODULE_PAYMENT_'.strtoupper($this->code).'_ORDER_SUCCESS';
        $keys[] = 'MODULE_PAYMENT_'.strtoupper($this->code).'_ORDER_CANCELLED';
        $keys[] = 'MODULE_PAYMENT_'.strtoupper($this->code).'_ORDER_FAILED';
        $keys[] = 'MODULE_PAYMENT_'.strtoupper($this->code).'_RESTOCK';
		$keys[] = 'MODULE_PAYMENT_'.strtoupper($this->code).'_MINAMOUNT';
		$keys[] = 'MODULE_PAYMENT_'.strtoupper($this->code).'_MAXAMOUNT';
		$keys[] = 'MODULE_PAYMENT_'.strtoupper($this->code).'_GEOZONE';
		
		if($this->code == 'sisowoverboeking'|| $this->code == 'sisowebill')
		{
			$keys[] = 'MODULE_PAYMENT_'.strtoupper($this->code).'_DAYS';
			$keys[] = 'MODULE_PAYMENT_'.strtoupper($this->code).'_INCLUDE';
		}
		else if ($this->code == 'sisowklarna' || $this->code == 'sisowklarnaacc')
		{
			$keys[] = 'MODULE_PAYMENT_'.strtoupper($this->code).'_KLARNAID';
		}
		
		return $keys;
    }
	
	public function check() 
	{
		if (!isset($this->_check)) {
			$check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_".strtoupper($this->code)."_STATUS'");
			$this->_check = tep_db_num_rows($check_query);
		}
		
		return $this->_check;
    }
	
	private function update_stock($decrease = true, $orderid = '')
    {        
		if($decrease)
		{
			global $order;
			
			for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
				// Stock Update - Joao Correia
				if (STOCK_LIMITED == 'true') 
				{
					if (DOWNLOAD_ENABLED == 'true') 
					{
						$stock_query_raw = "SELECT products_quantity, pad.products_attributes_filename
										FROM " . TABLE_PRODUCTS . " p
										LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa
										ON p.products_id=pa.products_id
										LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
										ON pa.products_attributes_id=pad.products_attributes_id
										WHERE p.products_id = '" . tep_get_prid($order->products[$i]['id']) . "'";
						// Will work with only one option for downloadable products
						// otherwise, we have to build the query dynamically with a loop
					
						$products_attributes = $order->products[$i]['attributes'];
						if (is_array($products_attributes)) {
							$stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'";
						}
						$stock_query = tep_db_query($stock_query_raw);
					} 
					else 
					{
						$stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
					}
				  
					if (tep_db_num_rows($stock_query) > 0) 
					{
						$stock_values = tep_db_fetch_array($stock_query);
						// do not decrement quantities if products_attributes_filename exists
						if ((DOWNLOAD_ENABLED != 'true') || (!$stock_values['products_attributes_filename'])) 
						{
							$stock_left = $stock_values['products_quantity'] - $order->products[$i]['qty'];
						} 
						else 
						{
							$stock_left = $stock_values['products_quantity'];
						}
					
						tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
						
						if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) 
						{
							tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
						}
					}
				}
				// Update products_ordered (for bestsellers list)
				tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
			}
		}
		else
		{
			require_once(DIR_WS_CLASSES . 'order.php');
			$order = new order($orderid);

			for ($i=0, $n=sizeof($order->products); $i<$n; $i++) { 
				// Stock Update - Joao Correia
				if (STOCK_LIMITED == 'true') {
					if (DOWNLOAD_ENABLED == 'true') {
						$stock_query_raw = "SELECT products_quantity, pad.products_attributes_filename
									FROM " . TABLE_PRODUCTS . " p
									LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa
									ON p.products_id=pa.products_id
									LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
									ON pa.products_attributes_id=pad.products_attributes_id
									WHERE p.products_id = '" . tep_get_prid($order->products[$i]['id']) . "'";
						// Will work with only one option for downloadable products
						// otherwise, we have to build the query dynamically with a loop
						$products_attributes = $order->products[$i]['attributes'];
						if (is_array($products_attributes)) {
							$stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'";
						}
						$stock_query = tep_db_query($stock_query_raw);
					  } else {
							$stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
					  }
			  
					if (tep_db_num_rows($stock_query) > 0) {
						$stock_values = tep_db_fetch_array($stock_query);
						// do not decrement quantities if products_attributes_filename exists
						if ((DOWNLOAD_ENABLED != 'true') || (!$stock_values['products_attributes_filename'])) {
							$stock_left = $stock_values['products_quantity'] + $order->products[$i]['qty'];
						} else {
							$stock_left = $stock_values['products_quantity'];
						}

						tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
						if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) {
							tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
						}
					}
				}

				// Update products_ordered (for bestsellers list)
				tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered - " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
			}
		}
    }
	
	private function SaveOrder()
	{
		global $customer_id, $languages_id, $order, $order_total_modules, $order_totals;
					
		//insert the order into the database
		$sql_data_array = array('customers_id' => $customer_id,
									'customers_name' => $order->customer['firstname'] . ' ' . $order->customer['lastname'],
									'customers_company' => $order->customer['company'],
									'customers_street_address' => $order->customer['street_address'],
									'customers_suburb' => $order->customer['suburb'],
									'customers_city' => $order->customer['city'],
									'customers_postcode' => $order->customer['postcode'],
									'customers_state' => $order->customer['state'],
									'customers_country' => $order->customer['country']['title'],
									'customers_telephone' => $order->customer['telephone'],
									'customers_email_address' => $order->customer['email_address'],
									'customers_address_format_id' => $order->customer['format_id'],
									'delivery_name' => $order->delivery['firstname'] . ' ' . $order->delivery['lastname'],
									'delivery_company' => $order->delivery['company'],
									'delivery_street_address' => $order->delivery['street_address'],
									'delivery_suburb' => $order->delivery['suburb'],
									'delivery_city' => $order->delivery['city'],
									'delivery_postcode' => $order->delivery['postcode'],
									'delivery_state' => $order->delivery['state'],
									'delivery_country' => $order->delivery['country']['title'],
									'delivery_address_format_id' => $order->delivery['format_id'],
									'billing_name' => $order->billing['firstname'] . ' ' . $order->billing['lastname'],
									'billing_company' => $order->billing['company'],
									'billing_street_address' => $order->billing['street_address'],
									'billing_suburb' => $order->billing['suburb'],
									'billing_city' => $order->billing['city'],
									'billing_postcode' => $order->billing['postcode'],
									'billing_state' => $order->billing['state'],
									'billing_country' => $order->billing['country']['title'],
									'billing_address_format_id' => $order->billing['format_id'],
									'payment_method' => $order->info['payment_method'],
									'cc_type' => $order->info['cc_type'],
									'cc_owner' => $order->info['cc_owner'],
									'cc_number' => $order->info['cc_number'],
									'cc_expires' => $order->info['cc_expires'],
									'date_purchased' => 'now()',
									'orders_status' => $order->info['order_status'],
									'currency' => $order->info['currency'],
									'currency_value' => $order->info['currency_value']);

		tep_db_perform(TABLE_ORDERS, $sql_data_array);
		
		//Get order_id
		$insert_id = tep_db_insert_id();
		$this->order_id = $insert_id;
		
		//Insert order state into the database
		$ex = tep_db_query("update " . TABLE_ORDERS . " set orders_status = '".$this->_status_pending."', last_modified = now() where orders_id = '" . $this->order_id . "'");
		$sql_data_array = array('orders_id' => $this->order_id,
						'orders_status_id' => $this->_status_pending,
						'date_added' => 'now()',
						'customer_notified' => '1',
						'comments' => $order->info['comments']);
		tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);

		//Insert the order totals into the database
		for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) 
		{
			$sql_data_array = array('orders_id' => $insert_id,
									'title' => $order_totals[$i]['title'],
									'text' => $order_totals[$i]['text'],
									'value' => $order_totals[$i]['value'],
									'class' => $order_totals[$i]['code'],
									'sort_order' => $order_totals[$i]['sort_order']);

			tep_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array);
		}

		//Insert the products into the database
		for ($i=0, $n=sizeof($order->products); $i<$n; $i++) 
		{
			$sql_data_array = array('orders_id' => $insert_id,
									'products_id' => tep_get_prid($order->products[$i]['id']),
									'products_model' => $order->products[$i]['model'],
									'products_name' => $order->products[$i]['name'],
									'products_price' => $order->products[$i]['price'],
									'final_price' => $order->products[$i]['final_price'],
									'products_tax' => $order->products[$i]['tax'],
									'products_quantity' => $order->products[$i]['qty']);

			tep_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array);

			$order_products_id = tep_db_insert_id();

			$attributes_exist = '0';
						
			if (isset($order->products[$i]['attributes'])) 
			{
				$attributes_exist = '1';
				
				for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) 
				{
					if (DOWNLOAD_ENABLED == 'true') 
					{
						$attributes_query = "select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount , pad.products_attributes_filename
											from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa
											left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
											on pa.products_attributes_id=pad.products_attributes_id
											where pa.products_id = '" . $order->products[$i]['id'] . "'
											and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "'
											and pa.options_id = popt.products_options_id
											and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "'
											and pa.options_values_id = poval.products_options_values_id
											and popt.language_id = '" . $languages_id . "'
											and poval.language_id = '" . $languages_id . "'";
						$attributes = tep_db_query($attributes_query);
					} 
					else 
					{
						$attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . $order->products[$i]['id'] . "' and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");
					}
					
					$attributes_values = tep_db_fetch_array($attributes);

					$sql_data_array = array('orders_id' => $insert_id,
											'orders_products_id' => $order_products_id,
											'products_options' => $attributes_values['products_options_name'],
											'products_options_values' => $attributes_values['products_options_values_name'],
											'options_values_price' => $attributes_values['options_values_price'],
											'price_prefix' => $attributes_values['price_prefix']);

					tep_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES, $sql_data_array);

					if ((DOWNLOAD_ENABLED == 'true') && isset($attributes_values['products_attributes_filename']) && tep_not_null($attributes_values['products_attributes_filename'])) 
					{
						$sql_data_array = array('orders_id' => $insert_id,
												'orders_products_id' => $order_products_id,
												'orders_products_filename' => $attributes_values['products_attributes_filename'],
												'download_maxdays' => $attributes_values['products_attributes_maxdays'],
												'download_count' => $attributes_values['products_attributes_maxcount']);

						tep_db_perform(TABLE_ORDERS_PRODUCTS_DOWNLOAD, $sql_data_array);
					}
				}
			}
		}
	}
	
	private function check_cart()
    {
        global $cartID, $cart;

        if (empty($cart->cartID)) {
            $cartID = $cart->cartID = $cart->generate_cart_id();
        }

        if (!tep_session_is_registered('cartID')) {
            tep_session_register('cartID');
        }
    }
	
	private function UpdateOrderStatus($statusid, $orderid, $commentaar)
	{
		$ex = tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . $statusid . "', last_modified = now() where orders_id = '" . $orderid . "'");
		$sql_data_array = array('orders_id' => $orderid,
				'orders_status_id' => $statusid,
				'date_added' => 'now()',
				'customer_notified' => '1',
				'comments' => tep_db_prepare_input($commentaar));
		tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
	}
	
	private function Prepare()
	{
		global $order, $customer_id;

        $customer = $order->customer;
        $orderinfo = $order->info;
        $producten = $order->products;
        $billing = $order->billing;
        $delivery = $order->delivery;
        $billing_country = $billing['country'];
        $shipping_country = $delivery['country'];
			
		$this->arg = array();
				
		$this->arg['billing_company'] = $billing['company'];
		$this->arg['billing_firstname'] = $billing['firstname'];
		$this->arg['billing_lastname'] = $billing['lastname'];
		$this->arg['billing_mail'] = $customer['email_address'];
        $this->arg['billing_company'] = $billing['company'];
		$this->arg['billing_address1'] = $billing['street_address'];
		$this->arg['billing_address2'] = $billing['suburb'];
		$this->arg['billing_zip'] = $billing['postcode'];
		$this->arg['billing_city'] = $billing['city'];
		$this->arg['billing_phone'] = $customer['telephone'];
		$this->arg['billing_countrycode'] = $billing_country['iso_code_2'];
		
		if(in_array($billing_country['iso_code_2'], array('AU','AT','BE','BR','CA','CH','CN','DE','ES','GB','FR','IT','NL','PL','PT','RU','US')))
			$this->arg['locale'] = $billing_country['iso_code_2'];
		else
			$this->arg['locale'] = 'US';
        
        $gebdatum = tep_db_fetch_array(tep_db_query("SELECT customers_dob FROM customers WHERE customers_id = '".$customer_id."'") );
		
        $this->arg['birthdate'] = substr($gebdatum['customers_dob'], 8, 2).substr($gebdatum['customers_dob'], 5, 2).substr($gebdatum['customers_dob'], 0, 4);
		$this->arg['ipaddress'] = $_SERVER['REMOTE_ADDR'];
        
		$this->arg['shipping_company'] = $billing['company'];
        $this->arg['shipping_firstname'] = $delivery['firstname'];
        $this->arg['shipping_lastname'] = $delivery['lastname'];
        $this->arg['shipping_mail'] = $customer['email_address'];
        $this->arg['shipping_company'] = $delivery['company'];
        $this->arg['shipping_address1'] = $delivery['street_address'];
        $this->arg['shipping_address2'] = $delivery['suburb'];
        $this->arg['shipping_zip'] = $delivery['postcode'];
        $this->arg['shipping_city'] = $delivery['city'];
        $this->arg['shipping_country'] = $shipping_country['title'];
        $this->arg['shipping_countrycode'] = $shipping_country['iso_code_2'];
        $this->arg['shipping_phone'] = $customer['telephone'];;
        $this->arg['shipping'] = round($orderinfo['shipping_cost'] * 100, 0); //verzendkosten in centen
        
        $this->arg['tax'] = round($orderinfo['tax'], 2) * 100;
        $this->arg['currency'] = $orderinfo['currency'];
		
		if(isset($this->_days) && $this->_days > 0)
			$this->arg['days'] = $this->_days;
			
		if(isset($this->_include) && $this->_include)
			$this->arg['including'] = 'true';
		
		if($this->_testmode)
			$this->arg['testmode'] = 'true';

        if(isset($producten))
        {
            $prijs = round(($orderinfo['shipping_cost'] * 100) / 119, 2);
            array_push($producten, Array('qty'=>'1', 'name'=>'Bezorgkosten', 'model'=>'shipping', 'tax'=>'19', 'tax_description'=>'BTW', 'price'=>$prijs, 'final_price'=>$prijs, 'weight'=>'0', 'id'=>'0'));
            
            $productnr = 1;
            $gewicht = 0;
            foreach ($producten as $product) {
                $gewicht = $gewicht + $product['weight'];

                $this->arg['product_id_'.$productnr] = $product['model'];
                $this->arg['product_description_'.$productnr] = $product['name'];
                $this->arg['product_quantity_'.$productnr] = $product['qty'];
                $this->arg['product_netprice_'.$productnr] = round($product['final_price']*100.0);
                $this->arg['product_total_'.$productnr] = round((($product['final_price'] * $product['qty']) * (($product['tax'] + 100.0) / 100.0) )*100.0);
                $this->arg['product_nettotal_'.$productnr] = round(($product['final_price'] * $product['qty']) *100);
                $this->arg['product_tax_'.$productnr] = round(((($product['final_price'] * $product['qty']) * (($product['tax'] + 100.0) / 100.0) - ($product['final_price'] * $product['qty']) )*100.0));
                $this->arg['product_taxrate_'.$productnr] = round($product['tax'] * 100.0);

                $productnr++;
            }
        }
	}
	
	private function SendOrderMail($order, $orderid, $paymentclass, $params)
	{
		require_once(DIR_WS_CLASSES . 'currencies.php');	
				
		$currencies = new currencies();
		
		$payment = $paymentclass->code;
		$$payment = $paymentclass;
		
		$insert_id 		= $orderid;
		$order_totals 	= $order->totals;
		$customer_id 	= $order->customer['id'];
		
		$comment_query = tep_db_query("SELECT MIN(`orders_status_history_id`), comments FROM `orders_status_history` WHERE orders_id = " . $insert_id);
		$comment = tep_db_fetch_array($comment_query);
		$order->info['comments'] = $comment['comments'];
		
		$languages_id = $params['language_id'];
		$language = $params['language'];
		$billto = $params['billto'];
		$sendto = $params['sendto'];
		
		require_once(DIR_WS_LANGUAGES . $language . '/checkout_process.php');

		$products_ordered = '';
		for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
			$products_ordered_attributes = '';
			
			if (isset($order->products[$i]['attributes'])) {
				for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
					if (DOWNLOAD_ENABLED == 'true') {
						 $attributes_query = "select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount , pad.products_attributes_filename 
											   from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa 
											   left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
												on pa.products_attributes_id=pad.products_attributes_id
											   where pa.products_id = '" . (int)$order->products[$i]['id'] . "' 
												and pa.options_id = '" . (int)$order->products[$i]['attributes'][$j]['option_id'] . "' 
												and pa.options_id = popt.products_options_id 
												and pa.options_values_id = '" . (int)$order->products[$i]['attributes'][$j]['value_id'] . "' 
												and pa.options_values_id = poval.products_options_values_id 
												and popt.language_id = '" . (int)$languages_id . "' 
												and poval.language_id = '" . (int)$languages_id . "'";
						$attributes = tep_db_query($attributes_query);
					} 
					else {
						$attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . (int)$order->products[$i]['id'] . "' and pa.options_id = '" . (int)$order->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . (int)$order->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . (int)$languages_id . "' and poval.language_id = '" . (int)$languages_id . "'");
					}
					$attributes_values = tep_db_fetch_array($attributes);
					$products_ordered_attributes .= "\n\t" . $attributes_values['products_options_name'] . ' ' . $attributes_values['products_options_values_name'];
				}
			}
			$products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . $products_ordered_attributes . "\n";
		}
		
		/*
		//below original order mail
		//can be replaced with an custom order mail
		*/
		$email_order = STORE_NAME . "\n" . 
                 EMAIL_SEPARATOR . "\n" . 
                 EMAIL_TEXT_ORDER_NUMBER . ' ' . $insert_id . "\n" .
                 EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $insert_id, 'SSL', false) . "\n" .
                 EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";
		  if ($order->info['comments']) {
			$email_order .= tep_db_output($order->info['comments']) . "\n\n";
		  }
		  $email_order .= EMAIL_TEXT_PRODUCTS . "\n" . 
						  EMAIL_SEPARATOR . "\n" . 
						  $products_ordered . 
						  EMAIL_SEPARATOR . "\n";

		  for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {
			$email_order .= strip_tags($order_totals[$i]['title']) . ' ' . strip_tags($order_totals[$i]['text']) . "\n";
		  }

		  if ($order->content_type != 'virtual') {
			$email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" . 
							EMAIL_SEPARATOR . "\n" .
							tep_address_label($customer_id, $sendto, 0, '', "\n") . "\n";
		  }

		  $email_order .= "\n" . EMAIL_TEXT_BILLING_ADDRESS . "\n" .
						  EMAIL_SEPARATOR . "\n" .
						  tep_address_label($customer_id, $billto, 0, '', "\n") . "\n\n";
		
		  if (is_object($$payment)) {
			$email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" . 
							EMAIL_SEPARATOR . "\n";
			$payment_class = $$payment;
			$email_order .= $order->info['payment_method'] . "\n\n";
			if (isset($payment_class->email_footer)) {
			  $email_order .= $payment_class->email_footer . "\n\n";
			}
		  }
		  tep_mail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);

		// send emails to other people
		  if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
			tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
		  }
	}
}
?>

And here is the code from /ext/modules/payment/sisow/notify.php

<?php
chdir('../../../../');
require_once('includes/application_top.php');

if(isset($_GET['notify']) || isset ($_GET['callback']))
{
	$payment = $_GET['pmt'];

	if(!file_exists(DIR_FS_CATALOG . DIR_WS_MODULES .'payment/'. $payment . '.php'))
		exit('no payment class');
		  
	require_once(DIR_FS_CATALOG . DIR_WS_MODULES .'payment/'. $payment . '.php');
		
	$paymentmodule = new $payment();

	$q = tep_db_query('select * from ' . TABLE_ORDERS . ' where orders_id=\'' . $order_id . '\'');
	$order = tep_db_fetch_array($q);
	if ($order && $order['orders_status'] != 1 && $order['orders_status'] != $paymentmodule->_status_pending && $order['orders_status'] != $paymentmodule->_status_failure && $order['orders_status'] != $paymentmodule->_status_cancel) {
		echo 'osCommerce status not allowed ' . $order['orders_status'];
		exit;
	}

	$params = array('billto' => $_GET['billto'],
						'sendto'=> $_GET['sendto'],
						'language'=> $_GET['language'],
						'language_id'=> $_GET['languageid']
						);
		
	$paymentmodule->notify($_GET['ec'], $_GET['trxid'], $paymentmodule, $params);
	exit;
}
else
{
	if ($_GET['status'] == 'Success') 
	{		
		if ($cart) 
			$cart->reset(true);

		tep_redirect(tep_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'SSL'));
	}
	else {
		tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=Betaling niet geslaagd!', 'SSL'));
	}
}
?>

I can't figure out why it's not working.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...