Jump to content
Latest News: (loading..)
Sign in to follow this  
milerwan

Fix duplicate order ATOS/SIPS RETOUR AUTO (ATOS 1.0)

Recommended Posts

Contributions concerned:
- Paiment ATOS/SIPS RETOUR AUTO : http://addons.oscommerce.com/info/8253
 
For users of the ATOS / SIPS RETURN AUTO contribution, which encounter a problem of duplicate order after payment, I propose a correction that definitively solves this bug.
 
Here are some important points about the changes to the atos.php file:
1. Changes to the calculation of the decimals of the amount cashed (original is an intermittent error of 1 cent against the shop in relation to the exact amount of the order, this corrects it)
2. Fix duplicate order
3. Change to IP v6 (otherwise error / failure when paying for IP v6 users)
 
In the atos.php file (includes/modules/payment/atos.php), modify/replace the makeRequest function from line 375 as follows:
    // ----------------------------------------------------------------
    // makeRequest()
    //
    // Make the request by executing the request external application
    function makeRequest($amount, $currency) {
      global $customer_id, $_SERVER, $language;

//      $amount = sprintf("%03d", $amount * $this->_getCurrencyUnit($currency));
      $amount = tep_round($amount,2) * $this->_getCurrencyUnit($currency);

      $pathfile = $this->_getPathFileName();

      $command  = MODULE_PAYMENT_ATOS_BIN_REQUEST;
      $command .= " " . $this->os_info['quote'] . "pathfile=" . $pathfile . $this->os_info['quote'];
      $command .= " merchant_id=" . MODULE_PAYMENT_ATOS_ID;
      $command .= " amount=" . $amount;
      $command .= " currency_code=" . $this->_getCurrencyCode(DEFAULT_CURRENCY);
      $command .= " language=" . $this->_getLanguageCode($language);

	//Retour automatique a la boutique apres paiement by brouillard s'embrouille
      $command .= " data=NO_RESPONSE_PAGE";
      $command .= " " . $this->os_info['quote'] . "normal_return_url=" . tep_href_link('atos_response.php', '', 'SSL', false) . $this->os_info['quote'];
      $command .= " " . $this->os_info['quote'] . "cancel_return_url=" . tep_href_link('atos_response.php', '', 'SSL', false) . $this->os_info['quote'];
	//Fin Retour automatique a la boutique apres paiement by brouillard s'embrouille

// BOF Fix doublon commande
//      $command .= " " . $this->os_info['quote'] . "automatic_response_url=" . tep_href_link(FILENAME_CHECKOUT_PROCESS, tep_session_name() . '=' . tep_session_id(), 'NONSSL', false) . $this->os_info['quote'];
      $command .= " " . $this->os_info['quote'] . "automatic_response_url=" . tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'NONSSL', false) . $this->os_info['quote'];
// EOF Fix doublon commande

      $command .= " customer_id=" . $customer_id;

	// IP V6 fix
//      $command .= " customer_ip_address=" . $_SERVER['REMOTE_ADDR'];
      $command .= " customer_ip_address=" . substr($_SERVER['REMOTE_ADDR'], 0, 19);

      if (!@ini_get("safe_mode"))
	  $command .= ' 2>&1';
      $sips_result = exec($command);

      $sips = array();
      $sips_values     = preg_split ("/!/", $sips_result);
      $sips['code']    = $sips_values[1];
      $sips['error']   = $sips_values[2];
      $sips['message'] = $sips_values[3];
      $sips['command'] = $command;
      $sips['output']  = $sips_result;
	
      if (!isset($sips['code'])) {
		$sips['code']   = -1;
		$sips['error']  = $sips_result;
      }
	
      if ($sips['code'] != 0) {
		$sips['amount'] = $amount;
		$sips['lang']   = $lang;
		$sips['id']     = tep_session_id();
      }
	
      return $sips;
    }

Obviously, this change preserves the automatic return to the shop.  :)

Edited by milerwan

Osc v2.3.4 BS "custom"

Share this post


Link to post
Share on other sites

Improvement code for the calculation of the rounding :

//      $amount = sprintf("%03d", $amount * $this->_getCurrencyUnit($currency));
      $amount = tep_round($amount,2) * $this->_getCurrencyUnit($currency);
      $amount = sprintf("%03d", tep_round($amount,2));

NB: In case of currencies rates with decimals.


Osc v2.3.4 BS "custom"

Share this post


Link to post
Share on other sites

Improvement code for the calculation of the rounding :

//      $amount = sprintf("%03d", $amount * $this->_getCurrencyUnit($currency));
      $amount = tep_round($amount,2) * $this->_getCurrencyUnit($currency);
      $amount = sprintf("%03d", tep_round($amount,2));
NB: In case of currencies rates with decimals.

 

 

Sorry use this code, because tep_round is not good for sprintf occurence and redo the calculating error :

//      $amount = sprintf("%03d", $amount * $this->_getCurrencyUnit($currency));
      $amount = tep_round($amount,2) * $this->_getCurrencyUnit($currency);
      $amount = sprintf("%03d", round($amount,2));
Edited by milerwan

Osc v2.3.4 BS "custom"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×