Jump to content

Upgrading from 1.4 to 1.5 , how to get my code to work?


Recommended Posts

Hi,

 

I've got a module which seems to have a portion of code for prestashop 1.4 (if I ain't wrong)

 

Does anybody know how to "translate" this part so that it could work in version 1.5 please?

 

                   
                    $id_cart=$CMCIC_bruteVars['reference'];
                            
                    $cart = new Cart($id_cart);
                    if ($cart->id_customer == 0 OR $cart->id_address_delivery == 0 OR $cart->id_address_invoice == 0 OR !$abcd_cmcic30->active)
                            Tools::redirectLink(__PS_BASE_URI__.'order.php?step=1');
                 
                    $total = floatval($cart->getOrderTotal(true, 3));
                    $id_currency = intval($cart->id_currency);
                  

                    $shop_name = htmlentities(Configuration::get('PS_SHOP_NAME'), NULL, 'utf-8');

                    $customer = new Customer(intval($cart->id_customer));
   

                    // $abcd_cmcic30->validateOrder((int)$cart->id, _PS_OS_PAYMENT_, $total, 'CB (CIC)', 'N° autorisation : '.$CMCIC_bruteVars['numauto'].' N° Panier : '.$CMCIC_bruteVars['reference'], NULL, $id_currency, false, $cart->secure_key);
                    
                    
                    $abcd_cmcic30->validateOrder((int)$cart->id, Configuration::get('PS_OS_PAYMENT'), $total, 'CB (CIC)', 'N° autorisation : '.$CMCIC_bruteVars['numauto'].' N° Panier : '.$CMCIC_bruteVars['reference'], array(), $id_currency, false, $customer->secure_key);
                  
                    $order = new Order($abcd_cmcic30->currentOrder);

 

I would be very grateful for any information you could offer me ! :)

Thanks.

Link to comment
Share on other sites

In fact, this page is supposed to send back a response to the bank I'm working with, in order to validate a payment. If I put this part of the code in comment, everything works fine (I mean the bank tells me it receives a validate answer) but with this code it seems like it gets stuck. However it doesn't look like that there's an error on this page, so that's why I was wondering if this code wasn't suppose to work with version 1.4 and maybe not 1.5.

 

Thanks for you help!

Link to comment
Share on other sites

Well, it's not that easy to explain! (especially when you know I'm french :))

 

I'm gonna try to be more explicit :

 

when the payment is done, the bank gives back an answer to my file "validate.php".

In this file, depending on the answer, 2 cases are possible.

First, the payment could not be done : the file "validate.php" prepares a receipt for my bank and sends it back. Nothing is done concerning the shop, commands, carts, etc., which is logical.

 

If the payment is ok, then my file prepares a receipt for the bank as well, sending it back to confirm the transaction. In this case some operations are done to manage the shop, which is the portion of code I wrote in my first entry.

 

What I don't understrand is that when the payment is refused the bank says it did receive the receipt, so everything works fine.

In case of an accepted payment (so when the script goes through the code I wrote earlier) my bank says it doesn't receive the receipt. If I do put in comment this part of code, then it says it received the receipt... So my conclusion was to say that this part was the problem. (yes, you can consider me a genius..... lol)

 

Therefore, my first question was : is it a problem concerning the writing itself as I am under prestashop 1.5 and it seems to be written for 1.4?

If no, would you have any idea what the deal could be?

 

Thanks again.

Kim

Link to comment
Share on other sites

what i would do is surround your entire coding within a try/catch block, and see if you are encountering any exceptions.

try 
{

//your code goes here...

} catch (Exception $e)
{
   echo $e->getMessage();
}

then from a browser window, execute the php file pretending you are the remote payment gateway and see what gets output to the browser window.

Link to comment
Share on other sites

Hi!

Well I tried what you told me and there are no error message shown..

What I tried as well is to comment each part of my code separately and I discovered that when I comment this one, everything works fine :

 

  $abcd_cmcic30->validateOrder((int)$cart->id, Configuration::get('PS_OS_PAYMENT'), $total, 'CB (CIC)', 'N° autorisation : '.$CMCIC_bruteVars['numauto'].' N° Panier : '.$CMCIC_bruteVars['reference'], array(), $id_currency, false, $customer->secure_key);

 

Is "validateOrder" called the right way for version 1.5? Are the arguments retrieved correctly before?

 

Kim

Link to comment
Share on other sites

are you getting a blank white screen when you try this?  if so, edit the "config/defines.inc.php" and change dev mode to true, then try it again.

define('_PS_MODE_DEV_', true);

The format of the validateOrder call looks correct, but you have not documented the values of the following fields, so it is hard to say what the problem is

$total

$CMCIC_bruteVars['numauto']

$CMCIC_bruteVars['reference']

$id_currency

$cart->id

$customer->secure_key

 

I would also add some echo statements so you ensure the values you are expecting to receive are being received properly.

Link to comment
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
×
×
  • Create New...