Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Bind Payment module to a zones


Guest

Recommended Posts

I'm using the Dutch payment module "Way2Pay" and would like bind it to a zone, bud the Way2Pay module hasn't that options to choose or select a zone.

 

I already compare it with the module COD which has that option to bind it to a zone, bud it did not work.

 

I think that is hes something todo with this line in COD:

 

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_COD_ZONE', '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())");

 

And this line in Way2Pay:

 

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('E-Mail Address', 'MODULE_PAYMENT_WAY2PAY_ID', '[email protected] 'The e-mail address to use for the Way2Pay service', '6', '4', now())");

 

does someone knows how I setup up right?

Link to comment
Share on other sites

John, I am running into the same problem here. I have searched both the Dutch and the English forums but have not found an aswer (yet).

 

Were you able to get this to work in the days that have passed since your post?

If so...Would you like to share you code?

 

Thanx in advance.

 

Regards,

 

Remko de Koning.

Link to comment
Share on other sites

No, not yet.....

 

But I keep on trying..!!

 

I will report here if I have the solution!!

 

 

I see that you are using my (updated from zlack) tracktrace module, Nice isn't.!!

Link to comment
Share on other sites

Any way, wy do you need that, because your shop has on this moment just 1 languase??

 

Also see that you are from Spikcity Essenstraat, I live there to for a few yours ago (Cederstraat) . (nice town) I live now in Schiedam. See you around on internet.

Link to comment
Share on other sites

This community is definitely very powerfull. Lot's of great contributions. Like the one you made!! I am using my own (actualy my wife's) shop sort of a beta shop for a shop I am helping someone else with. This one is for a market salesman who wants to sell his fabrics on the internet to people in the European Community.

His shop is still under development and hosted on my domain (De Stoffenstunter)

Soon this shop will go live on it's own domain.

I can image the confusing this might have given :huh:

 

Unfortunatly I am not able to write php myself but I am able to read and understand most of it. Hopefully someday I am able to contribute myself and help others.

 

And yes.....it's a small world.

 

Remko

Link to comment
Share on other sites

I couldn't let this rest. So I started comparing it with different payment modules.

What I (and you) noticed is that there was no link with the payment zone. I have added that line.

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_WAY2PAY_ZONE', '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())");

 

Also I made sure it was visible in the funtion keys:

    function keys() {
     return array('MODULE_PAYMENT_WAY2PAY_STATUS', 'MODULE_PAYMENT_WAY2PAY_ZONE', 'MODULE_PAYMENT_WAY2PAY_ID','MODULE_PAYMENT_WAY2PAY_ORDERDESC', 'MODULE_PAYMENT_WAY2PAY_ADDTID', 'MODULE_PAYMENT_WAY2PAY_ENVIRONMENT', 'MODULE_PAYMENT_WAY2PAY_METHOD','MODULE_PAYMENT_WAY2PAY_POSTTECH', 'MODULE_PAYMENT_WAY2PAY_ORDER_STATUS_ID', 'MODULE_PAYMENT_WAY2PAY_SORT_ORDER');

 

Now it was visible for customers but it still was not working correctly. It still did not change when someone from outside the Netherlands bought something.

I noticed that several pieces of code were commented out.

 

// vdll     if ((int)MODULE_PAYMENT_WAY2PAY_ORDER_STATUS_ID > 0) {
// vdll       $this->order_status = MODULE_PAYMENT_WAY2PAY_ORDER_STATUS_ID;
// vdll    }

// vdll      if (is_object($order)) $this->update_status();

 

This was undone and it seems to be working when you change countries.

 

However. My Way2Pay submission is still in progress so I have no way of testing if it actualy works.

Perhaps you have a way of testing this.

 

Please keep in mind what I mentioned before. I am not a programmer so BACKUP your things first if you want to test this. :blink:

 

Below you will find the complete code of WAY2PAY.PHP

 

Remko

 

<?php
/*
 $Id: way2pay.php,v 0.5 2003/06/11 19:57:15 jqb Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 Redglove
 Authors: JQB; Redglove (www.redglove.nl)

 Released under the GNU General Public License
*/

class W2PMerchantXML 
{
   var $merchid;
   var $transid;
   var $merchname;
   var $description;
   var $itemid;
   var $itemname;
   var $amount;
   var $quantity;
   var $vatamount;
   var $totalamount;
   var $message;
   var $chargeshipping;
   var $maxrefundperiod;
   var $w2pkey;
   
   function W2PMerchantXML ($aa) 
   {
       foreach ($aa as $k=>$v)
           $this->$k = $aa[$k];
   }
}
class W2PResultXML 
{
   var $purchaseid;
   var $result;
   var $errno;
   var $errdesc;

   function W2PResultXML ($aa) 
   {
       foreach ($aa as $k=>$v)
           $this->$k = $aa[$k];
   }
}
 class way2pay {
   var $code, $title, $description, $enabled;

// class constructor
   function way2pay() {
     global $order;

     $this->code = 'way2pay';
     $this->title = MODULE_PAYMENT_WAY2PAY_TEXT_TITLE;
     $this->description = MODULE_PAYMENT_WAY2PAY_TEXT_DESCRIPTION;
     $this->sort_order = MODULE_PAYMENT_WAY2PAY_SORT_ORDER;
     $this->enabled = ((MODULE_PAYMENT_WAY2PAY_STATUS == 'True') ? true : false);

   if ((int)MODULE_PAYMENT_WAY2PAY_ORDER_STATUS_ID > 0) {
    $this->order_status = MODULE_PAYMENT_WAY2PAY_ORDER_STATUS_ID;
   }

     if (is_object($order)) $this->update_status();

 if (MODULE_PAYMENT_WAY2PAY_ENVIRONMENT == 'Productie (www.way2pay.nl)') {
 if(MODULE_PAYMENT_WAY2PAY_METHOD == 'No'){
      	 $this->form_action_url = 'https://www.way2pay.nl/merchant/payments-w2p.asp';
 } else {
	 $this->form_action_url = 'https://www.way2pay.nl/merchant/payments-w2pex.asp';
 }	
   } else {
   if(MODULE_PAYMENT_WAY2PAY_METHOD == 'No'){
      	 $this->form_action_url = 'https://merchant.way2pay.nl/merchant/payments-w2p.asp';
 } else {
	 $this->form_action_url = 'https://merchant.way2pay.nl/merchant/payments-w2pex.asp';
 }	
   }
}

// class methods
   function update_status() {
     global $order;

     if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_WAY2PAY_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_WAY2PAY_ZONE . "' and zone_country_id = '" . $order->delivery['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->delivery['zone_id']) {
           $check_flag = true;
           break;
         }
       }

       if ($check_flag == false) {
         $this->enabled = 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 $checkout_form_action, $checkout_form_submit;
 $checkout_form_submit = tep_image_submit('button_confirmway2pay_order.gif', 'Betaal met Way2Pay'); //Redglove JQB
 //https://merchant.way2pay.nl/pix/voorstel1/
if (MODULE_PAYMENT_WAY2PAY_ENVIRONMENT == 'Productie (www.way2pay.nl)') {
 if(MODULE_PAYMENT_WAY2PAY_METHOD == 'No'){
      	 $checkout_form_action = 'https://www.way2pay.nl/merchant/payments-w2p.asp';
 } else {
	 $checkout_form_action = 'https://www.way2pay.nl/merchant/payments-w2pex.asp';
 }	
   } else {
   if(MODULE_PAYMENT_WAY2PAY_METHOD == 'No'){
      	 $checkout_form_action = 'https://merchant.way2pay.nl/merchant/payments-w2p.asp';
 } else {
	 $checkout_form_action = 'https://merchant.way2pay.nl/merchant/payments-w2pex.asp';
 }	
   }
   }

   function process_button() {
       global $HTTP_POST_VARS, $order, $shipping_selected, $currencies;
  
     //$way2pay_cancel_return = 'payment_error=1&';
  $Tid = ($order->customer['lastname'] . '-' . date('YmdHis'));
 
  if (MODULE_PAYMENT_WAY2PAY_ADDTID == 'Yes') {
   $Itemname = MODULE_PAYMENT_WAY2PAY_ORDERDESC." ".$Tid;
 } else {
 $Itemname = MODULE_PAYMENT_WAY2PAY_ORDERDESC;
 }
// DE form variabelen  
  $process_button_string = tep_draw_hidden_field('TID', $Tid) .
                              tep_draw_hidden_field('MERID', MODULE_PAYMENT_WAY2PAY_ID) .
                              tep_draw_hidden_field('MNAME', 'Doesnt matter') .
                              tep_draw_hidden_field('ITEMNAME', $Itemname) .
                              tep_draw_hidden_field('AMT', number_format($order->info['total'] * $currencies->currencies['EUR']['value'], 2, ',', '')) .
                              tep_draw_hidden_field('SURL', tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL')) .
                              tep_draw_hidden_field('FURL', tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL'));

     return $process_button_string;
   }


   function before_process() {
   global $HTTP_GET_VARS, $HTTP_POST_VARS;
 
// geen APN
if ($HTTP_GET_VARS['ErrNo'] != '0' And MODULE_PAYMENT_WAY2PAY_METHOD == 'No') {
	 tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(MODULE_PAYMENT_WAY2PAY_TEXT_ERROR_BEFORE . $HTTP_GET_VARS['ErrDesc'] . MODULE_PAYMENT_WAY2PAY_TEXT_ERROR_AFTER), 'SSL', true, false));
} 
// Wel APN
else if (MODULE_PAYMENT_WAY2PAY_METHOD == 'Yes') {
 $strXML = ""; // initieren lokale resultstring
  	 $strXML = $HTTP_POST_VARS['resultXML']; // uitlezen xml bericht van way2pay
 
	 //terugontvangen XML is er niet, terug naar payment scherm	
 if (strlen($strXML) == "0") {
	 ErrorHandling("APN: MP1800 IInvalid Error XML posted; XML blank.");
	 }
 $arrError = readXML($strXML);
	 // terug ontvangen XML geeft parse error, terug naar payment scherm
 if (!is_array($arrError)) {
	 $STRingerror = "APN: MP1801, Invalid Error XML posted; parsing error.";
	 tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(MODULE_PAYMENT_WAY2PAY_TEXT_ERROR_BEFORE . $STRingerror . MODULE_PAYMENT_WAY2PAY_TEXT_ERROR_AFTER), 'SSL', true, false));
	 }
 $objErrInfo = new W2PMerchantXML($arrError);
	 
	 // Receiving XML results in reading error, back to payment screen
	 if (!is_object($objErrInfo)) {
   ErrorHandling("APN: MP1802, Invalid Error XML posted; Could not read into object.");
   }
 // Receiving XML seems ok, read error number!
 $APNError = $objErrInfo->errno;	
 
 If ($APNError != '') { // failure, transactie wordt voortijdig afgebroken of door gebruiker geannuleerd.
	 ErrorHandling("APN: ".$objErrInfo->errno." ".$objErrInfo->errdesc);
 } else	{
 //Success No Error code from Way2Pay so return a post
	 
	 if (MODULE_PAYMENT_WAY2PAY_ENVIRONMENT == 'Productie (www.way2pay.nl)') {
   $strServer = "https://www.way2pay.nl/";      
	 } else {
   $strServer = "https://merchant.way2pay.nl/";        
	 }	
	 $strPOSTUrl = $strServer . "merchant/process/payment-confirm.asp";
	 $arrMerch = readXML($strXML);
   
	 $objMerchInfo = new W2PMerchantXML($arrMerch);
	 $strMerchID = $objMerchInfo->merchid;
      	 $strTransID = $objMerchInfo->transid;
	 
	 // Winhttp alleen van toepassing als APN geactiveerd is
	 if(MODULE_PAYMENT_WAY2PAY_POSTTECH == 'Winhttp'){
	 $objWinHTTP = new COM("WinHttp.WinHttpRequest.5");
       
         $objWinHTTP->Open("POST", $strPOSTUrl, True);
         $objWinHTTP->SetRequestHeader("Content-Type", "application/x-www-form-urlencoded");
         $objWinHTTP->SetRequestHeader("Referer", $strMerchID);
         $objWinHTTP->Option(4, 1);
         $objWinHTTP->Send("inputXML=" . urlencode($strXML));
         $objWinHTTP->WaitForResponse();
       
         $strXMLReturn = $objWinHTTP->ResponseText();
   $objWinHTTP = null;}
	 
	 
	 else {
	 
	 $objReq = curl_init();
	 
	 curl_setopt($objReq, CURLOPT_URL, $strPOSTUrl); 
         curl_setopt($objReq, CURLOPT_TIMEOUT, 60); // No of seconds you want to allow the CURL request to complete.
         curl_setopt($objReq, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($objReq, CURLOPT_POST, 1); 
         curl_setopt($objReq, CURLOPT_FOLLOWLOCATION, 1);
         curl_setopt($objReq, CURLOPT_REFERER, $strServer);
         curl_setopt($objReq, CURLOPT_SSL_VERIFYHOST, 1);
         curl_setopt($objReq, CURLOPT_POSTFIELDS, "inputXML=" . urlencode($strXML));
	 
	 $strXMLReturn = curl_exec($objReq);
	 
	 curl_close($objReq); 
	 
	 }

      	 
	 $arrError = readXML($strXMLReturn);
	 if (!is_array($arrError)) {
          	 ErrorHandling("MP1903, Invalid XML returned; parsing error.");    
           }
	 
	 $objErrInfo = new W2PResultXML($arrError);
   if (!is_object($objErrInfo)) {
  	 ErrorHandling ("MP1904, Invalid XML returned; Could not read into object.");    
           }
   if ($objErrInfo->errno == "MP9999") { //iets met creditcard
   header("Location: " . $strServer . "merchant/payments-redirect.asp?W2PUID=" . urlencode($objErrInfo->w2puid));    
           }
	 
 }
 
} else {
return false;
}
  } 

function ErrorHandling($Error){
 tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(MODULE_PAYMENT_WAY2PAY_TEXT_ERROR_BEFORE . $Error . MODULE_PAYMENT_WAY2PAY_TEXT_ERROR_AFTER), 'SSL', true, false));    
}

   function after_process() {
     return false;
   }

   function output_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_WAY2PAY_STATUS'");
       $this->_check = tep_db_num_rows($check_query);
     }
     return $this->_check;
   }

   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 ('Enable Way2pay Module', 'MODULE_PAYMENT_WAY2PAY_STATUS', 'True', 'Do you want to accept Way2Pay payments?', '6', '3', '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, use_function, set_function, date_added) values ('Payment Zone', 'MODULE_PAYMENT_WAY2PAY_ZONE', '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())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('E-Mail Address', 'MODULE_PAYMENT_WAY2PAY_ID', '[email protected]', 'The e-mail address to use for the Way2Pay service', '6', '4', now())");
 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Order Description', 'MODULE_PAYMENT_WAY2PAY_ORDERDESC', 'Order Description', 'The order description', '6', '4', 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 ('Add TID?', 'MODULE_PAYMENT_WAY2PAY_ADDTID', 'No', 'Add Transaction ID to Order description?', '6', '6', 'tep_cfg_select_option(array(\'Yes\',\'No\'), ', 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 ('Environment', 'MODULE_PAYMENT_WAY2PAY_ENVIRONMENT', 'Test (merchant.way2pay.nl)', 'The environment', '6', '6', 'tep_cfg_select_option(array(\'Test (merchant.way2pay.nl)\',\'Productie (www.way2pay.nl)\'), ', 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_WAY2PAY_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', 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 ('Automated Payment Notification', 'MODULE_PAYMENT_WAY2PAY_METHOD', 'No', 'APN enabled?', '6', '6', 'tep_cfg_select_option(array(\'Yes\',\'No\'), ', 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 ('Post method', 'MODULE_PAYMENT_WAY2PAY_POSTTECH', 'Winhttp', 'Winhttp or Curl in case of APN?', '6', '6', 'tep_cfg_select_option(array(\'Winhttp\',\'Curl\'), ', 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 Order Status', 'MODULE_PAYMENT_WAY2PAY_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this value', '6', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");
   }

   function remove() {
     tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
   }

   function keys() {
     return array('MODULE_PAYMENT_WAY2PAY_STATUS', 'MODULE_PAYMENT_WAY2PAY_ZONE', 'MODULE_PAYMENT_WAY2PAY_ID','MODULE_PAYMENT_WAY2PAY_ORDERDESC', 'MODULE_PAYMENT_WAY2PAY_ADDTID', 'MODULE_PAYMENT_WAY2PAY_ENVIRONMENT', 'MODULE_PAYMENT_WAY2PAY_METHOD','MODULE_PAYMENT_WAY2PAY_POSTTECH', 'MODULE_PAYMENT_WAY2PAY_ORDER_STATUS_ID', 'MODULE_PAYMENT_WAY2PAY_SORT_ORDER');
   }
 }
 
 
function readXML($xmlData) 
{
   // read the xml database of W2PXMLs
   $parser = xml_parser_create();
   xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
   xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
   xml_parse_into_struct($parser, $xmlData, $values, $tags);
   xml_parser_free($parser);

   // loop through the structures
   foreach ($tags as $key=>$val) 
   {
       if ($key == "root") 
       {
           $molranges = $val;
           // each contiguous pair of array entries are the 
           // lower and upper range for each molecule definition
           /*
           for ($i=0; $i < count($molranges); $i+=2) 
           {
               $offset = $molranges[$i] + 1;
               $len = $molranges[$i + 1] - $offset;
               $tdb[] = parseW2PXML(array_slice($values, $offset, $len));
           }
           */
           $offset = 1;
           $len = 14;
           $tdb = parseXML(array_slice($values, $offset, $len));
       } 
       else 
       {
           continue;
       }
   }
   return $tdb;
}

function parseXML($mvalues) 
{
   for ($i=0; $i < count($mvalues); $i++)
   {
       $mol[$mvalues[$i]["tag"]] = $mvalues[$i]["value"];
   }
   
   return $mol;
}

?>

Link to comment
Share on other sites

Hi Remko,

 

I tested it, and so for as I can see...It's working..! TOPPIE

 

If there are any problems I will reported here, but for now it looks good.

 

Thx and Cheerio

 

Did you setup your zones correctly and singed up as a customer with a shipping address outside the netherlands..??

 

Let me know..

Link to comment
Share on other sites

I did and as far as I can see it worked. My submission at Way2Pay is almast done so I will be able to do final testing myself.

 

Glad to be of help.

 

Remko

 

Succes met je shop...Wie weet kom ik nog wel eens bij je langs. B)

Link to comment
Share on other sites

If you need some RAID, your welcome.

 

My live shop is still running 2.2CSV and now tunning MS2 separetly.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...