/[drupal]/contributions/modules/uc_turkish_banks/uc_turkish_banks.module
ViewVC logotype

Diff of /contributions/modules/uc_turkish_banks/uc_turkish_banks.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.9, Tue Nov 11 21:14:40 2008 UTC revision 1.10, Sun Nov 16 10:00:42 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: uc_turkish_banks.module,v 1.8 2008/11/11 19:29:24 bakyildiz Exp $  // $Id: uc_turkish_banks.module,v 1.7 2008/06/23 04:57:36 bakyildiz Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 313  function uc_turkish_banks_add_form($acti Line 313  function uc_turkish_banks_add_form($acti
313      $allowed_users = explode(',', $value['users']);      $allowed_users = explode(',', $value['users']);
314    }    }
315    $form['bank'] = array('#type' => 'fieldset',    $form['bank'] = array('#type' => 'fieldset',
316      '#title' => t('Genel Tanimlar'),      '#title' => t('General Definitions'),
317      '#collapsible' => TRUE,      '#collapsible' => TRUE,
318      '#collapsed' => FALSE,      '#collapsed' => FALSE,
319      '#weight' => 0,      '#weight' => 0,
# Line 364  function uc_turkish_banks_add_form($acti Line 364  function uc_turkish_banks_add_form($acti
364    $form['bank']['processtype'] = array('#type' => 'select',    $form['bank']['processtype'] = array('#type' => 'select',
365      '#title' => t('Process Type'),      '#title' => t('Process Type'),
366      '#default_value' => $value['processtype'],      '#default_value' => $value['processtype'],
367      '#description' => t('Auth: Satis PreAuth: On Otorizasyon.'),      '#description' => t('Auth: Authorize and capture immediately PreAuth: Only Authorize.'),
368      '#options' => array(      '#options' => array(
369        'Auth' => t('Auth'),        'Auth' => t('Auth'),
370        'PreAuth' => t('PreAuth'),        'PreAuth' => t('PreAuth'),
# Line 372  function uc_turkish_banks_add_form($acti Line 372  function uc_turkish_banks_add_form($acti
372      '#weight' => 1,      '#weight' => 1,
373      '#required' => TRUE,      '#required' => TRUE,
374    );    );
   
375    $form['bank']['cardname'] = array('#type' => 'textfield',    $form['bank']['cardname'] = array('#type' => 'textfield',
376      '#title' => t('Card Name'),      '#title' => t('Card Name'),
377      '#default_value' => $value['cardname'],      '#default_value' => $value['cardname'],
# Line 382  function uc_turkish_banks_add_form($acti Line 381  function uc_turkish_banks_add_form($acti
381    );    );
382    
383    $form['bank']['valid_until'] = array('#type' => 'select',    $form['bank']['valid_until'] = array('#type' => 'select',
384      '#title' => t('Experiation Date'),      '#title' => t('Expiration Date'),
385      '#type' => 'date',      '#type' => 'date',
386      '#default_value' => $default_valid_until,      '#default_value' => $default_valid_until,
387      '#required' => TRUE,      '#required' => TRUE,
# Line 489  function uc_turkish_banks_delete_confirm Line 488  function uc_turkish_banks_delete_confirm
488  function uc_turkish_banks_order($op, $arg1, $arg2) {  function uc_turkish_banks_order($op, $arg1, $arg2) {
489    switch ($op) {    switch ($op) {
490      case 'save':      case 'save':
491        list($bank_temp, $amount_temp, $bank_cid, $taksit)=explode('|', $_SESSION['taksit']);        list($bank_temp, $amount_temp, $bank_cid, $instalment) = explode('|', $_SESSION['taksit']);
492        //print "TEST:".$_SESSION['bank_cid'].' '. $bank.' '.$amount ;        //print "TEST:".$_SESSION['bank_cid'].' '. $bank.' '.$amount ;
493        db_query("UPDATE {uc_order_line_items} SET title = '%s', amount = %f, weight = 0 WHERE order_id = %d AND type = 'instalment'", $bank_temp, $amount_temp, $arg1->order_id);        db_query("UPDATE {uc_order_line_items} SET title = '%s', amount = %f, weight = 0 WHERE order_id = %d AND type = 'instalment'", $bank_temp, $amount_temp, $arg1->order_id);
494        if (db_affected_rows() == 0) {        if (db_affected_rows() == 0) {
# Line 704  function uc_payment_method_banks($op, &$ Line 703  function uc_payment_method_banks($op, &$
703         if ($_SESSION['bank_cid'] <> '')         if ($_SESSION['bank_cid'] <> '')
704         {         {
705         $bank_cid =substr($_SESSION['bank_cid'],0,strpos($_SESSION['bank_cid'],'_') );         $bank_cid =substr($_SESSION['bank_cid'],0,strpos($_SESSION['bank_cid'],'_') );
706         $taksit = substr($_SESSION['bank_cid'],strpos($_SESSION['bank_cid'],'_')+1,1);         $instalment = substr($_SESSION['bank_cid'],strpos($_SESSION['bank_cid'],'_')+1,1);
707         $bank_datail = db_fetch_object(db_query("SELECT * FROM {uc_turkish_banks} WHERE cid = %d",$bank_cid ));         $bank_datail = db_fetch_object(db_query("SELECT * FROM {uc_turkish_banks} WHERE cid = %d",$bank_cid ));
708         if (db_affected_rows() > 0) {         if (db_affected_rows() > 0) {
709         $title= $bank_datail->bankname. ' x '.$taksit;         $title= $bank_datail->bankname. ' x '.$instalment;
710         }         }
711         $review[] = array('title' => t('Instalment'), 'data' => $title);         $review[] = array('title' => t('Instalment'), 'data' => $title);
712         }         }
# Line 832  function uc_turkish_banks_complete($cart Line 831  function uc_turkish_banks_complete($cart
831    }    }
832  }  }
833    
834  /*******************************************************************************  /*
835   * Hook Functions (Ubercart)   * Hook Functions (Ubercart)
836   *******************************************************************************/   */
837    
838  function uc_turkish_banks_payment_gateway() {  function uc_turkish_banks_payment_gateway() {
839    $gateways[] = array(    $gateways[] = array(
840      'id' => 'banks',      'id' => 'banks',
841      'title' => t('Garanti Bank'),      'title' => t('A Turkish Bank'),
842      'description' => t('Process credit card payments using Garanti Bank Gateway'),      'description' => t('Process credit card payments using a Turkish Bank Gateway'),
843      'settings' => 'uc_turkish_banks_settings_form',      'settings' => 'uc_turkish_banks_settings_form',
844      'credit' => 'uc_turkish_banks_charge',      'credit' => 'uc_turkish_banks_charge',
845    );    );
# Line 848  function uc_turkish_banks_payment_gatewa Line 847  function uc_turkish_banks_payment_gatewa
847    return $gateways;    return $gateways;
848  }  }
849    
850  /*******************************************************************************  /*
851   * Callback Functions, Forms, and Tables   * Callback Functions, Forms, and Tables
852   ******************************************************************************/   */
853    
854  /**  /**
855   * Callback for payment gateway settings.   * Callback for payment gateway settings.
# Line 909  function uc_turkish_banks_settings_form( Line 908  function uc_turkish_banks_settings_form(
908      '#weight' => 1,      '#weight' => 1,
909      '#required' => TRUE,      '#required' => TRUE,
910    );    );
   
911    $form['bank']['cardname'] = array('#type' => 'textfield',    $form['bank']['cardname'] = array('#type' => 'textfield',
912      '#title' => t('Card Name'),      '#title' => t('Card Name'),
913      '#default_value' => variable_get('cardname', ''),      '#default_value' => variable_get('cardname', ''),
# Line 926  function uc_turkish_banks_charge($order_ Line 924  function uc_turkish_banks_charge($order_
924      drupal_set_message(t('The Bank Gateway service requires cURL.  Please talk to your system administrator to get this configured.'));      drupal_set_message(t('The Bank Gateway service requires cURL.  Please talk to your system administrator to get this configured.'));
925      return array('success' => FALSE);      return array('success' => FALSE);
926    }    }
927    // XML request schema    // XML request sablonu
928    $request = "DATA=<?xml version=\"1.0\" encoding=\"ISO-8859-9\"?>".    $request = "DATA=<?xml version=\"1.0\" encoding=\"ISO-8859-9\"?>".
929    "<CC5Request>".  "<CC5Request>".
930    "<Name>{NAME}</Name>".  "<Name>{NAME}</Name>".
931    "<Password>{PASSWORD}</Password>".  "<Password>{PASSWORD}</Password>".
932    "<ClientId>{CLIENTID}</ClientId>".  "<ClientId>{CLIENTID}</ClientId>".
933    "<IPAddress>{IP}</IPAddress>".  "<IPAddress>{IP}</IPAddress>".
934    "<Email>{EMAIL}</Email>".  "<Email>{EMAIL}</Email>".
935    "<Mode>P</Mode>".  "<Mode>P</Mode>".
936    "<OrderId>{OID}</OrderId>".  "<OrderId>{OID}</OrderId>".
937    "<GroupId></GroupId>".  "<GroupId></GroupId>".
938    "<TransId></TransId>".  "<TransId></TransId>".
939    "<UserId></UserId>".  "<UserId></UserId>".
940    "<Type>{TYPE}</Type>".  "<Type>{TYPE}</Type>".
941    "<Number>{CCNO}</Number>".  "<Number>{CCNO}</Number>".
942    "<Expires>{CCTAR}</Expires>".  "<Expires>{CCTAR}</Expires>".
943    "<Cvv2Val>{CV2}</Cvv2Val>".  "<Cvv2Val>{CV2}</Cvv2Val>".
944    "<Total>{TUTAR}</Total>".  "<Total>{TUTAR}</Total>".
945    "<Currency>949</Currency>".  "<Currency>949</Currency>".
946    "<Taksit></Taksit>".  "<Taksit></Taksit>".
947    "<BillTo>".  "<BillTo>".
948    "<Name></Name>".  "<Name>{BName}</Name>".
949    "<Street1></Street1>".  "<Street1>{BStreet1}</Street1>".
950    "<Street2></Street2>".  "<Street2>{BStreet2}</Street2>".
951    "<Street3></Street3>".  "<Street3></Street3>".
952    "<City></City>".  "<City>{BCity}</City>".
953    "<StateProv></StateProv>".  "<StateProv></StateProv>".
954    "<PostalCode></PostalCode>".  "<PostalCode>{BPostal}</PostalCode>".
955    "<Country></Country>".  "<Country>{BCountry}</Country>".
956    "<Company></Company>".  "<Company>{BCompany}</Company>".
957    "<TelVoice></TelVoice>".  "<TelVoice>{BTel}</TelVoice>".
958    "</BillTo>".  "</BillTo>".
959    "<ShipTo>".  "<ShipTo>".
960    "<Name></Name>".  "<Name>{SName}</Name>".
961    "<Street1></Street1>".  "<Street1>{SStreet1}</Street1>".
962    "<Street2></Street2>".  "<Street2>{SStreet2}</Street2>".
963    "<Street3></Street3>".  "<Street3></Street3>".
964    "<City></City>".  "<City>{SCity}</City>".
965    "<StateProv></StateProv>".  "<StateProv></StateProv>".
966    "<PostalCode></PostalCode>".  "<PostalCode>{SPostal}</PostalCode>".
967    "<Country></Country>".  "<Country>{SCountry}</Country>".
968    "</ShipTo>".  "</ShipTo>".
969    "<Extra></Extra>".  "<Extra></Extra>".
970    "</CC5Request>";  "</CC5Request>";
971    
972    $order = uc_order_load($order_id);    $order = uc_order_load($order_id);
973    $taksit = 0;    $instalment = 0;
974    while (strlen($order->payment_details['cc_exp_month'])==1 ){    if (strlen($order->payment_details['cc_exp_month']) == 1) {
975      $order->payment_details['cc_exp_month']= "0".$order->payment_details['cc_exp_month'];      $order->payment_details['cc_exp_month'] = '0'. $order->payment_details['cc_exp_month'];
976    }    }
977    $url = variable_get('bankurl', '');    $url = variable_get('bankurl', '');
   
978    $request = str_replace("{NAME}", variable_get('username', ''), $request);    $request = str_replace("{NAME}", variable_get('username', ''), $request);
979    $request = str_replace("{PASSWORD}", variable_get('password', ''), $request);    $request = str_replace("{PASSWORD}", variable_get('password', ''), $request);
980    $request = str_replace("{CLIENTID}", variable_get('clientid', ''), $request);    $request = str_replace("{CLIENTID}", variable_get('clientid', ''), $request);
# Line 985  function uc_turkish_banks_charge($order_ Line 982  function uc_turkish_banks_charge($order_
982    $request = str_replace("{OID}", $order_id, $request);    $request = str_replace("{OID}", $order_id, $request);
983    $request = str_replace("{TYPE}", variable_get('processtype', 'test'), $request);    $request = str_replace("{TYPE}", variable_get('processtype', 'test'), $request);
984    $request = str_replace("{CCNO}", $order->payment_details['cc_number'], $request);    $request = str_replace("{CCNO}", $order->payment_details['cc_number'], $request);
985    $request = str_replace("{CCTAR}", $order->payment_details['cc_exp_month'].substr($order->payment_details['cc_exp_year'],2), $request);    $request = str_replace("{CCTAR}", $order->payment_details['cc_exp_month'] . substr($order->payment_details['cc_exp_year'], 2), $request);
986    $request = str_replace("{CV2}", $order->payment_details['cc_cvv'], $request);    $request = str_replace("{CV2}", $order->payment_details['cc_cvv'], $request);
987    $request = str_replace("{TUTAR}", $amount, $request);    $request = str_replace("{TUTAR}", $amount, $request);
988    //$request = str_replace("{TAKSIT}", $taksit, $request);    $request = str_replace("{BName}", $order->payment_details['billing_first_name'] .' '. $order->payment_details['billing_last_name'], $request);
989      $request = str_replace("{BStreet1}", $order->payment_details['billing_street1'], $request);
990      $request = str_replace("{BStreet2}", $order->payment_details['billing_street2'], $request);
991      $request = str_replace("{BCity}", $order->payment_details['billing_city'], $request);
992      $request = str_replace("{BPostal}", $order->payment_details['billing_postal_code'], $request);
993      $request = str_replace("{BCountry}", $order->payment_details['billing_country'], $request);
994      $request = str_replace("{BCompany}", $order->payment_details['billing_company'], $request);
995      $request = str_replace("{BTel}", $order->payment_details['billing_phone'], $request);
996      $request = str_replace("{SName}", $order->payment_details['delivery_first_name'] .' '. $order->payment_details['delivery_last_name'], $request);
997      $request = str_replace("{SStreet1}", $order->payment_details['delivery_street1'], $request);
998      $request = str_replace("{SStreet2}", $order->payment_details['delivery_street2'], $request);
999      $request = str_replace("{SCity}", $order->payment_details['delivery_city'], $request);
1000      $request = str_replace("{SPostal}", $order->payment_details['delivery_postal_code'], $request);
1001      $request = str_replace("{SCountry}", $order->payment_details['delivery_country'], $request);
1002    
1003      //$request = str_replace("{TAKSIT}", $instalment, $request);
1004    
1005    $ch = curl_init();    // initialize curl handle    $ch = curl_init();                              // initialize curl handle
1006    curl_setopt($ch, CURLOPT_URL, $url); // set url to post to    curl_setopt($ch, CURLOPT_URL, $url);            // set url to post to
   //curl_setopt($ch, CURLOPT_VERBOSE, 0);  
   //curl_setopt($ch, CURLOPT_POST, 1);  
   //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);  
   //curl_setopt($ch, CURLOPT_NOPROGRESS, 1);  
   //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);  
1007    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
1008    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
1009    curl_setopt($ch, CURLOPT_SSLVERSION, 3);    curl_setopt($ch, CURLOPT_SSLVERSION, 3);
1010    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    // return into a variable
1011    curl_setopt($ch, CURLOPT_TIMEOUT, 90); // times out after 4s    curl_setopt($ch, CURLOPT_TIMEOUT, 90);          // times out after 4s
1012    curl_setopt($ch, CURLOPT_POSTFIELDS, $request); // add POST fields    curl_setopt($ch, CURLOPT_POSTFIELDS, $request); // add POST fields
1013    
1014    $result = curl_exec($ch); // run the whole process    $result = curl_exec($ch);                       // run the whole process
1015    
1016    if ($error = curl_error($ch)) {    if ($error = curl_error($ch)) {
1017      watchdog('uc_turkish_banks', $error, WATCHDOG_ERROR);      watchdog('uc_turkish_banks', $error, WATCHDOG_ERROR);
1018    }    }
1019    curl_close($ch);    curl_close($ch);
1020    
1021    $response = "";    $response = '';
1022    $order_id = "";    $order_id = '';
1023    $auth_code = "";    $auth_code = '';
1024    $proc_return_code = "";    $proc_return_code = '';
1025    $err_msg = "";    $err_msg = '';
1026    $host_msg = "";    $host_msg = '';
1027    
1028    $response_tag = "Response";    $response_tag = "Response";
1029    $posf = strpos($result, "<". $response_tag .">");    $posf = strpos($result, "<". $response_tag .">");
1030    $posl = strpos($result, "</". $response_tag .">");    $posl = strpos($result, "</". $response_tag .">");
1031    $posf = $posf+ strlen($response_tag) +2 ;    $posf = $posf + strlen($response_tag) + 2 ;
1032    $response = substr($result, $posf, $posl - $posf);    $response = substr($result, $posf, $posl - $posf);
1033    
1034    $response_tag = "OrderId";    $response_tag = "OrderId";
1035    $posf = strpos($result, "<". $response_tag .">");    $posf = strpos($result, "<". $response_tag .">");
1036    $posl = strpos($result, "</". $response_tag .">");    $posl = strpos($result, "</". $response_tag .">");
1037    $posf = $posf+ strlen($response_tag) +2;    $posf = $posf + strlen($response_tag) + 2;
1038    $order_id = substr($result, $posf, $posl - $posf);    $order_id = substr($result, $posf, $posl - $posf);
1039    
1040    $response_tag = "AuthCode";    $response_tag = "AuthCode";
1041    $posf = strpos($result, "<". $response_tag .">");    $posf = strpos($result, "<". $response_tag .">");
1042    $posl = strpos($result, "</". $response_tag .">");    $posl = strpos($result, "</". $response_tag .">");
1043    $posf = $posf+ strlen($response_tag) +2;    $posf = $posf + strlen($response_tag) + 2;
1044    $auth_code = substr($result, $posf, $posl - $posf);    $auth_code = substr($result, $posf, $posl - $posf);
1045    
1046    $response_tag = "ProcReturnCode";    $response_tag = "ProcReturnCode";
1047    $posf = strpos($result, "<". $response_tag .">");    $posf = strpos($result, "<". $response_tag .">");
1048    $posl = strpos($result, "</". $response_tag .">");    $posl = strpos($result, "</". $response_tag .">");
1049    $posf = $posf+ strlen($response_tag) +2;    $posf = $posf + strlen($response_tag) + 2;
1050    $proc_return_code = substr($result, $posf, $posl - $posf);    $proc_return_code = substr($result, $posf, $posl - $posf);
1051    
1052    $response_tag = "ErrMsg";    $response_tag = "ErrMsg";
1053    $posf = strpos($result, "<". $response_tag .">");    $posf = strpos($result, "<". $response_tag .">");
1054    $posl = strpos($result, "</". $response_tag .">");    $posl = strpos($result, "</". $response_tag .">");
1055    $posf = $posf+ strlen($response_tag) +2;    $posf = $posf + strlen($response_tag) + 2;
1056    $err_msg = substr($result, $posf, $posl - $posf);    $err_msg = substr($result, $posf, $posl - $posf);
1057    
1058    $x_response_code = $response;    $x_response_code = $response;

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

  ViewVC Help
Powered by ViewVC 1.1.2