News:

Looking for documentation? Take a look on our wiki

Main Menu

TWYP nearly finished

Started by Hans Natvig, January 14, 2005, 23:17:11 PM

Previous topic - Next topic

Hans Natvig

I'm nearly finished with a new payment module for TWYP. The procedure is much more complicated than PayPal, but PayPal like since it does not involve CC-information on the shop pages. However the shop need to create a secret code to send to the bank, and finally compare the code with what is returned from the bank. The code must be remain invisible to the user att all times.

My ideas was to store the secret code in the pshop_order_payment::order_payment_code field since it is not used for CC infor in the PayPal case. But I cannot figure out how to make DB changes from the Payment Extra Info field in the Admin Interface.

Have tried this without any luck:


$q = \"UPDATE mos_pshop_order_payment SET\";
$q .= \" order_payment_code='\" . $tasecret . \"' \";
$q .= \"WHERE order_id=\" . $order_id;
$dbv = new ps_DB;
$dbv->query($q);
$dbv->next_record();


Would be extremely grateful for any help on this issue.

Soeren

Hello,

you must be sure to have set the variables $order_id and $tasecret with the correct value on the checkout.thankyou.php page.

ciao, Soeren
The future of eCommerce: VirtueMart & Joomla!
http://virtuemart.net

Hans Natvig

It should be sufficient to set the variables $order_id and $tasecret in the Payment Extra Info area, right?

Perhaps I should publish the complete Payment Extra Info code. It's not yet finished but it works (everything except the storing the tasecret in the database for later use). Here it is:


<?php

/* ###########################################*/
function twyp_send_ssl($host$path$data) {
  
$port 443;

  
$fp fsockopen(\"ssl://\".$host$port$errno$errstr$timeout = 30);

  if(!
$fp){
    //error tell us
    echo \"
$errstr ($errno)\\\\n\";
    return false;
  }else{
    //send the server request
    fputs(
$fp, \"POST $path HTTP/1.1\\\\r\\\\n\"«»);
    fputs(
$fp, \"Host: $host\\\\r\\\\n\"«»);
    fputs(
$fp, \"Content-type: text/xml\\\\r\\\\n\"«»);
    fputs(
$fp, \"Content-length: \".strlen($data).\"\\\\r\\\\n\"«»);
    fputs(
$fp, \"Connection: close\\\\r\\\\n\\\\r\\\\n\"«»);
    fputs(
$fp$data . \"\\\\r\\\\n\\\\r\\\\n\"«»); 

    //loop through the response from the server
    while(!feof(
$fp)) {
      
$outputarray = fgets($fp, 4096);
    }

    //close fp
    fclose(
$fp);
  }

  return true;
}


/* ##################################################### */
function twyp_redirect(
$host$path$syncid) {
  header (\"Location: https://
$host$path?syncid=$syncid\"«»);
  die (\"<A HREF=\\\\\"https://
$host$path?syncid=$syncid\\\\\">GO!</A>\"«»);
}

/* Get the Configuration File for twyp */
require_once(CLASSPATH .\"payment/ps_twyp.cfg.php\"«»);    

// *** DATAPOST URL ***
  if(TWYP_TEST_REQUEST == 'N') {
    
$host = \"twyp.nl\"; // Production server
  } else if (TWYP_TEST_REQUEST == 'Y') {
    
$host = \"twyp.mt.kassadomein.com\"; // Test server
  } else {
    
$host = \"\"; // Should not come here
  }

$path = \"/payment/SilverStream/Pages/ControlServlet\";

// *** GENERATE SYNCID ***
$ymd = date(\"Ymd\"«»);
$order_id = $db->f(\"order_id\"«»);
$syncid = TWYP_SHOPCODE . \"m\" . $ymd . \"n\" . $order_id;
// *** GENERATING TASECRETCODE ***
$src4secret = $order_id . \" Zzz \" . $syncid;
$tasecret = md5($src4secret);

    
$q = \"UPDATE mos_pshop_order_payment SET\";
$q .= \" order_payment_code='\" . $tasecret . \"' \";
$q .= \"WHERE order_id=\" . $order_id;
$dbv = new ps_DB;
$dbv->query($q);
$dbv->next_record();


if (
$user->title !=\"\"«»)
  
$customername = $user->title;
if (
$user->first_name !=\"\"«»)
  
$customername .= \" \" . $user->first_name;
if (
$user->middle_name !=\"\"«»)
  
$customername .= \" \" . $user->middle_name;
if (
$user->last_name !=\"\"«»)
  
$customername .= \" \" . $user->last_name;

$customeraddress = \"$user->address_1\" . \"$user->address_2\";
$customercity = $user->city;
$customerzipcode = $user->zip;
$customercountry = $user->country;
$currency = $_SESSION['vendor_currency'];
$ordertotal = $db->f(\"order_total\"«»);
$language = \"en\";
$customerid = $db->f(\"customer_id\"«»);
$orderdescription = \"Whatever\";

// Maximum of 70 chars in URL's
$dataposturl = SECUREURL . \"administrator/components/com_phpshop/twyp_notify.php\";
$resulturl = SECUREURL . \"index.php?option=com_phpshop&amp;page=checkout.result&amp;order_id=\" . $order_id;
$cancelurl = $resulturl;

// *** XML-DATA ***
$file = (CLASSPATH . \"payment/requestXML.txt\"«»);
$fp = fopen($file, \"r\"«»);
$data = fread($fp, filesize($file));
fclose(
$fp);

$data = str_replace(\"@@shopcode@@\", TWYP_SHOPCODE, $data);
$data = str_replace(\"@@tasecret@@\", $tasecret$data);
$data = str_replace(\"@@syncid@@\", $syncid$data);
$data = str_replace(\"@@language@@\", $language$data);
$data = str_replace(\"@@amount@@\", $ordertotal$data);
$data = str_replace(\"@@currency@@\", $currency$data);
$data = str_replace(\"@@ordernumber@@\", $order_id$data);
$data = str_replace(\"@@orderdescription@@\", $orderdescription$data);
$data = str_replace(\"@@customerid@@\", $customerid$data);
$data = str_replace(\"@@customername@@\", trim($customername), $data);
$data = str_replace(\"@@customeraddress@@\", $customeraddress$data);
$data = str_replace(\"@@customercity@@\", $customercity$data);
$data = str_replace(\"@@customerzipcode@@\", $customerzipcode$data);
$data = str_replace(\"@@customercountry@@\", $customercountry$data);
$data = str_replace(\"@@dataposturl@@\", $dataposturl$data);
$data = str_replace(\"@@resulturl@@\", $resulturl$data);
$data = str_replace(\"@@cancelurl@@\", $cancelurl$data);

$fp = fopen(CLASSPATH .\"payment/ps_twyp.log\", \"a\"«»);
fwrite(
$fp, \"\\\\n\" . date(\"Y-m-d H:i:«»s\"«») . \": Request till TWYP med syncid $syncid och ordernumber $order_id och tasecret $tasecret\" . \"\\\\n\" . \"data $data\" . \"\\\\n\"«»);
fclose(
$fp);

if(!twyp_send_ssl(
$host$path$data)) {
  zfFatal(\"shop_kk93_request.php3: Fel uppstod n‰r TWYP-servern skulle kontaktas fˆr att hantera betalningen\"«»);
 }

twyp_redirect(
$host$path$syncid);
?>



igor

should this work with Joomla and does it work with the new Twyp environment ?
Igor