Forums / Addon Payment Modules / Custom Payment module won't redirect to "checkout success" page

Custom Payment module won't redirect to "checkout success" page

Started by eurorage on 5 Feb 2011, 5:30 PM · Views: 4,522

Results 1 to 3 of 3
5 Feb 2011, 5:30 PM
#1
eurorage avatar

eurorage

New Zenner

Join Date:
Oct 2010
Posts:
7
Plugin Contributions:
0

Custom Payment module won't redirect to "checkout success" page

Hi.

I have a little proble mwith a custom payment module, which should properly work in 1.3.8

I have a 1.3.9h version and installed the module. I've changed some files which should have been changed in order the script to work. The checkout process goes fine. It redirects to the payment site properly, the test payment has been done, then it redirects back to the special php file (which code I've posted below). The page stays blank and doesn't redirect to checkout success page.
I've checked the database after the payment was done, and it stops before redirection function.

<?php
  require('includes/configure.php');
  function p24_weryfikujNOSSL($p24_id_sprzedawcy,$p24_session_id,$p24_order_id,$p24_kwota="") 
  {
    $header  = "POST /transakcjanossl.php HTTP/1.1\r\n";
    $header .= "Host: secure.przelewy24.pl\r\n"; 
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
  
    $fp = fsockopen ("secure.przelewy24.pl", 80, $errno, $errstr, 30);
    $P[] = urlencode("p24_id_sprzedawcy")."=".urlencode($p24_id_sprzedawcy); 
    $P[] = urlencode("p24_session_id")."=".urlencode($p24_session_id); 
    $P[] = urlencode("p24_order_id")."=".urlencode($p24_order_id); 
    if($p24_kwota != "") $P[] = urlencode("p24_kwota")."=".urlencode($p24_kwota); 
    $post = join("&",$P);
  
    $req .= "Content-Length: ".strlen( $post )."\r\n\r\n";
    $req .= $post;
  
    if (!$fp) {
      die ("CONNECTION ERROR");
    } else {
      fputs ($fp, $header . $req);
      $res = false;
      while (!feof($fp)) {
        $line = ereg_replace("[\n\r]","",fgets ($fp, 1024));
        if($line != "RESULT" and !$res) continue;
        if($res)$RET[] = $line;
        else $res = true; 
      }
    }
    fclose ($fp);
    return $RET;
  }
  
  
  function p24_weryfikujSSL($p24_id_sprzedawcy,$p24_session_id,$p24_order_id,$p24_kwota="")
  {
  	  $url = "https://secure.przelewy24.pl/transakcja.php";
      $P[] = "p24_id_sprzedawcy=".$p24_id_sprzedawcy;
      $P[] = "p24_session_id=".$p24_session_id;
      $P[] = "p24_order_id=".$p24_order_id;
      if($p24_kwota != "") $P[] = "p24_kwota=".$p24_kwota;

      $user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_POST,1);
      if(count($P)) curl_setopt($ch, CURLOPT_POSTFIELDS,join("&",$P));
      curl_setopt($ch, CURLOPT_URL,$url);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2);
      curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
      if(count($H)) curl_setopt ($ch, CURLOPT_HTTPHEADER, $H);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
      $result=curl_exec ($ch);
      curl_close ($ch);
      $T = explode(chr(13).chr(10),$result);  

      foreach($T as $line)
      {
        $line = ereg_replace("[\n\r]","",$line);
        if($line != "RESULT" and !$res) continue;
        if($res)$RET[] = $line;
        else $res = true; 
      }
      
  return $RET;
  }

  if(isset($_POST["p24_session_id"]) and isset($_POST["p24_order_id"])) 
  {
  	  require('includes/application_top.php');

      // set the application parameters
      $o_conf=$db->Execute('select configuration_key as cfgKey, configuration_value as cfgValue from '.TABLE_CONFIGURATION);
  	  while(!$o_conf->EOF) 
	  {
	  	define($o_conf->fields['cfgKey'],$o_conf->fields['cfgValue']);
	  	$o_conf->MoveNext();
	  }

      $isSSL=function_exists('curl_init')&&function_exists('curl_setopt')&&function_exists('curl_exec')&&function_exists('curl_close');
      $o_tmp=$db->Execute("select orders_id,p24_languages_code,customers_id from " . TABLE_ORDERS . " where p24_session_id = '" . $_POST["p24_session_id"] . "'");

      $i_orders_id=(int) $o_tmp->fields['orders_id'];
      
      // get amount
      $o_amount=$db->Execute('SELECT value FROM zc_orders_total WHERE class="ot_total" AND orders_id='.$i_orders_id);
      $f_amount=$o_amount->fields['value'];
      $f_amount=number_format($f_amount, 2, '.', '')*100;
      
      //verify
      
      $WYNIK = $isSSL?p24_weryfikujSSL(MODULE_PAYMENT_PRZELEWY24_ID,$_POST["p24_session_id"],$_POST["p24_order_id"],$f_amount):
                     p24_weryfikujNOSSL(MODULE_PAYMENT_PRZELEWY24_ID,$_POST["p24_session_id"],$_POST["p24_order_id"],$f_amount);

      
      $languages_code=$o_tmp->fields["p24_languages_code"];
      $customers_id=$o_tmp->fields["customers_id"];

      if($i_orders_id>0)
      {

        //load language texts
     	$o_dir=$db->Execute("select directory from ".TABLE_LANGUAGES." where code = '".$languages_code."'");
        $s_language=$o_dir->fields['directory'];
     	if(strlen($s_language)==0) $s_language='polish';

     	// include the language translations
        require(DIR_WS_LANGUAGES.$s_language.'.php');
        require(DIR_WS_LANGUAGES.$s_language.'/modules/payment/przelewy24.php');

        //load order data
        require('mycustomadmindirectory/'.DIR_WS_CLASSES.'order.php');
        $o_order=new order($i_orders_id);

        // send email notification and store payment info
        $email=zen_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $i_orders_id, 'SSL');
        zen_mail
        (
        	$order->customer['name'], 
        	$order->customer['email_address'], 
        	EMAIL_TEXT_SUBJECT, 
        	$email, 
        	STORE_OWNER, 
        	STORE_OWNER_EMAIL_ADDRESS
        );
        
        $db->Execute("insert into ".TABLE_ORDERS_STATUS_HISTORY." (orders_id, orders_status_id, date_added, customer_notified, comments) values
                       ('".$i_orders_id."','".($WYNIK[0]=="TRUE"?2:1)."',now(),'1','".($WYNIK[0]=="TRUE"?TEXT_SUCCESS:TEXT_ERROR)."')");
		$db->Execute("delete from ".TABLE_CUSTOMERS_BASKET." where customers_id = '".(int)$customers_id . "'");
        $db->Execute("delete from ".TABLE_CUSTOMERS_BASKET_ATTRIBUTES." where customers_id='".(int)$customers_id."'");
    }
	
    if($WYNIK[0]=="TRUE")
    {
      $db->Execute("UPDATE ".TABLE_ORDERS." SET orders_status='2' WHERE orders_id='".$i_orders_id."'");
// IT STOPS HERE ! The order status gets changed to 2, but redirecton doesn't work.      zen_redirect(zen_href_link(FILENAME_CHECKOUT_SUCCESS, 'referer=przelewy24', 'SSL'));
    }
    else 
    {
      zen_redirect(zen_href_link('przelewy24_error', '', 'SSL'));
    }
  }
?>

Any ideas why doesn't it redirect? I want to add, that error page redirection (test payment error) works flawlessly. The redirection to error page is placed in the other (main module) file.

Few lines of the main file code:

    	header('Content-Type: text/html; charset=utf-8');
	    echo '<html><head></head><body onload="document.getElementById(\'przelewy24\').submit();">';
	    echo "<form id=\"przelewy24\" method=\"post\" action=\"https://secure.przelewy24.pl/index.php\" accept-charset=\"ISO-8859-2\">";

	    $s_my_currency='PLN';
	    
	    $s_languages_code=isset($HTTP_GET_VARS['languages_code'])&&strlen($HTTP_GET_VARS['languages_code'])>0?$HTTP_GET_VARS['languages_code']:'pl';
	    $sa_option=array
       			   (
       			  	'p24_session_id'		=>	$s_session_id,
       			  	'p24_id_sprzedawcy'		=>	MODULE_PAYMENT_PRZELEWY24_ID,
       			  	'p24_email'				=>	$order->customer['email_address'],
       			  	'p24_kwota'				=>	number_format(($order->info['total']*$currencies->get_value($s_my_currency)),2,'.','')*100,
       			  	'p24_opis'				=>	'Zamówienie nr: '.$insert_id.', '.$order->customer['firstname'].' '.$order->customer['lastname'].', '.date('Ymdhi').', '.STORE_NAME,
       			  	'p24_langugage'			=>	$s_languages_code,
       			  	'p24_klient'			=>	iconv('ISO-8859-2','UTF-8',$order->delivery['firstname']).' '.
       			   									iconv('ISO-8859-2','UTF-8',$order->delivery['lastname']),
       			  	'p24_adres'				=>	iconv('ISO-8859-2','UTF-8',$order->delivery['street_address']),
       			  	'p24_miasto'			=>	iconv('ISO-8859-2','UTF-8',$order->delivery['city']),
       			  	'p24_kod'				=>	$order->delivery['postcode'],
       			  	'p24_kraj'				=>	$order->delivery['country']['iso_code_2'],
       			  	'p24_return_url_ok'		=>	'http://'.
       			   									$_SERVER['HTTP_HOST'].'/'.MODULE_PAYMENT_PRZELEWY24_SUBDIR.
       			   										'/przelewy24.php',
       			this one works ! >> 	'p24_return_url_error'	=>	zen_href_link('index.php?main_page=przelewy24_error', '', 'SSL',false,false,true)
       			   );
       			  
       	$sa_hidden_fields=array();
	    foreach($sa_option as $s_name=>$s_value)
	    {
	    	$sa_hidden_fields[]=zen_draw_hidden_field($s_name,$s_value);
	    }
	    echo implode("\n",$sa_hidden_fields)."\n";
	    echo '</form><p>Przekierowanie na stronę serwisu przelewy24.pl...</p>';
	    
	exit(0);
	}
5 Feb 2011, 5:55 PM
#2
eurorage avatar

eurorage

New Zenner

Join Date:
Oct 2010
Posts:
7
Plugin Contributions:
0

Re: Custom Payment module won't redirect to "checkout success" page

Update.

When I execute przelewy24.php file, these errors are showed (after checkout process):

[05-Feb-2011 18:49:59] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/mysite/domains/mysite.eu/public_html/includes/languages/cherry_zen/polish.php:1) in /home/xxx/domains/mysite.eu/public_html/includes/init_includes/init_templates.php on line 78
[05-Feb-2011 18:50:00] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/xxx/domains/mysite.eu/public_html/includes/languages/cherry_zen/polish.php:1) in /home/xxx/domains/mysite.eu/public_html/includes/functions/functions_general.php on line 45

5 Feb 2011, 7:14 PM
#3
eurorage avatar

eurorage

New Zenner

Join Date:
Oct 2010
Posts:
7
Plugin Contributions:
0

Re: Custom Payment module won't redirect to "checkout success" page

Finally fixed !.

Some of the files were screwed by notepad/cuteftp editing software.

The edited files had weird letters before <?php syntax. Damn programs !