/** * callbackAction * This method isn't called from the project * but it is called from a bank gateway service * in order to set as payed the order processed * * IMPORTANT: * This method was within the /default/orders controller and it has been moved here * because the access to the /default/orders is denied without an authentication process * /default/common controller is accessible without login process. */ public function callbackAction() { $request = $this->getRequest(); $response = $request->getParams(); if (!empty($response['custom']) && is_numeric(trim($response['custom']))) { // Getting the md5 value in order to match with the class name. $classrequest = $request->gateway; // Orderid back from the bank $order_id = trim($response['custom']); // Get the bank selected using the MD5 code $bank = Banks::findbyMD5($classrequest); if (!empty($bank[0]['classname'])) { if (!empty($bank[0]['classname']) && class_exists($bank[0]['classname'])) { $class = $bank[0]['classname']; $payment = new $class($response['custom']); // Check if the method "Response" exists in the Payment class and send all the bank information to the payment module if (method_exists($class, "Response")) { Shineisp_Commons_Utilities::logs("Callback called: {$class}\nParameters: " . json_encode($response), "payments.log"); $payment->Callback($response); } } } } die; }
protected function checkFields() { parent::checkFields(); if ($this->amount == NULL) { throw new IgfsMissingParException("Missing amount"); } if ($this->refTranID == NULL) { if ($this->pan == NULL) { if ($this->payInstrToken == NULL) { Shineisp_Commons_Utilities::logs("---> Missing refTranID", 'bnl_igfs.log'); } } } return false; if ($this->pan != NULL) { // Se è stato impostato il pan verifico... if ($this->pan == "") { Shineisp_Commons_Utilities::logs("---> Missing pan", 'bnl_igfs.log'); } return false; } if ($this->payInstrToken != NULL) { // Se è stato impostato il payInstrToken verifico... if ($this->payInstrToken == "") { Shineisp_Commons_Utilities::logs("---> Missing payInstrToken", 'bnl_igfs.log'); } return false; } if ($this->pan != NULL or $this->payInstrToken != NULL) { if ($this->currencyCode == NULL) { Shineisp_Commons_Utilities::logs("---> Missing currencyCode", 'bnl_igfs.log'); } return false; } }
protected function checkFields() { parent::checkFields(); if ($this->shopID == NULL || "" == $this->shopID) { Shineisp_Commons_Utilities::logs("---> Missing shopID", 'bnl_igfs.log'); } return false; }
protected function checkFields() { parent::checkFields(); if ($this->amount == NULL) { Shineisp_Commons_Utilities::logs("---> Missing amount", 'bnl_igfs.log'); } return false; if ($this->refTranID == NULL) { Shineisp_Commons_Utilities::logs("---> Missing refTranID", 'bnl_igfs.log'); } return false; }
/** * activateItems: activate one or more order items based on autosetup flag * * @param orderId: order id to activate * autosetup: autosetup value to manage * @return true|false */ public static function activateItems($orderId, $autosetup = 0) { Shineisp_Commons_Utilities::logs(__METHOD__ . "(" . $orderId . ", " . $autosetup . ")"); $autosetup = intval($autosetup); if ($autosetup === 0) { return true; } $activableItems = OrdersItems::getAllActivableItems($orderId); if (empty($activableItems)) { Shineisp_Commons_Utilities::logs(__METHOD__ . "(" . $orderId . ", " . $autosetup . "): no activable product"); return true; } foreach ($activableItems as $item) { if (empty($item->parameters) && empty($item->callback_url)) { Shineisp_Commons_Utilities::logs(__METHOD__ . "(" . $orderId . ", " . $autosetup . "): product " . serialize($item) . " with no parameter set"); // parameters are needed for both domains and hosting. continue; } // echo $item->Products->autosetup; // var_dump( isset($item->Products) && isset($item->Products->autosetup) && intval($item->Products->autosetup) === $autosetup ); if (isset($item->Products) && isset($item->Products->autosetup) && intval($item->Products->autosetup) === intval($autosetup)) { Shineisp_Commons_Utilities::logs(__METHOD__ . "(" . $orderId . ", " . $autosetup . "): Hosting Detail Id #" . $item->detail_id . " start activation"); OrdersItems::activate($item->detail_id); } if (isset($item->tld_id) && intval($item->tld_id) > 0 && DomainsTlds::getAutosetup($item->tld_id) === $autosetup) { Shineisp_Commons_Utilities::logs("Orders::activateItems(" . $orderId . ", " . $autosetup . "): Domain Detail Id " . $item->detail_id . " start activation"); OrdersItems::activate($item->detail_id); } } Shineisp_Commons_Utilities::logs(__METHOD__ . "(" . $orderId . ", " . $autosetup . "). End activations"); }
/** * CREATE THE ORDER FOR ALL THE AUTORENEWABLE DOMAINS/SERVICES * Check all the services [domains, products] and create the orders for each customer only if the service has been set as renewable * @return void */ public static function checkServices() { try { $i = 0; $customers = array(); /* We have to start to get all the domains that them expiring date is today then we have to create a custom array sorted by customerID in order to group services and domains of a specific customer. */ // Get all the active domains that expire in 1 day $domains = Domains::getExpiringDomainsByDays(1, Statuses::id("active", "domains")); if ($domains) { Shineisp_Commons_Utilities::log("There are (" . count($domains) . ") new domains to renew"); // Create the customer group list for the email summary foreach ($domains as $domain) { if (is_numeric($domain['reseller'])) { $invoice_dest = Customers::getAllInfo($domain['reseller']); $customers[$domain['customer_id']]['id'] = $invoice_dest['customer_id']; $customers[$domain['customer_id']]['fullname'] = $invoice_dest['firstname'] . " " . $invoice_dest['lastname'] . " " . $invoice_dest['company']; $customers[$domain['customer_id']]['email'] = $invoice_dest['email']; $customers[$domain['customer_id']]['language_id'] = $invoice_dest['language_id']; } else { $customers[$domain['customer_id']]['id'] = $domain['customer_id']; $customers[$domain['customer_id']]['fullname'] = $domain['fullname']; $customers[$domain['customer_id']]['email'] = $domain['email']; $customers[$domain['customer_id']]['language_id'] = $domain['language_id']; } $customers[$domain['customer_id']]['products'][$i]['name'] = $domain['domain']; $customers[$domain['customer_id']]['products'][$i]['type'] = "domain"; $customers[$domain['customer_id']]['products'][$i]['renew'] = $domain['renew']; $customers[$domain['customer_id']]['products'][$i]['expiring_date'] = $domain['expiringdate']; $customers[$domain['customer_id']]['products'][$i]['days'] = $domain['days']; // Get the last old order item id if (!empty($domain['oldorders'])) { // find the domain foreach ($domain['oldorders'] as $olditemorder) { // Get all the information from the old order $olditem = OrdersItems::getAllInfo($olditemorder['orderitem_id']); // Check if the old order item refers to the domain selected if (!empty($olditem['parameters']) && !empty($olditem['Orders']['OrdersItemsDomains'][0]['Domains']['tld_id'])) { // Get the old configuration parameters $params = json_decode($olditem['parameters'], true); // Zend_Debug::dump($olditem); // Zend_Debug::dump($params); // Zend_Debug::dump($domain['domain']); // Extract the domain name and match it with the domain selected if (!empty($params['domain']) && $params['domain']['name'] == $domain['domain']) { $customers[$domain['customer_id']]['products'][$i]['oldorderitemid'] = $olditemorder['orderitem_id']; } } } } Shineisp_Commons_Utilities::log("- " . $domain['domain']); $i++; } } /* * Now we have to get the services expired and we have to sum the previous $customers array with these * new information. */ // Get all the services active that expire the day after $services = OrdersItems::getExpiringServicesByDays(1, Statuses::id("complete", "orders")); if ($services) { Shineisp_Commons_Utilities::log("There are (" . count($services) . ") new services to renew"); // Create the customer group list for the email summary foreach ($services as $service) { if (is_numeric($service['reseller'])) { $invoice_dest = Customers::getAllInfo($service['reseller']); $customers[$service['customer_id']]['id'] = $invoice_dest['customer_id']; $customers[$service['customer_id']]['fullname'] = $invoice_dest['firstname'] . " " . $invoice_dest['lastname'] . " " . $invoice_dest['company']; $customers[$service['customer_id']]['email'] = $invoice_dest['email']; $customers[$service['customer_id']]['password'] = $invoice_dest['password']; $customers[$service['customer_id']]['language_id'] = $invoice_dest['language_id']; } else { $customers[$service['customer_id']]['id'] = $service['id']; $customers[$service['customer_id']]['fullname'] = $service['fullname']; $customers[$service['customer_id']]['email'] = $service['email']; $customers[$service['customer_id']]['password'] = $service['password']; $customers[$service['customer_id']]['language_id'] = $service['language_id']; } $customers[$service['customer_id']]['products'][$i]['name'] = $service['product']; $customers[$service['customer_id']]['products'][$i]['type'] = "service"; $customers[$service['customer_id']]['products'][$i]['renew'] = $service['renew']; $customers[$service['customer_id']]['products'][$i]['expiring_date'] = $service['expiringdate']; $customers[$service['customer_id']]['products'][$i]['days'] = $service['days']; $customers[$service['customer_id']]['products'][$i]['oldorderitemid'] = $service['detail_id']; Shineisp_Commons_Utilities::log("- " . $service['product']); $i++; } } // Create the email messages for the customers if (count($customers) > 0) { foreach ($customers as $customer) { $items = ""; // **** CREATE THE ORDER FOR ALL THE AUTORENEWABLE DOMAINS/SERVICES *** // ============================================================ // Renew all the services and domain where the customer has choosen the autorenew of the service. $orderID = Orders::renewOrder($customer['id'], $customer['products']); if (is_numeric($orderID)) { $link = Fastlinks::findlinks($orderID, $customer['id'], 'orders'); // Create the fast link to include in the email if (!empty($link[0]['code'])) { $url = "http://" . $_SERVER['HTTP_HOST'] . "/index/link/id/" . $link[0]['code']; } else { $url = "http://" . $_SERVER['HTTP_HOST']; } Shineisp_Commons_Utilities::sendEmailTemplate($customer['email'], 'order_renew', array('fullname' => $customer['fullname'], ':shineisp:' => $customer, 'url' => $url), null, null, null, null, $customer['language_id'], Settings::findbyParam('cron_notify')); } } } /* * Now we have to set as expired all the domains records that the date is the date of the expiring of the domain * // Expired */ $dq = Doctrine_Query::create()->update('Domains d')->set('d.status_id', Statuses::id('expired', 'domains'))->where('DATEDIFF(d.expiring_date, CURRENT_DATE) <= ?', 0)->addWhere('DATEDIFF(d.expiring_date, CURRENT_DATE) >= ?', 0); $dq->execute(null, Doctrine::HYDRATE_ARRAY); /* * Now we have to set as closed all the domains records that the date is older of -2 days * // Closed */ $dq = Doctrine_Query::create()->update('Domains d')->set('d.status_id', Statuses::id('suspended', 'domains'))->where('DATEDIFF(d.expiring_date, CURRENT_DATE) <= ?', -2); $dq->execute(null, Doctrine::HYDRATE_ARRAY); /* * Now we have to set as expired all the services records * // Expired */ $dq = Doctrine_Query::create()->update('OrdersItems oi')->set('oi.status_id', Statuses::id('expired', 'orders'))->where('DATEDIFF(oi.date_end, CURRENT_DATE) <= ?', 0); $dq->execute(null, Doctrine::HYDRATE_ARRAY); /* * Now we have to set as deleted all the services records * // Deleted */ $dq = Doctrine_Query::create()->update('OrdersItems oi')->set('oi.status_id', Statuses::id('deleted', 'orders'))->where('DATEDIFF(oi.date_end, CURRENT_DATE) <= ?', -2); $dq->execute(null, Doctrine::HYDRATE_ARRAY); Shineisp_Commons_Utilities::sendEmailTemplate(null, 'cron', array('cronjob' => 'Check Services'), null, null, null, null, null, Settings::findbyParam('cron_notify')); } catch (Exception $e) { Shineisp_Commons_Utilities::logs($e->getMessage(), "cron.log"); return false; } return true; }
/** * extractServersFromGroup: * extract servers from group accordingly to server group fill_type * @param INT $group_id: id of the group to extract from * @param INT $server_type: optional server type id to extract. If empty, one server for each type is extracted * @return ARRAY * */ public static function extractServersFromGroup($group_id, $server_type = null) { $arrOutput = array(); $group_id = isset($group_id) ? intval($group_id) : null; $server_type = isset($server_type) ? intval($server_type) : null; if (!$group_id) { return $arrOutput; } // Get the fill_type for requested group $ServersGroups = ServersGroups::find($group_id); if (!$ServersGroups || !isset($ServersGroups->fill_type)) { return $arrOutput; } $fill_type = (int) $ServersGroups->fill_type; /* '1' => 'Create services on the least full server', '2' => 'Fill default server until full then switch to next least used', '3' => 'Fill servers starting from the newest to the older', '4' => 'Fill servers starting from the older to the newest', '5' => 'Fill servers randomly', '6' => 'Fill manually. Only default server will be used.', '7' => 'Fill servers starting from the cheaper to the expensive.', '8' => 'Fill servers starting from the expensive to the cheaper.', */ // Get all servers inside this group $serverIds = ServersGroups::getServers($group_id, 's.*'); // Get servers details $ORM = Doctrine_Query::create()->from('Servers s')->leftJoin('s.Servers_Types st')->leftJoin('s.Statuses stat')->leftJoin('s.Panels panel')->leftJoin('s.Servers_Types')->leftJoin('s.CustomAttributesValues')->whereIn('s.server_id', $serverIds); if ($server_type) { $ORM = $ORM->andWhere('s.type_id = ?', $server_type); } $ORM = $ORM->execute(); // Create an array with type_id as index $arrServers = array(); foreach ($ORM as $y) { $type_id = $y->type_id; $server_id = $y->server_id; $services = isset($y->services) ? intval($y->services) : 0; $max_services = isset($y->max_services) && $y->max_services > 0 ? intval($y->max_services) : 10000; $buy_timestamp = isset($y->buy_date) ? strtotime($y->buy_date) : 0; $is_default = isset($y->is_default) ? intval($y->is_default) : 0; // Skip full servers if ($services >= $max_services) { Shineisp_Commons_Utilities::logs(__METHOD__ . " " . $server_type . " is full!", 'servers.log'); continue; } $usagePercent = round($services * 100 / $max_services); $arrServers[$type_id][$server_id] = $y->toArray(); $arrServers[$type_id][$server_id]['is_default'] = $is_default; $arrServers[$type_id][$server_id]['_usagePercent'] = $usagePercent; $arrServers[$type_id][$server_id]['_buyTimestamp'] = $buy_timestamp; } // Cycle servers by type foreach ($arrServers as $type_id => $serverType) { $tmp = array(); // temporary array // Extract server switch ($fill_type) { case 1: // 'Create services on the least full server' // 'Create services on the least full server' case 2: // 'Fill default server until full then switch to next least used' $method = $fill_type === 1 ? SORT_ASC : SORT_DESC; $tmp = Shineisp_Commons_ArraySorter::multisort($serverType, '_usagePercent', $method); break; case 3: // 'Fill servers starting from the newest to the older' // 'Fill servers starting from the newest to the older' case 4: // 'Fill servers starting from the older to the newest' $method = $fill_type === 3 ? SORT_DESC : SORT_ASC; $tmp = Shineisp_Commons_ArraySorter::multisort($serverType, '_buyTimestamp', $method); break; case 5: // 'Fill servers randomly' $randKey = array_rand($serverType); $tmp = array($randKey => $randKey); break; case 6: // 'Fill manually. Only default server will be used.' $tmp = Shineisp_Commons_ArraySorter::multisort($serverType, 'is_default', SORT_DESC); break; case 7: // 'Fill servers starting from the cheaper to the expensive.' // 'Fill servers starting from the cheaper to the expensive.' case 8: // 'Fill servers starting from the expensive to the cheaper.' $method = $fill_type === 7 ? SORT_ASC : SORT_DESC; $tmp = Shineisp_Commons_ArraySorter::multisort($serverType, 'cost', $method); } reset($tmp); $selectedServer = key($tmp); $arrOutput[$type_id][$selectedServer] = $arrServers[$type_id][$selectedServer]; } if (isset($server_type) && isset($arrOutput[$server_type])) { // return just the server array $key = key($arrOutput[$server_type]); $arrOutput = $arrOutput[$server_type][$key]; } Shineisp_Commons_Utilities::logs(__METHOD__ . '(' . $group_id . ', ' . $server_type . '): ' . serialize($arrOutput), 'servers.log'); // Return return $arrOutput; }
private function doDomainTask($task) { if (!isset($task['Domains']) || !isset($task['Domains']['Customers']) || !isset($task['Domains']['Customers']['customer_id'])) { PanelsActions::UpdateTaskLog($task['action_id'], $this->translations->translate('customer_id not found')); } $customer_id = intval($task['Domains']['Customers']['customer_id']); $ISP = Isp::getByCustomerId($customer_id); if (!$ISP || !isset($ISP['isp_id']) || !is_numeric($ISP['isp_id'])) { PanelsActions::UpdateTaskLog($task['action_id'], $this->translations->translate('isp_id not found')); return false; } try { // Getting domains details $domain = Domains::find($task['domain_id'], null, true); if (!empty($domain[0])) { $domain_name = $domain[0]['domain'] . "." . $domain[0]['tld']; // Get the associated registrar for the domain selected $registrar = Registrars::getRegistrarId($task['registrars_id']); if (!empty($registrar['class'])) { // Create the class registrar object $class = $registrar['class']; $regclass = new $class(); $action = $task['action']; // Check if the task is REGISTER or TRANSFER the domain name if ($action == "registerDomain") { $regclass->registerDomain($task['domain_id']); // Set the DNS ZONES DomainsTasks::AddTask($domain_name, "setDomainHosts"); // Update the domain information DomainsTasks::AddTask($domain_name, "updateDomain"); } elseif ($action == "transferDomain") { $regclass->transferDomain($task['domain_id']); } elseif ($action == "renewDomain") { $regclass->renewDomain($task['domain_id']); // Update the domain information DomainsTasks::AddTask($domain_name, "updateDomain"); } elseif ($action == "lockDomain") { $regclass->lockDomain($task['domain_id']); } elseif ($action == "unlockDomain") { $regclass->unlockDomain($task['domain_id']); // Update the domain information DomainsTasks::AddTask($domain_name, "updateDomain"); } elseif ($action == "setNameServers") { $regclass->setNameServers($task['domain_id']); } elseif ($action == "setDomainHosts") { $regclass->setDomainHosts($task['domain_id']); } else { $regclass->{$action}($task['domain_id']); } // Update the log description of the task DomainsTasks::UpdateTaskLog($task['task_id'], $this->translations->translate("Your request has been executed.")); // Update the status of the task DomainsTasks::UpdateTaskStatus($task['task_id'], Statuses::id('complete', 'domains_tasks')); // Set the task as "Complete" // Increment the task counter number DomainsTasks::UpdateTaskCounter($task['task_id']); // Set the status as Active Domains::setStatus($task['domain_id'], Statuses::id('active', 'domains_tasks')); } } } catch (Exception $e) { DomainsTasks::UpdateTaskLog($task['task_id'], $this->translations->translate($e->getMessage())); Shineisp_Commons_Utilities::SendEmail($ISP['email'], $ISP['email'], null, "Task error message: " . $task['Domains']['domain'] . "." . $task['Domains']['tld'], $e->getMessage()); Shineisp_Commons_Utilities::logs("Task error message: " . $task['Domains']['domain'] . "." . $task['Domains']['tld'] . ":" . $e->getMessage(), "tasks.log"); } return true; }
/** * Create a new client * * Executes the creation of new client in the IspConfig control panel * Note in order to not fail this command, it must meet the following requirements: * * - The customer must be registered in the db. * - The customer has bought a hosting plan * * @param array $task Must be a valid task * @return integer RemoteClientId * @access public */ public function create_client(array $task) { $clientId = ""; if (empty($task)) { throw new Exception('Task empty.', '3000'); } // Execute a custom event $this->events()->trigger('panels_create_client_before', __CLASS__, array('task' => $task)); $server = self::getServer($task['orderitem_id'], 'web'); // Connection to the SOAP system $client = $this->connect($server['server_id']); if (!$client) { throw new Exception("There is no way to connect the client with the IspConfig Panel.", "3010"); } try { // Get all the customer information $customer = Customers::getAllInfo($task['customer_id']); // Get the client id saved previously in the customer information page $customAttribute = CustomAttributes::getAttribute($task['customer_id'], 'client_id'); // Get the custom ISPConfig attribute set in the customer control panel if (is_numeric($customAttribute['value'])) { /** * Client_id (IspConfig Attribute Set in ShineISP database in the setup of the panel) * @see Shineisp_Controller_Plugin_SetupcPanelsModules */ $clientId = $customAttribute['value']; $record = $client->client_get($this->getSession(), $clientId); if ($record == false) { $clientId = ""; } } // Customer Profile $record['company_name'] = $customer['company']; $record['contact_name'] = $customer['firstname'] . " " . $customer['lastname']; $record['customer_no'] = $customer['customer_id']; $record['vat_id'] = $customer['vat']; $record['email'] = $customer['email']; $record['street'] = !empty($customer['Addresses'][0]['address']) ? $customer['Addresses'][0]['address'] : ""; $record['zip'] = !empty($customer['Addresses'][0]['code']) ? $customer['Addresses'][0]['code'] : ""; $record['city'] = !empty($customer['Addresses'][0]['city']) ? $customer['Addresses'][0]['city'] : ""; $record['state'] = !empty($customer['Addresses'][0]['area']) ? $customer['Addresses'][0]['area'] : ""; $record['country'] = !empty($customer['Addresses'][0]['Countries']['code']) ? $customer['Addresses'][0]['Countries']['code'] : ""; $record['mobile'] = Contacts::getContact($customer['customer_id'], "Mobile"); $record['fax'] = Contacts::getContact($customer['customer_id'], "Fax"); $record['telephone'] = Contacts::getContact($customer['customer_id']); // System Configuration $languagecode = Languages::get_code($customer['language_id']); $record['language'] = $languagecode; $record['usertheme'] = "default"; $record['template_master'] = 0; $record['template_additional'] = ""; $record['created_at'] = date(''); $record['web_php_options'] = "no,fast-cgi,cgi,mod,suphp,php-fpm"; $record['ssh_chroot'] = 'jailkit'; // Get the Json encoded parameters in the task $parameters = json_decode($task['parameters'], true); // Match all the ShineISP product system attribute and IspConfig attributes (see below about info) $retval = self::matchFieldsValues($parameters, $record); if (is_array($retval)) { $record = array_merge($record, $retval); } else { Shineisp_Commons_Utilities::logs("No hosting attribute parameters have been set in ShineISP. Check the hosting product attributes section.", "ispconfig.log"); } // Execute the SOAP action if (!empty($clientId) && is_numeric($clientId)) { $client->client_update($this->getSession(), $clientId, 1, $record); } else { $arrUsernames = array(); $arrUsernames = self::generateUsernames($customer); // Check if username is available foreach ($arrUsernames as $username) { if (!$client->client_get_by_username($this->getSession(), $username)) { break; } } // Create a random password string $password = Shineisp_Commons_Utilities::GenerateRandomString(); $record['username'] = $username; $record['password'] = $password; // Save the setup in the service setup field OrdersItems::set_setup($task['orderitem_id'], array('url' => 'http://' . $server['ip'] . ':8080', 'username' => $username, 'password' => $password), "webpanel"); // Adding the client in ISPConfig $clientId = $client->client_add($this->getSession(), 0, $record); // Update the custom customer attribute client_id CustomAttributes::saveElementsValues(array(array('client_id' => $clientId)), $task['customer_id'], "customers"); // Execute a custom event $this->events()->trigger('panels_create_client_after', __CLASS__, array('task' => $task, 'clientid' => $clientId, 'customerdata' => $record)); } // Create the log message Shineisp_Commons_Utilities::logs("ID: " . $task['action_id'] . " - " . __METHOD__ . " - Parameters: " . json_encode($record), "ispconfig.log"); // Logout from the IspConfig Remote System $client->logout($this->getSession()); return $clientId; } catch (Exception $e) { Shineisp_Commons_Utilities::logs(__METHOD__ . ": " . $e->getMessage()); echo $e->getMessage(); } }
public function execute() { try { $this->checkFields(); if ($this->serverURL != null) { $mapResponse = $this->executeHttp($this->serverURL); } else { $i = 0; $sURL = $this->serverURLs[$i]; $finished = false; while (!$finished) { try { $mapResponse = $this->executeHttp($sURL); $finished = true; } catch (Shineisp_Banks_BNL_ConnectionException $e) { $i++; if ($i < sizeof($this->serverURLs) && $this->serverURLs[$i] != null) { $sURL = $this->serverURLs[$i]; } else { throw $e; } } } } $this->parseResponseMap($mapResponse); $this->fields2Reset = true; if (!$this->error) { if (!$this->checkResponseSignature($mapResponse)) { Shineisp_Commons_Utilities::logs("--------> Error: " . json_encode($mapResponse), 'bnl_igfs.log'); return false; } return true; } else { Shineisp_Commons_Utilities::logs("--------> Error: " . json_encode($mapResponse), 'bnl_igfs.log'); return false; } } catch (Exception $e) { $this->resetFields(); $this->fields2Reset = true; $this->error = true; $this->errorDesc = $e->getMessage(); Shineisp_Commons_Utilities::logs("-------------> Error: " . $e->getMessage(), 'bnl_igfs.log'); return false; } }
/** * runActivate * run activation procedure if payment is confirmed and order is fully paid */ public static function runActivate($orderid) { Shineisp_Commons_Utilities::logs(__METHOD__ . ": payment confirmed."); // Let's check if we have the whole invoice paid. $isPaid = Orders::isPaid($orderid); // Check to see if order is totally paid. // This will generate invoice or, if an invoice is still present, it will overwrite it (proforma to invoice conversion) if ($isPaid) { Shineisp_Commons_Utilities::logs(__METHOD__ . ": isPaid ok, payment has been completed 100%"); // Set order status as "Paid" Orders::set_status($orderid, Statuses::id('paid', 'orders')); Shineisp_Commons_Utilities::logs(__METHOD__ . ": subscribed services activation starts "); // If we have to autosetup as soon as first payment is received, let's do here. Orders::activateItems($orderid, 4); // If automatic invoice creation is set to 1, we have to create the invoice $autoCreateInvoice = intval(Settings::findbyParam('auto_create_invoice_after_payment')); $invoiceId = intval(Orders::isInvoiced($orderid)); if (!$invoiceId) { // order not invoiced? Shineisp_Commons_Utilities::logs(__METHOD__ . ": order not invoiced."); if ($autoCreateInvoice === 1) { Shineisp_Commons_Utilities::logs(__METHOD__ . ": start order invoicing process."); // invoice not created yet. Let's create now Invoices::Create($orderid); } } else { Shineisp_Commons_Utilities::logs(__METHOD__ . ": invoice already created overwrite of the old invoice"); // set invoice as paid Invoices::overwrite($invoiceId); } } else { Shineisp_Commons_Utilities::logs(__METHOD__ . ": isPaid KO, payment not completed"); Shineisp_Commons_Utilities::logs(__METHOD__ . ": check if one or more services have been activated when a first payment is received"); // If we have to autosetup as soon as first payment is received, let's do here. Orders::activateItems($orderid, 3); } }
public function doCallbackPOST($url, $params) { //open connection $ch = curl_init(); $post_string = json_encode($params); //set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($post_string))); //execute post $result = curl_exec($ch); Shineisp_Commons_Utilities::logs("POST CALLBACK: url: " . $url . " - json: " . $post_string . " - result: " . $result, "api-callback.log"); //close connection curl_close($ch); }
/** * CallBack * This function is called by the bank server in order to confirm the transaction previously executed * @param $response from the Gateway Server * @return boolean */ public function CallBack($response) { Shineisp_Commons_Utilities::logs("Start callback", "iwbank.log"); // Get the orderid back from the bank post variables $orderid = trim($response['custom']); $ret = ""; $payer_id = $response["payer_id"]; $thx_id = $response["thx_id"]; $verify_sign = $response["verify_sign"]; $amount = $response["amount"]; $code = '2E121E96A508BDBA39782E43D2ACC12274A991A7EDE25502F42D99542D26CF3D'; //Inserire il merchant_key indicato all'interno del sito IWSMILE su POS VIRTUALE/Configurazione/Notifica Pagamento. $str = "thx_id=" . $thx_id . "&amount=" . $amount . "&verify_sign=" . $verify_sign; $str .= "&payer_id=" . $payer_id; $str .= "&merchant_key=" . $code; Shineisp_Commons_Utilities::logs("Callback parameters: {$str}", "iwbank.log"); $url = "https://checkout.iwsmile.it/Pagamenti/trx.check"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_POSTFIELDS, $str); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_POST, TRUE); $content = curl_exec($ch); $c_error = "NONE"; $ret = 'NON DISPONIBILE'; if (curl_errno($ch) != 0) { $c_error = curl_error($ch); } else { if (strstr($content, "OK")) { $ret = "VERIFICATO"; Shineisp_Commons_Utilities::logs("Order Completed: {$orderid}", "iwbank.log"); // Complete the order Orders::Complete($orderid, true); // Complete the order information and it executes all the tasks to do Shineisp_Commons_Utilities::logs("Confirm the payment for the order: {$orderid}", "iwbank.log"); Payments::confirm($orderid); // Set the payment confirm } elseif (strstr($content, "KO")) { // Order not verified $ret = 'NON VERIFICATO'; } elseif (strstr($content, "IR")) { // Request is not valid $ret = 'RICHIESTA NON VALIDA'; } elseif (strstr($content, "EX")) { // Request expired $ret = 'RICHIESTA SCADUTA'; } } curl_close($ch); Shineisp_Commons_Utilities::logs("Callback Payment Result: {$ret}", "iwbank.log"); Shineisp_Commons_Utilities::logs("End callback", "iwbank.log"); return true; }
/** * activate * Activate an order item * @param $orderItemId * @return true|false */ public static function activate($orderItemId) { Shineisp_Commons_Utilities::log(__METHOD__ . " - Activate Detail ID #" . $orderItemId); $orderItemId = intval($orderItemId); if ($orderItemId < 1) { // missing order item id from arguments return false; } // Get OrderItem $ordersItem = self::find($orderItemId); $ordersItem = $ordersItem->toArray(); $OrderItem = array_shift($ordersItem); if (!$OrderItem) { // order item not found return false; } // Get customerId related to this order $customerId = Orders::getCustomer($OrderItem['order_id']); /* * START ACTIVATIONS CODE */ $upgrade = Orders::isUpgrade($OrderItem['order_id']); $upgrade_uuid = false; if ($upgrade !== false) { $orderItem = OrdersItems::getDetail($upgrade); Shineisp_Commons_Utilities::logs(__METHOD__ . " - OITEM::" . print_r($orderItem, true)); $oldOrderId = $orderItem['order_id']; Orders::set_status($oldOrderId, Statuses::id("changed", "orders")); // Close the old order ::status changed OrdersItems::set_status($upgrade, Statuses::id("changed", "orders")); $upgrade_uuid = $orderItem['uuid']; // log Shineisp_Commons_Utilities::logs(__METHOD__ . " - Order changed from #" . $oldOrderId . " to #" . $OrderItem['order_id']); } if (empty($OrderItem['parameters'])) { Shineisp_Commons_Utilities::logs(__METHOD__ . " - Order items setup parameters empty"); return false; } // Is this an hosting? execute panel task // TODO: this should call an hook or an even bound to the panel if (isset($OrderItem['Products']) && isset($OrderItem['Products']['type']) && $OrderItem['Products']['type'] == 'hosting') { Shineisp_Commons_Utilities::logs(__METHOD__ . " Hosting task queued"); PanelsActions::AddTask($customerId, $OrderItem['detail_id'], "fullProfile", $OrderItem['parameters']); return true; } // Is this a domain? execute domain task if (isset($OrderItem['tld_id']) && intval($OrderItem['tld_id']) > 0) { $parameters = json_decode($OrderItem['parameters']); if (empty($parameters->domain)) { Shineisp_Commons_Utilities::logs(__METHOD__ . " Domain has been not set in the order detail #{$orderItemId}"); return false; } // Create the domain record $domain = Domains::Create($parameters->domain, intval($OrderItem['tld_id']), intval($customerId), $orderItemId); // Create the domain task if (!empty($parameters->domain) && !empty($parameters->action)) { $domains[] = array('domain' => $parameters->domain, 'action' => $parameters->action); $retval = DomainsTasks::AddTasks($domains); Shineisp_Commons_Utilities::logs(__METHOD__ . " Domain task queued"); } return $retval; } }
public function initAll() { // Get the Zend Event Manager $em = Shineisp_Registry::get('em'); $mainConfigfile = APPLICATION_PATH . "/configs/config.xml"; if (file_exists($mainConfigfile)) { $mainconfig = simplexml_load_file($mainConfigfile); } else { throw new Exception($mainConfigfile . " has been not found"); } if (!count($mainconfig->xpath("/shineisp/modules"))) { $modules = $mainconfig->addChild('modules'); } else { $modules = $mainconfig->xpath("/shineisp/modules"); } $path = PROJECT_PATH . "/library/Shineisp/Plugins" . DIRECTORY_SEPARATOR; // << The last slash is very important in the plugin path // Read all the directory recursivelly and get all the files and folders $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); foreach ($iterator as $filename => $path_object) { $pluginConfigFile = $filename; $info = pathinfo($filename); // Select only the plugins that have a xml configuration file if (!empty($info['extension']) && $info['extension'] == "xml") { // Get the directory of the plugin $PluginPath = $info['dirname']; // Delete the main plugin path $PluginBasePath = str_replace($path, "", $info['dirname']); // Convert the result as array $PluginBasePathArray = explode(DIRECTORY_SEPARATOR, $PluginBasePath); // Create the name of the Plugin class $pluginName = 'Shineisp_Plugins_' . implode("_", $PluginBasePathArray) . '_Main'; // Check if plugins looks good $reflectionClass = new ReflectionClass($pluginName); if (!($reflectionClass->isInstantiable() && $reflectionClass->implementsInterface('Shineisp_Plugins_Interface') && is_callable(array($pluginName, 'events')))) { Shineisp_Commons_Utilities::logs("Skipping not instantiable plugin '" . $pluginName . "'"); continue; } // Initialize $plugin = new $pluginName(); $plugin->events($em); // Check if the Main exists if (file_exists($pluginConfigFile) && is_readable($pluginConfigFile)) { $info = pathinfo($pluginConfigFile); if (!empty($info['extension']) && $info['extension'] == "xml") { if (file_exists($pluginConfigFile)) { $config = simplexml_load_file($pluginConfigFile); // If the config file has been created for the registrar ignore it // because the configuration is delegated to the registrar management if (isset($config->attributes()->type) && "registrars" == (string) $config->attributes()->type) { continue; } $panelName = (string) $config->attributes()->name; $var = (string) $config['var']; // Save the module setup in the config.xml file // Now we are checking if the module is already set in the config.xml file if (!count($mainconfig->xpath("/shineisp/modules/{$var}"))) { // The module is not present, we have to create it $module = $modules[0]->addChild($var); // Now we add the setup date as attribute $module->addAttribute('setup', date('YmdHis')); } else { // The module is present and we get it $module = $mainconfig->xpath("/shineisp/modules/{$var}"); // If the setup date attribute is present skip the module process setup if (!empty($module[0]) && $module[0]->attributes()->setup) { continue; } else { // The setup attribute is not present restart the module setup process $module[0]->addAttribute('setup', date('YmdHis')); } } $help = (string) $config->general->help ? (string) $config->general->help : NULL; $description = (string) $config->general->description ? (string) $config->general->description : NULL; $group_id = SettingsGroups::addGroup($config['name'], $description, $help); if (!empty($config->settings) && $config->settings->children()) { foreach ($config->settings->children() as $node) { $configclass = array(); $arr = $node->attributes(); $var = strtolower($config['var']) . "_" . (string) $arr['var']; $label = (string) $arr['label']; $type = (string) $arr['type']; $description = (string) $arr['description']; if ((string) $arr['configclass']) { $configclass = json_decode((string) $arr['configclass'], true); } if (!empty($var) && !empty($label) && !empty($type)) { SettingsParameters::addParam($label, $description, $var, $type, 'admin', 1, $group_id, $configclass); } } if (!empty($config->customfields)) { foreach ($config->customfields->children() as $node) { $arr = $node->attributes(); $var = (string) $node; $label = (string) $arr['label']; $type = (string) $arr['type']; $section = (string) $arr['section']; // Fetch panel_id from database if (!empty($panelName)) { $Panels = Panels::getAllInfoByName($panelName); } $panel_id = !empty($Panels) && isset($Panels['panel_id']) && $Panels['panel_id'] > 0 ? intval($Panels['panel_id']) : null; if (!empty($var) && !empty($label) && !empty($type)) { CustomAttributes::createAttribute($var, $label, $type, $section, $panel_id); } } } } } $xmlstring = $mainconfig->asXML(); // Prettify and save the xml configuration $dom = new DOMDocument('1.0'); $dom->loadXML($xmlstring); $dom->formatOutput = TRUE; $dom->preserveWhiteSpace = TRUE; $dom->saveXML(); if (!@$dom->save($mainConfigfile)) { throw new Exception("Error on saving the xml file in {$mainConfigfile} <br/>Please check the folder permissions"); } } } } } }
/** * processIPN * @return boolean */ private function processIPN($response) { $bank = self::getModule(); $url = $bank['test_mode'] ? $bank['url_test'] : $bank['url_official']; Shineisp_Commons_Utilities::logs("Paypal IPN Process [{$url}]", "paypal.log"); unset($response['controller']); unset($response['action']); unset($response['module']); unset($response['gateway']); Shineisp_Commons_Utilities::logs(json_encode($response), "paypal.log"); // Set up request to PayPal $request = curl_init(); curl_setopt_array($request, array(CURLOPT_URL => $url, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => http_build_query(array('cmd' => '_notify-validate') + $response), CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_HEADER => FALSE, CURLOPT_SSL_VERIFYPEER => TRUE, CURLOPT_CAINFO => 'cacert.pem')); // Execute request and get response and status code $response = curl_exec($request); $status = curl_getinfo($request, CURLINFO_HTTP_CODE); // Close connection curl_close($request); Shineisp_Commons_Utilities::logs("Response: {$response} Status: {$status}", "paypal.log"); if ($status == 200 && $response == 'VERIFIED') { return true; } else { return false; } }
/** * Response * Create the Order, Invoice and send an email to the customer * @param $response from the Gateway Server * @return order_id or false */ public function Response($response) { $bank = self::getModule(); $bankid = $bank['bank_id']; $url = $bank['test_mode'] ? $bank['url_test'] : $bank['url_official']; list($tid, $ksig) = explode(":", $bank['account']); Shineisp_Commons_Utilities::logs("-----> Callback starts!", "bnl_igfs.log"); $session = new Zend_Session_Namespace('Default'); $IgfsCgVerify = new Shineisp_Banks_BNL_Igfs_CgVerify(); $IgfsCgVerify->disableCheckSSLCert(); $IgfsCgVerify->timeout = 150000; $IgfsCgVerify->paymentID = $session->paymentid; $IgfsCgVerify->kSig = $ksig; $IgfsCgVerify->shopID = self::getOrderID(); $IgfsCgVerify->tid = $tid; $IgfsCgVerify->serverURL = $url; $requestdata = json_encode($IgfsCgVerify, true); Shineisp_Commons_Utilities::logs("---> IgfsCgVerify Request: {$requestdata}", 'bnl_igfs.log'); $result = $IgfsCgVerify->execute(); $responsedata = json_encode($IgfsCgVerify, true); Shineisp_Commons_Utilities::logs("-----> IgfsCgVerify Response: {$responsedata}", 'bnl_igfs.log'); if ($IgfsCgVerify->error) { Shineisp_Commons_Utilities::logs("-----> " . $IgfsCgVerify->rc . ": " . $IgfsCgVerify->error, 'bnl_igfs.log'); return false; } #Zend_Debug::dump($IgfsCgVerify); // Get the orderid back from the bank post variables $orderid = trim($response['custom']); $order = self::getOrder(); $amount = $order['grandtotal']; Shineisp_Commons_Utilities::logs("Adding the payment information: " . $IgfsCgVerify->tranID, "bnl_igfs.log"); $payment = Payments::addpayment($orderid, $IgfsCgVerify->tranID, $bankid, 0, $amount, date('Y-m-d H:i:s'), $order['customer_id'], $IgfsCgVerify->errorDesc); Shineisp_Commons_Utilities::logs("Set the order in the processing mode", "bnl_igfs.log"); Orders::set_status($orderid, Statuses::id("paid", "orders")); // Paid OrdersItems::set_status($orderid, Statuses::id("paid", "orders")); // Paid Shineisp_Commons_Utilities::logs("End callback", "bnl_igfs.log"); return $orderid; }