Jump to content

How to validate orders


aftermarket
 Share

Recommended Posts

I am trying to build a module to validate payments for a Canadian payment processor based on the paypal module for a school project. But I am unable to figure out how to validate orders without an IPN. The code that I use now, forces a validation of the order for all customers that go to the payment method page. But this creates problems if a customer goes back to the cart as his order is submitted. It also negates all other payment methods installed as the order has already been submitted, by the time they click another payment method. Any help would greatly be appreciated. Here is my code for the relevant section:

if($alertpay_ipn == '0')
       {
           $cartID = $params['cart']->id;
           $total = floatval(number_format($params['cart']->getOrderTotal(true, 3), 2, '.', ''));
           $this->validateOrder($cartID,_PS_OS_PAYPAL_ , $total, $this->displayName, NULL, $mailVars, $currency->id);
           $order = new Order($this->currentOrder);
           $GoBackURL = 'http://'.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'/modules/alertpay/validation1.php?key='.$customer->secure_key.'&id;_cart='.intval($params['cart']->id).'&id;_module='.intval($this->id);

       }
       else
       {
           $GoBackURL = 'http://'.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'order-confirmation.php?key='.$customer->secure_key.'&id;_cart='.intval($params['cart']->id).'&id;_module='.intval($this->id);    
       }
       $smarty->assign(array(
           'address' => $address,
           'country' => new Country(intval($address->id_country)),
           'customer' => $customer,
           'ap_merchant' => $ap_merchant,
           'purchase_type' => $purchase_type,
           'alertpay_order_detail' => $alertpay_order_detail,
           'prcount'        => $prcount,
           'header' => $header,
           'currency' => $currency,
           'alertpayUrl' => $this->getAlertPayUrl(),
           // products + discounts - shipping cost
           'amount' => number_format(Tools::convertPrice($params['cart']->getOrderTotal(true, 4), $currency), 2, '.', ''),
           // shipping cost + wrapping
           'shipping' =>  number_format(Tools::convertPrice(($params['cart']->getOrderShippingCost() + $params['cart']->getOrderTotal(true, 6)), $currency), 2, '.', ''),
           'discounts' => $params['cart']->getDiscounts(),
           'products' => $products,
           // products + discounts + shipping cost
           'total' => number_format(Tools::convertPrice($params['cart']->getOrderTotal(true, 3), $currency), 2, '.', ''),
           'id_cart' => intval($params['cart']->id),
           'goBackUrl' => $GoBackURL,
           'notify' => 'http://'.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'modules/alertpay/validation.php',
           'ap_cancelurl' => 'http://'.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'index.php',
           'this_path' => $this->_path
       ));

       return $this->display(__FILE__, 'alertpay.tpl');
   }

   public function hookPaymentReturn($params)
   {
       if (!$this->active)
           return ;

       return $this->display(__FILE__, 'confirmation.tpl');
   }

   public function getL($key)
   {
       $translations = array(
           'mc_gross' => $this->l('AlertPay key \'mc_gross\' not specified, can\'t control amount paid.'),
           'payment_status' => $this->l('Paypal key \'payment_status\' not specified, can\'t control payment validity'),
           'payment' => $this->l('Payment: '),
           'invoice' => $this->l('AlertPay key \'invoice\' not specified, can\'t rely to cart'),
           'txn_id' => $this->l('AlertPay key \'txn_id\' not specified, transaction unknown'),
           'mc_currency' => $this->l('Paypal key \'mc_currency\' not specified, currency unknown'),
           'cart' => $this->l('Cart not found'),
           'order' => $this->l('Order has already been placed'),
           'transaction' => $this->l('AlertPay Transaction ID: '),
           'verified' => $this->l('The AlertPay transaction could not be VERIFIED.'),
           'connect' => $this->l('Problem connecting to the AlertPay server.'),
           'nomethod' => $this->l('No communications transport available.'),
           'socketmethod' => $this->l('Verification failure (using fsockopen). Returned: '),
           'curlmethod' => $this->l('Verification failure (using cURL). Returned: '),
           'curlmethodfailed' => $this->l('Connection using cURL failed'),
       );
       return $translations[$key];
   }

   function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown', $message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false)
   {
       if (!$this->active)
           return ;

       $currency = $this->getCurrency();
       $cart = new Cart(intval($id_cart));
       $cart->id_currency = $currency->id;
       $cart->save();
       parent::validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod, $message, $extraVars, $currency_special, true);
   }
}

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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More