Author Topic: Hobex integration  (Read 5405 times)

Stefan Große

  • Beginner
  • *
  • Posts: 3
Hobex integration
« on: December 15, 2006, 15:35:30 pm »
hello,

i would like to integrate hobex(bank payment) in virtuemart. but my skills are not so good to integrate it.
now I seek a programmer to integrate hobex against payment.
   
If you are interested write me a email: stefan.grosse@achterdeck.com

Sorry for my english.

greets
stefan

[attachment cleanup by admin]

Stefan Große

  • Beginner
  • *
  • Posts: 3
Re: Hobex integration
« Reply #1 on: December 19, 2006, 12:21:51 pm »
hello,

now i have finished the hobex payment modul. but the order not confirmed in virtuemart.

can anybody help me?

sorry for my english

my code:
Code: [Select]
/**
*/
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

error_reporting(0);
/* schaltet die fehlermeldungen komplett aus */

class ps_hobex {

    var $payment_code = "HOBEX";
    var $classname = "ps_hobex";
 
    /**
    * Show all configuration parameters for this payment method
    * @returns boolean False when the Payment method has no configration
    */
    function show_configuration() {
   
      global $VM_LANG, $sess;
  $db =& new ps_DB;
      $payment_method_id = mosGetParam( $_REQUEST, 'payment_method_id', null );
      /** Read current Configuration ***/
      require_once(CLASSPATH ."payment/".$this->classname.".cfg.php");    ?>
      <table>
        <tr>
          <td><strong>TID</strong></td>
  <td><input type="text" name="HOBEX_TID" class="inputbox" value="<? echo HOBEX_TID ?>" /></td>
        </tr>
        <tr>
          <td><strong>Passwort</strong></td>
  <td><input type="text" name="HOBEX_LOGIN" class="inputbox" value="<? echo HOBEX_LOGIN ?>" /></td>
        </tr>
        <tr>
            <td><strong>Order Status for successful transactions</strong></td>
            <td>
                <select name="HOBEX_VERIFIED_STATUS" class="inputbox" >
                <?php
                $q 
"SELECT order_status_name,order_status_code FROM #__{vm}_order_status ORDER BY list_order";
                
$db->query($q);
                
$order_status_code = Array();
                
$order_status_name = Array();

                while (
$db->next_record()) {
                
$order_status_code[] = $db->f("order_status_code");
                
$order_status_name[] =  $db->f("order_status_name");
                }
                for (
$i 0$i sizeof($order_status_code); $i++) {
                
echo "<option value=\"" $order_status_code[$i];
                
if (HOBEX_VERIFIED_STATUS == $order_status_code[$i])
                
echo "\" selected=\"selected\">";
                
else
                
echo "\">";
                
echo $order_status_name[$i] . "</option>\n";
                    }
?>

                    </select>
            </td>
            <td>Select the order status to which the actual order is set, if the Hobex Transaction was successful.
            If using download selling options: select the status which enables the download (then the customer is instantly notified about the download via e-mail).
            </td>
        </tr>
            <tr>
            <td><strong>Order Status for failed transactions</strong></td>
            <td>
                <select name="HOBEX_INVALID_STATUS" class="inputbox" >
                <?php
                
for ($i 0$i sizeof($order_status_code); $i++) {
                
echo "<option value=\"" $order_status_code[$i];
                
if (HOBEX_INVALID_STATUS == $order_status_code[$i])
                
echo "\" selected=\"selected\">";
                
else
                
echo "\">";
                
echo $order_status_name[$i] . "</option>\n";
                    } 
?>

                    </select>
            </td>
            <td>Select an order status for failed Hobex transactions.</td>
        </tr>
      </table>
   <?php
      
// return false if there's no configuration
      
return true;
   }
   
    function 
has_configuration() {
      
// return false if there's no configuration
      
return true;
   }
   
  
/**
* Returns the "is_writeable" status of the configuration file
* @param void
* @returns boolean True when the configuration file is writeable, false when not
*/
   
function configfile_writeable() {
      return 
is_writeableCLASSPATH."payment/".$this->classname.".cfg.php" );
   }
   
  
/**
* Returns the "is_readable" status of the configuration file
* @param void
* @returns boolean True when the configuration file is writeable, false when not
*/
   
function configfile_readable() {
      return 
is_readableCLASSPATH."payment/".$this->classname.".cfg.php" );
   }   
  
/**
* Writes the configuration file for this payment method
* @param array An array of objects
* @returns boolean True when writing was successful
*/
   
function write_configuration( &$d ) {
      
      
$my_config_array = array("HOBEX_TID" => $d['HOBEX_TID'],
      
"HOBEX_LOGIN" => $d['HOBEX_LOGIN'],
  "HOBEX_VERIFIED_STATUS" => $d['HOBEX_VERIFIED_STATUS'],
  "HOBEX_INVALID_STATUS" => $d['HOBEX_INVALID_STATUS'],
      );
      
$config "<?php\n";
      
$config .= "defined('_VALID_MOS') or die('Direct Access to this location is not allowed.'); \n\n";
      foreach( 
$my_config_array as $key => $value ) {
        
$config .= "define ('$key', '$value');\n";
      }
      
      
$config .= "?>
";
 
  if ($fp = fopen(CLASSPATH ."payment/".$this->classname.".cfg.php", "w")) {
fputs($fp, $config, strlen($config));
           fclose ($fp);
           return true;
      }
      else {
           return false;
      }
   }
   
  /**************************************************************************
  ** name: process_payment()
  ** created by: jep
  ** description: process transaction authorize.net
  ** parameters: $order_number, the number of the order, we're processing here
  **            $order_total, the total $ of the order
  ** returns:
  ***************************************************************************/
   function process_payment($order_number, $order_total, &$d) {       
        global $vendor_mail, $vendor_currency, $VM_LAN, $vmLogger;
        $database = new ps_DB();
     
        $ps_vendor_id = $_SESSION["ps_vendor_id"];
        $auth = $_SESSION['auth'];
        $ps_checkout = new ps_checkout;
     
        /*** Get the Configuration File for Hobex ***/
        require_once(CLASSPATH ."payment/".$this->classname.".cfg.php");
       
        // Get user billing information
        $dbbt = new ps_DB;
        $qt = "SELECT * FROM #__{vm}_user_info WHERE user_id='".$auth["user_id"]."' AND address_type='BT'";
        $dbbt->query($qt);
        $dbbt->next_record();
        $user_info_id = $dbbt->f("user_info_id");
        if( $user_info_id != $d["ship_to_info_id"]) {
            // Get user billing information
            $dbst =& new ps_DB;
            $qt = "SELECT * FROM #__{vm}_user_info WHERE user_info_id='".$d["ship_to_info_id"]."' AND address_type='ST'";
            $dbst->query($qt);
            $dbst->next_record();
        } else {
            $dbst = $dbbt;
        }

if ($dbbt->f("extra_field_1") != ""){
// Ermittle Daten für Hobex Transfer
$account = $dbbt->f("bank_account_nr");
$bank = $dbbt->f("bank_sort_code");
$currencycode = "";
$countrycode = $dbbt->f("extra_field_1");
$amount = $order_total;
$my_trxn_number = uniqid();

// Erstelle Hobex-Objekt
$c = new Hobex();
$c->__construct();
$c->set_tid( HOBEX_TID , HOBEX_LOGIN );
$c->set_debit_info($account,$bank,$currencycode,$countrycode,$amount);
$c->set_debit_rinfo($my_trxn_number);

// Übermittle Hobex-Daten
$x = hbx_success($c, $t2, $content, $resp, $ret_txt );

// Hobex Fehlermeldungen
$ret_txts[0] = "Ok";
$ret_txts[1] = "Bankleitzahl falsch";
$ret_txts[2] = "Kontonummer ungültig";
$ret_txts[3] = "Bankverbindung ungültig";
$ret_txts[4] = "kein Betrag angegeben";
$ret_txts[5] = "Keine TID angegeben";
$ret_txts[6] = "Konto nicht angegeben";
$ret_txts[7] = "Ungltige Parameter";
$ret_txts[8] = "keine gültige Kreditkarte";
$ret_txts[9] = "Country-Code ungültig";
$ret_txts[10] = "Betrag nicht erlaubt";
$ret_txts[11] = "Ablaufdatum überschritten";
$ret_txts[20] = "BLZ nicht erforderlich";
$ret_txts[21] = "Flasche Länge bei Kontonummer";
$ret_txts[22] = "Paydelay nciht möglich";
$ret_txts[30] = "Authorisierungsfehler Kreditkarte";
$ret_txts[31] = "Kreditkarte nicht unterstützt";
$ret_txts[40] = "Limit für Terminal überschritten";
$ret_txts[41] = "Authorisierungsfehler";
$ret_txts[42] = "Kartenlimit überschritten";
$ret_txts[50] = "Beleg nicht vorhanden";
$ret_txts[61] = "Beleg nicht gefunden";
$ret_txts[90] = "Referenznummer zu lange";
$ret_txts[99] = "Login fehlgeschlagen";
$ret_txts[998] = "Parse Error";
$ret_txts[999] = "Unbekanntes Messageformat";
$ret_txts[9999] = "Schwerer Ausnahmefehler";
$ret_txts[99999] = "Unbekannter Fehler";

   
if( $x>0 ) {
// Wenn es sich um einen Hobex-Fehler handelt, dann gib den Fehler aus
$d["order_payment_log"] = $vmLogger->err( $ret_txts[trim($x)] );

//Catch Transaction ID
$d["order_payment_trans_id"] = $my_trxn_number;

return false;
}
else {
// Wenn kein Fehler vorhanden
$d["order_payment_log"] = $VM_LANG->_PHPSHOP_PAYMENT_TRANSACTION_SUCCESS . " Hobex sagt: ". $ret_txts[trim($x)] ;

//Catch Transaction ID
$d["order_payment_trans_id"] = $my_trxn_number;

/*// Update Order Status to Confirmed
$q = "UPDATE #__{vm}_orders SET ";
$q .="order_status='C',";
$q .="WHERE order_id='".$db->f("order_id")."' ";
$db->query( $q );*/

return true;
}
  }
  else {
// Wenn kein Ländercode vorhanden ist
$vmLogger->err( $VM_LANG->_PHPSHOP_PAYMENT_ERROR );

//Catch Transaction ID
$d["order_payment_trans_id"] = $c->get_xml_value("RETURNCODE");
return false;    
 
  }
       
}
}
/*** Get the XML Tree File for Hobex ***/
require_once(CLASSPATH ."payment/XML/Tree.php");


function hbx_success($cs_hobex, &$cs_transfer, &$content, &$response, &$ret_text) {

$ret_txt[0] = "Ok";
$ret_txt[1] = "Bankleitzahl falsch";
$ret_txt[2] = "Kontonummer ungültig";
$ret_txt[3] = "Bankverbindung ungültig";
$ret_txt[4] = "kein Betrag angegeben";
$ret_txt[5] = "Keine TID angegeben";
$ret_txt[6] = "Konto nicht angegeben";
$ret_txt[7] = "Ungltige Parameter";
$ret_txt[8] = "keine gültige Kreditkarte";
$ret_txt[9] = "Country-Code ungültig";
$ret_txt[10] = "Betrag nicht erlaubt";
$ret_txt[11] = "Ablaufdatum überschritten";
$ret_txt[20] = "BLZ nicht erforderlich";
$ret_txt[21] = "Flasche Länge bei Kontonummer";
$ret_txt[22] = "Paydelay nciht möglich";
$ret_txt[30] = "Authorisierungsfehler Kreditkarte";
$ret_txt[31] = "Kreditkarte nicht unterstützt";
$ret_txt[40] = "Limit für Terminal überschritten";
$ret_txt[41] = "Authorisierungsfehler";
$ret_txt[42] = "Kartenlimit überschritten";
$ret_txt[50] = "Beleg nicht vorhanden";
$ret_txt[61] = "Beleg nicht gefunden";
$ret_txt[90] = "Referenznummer zu lange";
$ret_txt[99] = "Login fehlgeschlagen";
$ret_txt[998] = "Parse Error";
$ret_txt[999] = "Unbekanntes Messageformat";
$ret_txt[9999] = "Schwerer Ausnahmefehler";
$ret_txt[99999] = "Unbekannter Fehler";

$content = $cs_hobex->get_hobex_xml();

$cs_transfer = new Transfer();
$cs_transfer->__construct($content);
$cs_transfer->do_transfer();

$response = $cs_transfer->get_hobex_xml();

$k = "RETURNCODE";
$rc = $cs_transfer->get_xml_value($k);

if ($rc<0) {
switch ($rc) {
case -998: $r = 998;
break;
case -998: $r = 998;
break;

default: $r = 9999;
}
}

if (!isset($ret_txt[$rc+0])) {
$rc = 99999;
}

$ret_text = $ret_txt[$rc+0];

return $rc;
//return $response;

}
/*
################################################################################
# HOBEX                                                                        #
#                                                                              #
# Description :  Class for creating HOBEX-XML-File                             #
# Company     :  SoHo Unzeitig KEG                                             #
# Urls        :                                                                #
# Create date :  2004-12-15                                                    #
# Last change :                                                                #
# Copyright   :                                                                #
################################################################################
*/

class Hobex{

var $id_com_tid = "TID";
var $id_com_psw ="Password";

var $id_debit ="Debit";
var $id_cancel ="Cancel";
var $id_dreport ="DailyReport";
var $id_rinfo ="ReceiptInfo";

var $id_dbt_account = "Account";
var $id_dbt_bank = "Bank";
var $id_dbt_currencycode = "CurrencyCode";
var $id_dbt_countrycode = "CountryCode";
var $id_dbt_amount = "Amount";
var $id_dbt_expire = "Expire";
var $id_dbt_inputtype = "InputType";
var $id_dbt_referencenumber = "ReferenceNumber";
var $id_dbt_reference = "Reference";
var $id_dbt_bankname = "BankName";
var $id_dbt_track2data = "Track2Data";
var $id_gen_receipt = "Receipt";

var $hbx_tree;
var $hbx_root;
var $hdx_debit;
var $hdx_cancel;
var $hdx_dreport;
var $hdx_rinfo;


function __construct(){

$this->hbx_tree = new XML_Tree;
$this->hbx_root =& $this->hbx_tree->addRoot('Hobex');
}

function set_tid($com_tid, $com_psw){

$this->hbx_root->addChild($this->id_com_tid,$com_tid);
$this->hbx_root->addChild($this->id_com_psw,$com_psw);
}

function set_debit_info($dbt_account, $dbt_bank, $dbt_currencycode, $dbt_countrycode, $dbt_amount){

$this->hdx_debit =& $this->hbx_root->addChild($this->id_debit);
$this->hdx_debit->addChild($this->id_dbt_account,$dbt_account);
$this->hdx_debit->addChild($this->id_dbt_bank,$dbt_bank);
$this->hdx_debit->addChild($this->id_dbt_currencycode,$dbt_currencycode);
$this->hdx_debit->addChild($this->id_dbt_countrycode,$dbt_countrycode);
$this->hdx_debit->addChild($this->id_dbt_amount,$dbt_amount);
}

function set_debit_rinfo($gen_reference){

$this->hdx_debit->addChild($this->id_dbt_referencenumber,$gen_reference);
}

function set_cancel_info($gen_receipt){

$this->hdx_cancel =& $this->hbx_root->addChild($this->id_cancel);
$this->hdx_cancel->addChild($this->id_gen_receipt,$gen_receipt);
}

function set_dreport_info(){

$this->hdx_dreport =& $this->hbx_root->addChild($this->id_dreport);
}

function set_rinfo_info($gen_receipt){

$this->hdx_rinfo =& $this->hbx_root->addChild($this->id_rinfo);
$this->hdx_rinfo->addChild($this->id_gen_receipt,$gen_receipt);
}

function create_xml(){

return $this->hbx_tree->dump();
}

function get_hobex_xml(){

$hbx_endtag ="</Hobex>";
$xml_endtag = "</XML>";
$xml_starttag = "<?xml version=\"1.0\"?>";
$xml_hobextag = "<XML version=\"1.0\">";

$tmp = $this->create_xml();
$tmp_array = explode("\n",$tmp);

$hlp = $tmp_array[0];
$tmp_array[0] = $tmp_array[1];
$tmp_array[1] = $hlp;

$key = array_search($hbx_endtag,$tmp_array);
$tmp_array[$key] = $xml_endtag;
$tmp_array[$key+1] = $hbx_endtag;

$key = array_search($xml_starttag,$tmp_array);
$tmp_array[$key] = $xml_hobextag;

$tmp = implode("\n",$tmp_array);

return $tmp;
}
}


class Transfer{

var $content = "";
var $hbx_uri = "vt.hobex.at";
var $hbx_port = 80;
var $errno = 0;
var $errdesc = "";
var $response = "";
var $xml;
var $xml_vals;
var $xml_index;

function __construct($content){
$this->content = $content;
}

function do_transfer(){
$len = strlen($this->content);
$fp = fsockopen($this->hbx_uri , $this->hbx_port , &$this->errno, &$this->errdesc );

if (!$fp) die ( "Couldn’t connect: $this->errno   $this->errdesc\n" );

fputs( $fp, "POST /vt/XML_InterfaceV2.asp HTTP/1.0\r\n");
fputs( $fp, "Content-Type: text/xml\r\n");
fputs( $fp, "Content-Length: $len\r\n\r\n");
fputs( $fp, $this->content);

$resp="";
$respText="";

while (!feof($fp)){

$respText=fgets( $fp, 1024 );
$reply[] = $respText;
$resp.=$respText;

}

fclose( $fp );

$this->response = $resp;
}

function get_response() {
return $this->response;
}

function extractxml() {

$tmp = $this->get_response();
$p = strpos($tmp, "<Hobex>");
$tmp = substr($tmp,$p,strlen($tmp));
return $tmp;
}

function parse_hobex_xml() {

$hbx_endtag ="</Hobex";
$xml_endtag = "</XML";
$xml_starttag = "<?xml version=\"1.0\"?";
$xml_hobextag = "<XML version=\"1.0\"";

$tmp = $this->extractxml();
$tmp_array = explode(">",$tmp);

$tmp_array[1] = $tmp_array[0];
$tmp_array[0] = $xml_starttag;

$key = array_search($xml_endtag,$tmp_array);
$tmp_array[$key] = $tmp_array[$key+1];
$x = array_pop($tmp_array);
$x = array_pop($tmp_array);

$tmp = implode(">\n",$tmp_array).">";

$this->do_xml_parse($tmp);
}



function do_xml_parse($input) {

$this->xml = $input;
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $this->xml, $this->xml_vals, $this->xml_index);
xml_parser_free($xml_parser);
}



function get_xml_value($value) {

if (!isset($this->xml)) {
$dummy = $this->parse_hobex_xml();
}

return $this->xml_vals[$this->xml_index[$value][0]]["value"];
}



function get_hobex_xml() {

if (!isset($this->xml)) {
$dummy = $this->parse_hobex_xml();
}

return $this->xml;
}
}

Stefan Große

  • Beginner
  • *
  • Posts: 3
Re: Hobex integration
« Reply #2 on: January 18, 2007, 12:22:53 pm »
Hello,

can nobody Help me?

greets Steve

oschellas

  • Beginner
  • *
  • Posts: 6
  • Skype Name: tcvdveer
Re: Hobex integration
« Reply #3 on: December 20, 2014, 17:55:53 pm »
I have made some plugins that work with Hobex (hobex.at),  see for more info http://www.webit.bz/virtuemart-c-31.html