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

Diff of /contributions/modules/uc_paygate/uc_paygate.module

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

revision 1.2.2.1, Sun Nov 2 19:23:01 2008 UTC revision 1.2.2.2, Wed Oct 7 14:17:31 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id:$  // $Id: uc_paygate.module,v 1.2.2.1 2008/11/02 19:23:01 maxheadroom Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 17  Line 17 
17  /**  /**
18   * Implementation of hook_menu().   * Implementation of hook_menu().
19   */   */
20  function uc_paygate_menu()  function uc_paygate_menu() {
 {  
21    $items['cart/paygate/complete'] = array(    $items['cart/paygate/complete'] = array(
22      'title' => 'PayGate transaction result',      'title' => 'PayGate transaction result',
23      'page callback' => 'uc_paygate_complete',      'page callback' => 'uc_paygate_complete',
24      'access arguments' => array('access content'),      'access arguments' => 'uc_paygate_completion_access',
25      'type' => MENU_CALLBACK,      'type' => MENU_CALLBACK,
26    );    );
27    
28    return $items;    return $items;
29  }  }
30    
31    function uc_paygate_completion_access() {
32      return TRUE;
33    }
34  /**  /**
35   * Implementation of hook_form_alter().   * Implementation of hook_form_alter().
36   */   */
37  function uc_paygate_form_alter(&$form, $form_state, $form_id)  function uc_paygate_form_alter(&$form, $form_state, $form_id) {
 {  
38    // normally a switch is used because you may want to alter more than    // normally a switch is used because you may want to alter more than
39    // one form and it is easy to add a new case for each form.    // one form and it is easy to add a new case for each form.
40    switch ($form_id)    switch ($form_id) {
   {  
41      // this is our form_id.      // this is our form_id.
42      case 'uc_cart_checkout_review_form':      case 'uc_cart_checkout_review_form':
43        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) {
       {  
44          $order = uc_order_load($order_id);          $order = uc_order_load($order_id);
45    
46          if ($order->payment_method == 'paygate') {          if ($order->payment_method == 'paygate') {
# Line 142  function uc_payment_method_paygate($op, Line 141  function uc_payment_method_paygate($op,
141        $form['paygate_settings']['paygate_return_url'] = array(        $form['paygate_settings']['paygate_return_url'] = array(
142        '#type' => 'textfield',        '#type' => 'textfield',
143        '#title' => t('Return URL'),        '#title' => t('Return URL'),
144        '#default_value' => variable_get('paygate_return_url', url('cart/paygate/complete/'. $order->order_id, array('absolute' => TRUE))),        '#default_value' => variable_get('paygate_return_url', url('cart/paygate/complete', array('absolute' => TRUE))),
145        '#description' => t('The URL to where PayGate must return after a transaction.'),        '#description' => t('The URL to where PayGate must return after a transaction. This normally not needed to be changed'),
146        );        );
147    
148        $form['paygate_settings']['uc_paygate_method_title'] = array(        $form['paygate_settings']['uc_paygate_method_title'] = array(
# Line 177  function uc_payment_method_paygate($op, Line 176  function uc_payment_method_paygate($op,
176  }  }
177    
178  // Form to build the submission to paygate.co.za  // Form to build the submission to paygate.co.za
179  function uc_paygate_form($order) {  function uc_paygate_form($form_state, $order) {
180    global $user;    global $user;
181    
182    if (variable_get('uc_currency_code', 'ZAR') != 'ZAR'){    if (variable_get('uc_currency_code', 'ZAR') != 'ZAR') {
183      drupal_set_message(t('PayGate can only use South African Rand (ZAR) as currency. Please contact the site owner about this problem at !site_mail', array('!site_mail' => variable_get('site_mail',''))), 'error');      drupal_set_message(t('PayGate can only use South African Rand (ZAR) as currency. Please contact the site owner about this problem at !site_mail', array('!site_mail' => variable_get('site_mail', ''))), 'error');
184      return;      return;
185    }    }
186    
187    if (variable_get(paygate_transaction_mode,'') == "Production"){    if (variable_get('paygate_transaction_mode', '') == "Production") {
188      $PAYGATE_ID=variable_get('paygate_id', '');      $PAYGATE_ID=variable_get('paygate_id', '');
189      $checksum_key = variable_get('paygate_checksum_key', '');      $checksum_key = variable_get('paygate_checksum_key', '');
190    }else{    }
191      else {
192      $PAYGATE_ID=variable_get('paygate_test_id', '');      $PAYGATE_ID=variable_get('paygate_test_id', '');
193      $checksum_key = variable_get('paygate_checksum_test_key', '');      $checksum_key = variable_get('paygate_checksum_test_key', '');
194    }    }
# Line 196  function uc_paygate_form($order) { Line 196  function uc_paygate_form($order) {
196    $REFERENCE = $order->order_id;    $REFERENCE = $order->order_id;
197    $AMOUNT = ($order->order_total)*100; //Paygate requires amount to be in cents    $AMOUNT = ($order->order_total)*100; //Paygate requires amount to be in cents
198    $CURRENCY =  'ZAR';    $CURRENCY =  'ZAR';
199    $RETURN_URL = url('cart/paygate/complete/');    $RETURN_URL = variable_get('paygate_return_url', url('cart/paygate/complete', array('absolute' => TRUE)));
200    $TRANSACTION_DATE = date('Y-m-d H:i');    $TRANSACTION_DATE = date('Y-m-d H:i');
201    $EMAIL = substr($order->primary_email, 0, 64);    $EMAIL = substr($order->primary_email, 0, 64);
202    
203    $checksum_data = $PAYGATE_ID."|".$REFERENCE."|".$AMOUNT."|".$CURRENCY."|".$RETURN_URL."|".$TRANSACTION_DATE."|".$EMAIL."|".$checksum_key;    $checksum_data = $PAYGATE_ID  ."|".  $REFERENCE  ."|".  $AMOUNT  ."|".  $CURRENCY  ."|".  $RETURN_URL  ."|".  $TRANSACTION_DATE  ."|".  $EMAIL  ."|".  $checksum_key;
204      $CHECKSUM = md5($checksum_data);      $CHECKSUM = md5($checksum_data);
205    
206      $data = array(      $data = array(
207      'PAYGATE_ID' => $PAYGATE_ID,        'PAYGATE_ID' => $PAYGATE_ID,
208      'REFERENCE' => $REFERENCE,        'REFERENCE' => $REFERENCE,
209      'AMOUNT' => $AMOUNT,        'AMOUNT' => $AMOUNT,
210      'CURRENCY' => $CURRENCY,        'CURRENCY' => $CURRENCY,
211      'RETURN_URL' => $RETURN_URL,        'RETURN_URL' => $RETURN_URL,
212      'TRANSACTION_DATE' => $TRANSACTION_DATE,        'TRANSACTION_DATE' => $TRANSACTION_DATE,
213      'EMAIL' => $EMAIL,        'EMAIL' => $EMAIL,
214      'CHECKSUM' => $CHECKSUM        'CHECKSUM' => $CHECKSUM
215      );      );
216    
217    $form['#action'] = 'https://www.paygate.co.za/paywebv2/process.trans';    $form['#action'] = 'https://www.paygate.co.za/paywebv2/process.trans';
# Line 224  function uc_paygate_form($order) { Line 224  function uc_paygate_form($order) {
224    '#type' => 'submit',    '#type' => 'submit',
225    '#value' => variable_get('uc_paygate_checkout_button', t('Submit Order')),    '#value' => variable_get('uc_paygate_checkout_button', t('Submit Order')),
226    );    );
   
227    return $form;    return $form;
228  }  }
229    
230  function uc_paygate_complete($cart_id = 0) {  function uc_paygate_complete($cart_id = 0) {
231    if (!$_POST){    if (!$_POST) {
232      return;      return;
233    }    }
234    if (variable_get(paygate_transaction_mode,'') == "Production"){    if (variable_get(paygate_transaction_mode, '') == "Production") {
235      $checksum_key = variable_get('paygate_checksum_key', '');      $checksum_key = variable_get('paygate_checksum_key', '');
236    }else{    }
237      else {
238      $checksum_key = variable_get('paygate_checksum_test_key', '');      $checksum_key = variable_get('paygate_checksum_test_key', '');
239    }    }
240    $s_front = url();    $s_front = url();
# Line 250  function uc_paygate_complete($cart_id = Line 250  function uc_paygate_complete($cart_id =
250    $CHECKSUM=$_POST['CHECKSUM'];    $CHECKSUM=$_POST['CHECKSUM'];
251    $RISK_INDICATOR=$_POST['RISK_INDICATOR'];    $RISK_INDICATOR=$_POST['RISK_INDICATOR'];
252    
253    $checksum_source = $PAYGATE_ID."|".$REFERENCE."|".$TRANSACTION_STATUS."|".$RESULT_CODE."|".$AUTH_CODE."|".$AMOUNT."|".$RESULT_DESC."|".$TRANSACTION_ID."|";    $checksum_source = $PAYGATE_ID ."|". $REFERENCE ."|". $TRANSACTION_STATUS ."|". $RESULT_CODE ."|". $AUTH_CODE ."|". $AMOUNT ."|". $RESULT_DESC ."|". $TRANSACTION_ID ."|";
254    if ($RISK_INDICATOR) $checksum_source .= $RISK_INDICATOR."|";    if ($RISK_INDICATOR) $checksum_source .= $RISK_INDICATOR ."|";
255    $checksum_source .= $checksum_key;    $checksum_source .= $checksum_key;
256    
257    $test_checksum = md5($checksum_source);    $test_checksum = md5($checksum_source);
258    
259    if ( $test_checksum != $CHECKSUM){    if ( $test_checksum != $CHECKSUM) {
260      watchdog('Paygate', t('Checksum failed for order !order_id.', array('!order_id' => check_plain($TRANSACTION_ID))));      watchdog('Paygate', t('Checksum failed for order !order_id.', array('!order_id' => check_plain($TRANSACTION_ID))));
261      drupal_set_message('Checksum error! Contact Site Owner.', 'error');      drupal_set_message('Checksum error! Contact Site Owner.', 'error');
262    }    }
# Line 268  function uc_paygate_complete($cart_id = Line 268  function uc_paygate_complete($cart_id =
268    
269    switch ($TRANSACTION_STATUS) {    switch ($TRANSACTION_STATUS) {
270       case '0':       case '0':
271         drupal_set_message(t('Transaction can not be completed due to an unexpected error: <br> Order no.: !reference <br>Returned result: <strong> !result_desc. </strong><br /> Please try again or contact the site owner at !site_mail.', array('!result_desc' => check_plain($RESULT_DESC), '!reference' => check_plain($REFERENCE), '!site_mail' => variable_get('site_mail',''))), 'error');         drupal_set_message(t('Transaction can not be completed due to an unexpected error: <br> Order no.: !reference <br>Returned result: <strong> !result_desc. </strong><br /> Please try again or contact the site owner at !site_mail.', array('!result_desc' => check_plain($RESULT_DESC), '!reference' => check_plain($REFERENCE), '!site_mail' => variable_get('site_mail', ''))), 'error');
272    
273         watchdog('Paygate', t('Transaction could not be completed.<br> Transaction ID: !order_id <br> Order no:: !reference <br>Returned result: !result_desc.', array('!order_id' => check_plain($TRANSACTION_ID), '!result_desc' => check_plain($RESULT_DESC), '!reference' => check_plain($REFERENCE))),'WATCHDOG_WARNING');         watchdog('Paygate', t('Transaction could not be completed.<br> Transaction ID: !order_id <br> Order no.: !reference <br>Returned result: !result_desc.'), array('!order_id' => check_plain($TRANSACTION_ID), '!result_desc' => check_plain($RESULT_DESC), '!reference' => check_plain($REFERENCE)), 'WATCHDOG_WARNING');
274    
275         $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>';
276         break;         break;
277    
278       case '1':       case '1':
# Line 285  function uc_paygate_complete($cart_id = Line 285  function uc_paygate_complete($cart_id =
285         break;         break;
286    
287       case '2':       case '2':
288         drupal_set_message(t('Transaction was not authorised:  <br> Order no.: !reference <br>Returned result: <strong> !result_desc. </strong><br /> Please contact your banking institution for further details.',array('!result_desc' => check_plain($RESULT_DESC), '!reference' => check_plain($REFERENCE), '!site_mail' => variable_get('site_mail',''))), 'error');         drupal_set_message(t('Transaction was not authorised:  <br> Order no.: !reference <br>Returned result: <strong> !result_desc. </strong><br /> Please contact your banking institution for further details.'), array('!result_desc' => check_plain($RESULT_DESC), '!reference' => check_plain($REFERENCE), '!site_mail' => variable_get('site_mail', '')), 'error');
289    
290         watchdog('Paygate', t('Transaction was not authorised.<br> Transaction ID: !order_id <br> Order no.: !reference <br> Returned result: !result_desc. <br>', array('!order_id' => check_plain($TRANSACTION_ID), '!result_desc' => check_plain($RESULT_DESC), '!reference' => check_plain($REFERENCE), '!site_mail' => variable_get('site_mail',''))),'WATCHDOG_WARNING');         watchdog('Paygate', t('Transaction was not authorised.<br> Transaction ID: !order_id <br> Order no.: !reference <br> Returned result: !result_desc. <br>'), array('!order_id' => check_plain($TRANSACTION_ID), '!result_desc' => check_plain($RESULT_DESC), '!reference' => check_plain($REFERENCE), '!site_mail' => variable_get('site_mail', '')), 'WATCHDOG_WARNING');
291    
292         $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>';
293         break;         break;
294    
295       default:       default:

Legend:
Removed from v.1.2.2.1  
changed lines
  Added in v.1.2.2.2

  ViewVC Help
Powered by ViewVC 1.1.2