natalie123123 Posted May 9, 2012 Share Posted May 9, 2012 (edited) Hi, I'm trying to integreate Securepay Directone (http://www.securepay...rts/prestashop/) as a credit/debit card payment gateway into my prestashop website. As far as I can tell, I have everything set up correctly. I have installed the Securepay Directone module, downloaded from the securepay website here: https://vault.secure...rs/end-to-end/. It is apparently compatible with version 1.4.7.0, which is the version I am running. The problem is, users can make payments ok on the Directone hosted payment page, but once they are redirected back to the Prestashop website they are returned a blank page (blank as in the theme is there, but no content in the center, no 'thanks for your order' etc). And the items purchased are still in the shopping cart - it's as if no order was made according to Prestashop (even though payment is taken successfully by Directone. The orders also aren't appearing in the BO. I don't know where to go from here, as Securepay are refusing to support this module. An example of the link to 'return to the website' once the payment is made on the Directone hosted payment page is this: http://www.mydomainn...onse_amount=001 It seems it's not working. Here's the php from validation.php from the Directone module: <?php include(dirname(__FILE__).'/../../config/config.inc.php'); include(dirname(__FILE__).'/directone.php'); $errors = ''; $result = false; $sp_h = new DirectOne(); $comments = ''; $orderData = array(); $get = ''.trim($_GET['id']).' '.trim($_GET['response_amount']); preg_match('/(?<invoice>[0-9]+) (?<total>[0-9]+)/', $get, $orderData); $invoice = intval($orderData['invoice']); $amount = ($orderData['total']/100); if($invoice && $amount) { $ip = $_SERVER['REMOTE_ADDR']; $host = gethostbyaddr($ip); $comments = 'DirectOne callback received from '.$ip.' ['.$host.'], who reports that $'.$amount.' was paid.'; $cart = new Cart(intval($invoice)); if (!$cart->id) { $errors = $sp_h->getL('cart').'<br />'; } elseif (Order::getOrderByCartId($invoice)) { $errors = $sp_h->getL('order').'<br />'; } else { $state = _PS_OS_PAYMENT_; $sp_h->setStatus($invoice,$state); $sp_h->validateOrder($invoice, $state, floatval($amount), 'Credit Card', $comments); } } if (!empty($errors) AND $invoice) { $sp_h->validateOrder(intval($invoice), _PS_OS_ERROR_, 0, 'Credit Card', $errors.'<br />'); } ?> And here's the php from Directone's confirm.php: <?php /* SSL Management */ $useSSL = true; include(dirname(__FILE__).'/../../config/config.inc.php'); include(dirname(__FILE__).'/../../header.php'); include(dirname(__FILE__).'/directone.php'); if (!$cookie->isLogged()) { Tools::redirect('authentication.php?back=order.php'); } $directone = new DirectOne(); echo $directone->Confirm($cart); include_once(dirname(__FILE__).'/../../footer.php'); ?> Please let me know if you can assist, I can provide more information if it will help. Thanks in advance. Edited May 9, 2012 by natalie123123 (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted May 9, 2012 Share Posted May 9, 2012 generally that blank page means you are receiving an error, but by default displaying errors is turned off. change your config\config.inc.php file so display_errors in 'on' and try again to see if an error will display now. @ini_set('display_errors', 'on'); Link to comment Share on other sites More sharing options...
natalie123123 Posted May 9, 2012 Author Share Posted May 9, 2012 (edited) Here's the error I'm receiving: Warning: preg_match(): Compilation failed: unrecognized character after (?< at offset 3 in /var/www/vhosts/thepoolroomgiftware.com.au/httpdocs/modules/directone/directone.php on line 263 Line 263 of directone.php reads: preg_match('/(?<invoice>[0-9]+) (?<total>[0-9]+)/', $get, $orderData); Edited May 9, 2012 by natalie123123 (see edit history) Link to comment Share on other sites More sharing options...
natalie123123 Posted May 9, 2012 Author Share Posted May 9, 2012 Here's the contents of directone.php: <?php class DirectOne extends PaymentModule { const INSTALL_SQL_FILE = 'install.sql'; private $_html = ''; private $_postErrors = array(); public function __construct() { $this->name = 'directone'; $this->tab = 'Payment'; $this->version = '1.0'; $this->currencies = true; $this->currencies_mode = 'radio'; parent::__construct(); $this->page = basename(__FILE__, '.php'); $this->displayName = $this->l('DirectOne (AU)'); $this->description = $this->l('Provides support for hosted credit-card payments via the DirectOne gateway'); $this->confirmUninstall = $this->l('Are you sure you want to delete your details ?'); } public function getUrl() { $test = Configuration::get($this->name.'_test'); return 'https://vault.safepay.com.au/cgi-bin/'.($test?'test':'make').'_payment.pl'; } public function install() { if (!file_exists(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE)) { die('Error: Missing SQL file'); } elseif (!$sql = file_get_contents(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE)) { die('Error: Empty/corrupt SQL install file'); } print "Here\n"; $sql = str_replace('PREFIX_', _DB_PREFIX_, $sql); $sql = preg_split("/;\s*[\r\n]+/", $sql); foreach ($sql as $query) { if ($query AND sizeof($query) AND !Db::getInstance()->Execute(trim($query))) { return false; } } if (!parent::install() OR !Configuration::updateValue($this->name.'_vendor', '') OR !Configuration::updateValue($this->name.'_test', 1) OR !$this->registerHook('payment') OR !$this->registerHook('paymentReturn')) { return false; } return true; } public function uninstall() { if (!Configuration::deleteByName($this->name.'_vendor') OR !Configuration::deleteByName($this->name.'_test') OR !parent::uninstall()) { return false; } return true; } public function getContent() { $this->_html = '<h2>DirectOne (AU)</h2>'; if (isset($_POST['submitDirectone'])) { if (empty($_POST['vendor'])) { $this->_postErrors[] = $this->l('Your DirectOne vendor name is required.'); } if (!isset($_POST['test'])) { $_POST['test'] = 1; } if (!sizeof($this->_postErrors)) { Configuration::updateValue($this->name.'_vendor', strval($_POST['vendor'])); Configuration::updateValue($this->name.'_test', intval($_POST['test'])); $this->displayConf(); } else { $this->displayErrors(); } } $this->displayFormSettings(); return $this->_html; } public function displayConf() { $this->_html .= ' <div class="conf confirm"> <img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" /> '.$this->l('Settings updated').' </div>'; } public function displayErrors() { $nbErrors = sizeof($this->_postErrors); $this->_html .= ' <div class="alert error"> <h3>'.($nbErrors > 1 ? $this->l('There are') : $this->l('There is')).' '.$nbErrors.' '.($nbErrors > 1 ? $this->l('errors') : $this->l('error')).'</h3> <ol>'; foreach ($this->_postErrors AS $error) { $this->_html .= '<li>'.$error.'</li>'; } $this->_html .= ' </ol> </div>'; } /** * Module admin settings */ public function displayFormSettings() { $conf = Configuration::getMultiple(array($this->name.'_vendor', $this->name.'_test')); $vendor = array_key_exists('vendor', $_POST) ? $_POST['vendor'] : (array_key_exists($this->name.'_vendor', $conf) ? $conf[$this->name.'_vendor'] : ''); $test = array_key_exists('test', $_POST) ? $_POST['test'] : (array_key_exists($this->name.'_test', $conf) ? $conf[$this->name.'_test'] : ''); $this->_html .= ' <form action="'.$_SERVER['REQUEST_URI'].'" method="post" style="clear: both;"> <fieldset> <legend><img src="../img/admin/contact.gif" />'.$this->l('Settings').'</legend> <label>'.$this->l('DirectOne Vendor Name').'</label> <div class="margin-form"><input type="text" size="33" name="vendor" value="'.htmlentities($vendor, ENT_COMPAT, 'UTF-8').'" /></div> <label>'.$this->l('Test mode').'</label> <div class="margin-form"> <input type="radio" name="test" value="1" '.($test ? 'checked="checked"' : '').' /> '.$this->l('Yes').' <input type="radio" name="test" value="0" '.(!$test ? 'checked="checked"' : '').' /> '.$this->l('No').' </div> <br /><br /><br /> <br /><center><input type="submit" name="submitDirectone" value="'.$this->l('Update settings').'" class="button" /></center> </fieldset> </form><br /><br /> <fieldset class="width3"> <legend><img src="../img/admin/warning.gif" />'.$this->l('Note').'</legend> '.$this->l('Always check the order messages to make sure that a DirectOne callback was received from directone.com.au before sending items.').'<br /> </fieldset>'; } /** * hookPayment * * Draws the DirectOne form on the payment selection page using the directone.tpl template. */ public function hookPayment($params) { if (!$this->active) { return; } global $smarty; $address = new Address(intval($params['cart']->id_address_invoice)); $customer = new Customer(intval($params['cart']->id_customer)); $vendor = Configuration::get($this->name.'_vendor'); $currency = $this->getCurrency(); $cart_id = intval($params['cart']->id); if (!Validate::isLoadedObject($address) OR !Validate::isLoadedObject($customer) OR !Validate::isLoadedObject($currency)) { return $this->l('DirectOne error: (invalid address or customer)'); } $products = $params['cart']->getProducts(); foreach ($products as $key => $product) { $products[$key]['name'] = str_replace('"', '\'', $product['name']); if (isset($product['attributes'])) { $products[$key]['attributes'] = str_replace('"', '\'', $product['attributes']); } $products[$key]['name'] = htmlentities(utf8_decode($product['name'])); $products[$key]['amount'] = number_format(Tools::convertPrice($product['price_wt'], $currency), 2, '.', ''); } $svar = array( 'address' => $address, 'country' => new Country(intval($address->id_country)), 'vendor' => $vendor, 'url' => $this->getUrl(), //shipping cost + wrapping 'shipping' => number_format(Tools::convertPrice(($params['cart']->getOrderShippingCost() + $params['cart']->getOrderTotal(true, 6)), $currency), 2, '.', ''), 'discounts' => $params['cart']->getDiscounts(), 'products' => $products, 'id_cart' => $cart_id, 'amount' => $params['cart']->getOrderTotal(true, 3), 'return' => 'http://'.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'modules/directone/confirm.php?id='.$cart_id.'&response_amount=', 'reply' => 'http://'.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'modules/directone/validation.php?id='.$cart_id.'&response_amount=', 'this_path' => $this->_path, ); $smarty->assign($svar); $this->setStatus($cart_id,0); return $this->display(__FILE__, 'directone.tpl'); } /** * It doesn't look like this is ever executed. */ public function hookPaymentReturn($params) { if (!$this->active) { return; } return $this->display(__FILE__, 'confirmation.tpl'); } /* Because it is not clear how to retrieve this information from the existing order. */ public function setStatus($id, $status) { $previous = $this->getStatus($id); if($previous == $status) return; if($previous != '') { return Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'directone_order` SET `status` = \''.pSQL($status).'\''); } else { return Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'directone_order` (`id`, `status`) VALUES('.intval($id).', \''.pSQL($status).'\')'); } } public function getStatus($id) { $result = Db::getInstance()->ExecuteS('SELECT `status` FROM `'._DB_PREFIX_.'directone_order` WHERE id = \''.intval($id).'\''); if(isset($result[0]) && !isset($result['status'])) { $result = $result[0]; } return $result['status']; } public function Confirm($params) { if (!$this->active) { return; } $get = ''.trim($_GET['id']).' '.trim($_GET['response_amount']); preg_match('/(?<invoice>[0-9]+) (?<total>[0-9]+)/', $get, $orderData); $invoice = $orderData['invoice']; $amount = ($orderData['total']/100); if($invoice && $amount) { global $smarty; $state = $this->getStatus($invoice); if($state == '0') { $comments = 'DirectOne payment was completed before callback. Confirm payment before processing.'; $state = _PS_OS_PREPARATION_; $this->validateOrder($invoice, $state, floatval($amount), 'Credit Card', $comments); $this->setStatus($invoice,$state); } if ($state == _PS_OS_PAYMENT_ OR $state == _PS_OS_OUTOFSTOCK_ OR $state == _PS_OS_PREPARATION) { $smarty->assign(array( 'status' => 'ok', 'id_order' => $invoice, )); } else { $smarty->assign('status', 'failed'); } //$params->delete(); return $this->display(__FILE__, 'confirmation.tpl'); } } public function getL($key) { $translations = array( 'payment' => $this->l('Payment: '), 'cart' => $this->l('Cart not found'), ); 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); } } Link to comment Share on other sites More sharing options...
natalie123123 Posted May 9, 2012 Author Share Posted May 9, 2012 (edited) I Googled the error, and I made the following change: Updated: preg_match('/(?<invoice>[0-9]+) (?<total>[0-9]+)/', $get, $orderData); To: preg_match('/(?P<invoice>[0-9]+) (?P<total>[0-9]+)/', $get, $orderData); (added the P's). I'm one step closer as now the confirm.php page now isn't blank and displays the 'Success Your order has been successfully completed.' message, but the order still isn't appearing in the BO, and the items remain in the cart. Another error also appears on the confirm page (below). I'm not sure if I need to do anything about this? Notice: Undefined index: status in /var/www/vhosts/thepoolroomgiftware.com.au/httpdocs/modules/directone/directone.php on line 252 Notice: Use of undefined constant _PS_OS_PREPARATION - assumed '_PS_OS_PREPARATION' in /var/www/vhosts/thepoolroomgiftware.com.au/httpdocs/modules/directone/directone.php on line 280 I appreciate all help received! Edited May 9, 2012 by natalie123123 (see edit history) Link to comment Share on other sites More sharing options...
natalie123123 Posted May 9, 2012 Author Share Posted May 9, 2012 (edited) Solved - I added the 'P's as above between all of the ?< in the Directone php files, and it's all working. Big smiles Edited May 9, 2012 by natalie123123 (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now