Package org.wso2.carbon.billing.core.dataobjects

Examples of org.wso2.carbon.billing.core.dataobjects.Subscription


        }
        List<Subscription> subscriptions = billingEngine.getActiveSubscriptions(customer);
        if (subscriptions == null || subscriptions.size() == 0) {
            return null;
        }
        Subscription subscription = subscriptions.get(0);
        if (subscription.getActiveUntil().getTime() <= System.currentTimeMillis()) {
            return null;
        }
        int itemId = subscription.getItem().getId();
        // fill with a correct item
        Item item =  billingEngine.getItem(itemId);
        subscription.setItem(item);
        return subscription;
    }
View Full Code Here


            throw new RegistryException(msg, e);
        }
        if (subscriptions == null || subscriptions.size() == 0) {
            return null;
        }
        Subscription subscription = subscriptions.get(0);
        if (subscription.getActiveUntil().getTime() <= System.currentTimeMillis()) {
            return null;
        }
        int itemId = subscription.getItem().getId();
        // fill with a correct item
        Item item;
        try {
            item = billingEngine.getItem(itemId);
        } catch (BillingException e) {
            String msg = "Error in getting the item for item id: " + itemId + ".";
            log.error(msg, e);
            throw new RegistryException(msg, e);
        }
        subscription.setItem(item);
        return subscription;
    }
View Full Code Here

                    "Error in retrieving the current billing package. The package info is null.";
            log.error(msg);
            throw new RegistryException(msg);
        }
        List<MultitenancyPackage> multitenancyPackages = mtBillingInfo.getMultitenancyPackages();
        Subscription subscription = getCurrentSubscription(tenantId);
        Item currentPackage;
        if (subscription == null) {
            currentPackage = null;
        } else {
            currentPackage = subscription.getItem();
        }
        MultitenancyPackage currentMultitenancyPackage = null;
        for (MultitenancyPackage multitenancyPackage : multitenancyPackages) {
            if (multitenancyPackage.getName().toLowerCase().contains("free") &&
                currentPackage == null) {
View Full Code Here

        customer.setEmail(tenantBean.getEmail());
        customer.setStartedDate(tenantBean.getCreatedDate().getTime());
        customer.setFullName(tenantBean.getFirstname()+" "+tenantBean.getLastname());

        customer.setId(tenantBean.getTenantId());
        Subscription subscription=new Subscription();
        subscription.setCustomer(customer);
        subscription.setActive(false);
        subscription.setActiveSince(Calendar.getInstance().getTime());
        Item item=new Item();
        subscription.setItem(item);
        String planName=tenantBean.getUsagePlan();
        subscription.setSubscriptionPlan(planName);
        int subscriptionId = 0;
        try {
            BillingDataAccessService dataAccessService = new BillingDataAccessService();
            subscriptionId = dataAccessService.addSubscription(subscription);
        } catch (Exception e) {
View Full Code Here

            return false;
        }
    }

    public static Subscription getActiveUsagePlan(int tenantId) throws Exception {
        Subscription subscription;
        try{
            BillingDataAccessService billingDataAccessService = new BillingDataAccessService();
            subscription = billingDataAccessService.getActiveSubscriptionOfCustomer(tenantId);
        }catch (Exception e){
            String msg = "Error occurred while getting the usage plan for tenant: " + tenantId + " " + e.getMessage();
View Full Code Here

    public static void updateUsagePlan(TenantInfoBean infoBean) throws Exception{
        String usagePlan = infoBean.getUsagePlan();
        try{
            BillingDataAccessService billingDataAccessService = new BillingDataAccessService();
            Subscription currentSubscription = billingDataAccessService.getActiveSubscriptionOfCustomer(infoBean.getTenantId());
            if(currentSubscription != null && currentSubscription.getSubscriptionPlan() != null){
                if(!currentSubscription.getSubscriptionPlan().equals(usagePlan)){
                    boolean updated = billingDataAccessService.changeSubscription(infoBean.getTenantId(), usagePlan);
                    if(updated){
                        log.debug("Usage plan was changed successfully from " + currentSubscription.getSubscriptionPlan() +
                                " to " + usagePlan);
                    }else{
                        log.debug("Usage plan was not changed");
                    }
                }
View Full Code Here

    }

    public static void activateUsagePlan(int tenantId) throws Exception {
        try{
            BillingDataAccessService dataAccessService = new BillingDataAccessService();
            Subscription subscription = dataAccessService.getActiveSubscriptionOfCustomer(tenantId);
            if(subscription!=null){
                String msg = "Cant activate subscription for tenant: " + tenantId +
                            ". An active subscription already exists";
                log.info(msg);
            }else{
                Subscription[] inactiveSubscriptions = dataAccessService.getInactiveSubscriptionsOfCustomer(tenantId);
                if(inactiveSubscriptions.length>0){
                    //I am doing this assuming that there wont be more than one subscription for a tenant
                    //at the time of activation. Logically it cant be.
                    subscription = inactiveSubscriptions[0];
                    boolean activated = dataAccessService.activateSubscription(subscription.getId());
                    if(activated){
                        log.debug("Subscription was activated for tenant: " + tenantId);
                    }
                }
            }
View Full Code Here

                TenantMgtServiceComponent.getRealmService(), tenant, tenantId));
        bean.setLastname(ClaimsMgtUtil.getLastNamefromUserStoreManager(
                TenantMgtServiceComponent.getRealmService(), tenant, tenantId));

        //getting the subscription plan
        Subscription subscription = TenantMgtUtil.getActiveUsagePlan(tenantId);
        if(subscription!=null){
            bean.setUsagePlan(subscription.getSubscriptionPlan());
        }else{
            bean.setUsagePlan("");
        }

        return bean;
View Full Code Here

        return customers;
    }

    public Subscription getSubscription (int subscriptionId) throws BillingException {
        boolean successful = false;
        Subscription subscription = null;
        try {
            dataAccessObject.beginTransaction();
            subscription = dataAccessObject.getSubscription(subscriptionId);
            successful = true;
        } finally {
View Full Code Here

        return subscription;
    }

    public Subscription getActiveSubscriptionOfCustomer(int customerId) throws BillingException {
        boolean successful = false;
        Subscription subscription;
        try {
            dataAccessObject.beginTransaction();
            subscription =
                    dataAccessObject.getActiveSubscriptionOfCustomer(customerId);
            successful = true;
View Full Code Here

TOP

Related Classes of org.wso2.carbon.billing.core.dataobjects.Subscription

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.