def upgrade_plan(self, shop_id, plan_config_id, charge_id):
        """
            Upgrades the plan for the current [shop_id] using the [plan_config_id].
            It also saved the [charge_id] on the plan model.
        """
        shop_model = self.get(id=shop_id)
        plan_config = PlanConfigService().get(id=plan_config_id)

        api_object = "application_charge" if plan_config.billing_type == "O" else "recurring_application_charge"
        charge = self.find_app_charge(api_object, shop_model, charge_id)

        if charge["status"] == "accepted":
            self.activate_charge(api_object, shop_model, charge["id"])
        elif charge["status"] == "declined":
            return False

        #Check if the charge is already activated
        charge = self.find_app_charge(api_object, shop_model, charge_id)

        if charge["status"] == "active":

            plan = PlanService().new(shop=shop_model)

            #copies all the attributes from the plan_config to the plan model
            for field in plan_config.update_fields():
                setattr(plan, field, getattr(plan_config, field, ""))

            plan.charge_id = charge_id
            plan.installed_at = datetime.utcnow()
            plan.save()
        else:
            return False

        return True
    def get_config(self):
        """
            Gets the config object.
            Created a new default config if it doesn't exists.
        """ 

        #lazy attribute
        if not "config" in self.__dict__:

            self.config = self.get_one(id=1)

            if self.config is None:

                self.config = self.new(id=1)

                if self.config.plan_config is None:

                    plan_config = PlanConfigService().new()
                    plan_config.save()

                    self.config.plan_config = plan_config

                self.config.save()

        return self.config