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{