/**
  * This function will run all applicable cron on recurring entity
  * @return array|bool
  */
 public function runCron($cron = 'All')
 {
     $recurring_order = array();
     $return_value = array();
     module_load_include('inc', 'commerce_recurring', 'commerce_recurring.rules');
     module_load_include('inc', 'mp_order', 'mp_order.rules');
     module_load_include('inc', 'mp_upgrade', 'mp_upgrade.rules');
     // Create Order Based on recurring entity due date
     $recurring_entity = $this->getEntity();
     if (in_array($cron, array('All', 'create_order'))) {
         $due_entities = commerce_recurring_rules_get_due_items();
         $entity_array = array();
         foreach ($due_entities['commerce_recurring_entities'] as $entity_key => $entity) {
             $entity_array[$entity->id] = $entity;
         }
         if (array_key_exists($this->getId(), $entity_array)) {
             // Passing recurring entity and create order
             $recurring_order = commerce_recurring_rules_generate_order_from_recurring($recurring_entity);
             if (!empty($recurring_order) && isset($recurring_order['commerce_order'])) {
                 $return_value['commerce_order'] = $recurring_order['commerce_order'];
                 global $entities;
                 $order = new CommerceOrder($recurring_order['commerce_order']->order_id);
                 $order->reload();
                 $entities['commerce_order'][$order->getId()] = $order;
                 mp_order_update_order_with_store_credit($recurring_order['commerce_order']);
                 mp_subscription_rules_action_update_recurring_billing_due_date($recurring_order['commerce_order']);
                 // Attaching order with recurring entity
             }
         }
     }
     //Payment and Order Status of Above Created Order
     if (in_array($cron, array('All', 'pending_payment'))) {
         $orders = $this->getCommerceRecurringOrderValues();
         foreach ($orders as $associated_oder) {
             $order = new CommerceOrder($associated_oder['target_id']);
             if ($order->getStatusValues() == 'recurring_pending') {
                 $card_response = commerce_cardonfile_rules_action_order_select_default_card($order->getEntity());
                 $total = $order->getFieldItems('commerce_order_total');
                 $charge_response = commerce_cardonfile_rules_action_order_charge_card($order->getEntity(), $total[0], $card_response['select_card_response']);
                 $return_value['charge_response'] = $charge_response;
             }
         }
     }
     //Upgrade Yearly Plan
     if (in_array($cron, array('All', 'upgrade'))) {
         $recurring_entities = mp_upgrade_rules_action_get_upgraded_items();
         if (array_key_exists($this->getId(), $recurring_entities['commerce_recurring_entities'])) {
             mp_upgrade_rules_action_upgrade_recurring_license($this->getEntity());
         }
     }
     return new Response(TRUE, $return_value, NULL);
 }
 /**
  * This function will process payment for pending orders
  * @return array|bool
  */
 public static function runCron($order, $check_pass = FALSE)
 {
     module_load_include('inc', 'commerce_recurring', 'commerce_recurring.rules');
     module_load_include('inc', 'mp_order', 'mp_order.rules');
     if ($check_pass == FALSE) {
         $payment_method = commerce_payment_method_instance_load('commerce_stripe|commerce_payment_commerce_stripe');
         $card_details = commerce_cardonfile_load_multiple_by_uid($order->uid, $payment_method['instance_id'], TRUE);
         foreach ($card_details as $key) {
             $card_data = commerce_cardonfile_load($key->card_id);
             $card_data->remote_id = '';
             commerce_cardonfile_save($card_data);
         }
     }
     $card_response = commerce_cardonfile_rules_action_order_select_default_card($order);
     $order_total = field_get_items('commerce_order', $order, 'commerce_order_total');
     $response = commerce_cardonfile_rules_action_order_charge_card($order, $order_total[0], $card_response['select_card_response']);
     return new Response(TRUE, $response, "");
 }