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

Diff of /contributions/modules/uc_setcom/uc_setcom.module

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

revision 1.1, Sun Nov 2 09:45:49 2008 UTC revision 1.2, Wed Oct 7 10:47:08 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id$  // $Id: uc_setcom.module,v 1.1.4.2 2009/10/07 08:14:04 maxheadroom Exp $
3    
4  /**  /**
5  * @file  * @file
6  * Integrates setcom.com's redirected payment service.  * Integrates setcom.com's redirected payment service.
7  *  *
8  * Developed by Quentin Campbell (Max_Headroom).  * Developed by Quentin Campbell (Max Headroom).
9  * Development sponsored by www.Setcom.com.  * Drupal 6 version development sponsored by  http://www.synecobusinessit.co.za.
10  */  */
11    require_once('uc_setcom.ca.inc');
12  /*******************************************************************************  /*******************************************************************************
13  * Hook Functions (Drupal)  * Hook Functions (Drupal)
14  ******************************************************************************/  ******************************************************************************/
# Line 16  Line 16 
16  /**  /**
17  * Implementation of hook_menu().  * Implementation of hook_menu().
18  */  */
19  function uc_setcom_menu($may_cache) {  function uc_setcom_menu() {
20    if ($may_cache) {    $items['cart/setcom/complete'] = array(
21      $items[] = array(      'title' => 'Setcom transaction result',
22        'path' => 'cart/setcom/complete',      'page callback' => 'uc_setcom_complete',
23        'title' => t('Setcom transaction result'),      'access callback' => 'uc_setcom_completion_access',
24        'callback' => 'uc_setcom_complete',      'type' => MENU_CALLBACK,
25        'access' => user_access('access content'),    );
       'type' => MENU_CALLBACK,  
       );  
   }  
26    return $items;    return $items;
27  }  }
28    
29    function uc_setcom_completion_access() {
30      return TRUE;
31    }
32  /**  /**
33  * Implementation of hook_form_alter().  * Implementation of hook_form_alter().
34  */  */
35  function uc_setcom_form_alter($form_id, &$form) {  function uc_setcom_form_alter(&$form, &$form_state, $form_id) {
36    if ($form_id == 'uc_cart_checkout_review_form' && ($order_id = intval($_SESSION['cart_order'])) > 0) {    if ($form_id == 'uc_cart_checkout_review_form' && ($order_id = intval($_SESSION['cart_order'])) > 0) {
37      $order = uc_order_load($order_id);      $order = uc_order_load($order_id);
38    
# Line 69  function uc_setcom_payment_method() { Line 69  function uc_setcom_payment_method() {
69      );      );
70    return $methods;    return $methods;
71  }  }
   
 /*******************************************************************************  
 * Hook Functions (Workflow_ng )  
 ******************************************************************************/  
   
 /**  
 * Implementation of hook_event_info  
 * Tell Workflow about the various setcom events.  
 */  
 function uc_setcom_event_info() {  
   $order_arg = array('#entity' => 'order', '#label' => t('Order'));  
   
   $events['payment_received'] = array(  
     '#label' => t('Payment received'),  
     '#module' => t('Setcom'),  
     '#arguments' => array(  
       'order' => $order_arg,  
       'account' => array('#entity' => 'user', '#label' => t('customer user account'))  
       ),  
     );  
   
   $events['payment_pending'] = array(  
     '#label' => t('Payment pending'),  
     '#module' => t('Setcom'),  
     '#arguments' => array(  
       'order' => $order_arg,  
       'account' => array('#entity' => 'user', '#label' => t('customer user account'))  
       ),  
     );  
   
   $events['payment_denied'] = array(  
     '#label' => t('Payment denied'),  
     '#module' => t('Setcom'),  
     '#arguments' => array(  
       'order' => $order_arg,  
       'account' => array('#entity' => 'user', '#label' => t('customer user account'))  
       ),  
     );  
   return $events;  
 }  
   
 /**  
 * Implementation of hook_configuration()  
 */  
 function uc_setcom_configuration() {  
   $configurations = array();  
    $configurations['uc_setcom_payment_received'] = array (  
     '#type' => 'configuration',  
     '#name' => 'uc_setcom_payment_received',  
     '#label' => 'Setcom payment received',  
     '#weight' => '0',  
     '#module' => 'Setcom',  
     '#active' => 1,  
     '#altered' => false,  
     '#event' => 'payment_received',  
     '#id' => 1,  
     );  
   
   $configurations['uc_setcom_payment_received']['action1'] = array (  
     '#type' => 'action',  
     '#name' => 'uc_order_action_update_status',  
     '#argument map' => array ('order' => 'order'),  
     '#settings' => array ('order_status' => 'setcom_payment_received'),  
     );  
   
    $configurations['uc_setcom_payment_received']['condition1'] = array (  
       '#type' => 'condition',  
       '#name' => 'uc_order_condition_order_status',  
       '#argument map' =>array ('order' => 'order',),  
       '#settings' =>array ('order_status' => 'pending',),  
     );  
   
   $configurations['uc_setcom_payment_pending'] = array (  
     '#weight' => '0',  
     '#module' => 'Setcom',  
     '#active' => 1,  
     '#label' => 'Setcom payment pending',  
     '#altered' => false,  
     '#event' => 'payment_pending',  
     '#type' => 'configuration',  
     '#id' => 1,  
     '#name' => 'uc_setcom_payment_pending',  
     );  
   
   $configurations['uc_setcom_payment_pending']['action1'] = array (  
     '#type' => 'action',  
     '#name' => 'uc_order_action_update_status',  
     '#argument map' =>array ('order' => 'order'),  
     '#settings' =>array ('order_status' => 'setcom_payment_pending'),  
     );  
   
   $configurations['uc_setcom_payment_pending']['condition1'] = array (  
       '#type' => 'condition',  
       '#name' => 'uc_order_condition_order_status',  
       '#argument map' =>array ('order' => 'order',),  
       '#settings' =>array ('order_status' => 'pending',),  
     );  
   
   $configurations['uc_setcom_payment_denied'] = array (  
     '#weight' => '0',  
     '#module' => 'Setcom',  
     '#active' => 1,  
     '#label' => 'Setcom payment denied',  
     '#altered' => false,  
     '#event' => 'payment_denied',  
     '#type' => 'configuration',  
     '#id' => 1,  
     '#name' => 'uc_setcom_payment_denied',  
     );  
   
   $configurations['uc_setcom_payment_denied']['action1'] = array (  
     '#type' => 'action',  
     '#name' => 'uc_order_action_update_status',  
     '#argument map' =>array ('order' => 'order'),  
     '#settings' =>array ('order_status' => 'setcom_payment_denied'),  
     );  
   
   $configurations['uc_setcom_payment_denied']['condition1'] = array (  
       '#type' => 'condition',  
       '#name' => 'uc_order_condition_order_status',  
       '#argument map' =>array ('order' => 'order',),  
       '#settings' =>array ('order_status' => 'pending',),  
     );  
   return $configurations;  
 }  
72    
73  /*******************************************************************************  /*******************************************************************************
74  * Callback Functions, Forms, and Tables  * Callback Functions, Forms, and Tables
# Line 274  function uc_payment_method_setcom($op, & Line 149  function uc_payment_method_setcom($op, &
149      $form['setcom_settings']['setcom_return_url'] = array(      $form['setcom_settings']['setcom_return_url'] = array(
150        '#type' => 'item',        '#type' => 'item',
151        '#title' => t('Return URL'),        '#title' => t('Return URL'),
152        '#value' => variable_get('setcom_return_url', url('cart/setcom/complete/', NULL, NULL, TRUE)),        '#value' => variable_get('setcom_return_url', url('cart/setcom/complete/', $options = array('query' => NULL, 'fragment' => NULL, 'absolute' => TRUE))),
153        '#description' => t('The URL to where Setcom must return to after a transaction. Please log in to your Setcom account and under Profile >> Selling Preferences >> Website Payment Preferences, enter this Return URL into the Redirect URL field under Auto-Redirect.'),        '#description' => t('The URL to where Setcom must return to after a transaction. Please log in to your Setcom account and under Profile >> Selling Preferences >> Website Payment Preferences, enter this Return URL into the Redirect URL field under Auto-Redirect.'),
154        );        );
155    
# Line 352  function uc_payment_method_setcom($op, & Line 227  function uc_payment_method_setcom($op, &
227    
228      $form['setcom_payment_methods']['uc_setcom_poli'] = array(      $form['setcom_payment_methods']['uc_setcom_poli'] = array(
229        '#type' => 'select',        '#type' => 'select',
230        '#title' => t('Allow payment by Setcom POLi'),        '#title' => t('Allow payment by Setcom POLi/SID'),
231        '#default_value' => variable_get('uc_setcom_poli', 0),        '#default_value' => variable_get('uc_setcom_poli', 0),
232        '#options' => $allowed_options,        '#options' => $allowed_options,
233        );        );
# Line 409  function uc_payment_method_setcom($op, & Line 284  function uc_payment_method_setcom($op, &
284  }  }
285    
286  // Form to build the submission to setcom.com  // Form to build the submission to setcom.com
287  function uc_setcom_form($order) {  function uc_setcom_form(&$form_state, $order) {
288    global $user;    global $user;
289    $country = uc_get_country_data(array('country_id' => $order->billing_country));    $country = uc_get_country_data(array('country_id' => $order->billing_country));
290    
291    if (variable_get('setcom_transaction_mode','test') == 'production'){    if (variable_get('setcom_transaction_mode', 'test') == 'production') {
292      $MerchantIdentifier = variable_get('setcom_merchant_id', '');      $merchant_identifier = variable_get('setcom_merchant_id', '');
293    }else{    }
294      $MerchantIdentifier = variable_get('setcom_test_merchant_id', '');    else{
295        $merchant_identifier = variable_get('setcom_test_merchant_id', '');
296    }    }
297    
298    $data = array(    $data = array(
299      'ButtonAction' => variable_get('setcom_button_action', 'checkout'),      'ButtonAction' => variable_get('setcom_button_action', 'checkout'),
300      'MerchantIdentifier' => $MerchantIdentifier,      'merchantIdentifier' => $merchant_identifier,
301      'CurrencyAlphaCode' => variable_get('setcom_currency', (variable_get('uc_currency_code', 'USD'))),      'CurrencyAlphaCode' => variable_get('setcom_currency', (variable_get('uc_currency_code', 'USD'))),
302      'MerchCustom' => $order->order_id,      'MerchCustom' => $order->order_id,
303      'TemplateID' => variable_get('setcom_template', 0),      'TemplateID' => variable_get('setcom_template', 0),
# Line 449  function uc_setcom_form($order) { Line 325  function uc_setcom_form($order) {
325      $data['IsVoucher'. $j] = 0;      $data['IsVoucher'. $j] = 0;
326      $i++;      $i++;
327    }    }
328      $do_shipping = variable_get('setcom_shipping', FALSE);
329    if (!variable_get('setcom_shipping', FALSE)) {    if (!$do_shipping) {
330      $data['LIDSKU'. $i] = 'shipping';      $data['LIDSKU'. $i] = 'shipping';
331      $data['LIDDesc'. $i] = 'Shipping cost';      $data['LIDDesc'. $i] = 'Shipping cost';
332      $data['LIDPrice'. $i] = uc_currency_format($order->quote['rate'], FALSE, FALSE, '.');      $data['LIDPrice'. $i] = uc_currency_format($order->quote['rate'], FALSE, FALSE, '.');
# Line 486  function uc_setcom_complete($cart_id = 0 Line 362  function uc_setcom_complete($cart_id = 0
362      drupal_goto(variable_get('uc_cart_checkout_complete_page', ''));      drupal_goto(variable_get('uc_cart_checkout_complete_page', ''));
363    }    }
364    
365    $errMsg = '';    $err_msg = '';
366    if(empty($tnxid)) {    if (empty($tnxid)) {
367      $errMsg .= 'tnxid not found.';      $err_msg .= 'tnxid not found.';
368    }    }
369    if(empty($checksum)) {    if (empty($checksum)) {
370      $errMsg .= 'checksum not found.';      $err_msg .= 'checksum not found.';
371    }    }
372    if(empty($parity)) {    if (empty($parity)) {
373      $errMsg .= 'parity not found.';      $err_msg .= 'parity not found.';
374    }    }
375    
376    if ($errMsg) {    if ($err_msg) {
377      drupal_set_message('Communication error: '. $errMsg . '<br> No futher action or processing will be done.', 'error');      drupal_set_message('Communication error: '. $err_msg .'<br> No futher action or processing will be done.', 'error');
378      if (variable_get('setcom_do_email', TRUE) == TRUE){      if (variable_get('setcom_do_email', TRUE) == TRUE) {
379        drupal_set_message('<b>The store owner has been notified and will look into the problem.', 'error');        drupal_set_message('<b>The store owner has been notified and will look into the problem.', 'error');
380        uc_setcom_send_error('Communication error: '. $errMsg, 'Communication error: '. $errMsg . ' No futher action or processing will be done.');        uc_setcom_send_error('Communication error: '. $err_msg, 'Communication error: '. $err_msg .' No futher action or processing will be done.');
381      }      }
382      watchdog('Setcom', $errMsg, WATCHDOG_WARNING);      watchdog('Setcom', $err_msg, WATCHDOG_WARNING);
383    }    }
384    
385    // Web page receives Synchro Auto-Redirect variables from Setcom.    // Web page receives Synchro Auto-Redirect variables from Setcom.
386    if (variable_get('setcom_transaction_mode','test') == 'production'){    if (variable_get('setcom_transaction_mode', 'test') == 'production') {
387      $MerchantIdentifier = variable_get('setcom_merchant_id', '');      $merchant_identifier = variable_get('setcom_merchant_id', '');
388      $username = variable_get('setcom_username', '');      $username = variable_get('setcom_username', '');
389      $password = variable_get('setcom_pwd', '');      $password = variable_get('setcom_pwd', '');
390    }else{    }
391      $MerchantIdentifier = variable_get('setcom_test_merchant_id', '1234567893');    else{
392        $merchant_identifier = variable_get('setcom_test_merchant_id', '1234567893');
393      $username = variable_get('setcom_test_username', 'testseller3@setcom.com');      $username = variable_get('setcom_test_username', 'testseller3@setcom.com');
394      $password = variable_get('setcom_test_pwd', 'testseller');      $password = variable_get('setcom_test_pwd', 'testseller');
395    }    }
# Line 520  function uc_setcom_complete($cart_id = 0 Line 397  function uc_setcom_complete($cart_id = 0
397    /*    /*
398    Now we open a communication line to the HTTP Synchro Service.    Now we open a communication line to the HTTP Synchro Service.
399    */    */
400    $setcom_string = 'method=' . 'order_synchro' .    $setcom_string = 'method='.'order_synchro'.
401    '&identifier=' . $MerchantIdentifier .    '&identifier='. $merchant_identifier .
402    '&usrname=' . $username .    '&usrname='. $username .
403    '&pwd=' . $password .    '&pwd='. $password .
404    '&tnxid=' . $tnxid .    '&tnxid='. $tnxid .
405    '&checksum=' . $checksum .    '&checksum='. $checksum .
406    '&parity=' . $parity;    '&parity='. $parity;
407    
408    // send $setcom_string to Setcom by utilizing CURL    // send $setcom_string to Setcom by utilizing CURL
409    $setcom_url = "https://www.setcom.com/secure/components/synchro.cfc?wsdl";    $setcom_url = "https://www.setcom.com/secure/components/synchro.cfc?wsdl";
# Line 537  function uc_setcom_complete($cart_id = 0 Line 414  function uc_setcom_complete($cart_id = 0
414    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
415    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
416    curl_setopt($ch, CURLOPT_HEADER, 0);    curl_setopt($ch, CURLOPT_HEADER, 0);
417    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
418    curl_setopt($ch, CURLOPT_POST, 1); // set POST method    curl_setopt($ch, CURLOPT_POST, 1); // set POST method
419    curl_setopt($ch, CURLOPT_POSTFIELDS, $setcom_string); // set Post variable    curl_setopt($ch, CURLOPT_POSTFIELDS, $setcom_string); // set Post variable
420    $setcom_result = curl_exec($ch); // Perform the POST and get the data returned by Setcom.    $setcom_result = curl_exec($ch); // Perform the POST and get the data returned by Setcom.
421    if (curl_errno($ch)) {    if (curl_errno($ch)) {
422      $sCurlError = curl_error($ch); // If CURL returns an error, stores it in a variable.      $scurlerror = curl_error($ch); // If CURL returns an error, stores it in a variable.
423      Drupal_set_message($sCurlError);      Drupal_set_message($scurlerror);
424    } else {    }
425      $sCurlError = '';    else {
426        $scurlerror = '';
427      curl_close($ch);      curl_close($ch);
428    }    }
429    if (empty($sCurlError)) {    if (empty($scurlerror)) {
430      //filter result for XML      //filter result for XML
431      $setcom_wddx = trim($setcom_result);      $setcom_wddx = trim($setcom_result);
432      $setcom_xml = wddx_deserialize($setcom_wddx);      $setcom_xml = wddx_deserialize($setcom_wddx);
# Line 595  function uc_setcom_complete($cart_id = 0 Line 473  function uc_setcom_complete($cart_id = 0
473      //transaction is unsuccessful      //transaction is unsuccessful
474      if ($error_code != '0') {      if ($error_code != '0') {
475        $somestring = '<strong>Your order has been Declined.</strong><br><br>';        $somestring = '<strong>Your order has been Declined.</strong><br><br>';
476        $somestring .= 'Sorry ' . $buyer_title . ' '  . $buyer_fname . ' ' . $buyer_surname . ' your payment to ' . $seller_email . ' was <strong>unsuccesful</strong>.<br><br>';        $somestring .= 'Sorry '. $buyer_title .' '. $buyer_fname .' '. $buyer_surname .' your payment to '. $seller_email .' was <strong>unsuccesful</strong>.<br><br>';
477        $somestring .= ' The order has not been processed<br><br>';        $somestring .= ' The order has not been processed<br><br>';
478        $somestring .= 'Error Code: ' . $error_code . '<br>';        $somestring .= 'Error Code: '. $error_code .'<br>';
479        $somestring .= 'Error Description: ' . $error_desc . '<br>';        $somestring .= 'Error Description: '. $error_desc .'<br>';
480        $somestring .= 'Error Solution: ' . $error_solution . '<br>';        $somestring .= 'Error Solution: '. $error_solution .'<br>';
481        drupal_set_message($somestring, 'error');        drupal_set_message($somestring, 'error');
482        watchdog('Setcom', $somestring, WATCHDOG_WARNING);        watchdog('Setcom', $somestring, WATCHDOG_WARNING);
483        $output = '<br /><a href="' . $s_front . '">Click to return to the front page.</a>';        $output = '<br /><a href="'. $s_front .'">Click to return to the front page.</a>';
484      } else { //end transaction is unsuccessful      }
485        else { //end transaction is unsuccessful
486        //transaction is successful        //transaction is successful
487        $cur_tnx_amount = getCurrency($tnx_amount,$currency);        $cur_tnx_amount = getcurrency($tnx_amount, $currency);
488        $somearray['tnx_amount'] = $tnx_amount/100; //returned amount is without decimal        $somearray['tnx_amount'] = $tnx_amount/100; //returned amount is without decimal
489    
490        if (!$pmt_type) {        if (!$pmt_type) {
491          $somearray['pmt_type'] ='unknown type';          $somearray['pmt_type'] ='unknown type';
       }else{  
         $somearray['pmt_type'] = $pmt_type;  
492        }        }
493          else{
494            $somearray['pmt_type'] = $pmt_type;
495          }
496    
497        $somearray['order'] = $seller_ref;        $somearray['order'] = $seller_ref;
498        $somestring = 'Your transaction is <strong>' . $tnx_status . '</strong><br><br>';        $somestring = 'Your transaction is <strong>'. $tnx_status .'</strong><br><br>';
499        $somestring .= 'Payment by ' . $somearray['pmt_type'] . '. <br>';        $somestring .= 'Payment by '. $somearray['pmt_type'] .'. <br>';
500        $somestring .= ' Thank you, '. $buyer_title . ' '  . $buyer_fname . ' ' . $buyer_surname . 'for your business<br>';        $somestring .= ' Thank you, '. $buyer_title .' '. $buyer_fname .' '. $buyer_surname .'for your business<br>';
501        $somestring .= '<strong>Transaction ID</strong>: ' . $tnx_id . '<br>';        $somestring .= '<strong>Transaction ID</strong>: '. $tnx_id .'<br>';
502        $somestring .= '<strong>Transaction Amount</strong>: ' . $cur_tnx_amount . '<br>';        $somestring .= '<strong>Transaction Amount</strong>: '. $cur_tnx_amount .'<br>';
503        $somestring .= '<strong>Funds Available</strong>: ' . $funds_avail . '<br>';        $somestring .= '<strong>Funds Available</strong>: '. $funds_avail .'<br>';
504        $somestring .= '<strong>Reference</strong>: ' . $seller_ref . '<br>';        $somestring .= '<strong>Reference</strong>: '. $seller_ref .'<br>';
505    
506        switch ($pmt_type) {        switch ($pmt_type) {
507        case 'Credit Card':        case 'Credit Card':
# Line 656  function uc_setcom_complete($cart_id = 0 Line 536  function uc_setcom_complete($cart_id = 0
536        }        }
537        if ($pmt_type != 'Credit Card' && $somearray['setting'] != 2) {        if ($pmt_type != 'Credit Card' && $somearray['setting'] != 2) {
538          foreach ($order_synchro->outcome->order->alerts->alert as $alerts) {          foreach ($order_synchro->outcome->order->alerts->alert as $alerts) {
539            $somestring .= '<br><br><u>Transaction notification from <strong>SETCOM</strong>: </u><fieldset>' . $alerts->text . '<br></fieldset><br>';            $somestring .= '<br><br><u>Transaction notification from <strong>SETCOM</strong>: </u><fieldset>'. $alerts->text .'<br></fieldset><br>';
540          }          }
541        }        }
542        if ($somestring) {        if ($somestring) {
# Line 665  function uc_setcom_complete($cart_id = 0 Line 545  function uc_setcom_complete($cart_id = 0
545        }        }
546      } //end tnx successful      } //end tnx successful
547      return $output;      return $output;
548    }else{ // END - [if (empty($sCurlError))]    }
549      else { // END - [if (empty($scurlerror))]
550      drupal_set_message(t('There was an error in the communication with Setcom. No confirmation reply from their server. ') , 'error');      drupal_set_message(t('There was an error in the communication with Setcom. No confirmation reply from their server. ') , 'error');
551      if (variable_get('setcom_do_email', TRUE) == TRUE){      if (variable_get('setcom_do_email', TRUE) == TRUE) {
552        drupal_set_message(t('<b>The store owner has been notified and will look into the problem.', 'error'));        drupal_set_message(t('<b>The store owner has been notified and will look into the problem.', 'error'));
553        uc_setcom_send_error('No Curl received', 'No Curl data was send from Setcom.');        uc_setcom_send_error('No Curl received', 'No Curl data was send from Setcom.');
554      }      }
# Line 683  function uc_setcom_complete($cart_id = 0 Line 564  function uc_setcom_complete($cart_id = 0
564  /**  /**
565  * helper function for transaction type.  * helper function for transaction type.
566  */  */
567  function uc_setcom_check_trans($somearray, $somestring){  function uc_setcom_check_trans($somearray, $somestring) {
568    $order_check = uc_order_load($somearray['order']);    $order_check = uc_order_load($somearray['order']);
569    
570    switch ($somearray['setting']) {    switch ($somearray['setting']) {
# Line 692  function uc_setcom_check_trans($somearra Line 573  function uc_setcom_check_trans($somearra
573      $output = uc_cart_complete_sale($order_check, variable_get('uc_new_customer_login', FALSE));      $output = uc_cart_complete_sale($order_check, variable_get('uc_new_customer_login', FALSE));
574      uc_order_comment_save($order_check->order_id, 0, $somestring);      uc_order_comment_save($order_check->order_id, 0, $somestring);
575      uc_payment_enter($order_check->order_id, 'Setcom', $somearray['tnx_amount'], 0, NULL, $somestring);      uc_payment_enter($order_check->order_id, 'Setcom', $somearray['tnx_amount'], 0, NULL, $somestring);
576      workflow_ng_invoke_event('payment_received', $order_check, $user->uid == 0 ? $account : $user);      ca_pull_trigger('setcom_payment_received', $order_check, $user->uid == 0 ? $account : $user);
577      break;      break;
578    
579    case 1:    case 1:
580      $somestring .= t('<strong>Order will only ship when funds clear in our bank account.</strong>');      $somestring .= t('<strong>Order will only ship when funds clear in our bank account.</strong>');
581      $output = uc_cart_complete_sale($order_check, variable_get('uc_new_customer_login', FALSE));      $output = uc_cart_complete_sale($order_check, variable_get('uc_new_customer_login', FALSE));
582      uc_order_comment_save($order_check->order_id, 0,  $somestring);      uc_order_comment_save($order_check->order_id, 0,  $somestring);
583      workflow_ng_invoke_event('payment_pending', $order_check, $user->uid == 0 ? $account : $user);      ca_pull_trigger('setcom_payment_pending', $order_check, $user->uid == 0 ? $account : $user);
584      break;      break;
585    
586    case 2:    case 2:
587      $somestring = t('<strong>We do not accept payment via ' . $somearray['pmt_type'] . '.</strong><br> We can not honour payment for this order.<br> If you have already made a payment, please contact Setcom to reverse this payment.<br> You can checkout the order again and select a different method of payment on the Setcom page.<br>');      $somestring = t('<strong>We do not accept payment via '. $somearray['pmt_type'] .'.</strong><br> We can not honour payment for this order.<br> If you have already made a payment, please contact Setcom to reverse this payment.<br> You can do a checkout the order again and select a different method of payment on the Setcom page.<br>');
588      $somestring .= uc_setcom_get_details();      $somestring .= uc_setcom_get_details();
589    
590      if (variable_get('setcom_do_email', TRUE) == TRUE){      if (variable_get('setcom_do_email', TRUE) == TRUE) {
591        uc_setcom_send_error(t('Payment method not allowed', 'Customer tried to buy with ' . $somearray['pmt_type'] . ', a payment method that is not allowed. Order no.:' . $order_check->order_id .' Order user ID:' . $order_check->uid));        uc_setcom_send_error(t('Payment method not allowed', 'Customer tried to buy with '. $somearray['pmt_type'] .', a payment method that is not allowed. Order no.:'. $order_check->order_id .' Order user ID:'. $order_check->uid));
592      }      }
593      drupal_set_message($somestring, 'error');      drupal_set_message($somestring, 'error');
594      watchdog('Setcom', $somestring, WATCHDOG_NOTICE);      watchdog('Setcom', $somestring, WATCHDOG_NOTICE);
595      $output ='<a href="' . url() . '">Click to return to the front page.</a>';      $output ='<a href="'. url() .'">Click to return to the front page.</a>';
596      $somestring = '';      $somestring = '';
597      workflow_ng_invoke_event('payment_denied', $order_check, $user->uid == 0 ? $account : $user);      ca_pull_trigger('setcom_payment_denied', $order_check, $user->uid == 0 ? $account : $user);
598      break;      break;
599    
600    case 3:    case 3:
601    default:    default:
602      $somestring .= '<br>' . t('Even though the transaction is successful, there was an error in that we could not determine which payment method was used in this transaction.');      $somestring .= '<br>'. t('Even though the transaction is successful, there was an error in that we could not determine which payment method was used in this transaction.');
603    
604      if (variable_get('setcom_do_email', TRUE) == TRUE){      if (variable_get('setcom_do_email', TRUE) == TRUE) {
605        $somestring .= t('<br>The store owner has been notified and will look into the problem.');        $somestring .= t('<br>The store owner has been notified and will look into the problem.');
606        uc_setcom_send_error('Transaction method error', 'Transaction method could not be determined. Contact Setcom regarding this problem. The order was not processed (stay Pending). Order no.:' . $order_check->order_id .' Order user ID:' . $order_check->uid);        uc_setcom_send_error('Transaction method error', 'Transaction method could not be determined. Contact Setcom regarding this problem. The order was not processed (stay Pending). Order no.:'. $order_check->order_id .' Order user ID:'. $order_check->uid);
607      }      }
608      watchdog('Setcom', $somestring, WATCHDOG_NOTICE);      watchdog('Setcom', $somestring, WATCHDOG_NOTICE);
609      $output ='<a href="' . url() . '">Click to return to the front page.</a>';      $output ='<a href="'. url() .'">Click to return to the front page.</a>';
610      uc_order_comment_save($order_check->order_id, 0, $somestring);      uc_order_comment_save($order_check->order_id, 0, $somestring);
611      break;      break;
612    
# Line 736  function uc_setcom_check_trans($somearra Line 617  function uc_setcom_check_trans($somearra
617  /**  /**
618  * helper function for payment type details.  * helper function for payment type details.
619  */  */
620  function uc_setcom_get_details(){  function uc_setcom_get_details() {
621    $is_allowed=array();    $is_allowed=array();
622    $is_allowed_wait=array();    $is_allowed_wait=array();
623    $not_allowed=array();    $not_allowed=array();
624    
625    if (variable_get('uc_setcom_credit_card', 0)==0){    if (variable_get('uc_setcom_credit_card', 0)==0) {
626      $is_allowed[] ='Credit Card';      $is_allowed[] ='Credit Card';
627    }elseif (variable_get('uc_setcom_credit_card', 0)==1){    }
628      elseif (variable_get('uc_setcom_credit_card', 0)==1) {
629      $is_allowed_wait[] = ' Credit Card';      $is_allowed_wait[] = ' Credit Card';
630    }else{    }
631      else {
632      $not_allowed[] =' Credit Card';      $not_allowed[] =' Credit Card';
633    }    }
634    
635    if (variable_get('uc_setcom_poli', 0)==0){    if (variable_get('uc_setcom_poli', 0)==0) {
636      $is_allowed[] =' POLi';      $is_allowed[] =' POLi/SID';
637    }elseif (variable_get('uc_setcom_credit_poli', 0)==1){    }
638      $is_allowed_wait[] = ' POLi';    elseif (variable_get('uc_setcom_credit_poli', 0)==1) {
639    }else{      $is_allowed_wait[] = ' POLi/SID';
640      $not_allowed[] =' POLi';    }
641      else {
642        $not_allowed[] =' POLi/SID';
643    }    }
644    
645    if (variable_get('uc_setcom_balance', 0)==0){    if (variable_get('uc_setcom_balance', 0)==0) {
646      $is_allowed[] =' Setcom Balance';      $is_allowed[] =' Setcom Balance';
647    }elseif (variable_get('uc_setcom_balance', 0)==1){    }
648      elseif (variable_get('uc_setcom_balance', 0)==1) {
649      $is_allowed_wait[] = ' Setcom Balance';      $is_allowed_wait[] = ' Setcom Balance';
650    }else{    }
651      else {
652      $not_allowed[] =' Setcom Balance';      $not_allowed[] =' Setcom Balance';
653    }    }
654    
655    if (variable_get('uc_setcom_echeque', 0)==0){    if (variable_get('uc_setcom_echeque', 0)==0) {
656      $is_allowed[] =' eCheque';      $is_allowed[] =' eCheque';
657    }elseif (variable_get('uc_setcom_echeque', 0)==1){    }
658      elseif (variable_get('uc_setcom_echeque', 0)==1) {
659      $is_allowed_wait[] = ' eCheque';      $is_allowed_wait[] = ' eCheque';
660    }else{    }
661      else {
662      $not_allowed[] =' eCheque';      $not_allowed[] =' eCheque';
663    }    }
664    
665    if (variable_get('uc_setcom_edeposit', 0)==0){    if (variable_get('uc_setcom_edeposit', 0)==0) {
666      $is_allowed[] =' eDeposit';      $is_allowed[] =' eDeposit';
667    }elseif (variable_get('uc_setcom_edeposit', 0)==1){    }
668      elseif (variable_get('uc_setcom_edeposit', 0)==1) {
669      $is_allowed_wait[] = ' eDeposit';      $is_allowed_wait[] = ' eDeposit';
670    }else{    }
671      else {
672      $not_allowed[] = ' eDeposit';      $not_allowed[] = ' eDeposit';
673    }    }
674    
675    $details = t('<u><h4>Setcom offers a variety of payment methods. The following conditions apply to this shop:</h4> </u>');    $details = t('<u><h4>Setcom offers a variety of payment methods. The following conditions apply to this shop:</h4> </u>');
676    
677    if ($is_allowed){    if ($is_allowed) {
678      $details .= t('<u>Accepted payment methods that clear and dispatch immediate: </u><br>') . implode(", ",$is_allowed) . '.<br>';      $details .= t('<u>Accepted payment methods that clear and dispatch immediate: </u><br>') . implode(", ", $is_allowed) .'.<br>';
679    }    }
680    if ($is_allowed_wait){    if ($is_allowed_wait) {
681      $details .= t('<u>Accepted payment methods that clear after a few days and will be dispatched only when payment received: </u><br>') . implode(", ",$is_allowed_wait) . '.<br>';      $details .= t('<u>Accepted payment methods that clear after a few days and will be dispatched only when payment received: </u><br>') . implode(", ", $is_allowed_wait) .'.<br>';
682    }    }
683    if ($not_allowed){    if ($not_allowed) {
684      $details .= t('<u>These payment methods are not accepted. Order will not be honoured should you use them: </u><br>') . implode(", ",$not_allowed) . '.<br>';      $details .= t('<u>These payment methods are not accepted. Order will not be honoured should you use them: </u><br>') . implode(", ", $not_allowed) .'.<br>';
685    }    }
686    return $details;    return $details;
687  }  }
# Line 798  function uc_setcom_get_details(){ Line 689  function uc_setcom_get_details(){
689  /**  /**
690  * helper function for error email.  * helper function for error email.
691  */  */
692  function uc_setcom_send_error($subject, $body){  function uc_setcom_send_error($subject, $body) {
693    $mail_to = variable_get('setcom_error_email', variable_get('site_mail', ini_get('sendmail_from')));    $mail_to = variable_get('setcom_error_email', variable_get('site_mail', ini_get('sendmail_from')));
694    drupal_mail('setcom_error', $mail_to, $subject, $body, $mail_to);  //  drupal_mail('setcom_error', $mail_to, $subject, $body, $mail_to);
695      /* TODO Create a hook_mail($key, &$message, $params) function to generate
696      the message body when called by drupal_mail. */
697      $account = array(); // Set this as needed
698      $language = user_preferred_language($account);
699      $object = array(); // Replace this as needed
700      $context['subject'] = $subject;
701      $context['body'] = $body;
702      $params = array('account' => $account, 'object' => $object, 'context' => $context);
703      drupal_mail('uc_setcom', 'setcom_error', $mail_to, $language, $params, $mail_to);
704  }  }
705    
706  /**  /**
# Line 819  if (!function_exists('wddx_deserialize') Line 719  if (!function_exists('wddx_deserialize')
719            }            }
720          }          }
721          return $struct;          return $struct;
722        }else if (!empty($xmlpacket->array)) { //jEdit thinks this is an error, maybe because of the use of 'array' name as an object variable?        }
723          else if (!empty($xmlpacket->array)) { //jEdit php parser thinks this is an error, maybe because of the use of 'array' name as an object variable?
724          $array = array();          $array = array();
725          foreach ($xmlpacket->xpath("array/*") as $var) {          foreach ($xmlpacket->xpath("array/*") as $var) {
726            array_push($array, wddx_deserialize($var));            array_push($array, wddx_deserialize($var));
727          }          }
728          return $array;          return $array;
729        } else if (!empty($xmlpacket->string)) {        }
730          else if (!empty($xmlpacket->string)) {
731          return (string) $xmlpacket->string;          return (string) $xmlpacket->string;
732        } else if (!empty($xmlpacket->number)) {        }
733          else if (!empty($xmlpacket->number)) {
734          return (int) $xmlpacket->number;          return (int) $xmlpacket->number;
735        } else {        }
736          else {
737          if (is_numeric((string) $xmlpacket)) {          if (is_numeric((string) $xmlpacket)) {
738            return (int) $xmlpacket;            return (int) $xmlpacket;
739          } else {          }
740            else {
741            return (string) $xmlpacket;            return (string) $xmlpacket;
742          }          }
743        }        }
744      }else {      }
745        else {
746        $sxe = simplexml_load_string($xmlpacket);        $sxe = simplexml_load_string($xmlpacket);
747        $datanode = $sxe->xpath("/wddxPacket[@version='1.0']/data");        $datanode = $sxe->xpath("/wddxPacket[@version='1.0']/data");
748        return wddx_deserialize($datanode[0]);        return wddx_deserialize($datanode[0]);
# Line 847  if (!function_exists('wddx_deserialize') Line 753  if (!function_exists('wddx_deserialize')
753  /**  /**
754  * Reformat amount values  * Reformat amount values
755  **/  **/
756  function getCurrency($amt, $cur) {  function getcurrency($amt, $cur) {
757    if (strlen($cur) > 0) {    if (strlen($cur) > 0) {
758      switch (strtoupper($cur)) {      switch (strtoupper($cur)) {
759    
# Line 856  function getCurrency($amt, $cur) { Line 762  function getCurrency($amt, $cur) {
762        break;        break;
763    
764      case 'GBP' :      case 'GBP' :
765        $cur_sym = '£';        $cur_sym = '�';
766        break;        break;
767    
768      case 'USD' :      case 'USD' :
# Line 870  function getCurrency($amt, $cur) { Line 776  function getCurrency($amt, $cur) {
776      default:      default:
777        $cur_sym = '';        $cur_sym = '';
778      }      }
779    } else {    }
780      else {
781      $cur_sym = '';      $cur_sym = '';
782    }    }
783    if ($amt < 0) {    if ($amt < 0) {
784      $amt=abs($amt);      $amt=abs($amt);
785      $new_amt = '-' . $cur_sym . number_format(($amt / 100),2,'.','');      $new_amt = '-'. $cur_sym . number_format(($amt / 100), 2, '.', '');
786    } else {    }
787      $new_amt = $cur_sym . number_format(($amt / 100),2,'.','');    else {
788        $new_amt = $cur_sym . number_format(($amt / 100), 2, '.', '');
789    }    }
790    return $new_amt;    return $new_amt;
791  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.2