Examples of BillingEngine


Examples of org.wso2.carbon.billing.core.BillingEngine

        }
    }

    public static void addSubscriptionInfo(SubscriptionInfoBean subscriptionInfoBean,
                                           UserRegistry userRegistry) throws Exception {
        BillingEngine billingEngine = billingManager.getBillingEngine(StratosConstants.MULTITENANCY_SCHEDULED_TASK_ID);

        Customer customer = getCurrentCustomer(userRegistry);
        // if customer doesn't exist, we are making a one
        if (customer == null) {
            int currentTenantId = userRegistry.getTenantId();
            TenantManager tenantManger = getRealmService().getTenantManager();
            Tenant currentTenant = (Tenant) tenantManger.getTenant(currentTenantId);
            if (currentTenant == null || currentTenant.getDomain() == null) {
                String msg = "Error in getting the customer information.";
                throw new Exception(msg);
            }
            customer = new Customer();
            customer.setName(currentTenant.getDomain());
            customer.setEmail(currentTenant.getEmail());
            customer.setStartedDate(new Date());

            billingEngine.addCustomer(customer);
        }

        String itemName = subscriptionInfoBean.getPackageName();
        if (itemName.toLowerCase().contains("free")) {
            return; //nothing to upgrade in a free package
        }
        List<Item> items = billingManager.getBillingEngine(StratosConstants.MULTITENANCY_SCHEDULED_TASK_ID).
                getItemsWithName(itemName);
        if (items == null || items.size() == 0) {
            String msg = "Invalid item name: " + itemName + ".";
            throw new Exception(msg);
        }
        Item item = items.get(0);

        // adding the subscription
        Subscription subscription = new Subscription();
        subscription.setItem(item);
        subscription.setCustomer(customer);
        subscription.setActive(true);
        subscription.setActiveSince(subscriptionInfoBean.getActiveSince());
        subscription.setActiveUntil(subscriptionInfoBean.getActiveUntil());

        billingEngine.addSubscription(subscription);
    }
View Full Code Here

Examples of org.wso2.carbon.billing.core.BillingEngine

        billingEngine.addSubscription(subscription);
    }

    public static Subscription getCurrentSubscription(UserRegistry userRegistry) throws Exception {
        BillingEngine billingEngine = billingManager.getBillingEngine(StratosConstants.MULTITENANCY_SCHEDULED_TASK_ID);

        Customer customer = getCurrentCustomer(userRegistry);
        if (customer == null) {
            return null;
        }
        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

Examples of org.wso2.carbon.billing.core.BillingEngine

    public static Customer getCurrentCustomer(UserRegistry userRegistry) throws Exception {
        int currentTenantId = userRegistry.getTenantId();
        TenantManager tenantManger = getRealmService().getTenantManager();
        Tenant currentTenant = (Tenant) tenantManger.getTenant(currentTenantId);
        BillingEngine billingEngine =
                billingManager.getBillingEngine(StratosConstants.MULTITENANCY_SCHEDULED_TASK_ID);
        List<Customer> customers = billingEngine.getCustomersWithName(currentTenant.getDomain());
        if (customers == null || customers.size() == 0) {
            return null;
        }
        return customers.get(0);
    }
View Full Code Here

Examples of org.wso2.carbon.billing.core.BillingEngine

        if (tenant == null) {
            return null;
        }
        String customerName = tenant.getDomain();

        BillingEngine billingEngine =
                billingManager.getBillingEngine(StratosConstants.MULTITENANCY_SCHEDULED_TASK_ID);
        Customer customer;
        try {
            List<Customer> customers = billingEngine.getCustomersWithName(customerName);
            if (customers == null || customers.size() == 0) {
                customer = null;
            } else {
                customer = customers.get(0);
            }
View Full Code Here

Examples of org.wso2.carbon.billing.core.BillingEngine

     * @param tenantId, tenant id
     * @throws RegistryException, if getting the current subscription type failed.
     * @return, Subscripiton
     */
    public static Subscription getCurrentSubscription(int tenantId) throws RegistryException {
        BillingEngine billingEngine =
                billingManager.getBillingEngine(StratosConstants.MULTITENANCY_SCHEDULED_TASK_ID);

        Customer customer = getCurrentBillingCustomer(tenantId);
        if (customer == null) {
            return null;
        }
        List<Subscription> subscriptions;
        try {
            subscriptions = billingEngine.getActiveSubscriptions(customer);
        } catch (BillingException e) {
            String msg = "Error in getting the current subscription.";
            log.error(msg, e);
            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);
        }
View Full Code Here

Examples of org.wso2.carbon.billing.core.BillingEngine

        }
        if (tenant == null) {
            return null;
        }
        String customerName = tenant.getDomain();
        BillingEngine billingEngine =
                billingManager.getBillingEngine(StratosConstants.MULTITENANCY_VIEWING_TASK_ID);
        Customer customer;
        try {
            if (billingEngine != null) {
                List<Customer> customers = billingEngine.getCustomersWithName(customerName);
                if (customers == null || customers.size() == 0) {
                    customer = null;
                } else {
                    customer = customers.get(0);
                }
View Full Code Here

Examples of org.wso2.carbon.billing.core.BillingEngine

     * @param tenantId, tenant id
     * @throws RegistryException, if getting the current subscription type failed.
     * @return, Subscripiton
     */
    public static Subscription getCurrentSubscription(int tenantId) throws RegistryException {
        BillingEngine billingEngine =
                billingManager.getBillingEngine(StratosConstants.MULTITENANCY_SCHEDULED_TASK_ID);

        Customer customer = getCurrentBillingCustomer(tenantId);
        if (customer == null) {
            return null;
        }
        List<Subscription> subscriptions;
        try {
            subscriptions = billingEngine.getActiveSubscriptions(customer);
        } catch (BillingException e) {
            String msg = "Error in getting the current subscription.";
            log.error(msg, e);
            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);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.