Search in sources :

Example 1 with HtmlInvoice

use of org.killbill.billing.invoice.template.HtmlInvoice in project killbill by killbill.

the class TestHtmlInvoiceGenerator method testGenerateInvoice.

@Test(groups = "fast")
public void testGenerateInvoice() throws Exception {
    final HtmlInvoice output = g.generateInvoice(createAccount(), createInvoice(), false, internalCallContext);
    Assert.assertNotNull(output);
    Assert.assertNotNull(output.getBody());
    Assert.assertEquals(output.getSubject(), "Your invoice");
}
Also used : HtmlInvoice(org.killbill.billing.invoice.template.HtmlInvoice) Test(org.testng.annotations.Test)

Example 2 with HtmlInvoice

use of org.killbill.billing.invoice.template.HtmlInvoice in project killbill by killbill.

the class TestHtmlInvoiceGenerator method testGenerateNullInvoice.

@Test(groups = "fast")
public void testGenerateNullInvoice() throws Exception {
    final HtmlInvoice output = g.generateInvoice(createAccount(), null, false, internalCallContext);
    Assert.assertNull(output);
}
Also used : HtmlInvoice(org.killbill.billing.invoice.template.HtmlInvoice) Test(org.testng.annotations.Test)

Example 3 with HtmlInvoice

use of org.killbill.billing.invoice.template.HtmlInvoice in project killbill by killbill.

the class TestHtmlInvoiceGenerator method testGenerateEmptyInvoice.

@Test(groups = "fast")
public void testGenerateEmptyInvoice() throws Exception {
    final Invoice invoice = Mockito.mock(Invoice.class);
    final HtmlInvoice output = g.generateInvoice(createAccount(), invoice, false, internalCallContext);
    Assert.assertNotNull(output);
    Assert.assertNotNull(output.getBody());
    Assert.assertEquals(output.getSubject(), "Your invoice");
}
Also used : HtmlInvoice(org.killbill.billing.invoice.template.HtmlInvoice) Invoice(org.killbill.billing.invoice.api.Invoice) HtmlInvoice(org.killbill.billing.invoice.template.HtmlInvoice) Test(org.testng.annotations.Test)

Example 4 with HtmlInvoice

use of org.killbill.billing.invoice.template.HtmlInvoice in project killbill by killbill.

the class EmailInvoiceNotifier method notify.

@Override
public void notify(final Account account, final Invoice invoice, final TenantContext context) throws InvoiceApiException {
    if (Strings.emptyToNull(account.getEmail()) == null) {
        throw new InvoiceApiException(new IllegalArgumentException("Email for account " + account.getId() + " not specified"), ErrorCode.EMAIL_SENDING_FAILED);
    }
    final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(account.getId(), context);
    final List<String> to = new ArrayList<String>();
    to.add(account.getEmail());
    final List<AccountEmail> accountEmailList = accountApi.getEmails(account.getId(), internalTenantContext);
    final List<String> cc = new ArrayList<String>();
    for (final AccountEmail email : accountEmailList) {
        cc.add(email.getEmail());
    }
    // Check if this account has the MANUAL_PAY system tag
    boolean manualPay = false;
    final List<Tag> accountTags = tagUserApi.getTags(account.getId(), ObjectType.ACCOUNT, internalTenantContext);
    for (final Tag tag : accountTags) {
        if (ControlTagType.MANUAL_PAY.getId().equals(tag.getTagDefinitionId())) {
            manualPay = true;
            break;
        }
    }
    final HtmlInvoice htmlInvoice;
    try {
        htmlInvoice = generator.generateInvoice(account, invoice, manualPay, internalTenantContext);
    } catch (final IOException e) {
        throw new InvoiceApiException(e, ErrorCode.EMAIL_SENDING_FAILED);
    }
    // take localized subject, or the configured one if the localized one is not available
    String subject = htmlInvoice.getSubject();
    if (subject == null) {
        subject = config.getInvoiceEmailSubject();
    }
    final EmailSender sender = new DefaultEmailSender(config);
    try {
        sender.sendHTMLEmail(to, cc, subject, htmlInvoice.getBody());
    } catch (final EmailApiException e) {
        throw new InvoiceApiException(e, ErrorCode.EMAIL_SENDING_FAILED);
    } catch (final IOException e) {
        throw new InvoiceApiException(e, ErrorCode.EMAIL_SENDING_FAILED);
    }
}
Also used : EmailApiException(org.killbill.billing.util.email.EmailApiException) ArrayList(java.util.ArrayList) AccountEmail(org.killbill.billing.account.api.AccountEmail) HtmlInvoice(org.killbill.billing.invoice.template.HtmlInvoice) DefaultEmailSender(org.killbill.billing.util.email.DefaultEmailSender) EmailSender(org.killbill.billing.util.email.EmailSender) IOException(java.io.IOException) DefaultEmailSender(org.killbill.billing.util.email.DefaultEmailSender) InvoiceApiException(org.killbill.billing.invoice.api.InvoiceApiException) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) Tag(org.killbill.billing.util.tag.Tag)

Example 5 with HtmlInvoice

use of org.killbill.billing.invoice.template.HtmlInvoice in project killbill by killbill.

the class DefaultInvoiceUserApi method getInvoiceAsHTML.

@Override
public String getInvoiceAsHTML(final UUID invoiceId, final TenantContext context) throws AccountApiException, IOException, InvoiceApiException {
    final Invoice invoice = getInvoice(invoiceId, context);
    if (invoice == null) {
        throw new InvoiceApiException(ErrorCode.INVOICE_NOT_FOUND, invoiceId);
    }
    final InternalTenantContext internalContext = internalCallContextFactory.createInternalTenantContext(invoiceId, ObjectType.INVOICE, context);
    final Account account = accountUserApi.getAccountById(invoice.getAccountId(), internalContext);
    // Check if this account has the MANUAL_PAY system tag
    boolean manualPay = false;
    final List<Tag> accountTags = tagApi.getTags(account.getId(), ObjectType.ACCOUNT, internalContext);
    for (final Tag tag : accountTags) {
        if (ControlTagType.MANUAL_PAY.getId().equals(tag.getTagDefinitionId())) {
            manualPay = true;
            break;
        }
    }
    final HtmlInvoice htmlInvoice = generator.generateInvoice(account, invoice, manualPay, internalContext);
    return htmlInvoice.getBody();
}
Also used : Account(org.killbill.billing.account.api.Account) InvoiceApiException(org.killbill.billing.invoice.api.InvoiceApiException) Invoice(org.killbill.billing.invoice.api.Invoice) HtmlInvoice(org.killbill.billing.invoice.template.HtmlInvoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) HtmlInvoice(org.killbill.billing.invoice.template.HtmlInvoice) Tag(org.killbill.billing.util.tag.Tag)

Aggregations

HtmlInvoice (org.killbill.billing.invoice.template.HtmlInvoice)5 Test (org.testng.annotations.Test)3 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)2 Invoice (org.killbill.billing.invoice.api.Invoice)2 InvoiceApiException (org.killbill.billing.invoice.api.InvoiceApiException)2 Tag (org.killbill.billing.util.tag.Tag)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Account (org.killbill.billing.account.api.Account)1 AccountEmail (org.killbill.billing.account.api.AccountEmail)1 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)1 DefaultEmailSender (org.killbill.billing.util.email.DefaultEmailSender)1 EmailApiException (org.killbill.billing.util.email.EmailApiException)1 EmailSender (org.killbill.billing.util.email.EmailSender)1