/** * 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']; if (!empty($response['item_number'])) { // Get the indexes of the order $orderid = trim($response['custom']); if (is_numeric($orderid) && is_numeric($bankid)) { // Replacing the comma with the dot in the amount value. $amount = str_replace(",", ".", $response['amount']); $payment = Payments::addpayment($orderid, $response['thx_id'], $bankid, 0, $amount); Orders::set_status($orderid, Statuses::id("paid", "orders")); // Paid OrdersItems::set_statuses($orderid, Statuses::id("paid", "orders")); // Paid return $orderid; } } }
/** * Execute all the registered tasks for the panel */ private function panelTask() { // Get 20 Active tasks items $tasks = PanelsActions::getTasks(Statuses::id("active", "domains_tasks"), Statuses::id('active', 'domains')); try { // Check all the tasks saved within the Panels_Actions table. foreach ($tasks as $task) { self::doPanelsTask($task); // Check if all orderitem of order is complete and if is ok set order to complete $OrderItem = OrdersItems::getDetail($task['orderitem_id']); if (is_numeric($OrderItem['order_id']) && Orders::checkIfOrderItemsAreCompleted($OrderItem['order_id'])) { Shineisp_Commons_Utilities::logs('Order #' . $OrderItem['order_id'] . ' has all items completed. Set order status to complete.', "tasks.log"); Orders::set_status($OrderItem['order_id'], Statuses::id("complete", "orders")); } } } catch (SoapFault $e) { $ISP = Isp::getActiveISP(); Shineisp_Commons_Utilities::SendEmail($ISP['email'], $ISP['email'], null, "Task error panel message", $e->getMessage()); return false; } }
/** * 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; } }
/** * Clean all the obsolete orders without expiring date * Set the obsolete orders as deleted */ public static function cleanNotPaidOrders() { $orders = Orders::find_all_not_paid_orders(); foreach ($orders as $order) { if (empty($order['expiring_date'])) { // Set all the order oldest more of 1 month as deleted $date1 = new DateTime($order['order_date']); $date2 = new DateTime(date('Y-m-d')); } else { // Set the expired orders as deleted $date1 = new DateTime($order['order_date']); $date2 = new DateTime($order['expiring_date']); } $interval = $date1->diff($date2); if ($interval->y <= 0 || $interval->m <= 0) { $customer = Customers::getAllInfo($order['customer_id']); // Get the fastlink attached $link_exist = Fastlinks::findlinks($order['order_id'], $order['customer_id'], 'orders'); if (count($link_exist) > 0) { $fastlink = $link_exist[0]['code']; } else { $fastlink = Fastlinks::CreateFastlink('orders', 'edit', json_encode(array('id' => $order['order_id'])), 'orders', $order['order_id'], $customer['customer_id']); } $customer_url = "http://" . $_SERVER['HTTP_HOST'] . "/index/link/id/{$fastlink}"; Shineisp_Commons_Utilities::sendEmailTemplate($customer['email'], 'order_deleted', array('orderid' => $order['order_number'], ':shineisp:' => $customer, 'fullname' => $customer['fullname'], 'url' => $customer_url), null, null, null, null, $customer['language_id'], Settings::findbyParam('cron_notify')); // Set the order as deleted Orders::set_status($order['order_id'], Statuses::id('deleted', 'orders')); } } return true; }
/** * 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); } }
/** * 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']; if (!empty($response['payment_status']) && $response['payment_status'] == "Completed") { if (!empty($response['item_number'])) { // Get the indexes of the order $orderid = trim($response['custom']); if (is_numeric($orderid) && is_numeric($bankid)) { // Replacing the comma with the dot in the amount value. $amount = str_replace(",", ".", $response['amount']); Shineisp_Commons_Utilities::logs("Adding the payment information: " . $response['thx_id'], "iwbank.log"); $payment = Payments::addpayment($orderid, $response['thx_id'], $bankid, 0, $amount); Shineisp_Commons_Utilities::logs("Set the order in the processing mode", "iwbank.log"); Orders::set_status($orderid, Statuses::id("paid", "orders")); // Paid OrdersItems::set_status($orderid, Statuses::id("paid", "orders")); // Paid return $orderid; } } } 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; }