Example #1
0
 /**
  * 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;
     }
 }
Example #2
0
 /**
  * addpayment
  * Add a payment information to a order
  * @param integer $orderid
  * @param string $transactionid
  * @param integer $bankid
  * @param boolean $status
  * @param float $amount
  */
 public static function addpayment($orderid, $transactionid, $bankid, $status, $amount, $paymentdate = null, $customer_id = null, $payment_description = null)
 {
     $payment = new Payments();
     // We make a double check to properly manage "null" output coming from Shineisp_Commons_Utilities::formatDateIn
     if (!empty($paymentdate)) {
         $paymentdate = Shineisp_Commons_Utilities::formatDateIn($paymentdate);
     }
     $paymentdate = !empty($paymentdate) ? $paymentdate : date('Y-m-d H:i:s');
     // Set the payment data
     $payment->order_id = $orderid;
     $payment->bank_id = $bankid;
     $payment->reference = $transactionid;
     $payment->confirmed = 0;
     $payment->income = $amount;
     // Additional fields for Orders::saveAll()
     $payment->paymentdate = $paymentdate;
     $payment->customer_id = isset($customer_id) ? intval($customer_id) : intval(Orders::getCustomer($orderid));
     $payment->description = isset($payment_description) ? $payment_description : null;
     $save = $payment->trySave();
     if ($save) {
         Shineisp_Commons_Utilities::logs("Payments::addPayment(): save ok");
         // Confirm payment, if needed. Invoices::confirm() will activate order.
         if ($status) {
             self::confirm($orderid, $status);
         }
     }
     return $save;
 }