/** * load all enabled extensions. * If force parameter provided,load all installed (for admin) * * @param bool $force_enabled_off * @void */ public function loadEnabledExtensions($force_enabled_off = false) { /** * @var Registry */ $registry = Registry::getInstance(); $ext_controllers = $ext_models = $ext_languages = $ext_templates = array(); $enabled_extensions = $extensions = array(); foreach ($this->db_extensions as $ext) { //check if extension is enabled and not already in the picked list if (($force_enabled_off && has_value($registry->get('config')->get($ext . '_status')) || $registry->get('config')->get($ext . '_status')) && !in_array($ext, $enabled_extensions) && has_value($ext)) { $priority = (int) $registry->get('config')->get($ext . '_priority'); $enabled_extensions[$priority][] = $ext; $controllers = $languages = $models = $templates = array('storefront' => array(), 'admin' => array()); if (is_file(DIR_EXT . $ext . '/main.php')) { /** @noinspection PhpIncludeInspection */ include DIR_EXT . $ext . '/main.php'; } $ext_controllers[$ext] = $controllers; $ext_models[$ext] = $models; $ext_languages[$ext] = $languages; $ext_templates[$ext] = $templates; $class = 'Extension' . preg_replace('/[^a-zA-Z0-9]/', '', $ext); if (class_exists($class)) { $extensions[] = $class; } } } $this->setExtensionCollection(new ExtensionCollection($extensions)); $this->enabled_extensions = array(); ksort($enabled_extensions); foreach ($enabled_extensions as $exts) { $this->enabled_extensions = array_merge($this->enabled_extensions, $exts); } ADebug::variable('List of loaded extensions', $enabled_extensions); $this->setExtensionControllers($ext_controllers); ADebug::variable('List of controllers used by extensions', $ext_controllers); $this->setExtensionModels($ext_models); ADebug::variable('List of models used by extensions', $ext_models); $this->setExtensionLanguages($ext_languages); ADebug::variable('List of languages used by extensions', $ext_languages); $this->setExtensionTemplates($ext_templates); ADebug::variable('List of templates used by extensions', $ext_templates); }
public function callback() { if (has_value($this->request->get['token']) && has_value($this->request->get['PayerID'])) { $this->loadLanguage('default_pp_express/default_pp_express'); $this->session->data['pp_express_checkout']['token'] = $this->request->get['token']; $this->session->data['pp_express_checkout']['PayerID'] = $this->request->get['PayerID']; $this->session->data['pp_express_checkout']['currency'] = $this->currency->getCode(); $this->session->data['payment_method'] = array('id' => 'default_pp_express', 'title' => $this->language->get('text_title'), 'sort_order' => $this->config->get('default_pp_express_sort_order')); if (!$this->config->get('default_pp_express_test')) { $api_endpoint = 'https://api-3t.paypal.com/nvp'; } else { $api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp'; } $payment_data = array('METHOD' => 'GetExpressCheckoutDetails', 'VERSION' => '98.0', 'USER' => html_entity_decode($this->config->get('default_pp_express_username'), ENT_QUOTES, 'UTF-8'), 'PWD' => html_entity_decode($this->config->get('default_pp_express_password'), ENT_QUOTES, 'UTF-8'), 'SIGNATURE' => html_entity_decode($this->config->get('default_pp_express_signature'), ENT_QUOTES, 'UTF-8'), 'TOKEN' => $this->session->data['pp_express_checkout']['token']); ADebug::variable('Paypal Express Debug Log sent callback:', var_export($payment_data, true)); $curl = curl_init($api_endpoint); curl_setopt($curl, CURLOPT_PORT, 443); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($payment_data)); $response = curl_exec($curl); curl_close($curl); $ec_details = $this->_parse_http_query($response); ADebug::variable('Paypal Express Debug Log Received callback:', var_export($ec_details, true)); $this->loadModel('extension/default_pp_express'); if ($this->customer->isLogged()) { $country_id = $this->model_extension_default_pp_express->getCountryIdByCode2($ec_details['SHIPTOCOUNTRYCODE']); if (mb_strlen($ec_details['SHIPTOSTATE']) == 2) { $zone_id = $this->model_extension_default_pp_express->getZoneId($country_id, $ec_details['SHIPTOSTATE']); } else { $zone_id = $this->model_extension_default_pp_express->getZoneIdByName($country_id, $ec_details['SHIPTOSTATE']); } $this->tax->setZone($country_id, $zone_id); $pp_shipping_data = array('firstname' => $ec_details['FIRSTNAME'], 'lastname' => $ec_details['LASTNAME'], 'address_1' => $ec_details['SHIPTOSTREET'], 'address_2' => has_value($ec_details['SHIPTOSTREET2']) ? $ec_details['SHIPTOSTREET2'] : '', 'city' => $ec_details['SHIPTOCITY'], 'zone_code' => $ec_details['SHIPTOSTATE'], 'zone_id' => $zone_id, 'iso_code_2' => $ec_details['SHIPTOCOUNTRYCODE'], 'country' => $ec_details['SHIPTOCOUNTRYNAME'], 'country_id' => $country_id, 'postcode' => $ec_details['SHIPTOZIP']); $this->loadModel('account/address'); $addresses = $this->model_account_address->getAddresses(); if (has_value($addresses)) { $pp_str = strtolower(str_replace(' ', '', implode('', $pp_shipping_data))); foreach ($addresses as $addr) { $check_arr = array('firstname' => $addr['firstname'], 'lastname' => $addr['lastname'], 'address_1' => $addr['address_1'], 'address_2' => $addr['address_2'], 'city' => $addr['city'], 'zone_code' => $addr['zone_code'], 'iso_code_2' => $addr['iso_code_2'], 'country' => $addr['country'], 'postcode' => $addr['postcode']); $check_str = strtolower(str_replace(' ', '', implode('', $check_arr))); if ($pp_str == $check_str) { $this->session->data['shipping_address_id'] = $addr['address_id']; break; } } } if (!has_value($this->session->data['shipping_address_id'])) { $this->session->data['shipping_address_id'] = $this->model_extension_default_pp_express->addShippingAddress($pp_shipping_data); } $this->session->data['payment_address_id'] = $this->session->data['shipping_address_id']; $this->redirect($this->html->getSecureURL('checkout/confirm')); } else { $country_id = $this->model_extension_default_pp_express->getCountryIdByCode2($ec_details['SHIPTOCOUNTRYCODE']); $this->loadModel('localisation/country'); $country = $this->model_localisation_country->getCountry($country_id); $country = $country['name']; if (mb_strlen($ec_details['SHIPTOSTATE']) == 2) { $zone_id = $this->model_extension_default_pp_express->getZoneId($country_id, $ec_details['SHIPTOSTATE']); } else { $zone_id = $this->model_extension_default_pp_express->getZoneIdByName($country_id, $ec_details['SHIPTOSTATE']); } $this->session->data['guest']['firstname'] = $ec_details['FIRSTNAME']; $this->session->data['guest']['lastname'] = $ec_details['LASTNAME']; $this->session->data['guest']['email'] = $ec_details['EMAIL']; $this->session->data['guest']['address_1'] = $ec_details['SHIPTOSTREET']; $this->session->data['guest']['address_2'] = has_value($ec_details['SHIPTOSTREET2']) ? $ec_details['SHIPTOSTREET2'] : ''; $this->session->data['guest']['postcode'] = $ec_details['SHIPTOZIP']; $this->session->data['guest']['city'] = $ec_details['SHIPTOCITY']; $this->session->data['guest']['country'] = $country; $this->session->data['guest']['country_id'] = $country_id; $this->session->data['guest']['zone'] = $ec_details['SHIPTOSTATE']; $this->session->data['guest']['zone_id'] = $zone_id; $this->tax->setZone($country_id, $zone_id); if ($this->request->get['to_confirm'] == 1) { $this->redirect($this->html->getSecureURL('checkout/guest_step_3')); } else { $this->redirect($this->html->getSecureURL('checkout/guest_step_2')); } } } }
public function __construct($tmpl_id = '', $page_id = '', $layout_id = '') { if (!IS_ADMIN) { // forbid for non admin calls throw new AException(AC_ERR_LOAD, 'Error: permission denied to change page layout'); } $this->registry = Registry::getInstance(); $this->tmpl_id = !empty($tmpl_id) ? $tmpl_id : $this->config->get('config_storefront_template'); //load all pages specific to set template. No cross template page/layouts $this->pages = $this->getPages(); //set current page for this object instance $this->_set_current_page($page_id, $layout_id); $this->page_id = $this->page['page_id']; //preload all layouts for this page and template //NOTE: layout_type: 0 Default, 1 Active layout, 2 draft layout, 3 template layout $this->layouts = $this->getLayouts(); //locate layout for the page instance. If not specified for this instance fist active layout is used foreach ($this->layouts as $layout) { if (!empty($layout_id)) { if ($layout['layout_id'] == $layout_id) { $this->active_layout = $layout; break; } } else { if ($layout['layout_type'] == 1) { $this->active_layout = $layout; break; } } } //if not layout set, use default (layout_type=0) layout if (count($this->active_layout) == 0) { $this->active_layout = $this->getLayouts(0); if (count($this->active_layout) == 0) { $message_text = 'No layout found for page_id/controller ' . $this->page_id . '::' . $this->page['controller'] . '!'; $message_text .= ' Requested data: template: ' . $tmpl_id . ', page_id: ' . $page_id . ', layout_id: ' . $layout_id; throw new AException(AC_ERR_LOAD_LAYOUT, $message_text); } } $this->layout_id = $this->active_layout['layout_id']; ADebug::variable('Template id', $this->tmpl_id); ADebug::variable('Page id', $this->page_id); ADebug::variable('Layout id', $this->layout_id); // Get blocks $this->all_blocks = $this->getAllBlocks(); $this->blocks = $this->_getLayoutBlocks(); }
/** * PR: Duplicate row from default language to new and translate if needed * @param string $table * @param $pkeys * @param int $new_language * @param int $from_language * @param string $specific_sql * @param string $translate_method * @return null|string */ private function _clone_language_rows($table, $pkeys, $new_language, $from_language = 1, $specific_sql = '', $translate_method = '') { if (empty($table) || empty($pkeys) || empty($new_language)) { return null; } // Locate autoincrement column $autoincrenent_sql = "SHOW COLUMNS FROM " . $table . " where Extra = 'auto_increment'"; $autoincrement = $this->db->query($autoincrenent_sql); $auto_column = $autoincrement->row['Field']; //get all fields that are translatable $translatable_fields = $this->_get_translatable_fields($table); //Build a keys string for select $keys_str = ''; $tcount = 0; foreach ($pkeys as $key) { if (!empty($keys_str)) { $keys_str .= ","; } $keys_str .= "{$key} "; } $sql = "SELECT " . $keys_str . " FROM " . $table . " WHERE language_id = " . $from_language . $specific_sql; $tables_query = $this->db->query($sql); if ($tables_query->num_rows) { $langs = array(); foreach ($this->available_languages as $lang) { $langs[$lang['language_id']] = $lang['filename']; } foreach ($tables_query->rows as $row) { #Check if to be saved data exists for new language $sql1 = "SELECT * FROM " . $table . " WHERE language_id = " . $new_language; $sql2 = "SELECT * FROM " . $table . " WHERE language_id = " . $from_language; $where_sql_1 = $where_sql_2 = ''; foreach ($pkeys as $key) { //Skip language_id and autoincrement from the key. autoincrement is unique by itself. if ($key != 'language_id' && $key != $auto_column) { if (in_array($row[$key], $langs)) { $where_sql_1 .= " AND {$key} = '" . $langs[$new_language] . "'"; $where_sql_2 .= " AND {$key} = '" . $langs[$from_language] . "'"; } else { $where_sql_1 .= " AND {$key} = '" . $row[$key] . "'"; $where_sql_2 .= " AND {$key} = '" . $row[$key] . "'"; } } } $sql1 .= $where_sql_1; $sql2 .= $where_sql_2; $check_query = $this->db->query($sql1); if ($check_query->num_rows <= 0) { ADebug::variable('class ALanguage missing language data: ', $sql1); //we have no data, clone it $insert_data = array(); $origin_query = $this->db->query($sql2); foreach ($origin_query->rows as $drow) { foreach ($drow as $fld_name => $value) { if ($fld_name == 'language_id') { $value = $new_language; } else { if ($fld_name == $auto_column) { $value = ''; } else { if ($fld_name == 'block' && $value == $langs[$from_language]) { //language specific field for main language block. use destination language $value = $langs[$new_language]; } else { if (count($translatable_fields) && in_array($fld_name, $translatable_fields)) { //we need to translate $value = $this->translate($this->_get_language_code($from_language), $value, $this->_get_language_code($new_language), $translate_method); } } } } $insert_data[$fld_name] = $this->db->escape($value); } } if (!empty($insert_data)) { $insrt_sql = "INSERT INTO " . $table . "(" . implode(',', array_keys($insert_data)) . ") VALUES ('" . implode("','", $insert_data) . "')"; ADebug::variable('class ALanguage cloning data: ', $insrt_sql); if ($table == DB_PREFIX . 'language_definitions') { //#PR There are some key condition in definitions that can be duplicate (CASE: block = 'english' main language ) skip //We assume that main language XML need to be present //TODO rename main language file to common.xml if (!$this->_is_definition_in_db($insert_data)) { $this->db->query($insrt_sql); } else { continue; } } else { if ($table == DB_PREFIX . 'product_tags') { // TODO. ac_product_tags still an issue. Will be clonned as duplication on each translation. // Issue. Can not check if translation is present because of no IDs present in ac_product_tags // Offset duplicate error for now. if (!$this->db->query($insrt_sql, true)) { //skip count on error continue; } } else { $this->db->query($insrt_sql); } } $tcount++; } } } if ($tcount > 0) { $this->cache->delete('lan.*'); } } return "Total: " . $tcount . " language entries cloned for table " . $table . "<br>"; }
public function verify3DSignature($data, $pares) { $this->load->model('checkout/order'); $timestamp = strftime("%Y%m%d%H%M%S"); $merchant_id = $this->config->get('default_realex_merchant_id'); $secret = $this->config->get('default_realex_secret'); $tmp = $timestamp . '.' . $merchant_id . '.' . $data['order_ref'] . '.' . $data['amount'] . '.' . $data['currency'] . '.' . $data['cc_number']; $hash = sha1($tmp); $tmp = $hash . '.' . $secret; $hash = sha1($tmp); $xml = ''; $xml .= '<request type="3ds-verifysig" timestamp="' . $timestamp . '">' . "\n"; $xml .= '<merchantid>' . $merchant_id . '</merchantid>' . "\n"; $xml .= '<account>' . $data['account'] . '</account>' . "\n"; $xml .= '<orderid>' . $data['order_ref'] . '</orderid>' . "\n"; $xml .= '<amount currency="' . $data['currency'] . '">' . (int) $data['amount'] . '</amount>' . "\n"; $xml .= '<card>' . "\n"; $xml .= '<number>' . $data['cc_number'] . '</number>' . "\n"; $xml .= '<expdate>' . $data['cc_expire'] . '</expdate>' . "\n"; $xml .= '<type>' . $data['cc_type'] . '</type>' . "\n"; $xml .= '<chname>' . $data['cc_owner'] . '</chname>' . "\n"; $xml .= '</card>' . "\n"; $xml .= '<pares>' . $pares . '</pares>' . "\n"; $xml .= '<sha1hash>' . $hash . '</sha1hash>' . "\n"; $xml .= '</request>' . "\n"; ADebug::variable('Running verify3DSignature: ', $xml); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://epage.payandshop.com/epage-3dsecure.cgi"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_USERAGENT, "AbanteCart " . VERSION); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); curl_close($ch); ADebug::variable('Response from verify3DSignature: ', $response); return simplexml_load_string($response); }
public function callback() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $order_id = $this->session->data['order_id']; $post = $this->request->post; if ($order_id) { $this->loadModel('checkout/order'); $this->loadModel('extension/default_realex'); $this->loadLanguage('default_realex/default_realex'); $pd = unserialize($this->encryption->decrypt($post['MD'])); $signature_result = $this->model_extension_default_realex->verify3DSignature($pd, $post['PaRes']); ADebug::checkpoint('Realex 3D processing'); ADebug::variable('Signature result:' . $signature_result); $v3d = array(); if ($signature_result->result == '00' && (strtoupper($signature_result->threedsecure->status) == 'Y' || strtoupper($signature_result->threedsecure->status) == 'A')) { if (strtoupper($signature_result->threedsecure->status) == 'Y') { $v3d['eci_ref'] = 5; } else { $v3d['eci_ref'] = 6; } $v3d['eci'] = (string) $signature_result->threedsecure->eci; $v3d['cavv'] = (string) $signature_result->threedsecure->cavv; $v3d['xid'] = (string) $signature_result->threedsecure->xid; } else { if ($pd['cc_type'] == 'mc') { $v3d['eci'] = 0; } else { $v3d['eci'] = 7; } // Enrolled but invalid response from ACS. No shift in liability. ECI = 7 if ($signature_result->result == '110' && strtoupper($signature_result->threedsecure->status) == 'Y') { $v3d['eci_ref'] = 4; $v3d['cavv'] = (string) $signature_result->threedsecure->cavv; $v3d['xid'] = (string) $signature_result->threedsecure->xid; } // Incorrect password entered. No shift in liability. ECI = 7 if ($signature_result->result == '00' && strtoupper($signature_result->threedsecure->status) == 'N') { $v3d['eci_ref'] = 7; $v3d['xid'] = (string) $signature_result->threedsecure->xid; } // Authentication Unavailable. No shift in liability. ECI = 7 if ($signature_result->result == '00' && strtoupper($signature_result->threedsecure->status) == 'U') { $v3d['eci_ref'] = 8; $v3d['xid'] = (string) $signature_result->threedsecure->xid; } // Invalid response from ACS. No shift in liability. ECI = 7 if (isset($signature_result->result) && $signature_result->result >= 500 && $signature_result->result < 600) { $v3d['eci_ref'] = 9; } if (!$this->config->get('default_realex_liability_shift')) { // this is the check for liability shift // Merchant does not want to accept, redirect to checkout with message $error = '3D secure authorization failed'; $message = $error; $message .= 'ECI (3D secure) result: (' . $v3d['eci'] . ')'; $message .= 'Timestamp: ' . (string) strftime("%Y%m%d%H%M%S"); $message .= 'Order Reference: ' . (string) $pd['order_ref']; $this->model_checkout_order->update($order_id, $this->config->get('default_realex_status_decline'), $message, FALSE); $this->session->data['error'] = $error; $this->redirect($this->html->getSecureURL('checkout/checkout')); } } $capture_result = $this->model_extension_default_realex->processPayment($pd, $v3d); ADebug::variable('Capture result:' . $capture_result); if ($capture_result->result != '00') { $this->session->data['error'] = (string) $capture_result->message . ' (' . (int) $capture_result->result . ')'; $this->redirect($this->html->getSecureURL('checkout/checkout')); } else { $this->redirect($this->html->getSecureURL('checkout/success')); } } else { $this->redirect($this->html->getSecureURL('account/login')); } }
/** * @param string $parent_controller * @return null|string */ public function dispatch($parent_controller = '') { ADebug::checkpoint('' . $this->class . '/' . $this->method . ' dispatch START'); //Process the controller, layout and children //check if we have missing class or everithing if (empty($this->class) && has_value($this->file)) { #Build back trace of calling functions to provide more details $backtrace = debug_backtrace(); $function_stack = ''; if (is_object($parent_controller) && strlen($parent_controller->rt()) > 1) { $function_stack = 'Parent Controller: ' . $parent_controller->rt() . ' | '; } for ($i = 1; $i < count($backtrace); $i++) { $function_stack .= ' < ' . $backtrace[$i]['function']; } $url = $this->request->server['REQUEST_URI']; $error = new AError('Error: URL: ' . $url . ' Could not load controller ' . $this->controller . '! Call stack: ' . $function_stack . '', AC_ERR_CLASS_CLASS_NOT_EXIST); $error->toLog()->toDebug(); $error->toMessages(); return null; } else { if (empty($this->file) && empty($this->class) || empty($this->method)) { $warning_txt = 'ADispatch: skipping unavailable controller …'; $warning = new AWarning($warning_txt); $warning->toDebug(); return null; } } //check for controller.pre $output_pre = $this->dispatchPrePost($this->controller . POSTFIX_PRE); /** @noinspection PhpIncludeInspection */ require_once $this->file; /** * @var $controller AController */ $controller = null; if (class_exists($this->class)) { $controller = new $this->class($this->registry, $this->args["instance_id"], $this->controller, $parent_controller); $controller->dispatcher = $this; } else { $error = new AError('Error: controller class not exist ' . $this->class . '!', AC_ERR_CLASS_CLASS_NOT_EXIST); $error->toLog()->toDebug(); } if (is_callable(array($controller, $this->method))) { /** * @var $dispatch ADispatcher */ $dispatch = call_user_func_array(array($controller, $this->method), $this->args); //Check if return is a dispatch and need to call new page if ($dispatch && is_object($dispatch)) { if ($this->args["instance_id"] == 0) { //If main controller come back for new dispatch return $dispatch->getController() . '/' . $dispatch->getMethod(); } else { // Call new dispatch for new controller and exit //???? need to put limit for recursion to prevent overflow $dispatch->dispatch(); return null; } } /** * Load layout and process children controllers * @method AController getChildren() */ $children = $controller->getChildren(); ADebug::variable('Processing children of ' . $this->controller, $children); $block_uids = array(); //Process each child controller foreach ($children as $child) { //???? Add highest Debug level here with backtrace to review this ADebug::checkpoint($child['controller'] . ' ( child of ' . $this->controller . ', instance_id: ' . $child['instance_id'] . ' ) dispatch START'); //Process each child and create dispatch to call recurcive $dispatch = new ADispatcher($child['controller'], array("instance_id" => $child['instance_id'])); $dispatch->dispatch($controller); // Append output of child controller to current controller if ($child['position']) { // maden for recognizing few custom_blocks in the same placeholder $controller->view->assign($child['block_txt_id'] . '_' . $child['instance_id'], $this->response->getOutput()); } else { $controller->view->assign($child['block_txt_id'], $this->response->getOutput()); } //clean up and remove output $this->response->setOutput(''); ADebug::checkpoint($child['controller'] . ' ( child of ' . $this->controller . ' ) dispatch END'); } //Request controller to generate output $controller->finalize(); //check for controller.pre $output_post = $this->dispatchPrePost($this->controller . POSTFIX_POST); //add pre and post controllers output $this->response->setOutput($output_pre . $this->response->getOutput() . $output_post); //clean up and destroy the object unset($controller); unset($dispatch); } else { $err = new AError('Error: controller method not exist ' . $this->class . '::' . $this->method . '!', AC_ERR_CLASS_METHOD_NOT_EXIST); $err->toLog()->toDebug(); } ADebug::checkpoint('' . $this->class . '/' . $this->method . ' dispatch END'); return null; }
/** * Layout Manager Class to handle layout in the admin * NOTES: Object can be constructed with specific template, page or layout id provided * Possible to create an object with no specifics to access layout methods. * @param string $tmpl_id * @param string $page_id * @param string $layout_id * @throws AException */ public function __construct($tmpl_id = '', $page_id = '', $layout_id = '') { if (!IS_ADMIN) { // forbid for non admin calls throw new AException(AC_ERR_LOAD, 'Error: permission denied to change page layout'); } $this->registry = Registry::getInstance(); $this->tmpl_id = !empty($tmpl_id) ? $tmpl_id : $this->config->get('config_storefront_template'); //do check for existance of storefront template in case when $tmpl_id not set if (empty($tmpl_id)) { //check is template an extension $template = $this->config->get('config_storefront_template'); $dir = $template . DIR_EXT_STORE . DIR_EXT_TEMPLATE . $template; $enabled_extensions = $this->extensions->getEnabledExtensions(); if (in_array($template, $enabled_extensions) && is_dir(DIR_EXT . $dir)) { $is_valid = true; } else { $is_valid = false; } //check if this is template from core if (!$is_valid && is_dir(DIR_ROOT . '/storefront/view/' . $template)) { $is_valid = true; } if (!$is_valid) { $this->tmpl_id = 'default'; } else { $this->tmpl_id = $template; } } else { $this->tmpl_id = $tmpl_id; } //load all pages specific to set template. No cross template page/layouts $this->pages = $this->getPages(); //set current page for this object instance $this->_set_current_page($page_id, $layout_id); $this->page_id = $this->page['page_id']; //preload all layouts for this page and template //NOTE: layout_type: 0 Default, 1 Active layout, 2 draft layout, 3 template layout $this->layouts = $this->getLayouts(); //locate layout for the page instance. If not specified for this instance fist active layout is used foreach ($this->layouts as $layout) { if (!empty($layout_id)) { if ($layout['layout_id'] == $layout_id) { $this->active_layout = $layout; break; } } else { if ($layout['layout_type'] == 1) { $this->active_layout = $layout; break; } } } //if not layout set, use default (layout_type=0) layout if (count($this->active_layout) == 0) { $this->active_layout = $this->getLayouts(0); if (count($this->active_layout) == 0) { $message_text = 'No template layout found for page_id/controller ' . $this->page_id . '::' . $this->page['controller'] . '!'; $message_text .= ' Requested data: template: ' . $tmpl_id . ', page_id: ' . $page_id . ', layout_id: ' . $layout_id; $message_text .= ' ' . genExecTrace('full'); throw new AException(AC_ERR_LOAD_LAYOUT, $message_text); } } $this->layout_id = $this->active_layout['layout_id']; ADebug::variable('Template id', $this->tmpl_id); ADebug::variable('Page id', $this->page_id); ADebug::variable('Layout id', $this->layout_id); // Get blocks $this->all_blocks = $this->getAllBlocks(); $this->blocks = $this->_getLayoutBlocks(); }
// Weight $registry->set('weight', new AWeight($registry)); // Length $registry->set('length', new ALength($registry)); // Cart $registry->set('cart', new ACart($registry)); } else { // Admin template load // Relative paths and directories define('RDIR_TEMPLATE', 'admin/view/default/'); // User $registry->set('user', new AUser($registry)); } // end admin load // Currency $registry->set('currency', new ACurrency($registry)); //Route to request process $router = new ARouter($registry); $registry->set('router', $router); $router->processRoute(ROUTE); // Output $registry->get('response')->output(); //Show cache stats if debugging if ($registry->get('config')->get('config_debug')) { ADebug::variable('Cache statistics: ', $registry->get('cache')->stats() . "\n"); } ADebug::checkpoint('app end'); //display debug info if ($router->getRequestType() == 'page') { ADebug::display(); }
public function processPayment($pd, $customer_stripe_id = '') { $response = ''; $this->load->model('checkout/order'); $this->load->language('default_stripe/default_stripe'); $order_info = $this->model_checkout_order->getOrder($pd['order_id']); try { require_once DIR_EXT . 'default_stripe/core/stripe_modules.php'; grantStripeAccess($this->config); //build charge data array $charge_data = array(); $charge_data['amount'] = $pd['amount']; $charge_data['currency'] = $pd['currency']; $charge_data['description'] = $this->config->get('store_name') . ' Order #' . $pd['order_id']; $charge_data['statement_descriptor'] = 'Order #' . $pd['order_id']; $charge_data['receipt_email'] = $order_info['email']; if ($this->config->get('default_stripe_settlement') == 'delayed') { $charge_data['capture'] = false; } else { $charge_data['capture'] = true; } //build cc details $cc_details = array('number' => $pd['cc_number'], 'exp_month' => $pd['cc_expire_month'], 'exp_year' => $pd['cc_expire_year'], 'cvc' => $pd['cc_cvv2'], 'name' => $pd['cc_owner']); $cc_details = array_merge($cc_details, array('address_line1' => $order_info['payment_address_1'], 'address_line2' => $order_info['payment_address_2'], 'address_city' => $order_info['payment_city'], 'address_zip' => $order_info['payment_postcode'], 'address_state' => $order_info['payment_zone'], 'address_country' => $order_info['payment_iso_code_2'])); //we need get the token for the card first $token = array(); $token = Stripe_Token::create(array('card' => $cc_details)); if (!$token || !$token['id']) { $msg = new AMessage(); $msg->saveError('Stripe failed to get card token for order_id ' . $pd['order_id'], 'Unable to use card for customer' . $customer_stripe_id); $response['error'] = $this->language->get('error_system'); return $response; } $charge_data['card'] = $token['id']; if ($order_info['shipping_method']) { $charge_data['shipping'] = array('name' => $order_info['firstname'] . ' ' . $order_info['lastname'], 'phone' => $order_info['telephone'], 'address' => array('line1' => $order_info['shipping_address_1'], 'line2' => $order_info['shipping_address_2'], 'city' => $order_info['shipping_city'], 'postal_code' => $order_info['shipping_postcode'], 'state' => $order_info['shipping_zone'], 'country' => $order_info['shipping_iso_code_2'])); } $charge_data['metadata'] = array(); $charge_data['metadata']['order_id'] = $pd['order_id']; if ($this->customer->getId() > 0) { $charge_data['metadata']['customer_id'] = (int) $this->customer->getId(); } ADebug::variable('Processing stripe payment request: ', $charge_data); $response = Stripe_Charge::create($charge_data); } catch (Stripe_CardError $e) { // card errors $body = $e->getJsonBody(); $response['error'] = $body['error']['message']; $response['code'] = $body['error']['code']; return $response; } catch (Stripe_InvalidRequestError $e) { // Invalid parameters were supplied to Stripe's API $body = $e->getJsonBody(); $msg = new AMessage(); $msg->saveError('Stripe payment failed with invalid parameters!', 'Stripe payment failed. ' . $body['error']['message']); $response['error'] = $this->language->get('error_system'); return $response; } catch (Stripe_AuthenticationError $e) { // Authentication with Stripe's API failed $body = $e->getJsonBody(); $msg = new AMessage(); $msg->saveError('Stripe payment failed to authenticate!', 'Stripe payment failed to authenticate to the server. ' . $body['error']['message']); $response['error'] = $this->language->get('error_system'); return $response; } catch (Stripe_ApiConnectionError $e) { // Network communication with Stripe failed $body = $e->getJsonBody(); $msg = new AMessage(); $msg->saveError('Stripe payment connection has failed!', 'Stripe payment failed connecting to the server. ' . $body['error']['message']); $response['error'] = $this->language->get('error_system'); return $response; } catch (Stripe_Error $e) { // Display a very generic error to the user, and maybe send $body = $e->getJsonBody(); $msg = new AMessage(); $msg->saveError('Stripe payment has failed!', 'Stripe processing failed. ' . $body['error']['message']); $response['error'] = $this->language->get('error_system'); return $response; } catch (Exception $e) { // Something else happened, completely unrelated to Stripe $msg = new AMessage(); $msg->saveError('Unexpected error in stripe payment!', 'Stripe processing failed. ' . $e->getMessage() . "(" . $e->getCode() . ")"); $response['error'] = $this->language->get('error_system'); //log in AException $ae = new AException($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine()); ac_exception_handler($ae); return $response; } //we still have no result. something unexpected happend if (empty($response)) { $response['error'] = $this->language->get('error_system'); return $response; } ADebug::variable('Processing stripe payment response: ', $response); //Do we have an error? exit with no records if ($response['failure_message'] || $response['failure_code']) { $response['error'] = $response['failure_message']; $response['code'] = $response['failure_code']; return $response; } $message .= 'Order id: ' . (string) $pd['order_id'] . "\n"; $message .= 'Charge id: ' . (string) $response['id'] . "\n"; $message .= 'Transaction Timestamp: ' . (string) date('m/d/Y H:i:s', $response['created']); if ($response['paid']) { //finalize order only if payment is a success $this->model_checkout_order->addHistory($pd['order_id'], $this->config->get('config_order_status_id'), $message); if ($this->config->get('default_stripe_settlement') == 'auto') { //auto complete the order in sattled mode $this->model_checkout_order->confirm($pd['order_id'], $this->config->get('default_stripe_status_success_settled')); } else { //complete the order in unsattled mode $this->model_checkout_order->confirm($pd['order_id'], $this->config->get('default_stripe_status_success_unsettled')); } } else { // Some other error, assume payment declined $this->model_checkout_order->addHistory($pd['order_id'], $this->config->get('default_stripe_status_decline'), $message); $response['error'] = "Payment has failed! " . $response['failure_message']; $response['code'] = $response['failure_code']; } return $response; }
public function send() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $this->loadLanguage('default_stripe/default_stripe'); //validate input $post = $this->request->post; //check if saved cc mode is used if (!$post['use_saved_cc']) { if (empty($post['cc_number'])) { $json['error'] = $this->language->get('error_incorrect_number'); } if (empty($post['cc_owner'])) { $json['error'] = $this->language->get('error_incorrect_name'); } if (empty($post['cc_expire_date_month']) || empty($post['cc_expire_date_year'])) { $json['error'] = $this->language->get('error_incorrect_expiration'); } if (strlen($post['cc_cvv2']) != 3 && strlen($post['cc_cvv2']) != 4) { $json['error'] = $this->language->get('error_incorrect_cvv'); } } if (isset($json['error'])) { $this->load->library('json'); $this->response->setOutput(AJson::encode($json)); return null; } $this->loadModel('checkout/order'); $this->loadModel('extension/default_stripe'); $this->loadLanguage('default_stripe/default_stripe'); $order_id = $this->session->data['order_id']; $order_info = $this->model_checkout_order->getOrder($order_id); // currency code $currency = $this->currency->getCode(); // order amount without decimal delimiter $amount = round($this->currency->convert($this->cart->getFinalTotal(), $this->config->get('config_currency'), $currency), 2) * 100; $cardnumber = preg_replace('/[^0-9]/', '', $post['cc_number']); $cvv2 = preg_replace('/[^0-9]/', '', $post['cc_cvv2']); // Card owner name $cardname = html_entity_decode($post['cc_owner'], ENT_QUOTES, 'UTF-8'); $cardtype = $post['cc_type']; // card expire date mmyy $cardissue = $post['cc_issue']; ADebug::checkpoint('Stripe Payment: Order ID ' . $order_id); $pd = array('amount' => $amount, 'currency' => $currency, 'order_id' => $order_id, 'cc_number' => $cardnumber, 'cc_expire_month' => $post['cc_expire_date_month'], 'cc_expire_year' => $post['cc_expire_date_year'], 'cc_owner' => $cardname, 'cc_cvv2' => $cvv2, 'cc_issue' => $cardissue); $p_result = $this->model_extension_default_stripe->processPayment($pd, $customer_stripe_id); ADebug::variable('Processing payment result: ', $p_result); if ($p_result['error']) { // transaction failed $json['error'] = (string) $p_result['error']; if ($p_result['code']) { $json['error'] .= ' (' . $p_result['code'] . ')'; } } else { if ($p_result['paid']) { $json['success'] = $this->html->getSecureURL('checkout/success'); } else { //Unexpected result $json['error'] = $this->language->get('error_system'); } } //init controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); $this->load->library('json'); $this->response->setOutput(AJson::encode($json)); }