Examples of BillingEngine


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

        return getCurrentInvoiceOfCustomer(registry);
    }

    public int addPayment(Payment payment, String amount) throws Exception {
        BillingManager billingManager = Util.getBillingManager();
        BillingEngine billingEngine =
                billingManager.getBillingEngine(StratosConstants.MULTITENANCY_SCHEDULED_TASK_ID);
        Cash cashAmount = new Cash(amount);
        payment.setAmount(cashAmount);
        if(payment.getInvoice()!=null){
            payment.setSubscriptions(billingEngine.getInvoiceSubscriptions(payment.getInvoice().getId()));
        }
        int paymentId = billingEngine.addPayment(payment);
        if(paymentId>0){
            payment.setId(paymentId);
            sendPaymentReceivedEmail(payment);
        }
        return paymentId;
View Full Code Here

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

        return paymentId;
    }

    public PaginatedBalanceInfoBean getPaginatedBalances(int pageNumber) throws Exception {
        BillingManager billingManager = Util.getBillingManager();
        BillingEngine billingEngine =
                billingManager.getBillingEngine(StratosConstants.MULTITENANCY_SCHEDULED_TASK_ID);
        List<OutstandingBalanceInfoBean> balanceBeans = billingEngine.getAllOutstandingBalances(null); //no tenant domain
        PaginatedBalanceInfoBean paginatedBalanceBean = new PaginatedBalanceInfoBean();
        DataPaginator.doPaging(pageNumber, balanceBeans, paginatedBalanceBean);

        return paginatedBalanceBean;
    }
View Full Code Here

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

        return paginatedBalanceBean;
    }

    public OutstandingBalanceInfoBean[] getOutstandingBalance(String tenantDomain) throws Exception {
        BillingManager billingManager = Util.getBillingManager();
        BillingEngine billingEngine =
                billingManager.getBillingEngine(StratosConstants.MULTITENANCY_SCHEDULED_TASK_ID);
        List<OutstandingBalanceInfoBean> balanceBeans = billingEngine.getAllOutstandingBalanceInfoBeans(tenantDomain);
        return balanceBeans.toArray(new OutstandingBalanceInfoBean[balanceBeans.size()]);
    }
View Full Code Here

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

    }

    private MultitenancyInvoice getPastInvoiceById(UserRegistry registry,
                                               int invoiceId) throws Exception {
        BillingManager billingManager = Util.getBillingManager();
        BillingEngine billingEngine =
                billingManager.getBillingEngine(StratosConstants.MULTITENANCY_SCHEDULED_TASK_ID);

        Invoice invoice = billingEngine.getInvoice(invoiceId);
        if (invoice == null) {
            return null;
        }
       
        Customer customer = getCurrentCustomer(registry, billingEngine);
        if (customer == null || customer.getId() != invoice.getCustomer().getId()) {
            String msg = "Trying to looking at an invoice of another customer, customer: " +
                            (customer == null ? "unknown" : customer.getId()) + ", invoice: " +
                            invoice.getId() + ".";
            log.error(msg);
            throw new Exception(msg);
        }
       
        MultitenancyInvoice multitenancyInvoice = new MultitenancyInvoice();
        multitenancyInvoice.setInvoiceId(invoice.getId());
        multitenancyInvoice.setBillingDate(invoice.getDate());
        multitenancyInvoice.setBoughtForward(invoice.getBoughtForward().serializeToString());
        multitenancyInvoice.setCarriedForward(invoice.getCarriedForward().serializeToString());
        multitenancyInvoice.setStartDate(invoice.getStartDate());
        multitenancyInvoice.setEndDate(invoice.getEndDate());
        multitenancyInvoice.setTotalCost(invoice.getTotalCost().serializeToString());
        multitenancyInvoice.setTotalPayments(invoice.getTotalPayment().serializeToString());

        List<Subscription> subscriptions = invoice.getSubscriptions();
        MultitenancySubscription[] multitenancySubscriptions =
                new MultitenancySubscription[subscriptions.size()];
        for (int i = 0; i < subscriptions.size(); i++) {
            Subscription subscription = subscriptions.get(i);
            MultitenancySubscription multitenancySubscription = new MultitenancySubscription();
            multitenancySubscription.setSubscribedPackage(subscription.getItem().getName());
            multitenancySubscription.setActiveSince(subscription.getActiveSince());
            multitenancySubscription.setActiveUntil(subscription.getActiveUntil());
            multitenancySubscription.setActive(subscription.isActive());

            // now iterating the items
            List<Item> billedItems = billingEngine.getBilledItems(subscription);
            BilledEntry[] itemEntries = new BilledEntry[billedItems.size()];
            for (int j = 0; j < billedItems.size(); j++) {
                Item billedItem = billedItems.get(j);
                if (billedItem.getName().equals(multitenancySubscription.getSubscribedPackage())) {
                    // ignoring the parent item..
View Full Code Here

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

    private MultitenancyInvoice getCurrentInvoiceOfCustomer(UserRegistry registry) throws Exception {
        // we have to generate the invoice for this.
       

        BillingManager billingManager = Util.getBillingManager();
        BillingEngine billingEngineViewer =
                billingManager.getBillingEngine(StratosConstants.MULTITENANCY_VIEWING_TASK_ID);
        Customer customer = getCurrentCustomer(registry, billingEngineViewer);
        if (customer == null) {
            // no customer => no invoices
            return null;
        }
       
        BillingEngineContext billingEngineContext = new BillingEngineContext();
        billingEngineContext.setCustomer(customer);
        billingEngineViewer.generateBill(billingEngineContext);

        // reloading the customer with new updates
        customer = billingEngineContext.getCustomer();
        Invoice invoice = customer.getActiveInvoice();
View Full Code Here

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

        return customers.get(0);
    }

    private BillingPeriod[] getAvailableBillingPeriods(UserRegistry registry) throws Exception {
        BillingManager billingManager = Util.getBillingManager();
        BillingEngine billingEngine =
                billingManager.getBillingEngine(StratosConstants.MULTITENANCY_SCHEDULED_TASK_ID);
       
        Customer customer = getCurrentCustomer(registry, billingEngine);
        if (customer == null) {
            return new BillingPeriod[0];
        }
       
        List<Invoice> invoices = billingEngine.getInvoices(customer);
        if (invoices == null || invoices.size() == 0) {
            return new BillingPeriod[0];
        }
       
        BillingPeriod[] billingPeriods = new BillingPeriod[invoices.size()];
View Full Code Here

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

        return billingPeriods;
    }

    private void sendPaymentReceivedEmail(Payment payment) throws Exception{
        BillingManager billingManager = Util.getBillingManager();
        BillingEngine billingEngine =
                billingManager.getBillingEngine(StratosConstants.MULTITENANCY_SCHEDULED_TASK_ID);
        if(payment.getInvoice()!=null){
            Invoice invoice = billingEngine.getInvoice(payment.getInvoice().getId());
            if(invoice!=null){
                Customer customer = invoice.getCustomer();
                if(customer!=null){
                    Map<String, String> mailParameters = new HashMap<String, String>();
                    mailParameters.put("date",
                            new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(payment.getDate()));
                    mailParameters.put("transaction-id", payment.getDescription());
                    mailParameters.put("amount", payment.getAmount().toString());
                    mailParameters.put("invoice-id", String.valueOf(payment.getInvoice().getId()));

                    try{
                        TenantManager tenantManager = Util.getRealmService().getTenantManager();
                        Tenant tenant = (Tenant) tenantManager.getTenant(customer.getId());
                        String customerName =
                                ClaimsMgtUtil.getFirstName(Util.getRealmService(), tenant, customer.getId());
                        if(customerName!=null){
                            mailParameters.put("customer-name", customerName);
                        }else{
                            mailParameters.put("customer-name", "");
                        }

                    }catch(Exception e){
                        log.error("Could not get tenant information for tenant: " +
                                customer.getName() + "\n" + e.getMessage());
                        mailParameters.put("customer-name", "");
                    }

                    //sending the mail to the customer
                    billingEngine.sendPaymentReceivedEmail(
                            customer.getEmail(),
                            BillingConstants.PAYMENT_RECEIVED_EMAIL_CUSTOMER_FILE,
                            mailParameters);

                    String financeEmail = CommonUtil.getStratosConfig().getFinanceNotificationEmail();
                    //customer's first name is not important to finance team. Therefore it is
                    //being replace with the domain name
                    mailParameters.put("customer-name", customer.getName());
                    billingEngine.sendPaymentReceivedEmail(
                            financeEmail,
                            BillingConstants.PAYMENT_RECEIVED_EMAIL_WSO2_FILE,
                            mailParameters
                    );
                }else{
View Full Code Here

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

public class BillingJob implements Job {
    private static final Log log = LogFactory.getLog(BillingJob.class);

    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        // first we generate the bill
        BillingEngine billingEngine =
                (BillingEngine) jobExecutionContext.getMergedJobDataMap().get(
                        BillingConstants.BILLING_ENGINE_KEY);
        SchedulerContext schedulerContext =
                (SchedulerContext) jobExecutionContext.getMergedJobDataMap().get(
                        BillingConstants.SCHEDULER_CONTEXT);
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            long startTime = System.currentTimeMillis();
            log.info("Bill generation started at " + dateFormat.format(new Date(System.currentTimeMillis())));
            billingEngine.generateBill(schedulerContext);
            log.info("Bill generation completed at " + dateFormat.format(new Date(System.currentTimeMillis())));
            long timeTaken = System.currentTimeMillis() - startTime;
            log.info("Time taken for bill generation: " + timeTaken/1000 + "s");
        } catch (BillingException e) {
            String msg = "Error in generating the bill";
View Full Code Here

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

        return subscriptionInfoBean;
    }

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

        Subscription subscription = getCurrentSubscription(userRegistry);
        if (subscription == null) {
            // nothing to un-subscribe
            return;
        }
        // what we are doing here is, set the activeUntil to today and save it
        subscription.setActiveUntil(new Date());
        billingEngine.updateSubscription(subscription);
    }
View Full Code Here

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

        if (subscription != null && subscription.getItem() != null &&
                subscription.getItem().getName().equals(packageName)) {
            // then we are just extending (or just shortning) the subscription
            subscription.setActiveUntil(activeUntilDate);
            BillingEngine billingEngine =
                    billingManager.getBillingEngine(StratosConstants.MULTITENANCY_SCHEDULED_TASK_ID);

            billingEngine.updateSubscription(subscription);
        }
        else {
            cancelSubscriptionInfo(userRegistry);
            SubscriptionInfoBean subscriptionInfoBean = new SubscriptionInfoBean();
            subscriptionInfoBean.setActiveSince(new Date());
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.