public Invoice getInvoice() { if (invoice != null && invoice.getCreatedAt() == null) { invoice = fetch(invoice, Invoice.class); } return invoice; }
/** * Fetches the original invoice if the href is populated, otherwise return the current original invoice. * * @return fully loaded original invoice */ public Invoice getOriginalInvoice() { if (originalInvoice != null && originalInvoice.getHref() != null && !originalInvoice.getHref().isEmpty()) { originalInvoice = fetch(originalInvoice, Invoice.class); } return originalInvoice; }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (subscriptionIds != null ? subscriptionIds.hashCode() : 0); result = 31 * result + (subscriptionId != null ? subscriptionId.hashCode() : 0); result = 31 * result + (invoiceNumberPrefix != null ? invoiceNumberPrefix.hashCode() : 0); result = 31 * result + (date != null ? date.hashCode() : 0); result = 31 * result + (closedAt != null ? closedAt.hashCode() : 0); return result; } }
@Test(groups = "fast") public void testGetId() throws Exception { final Invoice invoice = new Invoice(); Assert.assertNull(invoice.getId()); invoice.setInvoiceNumber(9999); Assert.assertEquals(invoice.getId(), "9999"); invoice.setInvoiceNumberPrefix("FR"); Assert.assertEquals(invoice.getId(), "FR9999"); }
Assert.assertEquals(invoice.getAccount().getHref(), "https://api.recurly.com/v2/accounts/1"); Assert.assertTrue(invoice.hasOriginalInvoices()); Assert.assertEquals(invoice.getUuid(), "421f7b7d414e4c6792938e7c49d552e9"); Assert.assertEquals(invoice.getState(), "open"); Assert.assertEquals((int) invoice.getInvoiceNumber(), 1402); Assert.assertEquals(invoice.getPoNumber(), "abc-123"); Assert.assertEquals(invoice.getVatReverseChargeNotes(), "Some reverse charge notes"); Assert.assertEquals(invoice.getCustomerNotes(), "Some notes"); Assert.assertEquals(invoice.getTermsAndConditions(), "t and c"); Assert.assertEquals((int) invoice.getNetTerms(), 0); Assert.assertNull(invoice.getVatNumber()); Assert.assertEquals(invoice.getGatewayCode(), "Some Gateway Code"); Assert.assertEquals((int) invoice.getSubtotalInCents(), 9900); Assert.assertEquals((int) invoice.getTaxInCents(), 0); Assert.assertEquals((int) invoice.getTotalInCents(), 9900); Assert.assertEquals(invoice.getCurrency(), "USD"); Assert.assertEquals(invoice.getTaxType(), "usst"); Assert.assertEquals(invoice.getTaxRegion(), "CA"); Assert.assertEquals(invoice.getTaxRate(), new BigDecimal("0.0875")); Assert.assertEquals(invoice.getCreatedAt(), new DateTime("2011-08-25T12:00:00Z")); Assert.assertEquals(invoice.getUpdatedAt(), new DateTime("2011-08-25T12:00:00Z")); Assert.assertEquals(invoice.getClosedAt(), new DateTime("2011-08-25T12:00:00Z")); Assert.assertNotNull(invoice.getLineItems()); Assert.assertEquals(invoice.getLineItems().size(), 1); Assert.assertEquals(invoice.getInvoiceNumberPrefix(), "FR"); Assert.assertEquals(invoice.getId(), "FR1402"); final Adjustment adjustment = invoice.getLineItems().get(0); Assert.assertEquals(adjustment.getDescription(), "Charge for extra bandwidth");
final Invoice invoice = new Invoice(); invoice.setAccount(createRandomAccount(seed)); invoice.setUuid(randomAlphaNumericString(20, seed)); invoice.setState("open"); invoice.setInvoiceNumber(randomInteger(10000, seed)); invoice.setPoNumber(randomNumericString(5, seed)); invoice.setVatNumber(randomAlphaNumericString(5, seed)); invoice.setSubtotalInCents(randomInteger(1000, seed)); invoice.setTaxInCents(randomInteger(1000, seed)); invoice.setTotalInCents(randomInteger(1000, seed)); invoice.setCurrency(randomCurrency(seed)); invoice.setCreatedAt(NOW); invoice.setCollectionMethod("credit_card"); invoice.setNetTerms(randomInteger(100, seed)); invoice.setCustomerNotes("Customer Notes " + randomAlphaString(20, seed)); invoice.setTermsAndConditions("Terms and Conditions " + randomAlphaString(20, seed)); invoice.setVatReverseChargeNotes("VAT Reverse Charge Notes " + randomAlphaString(20, seed)); adjustments.add(createRandomAdjustment(seed + i)); invoice.setLineItems(adjustments); transactions.add(createRandomTransaction(seed + i)); invoice.setTransactions(transactions);
Assert.assertEquals(invoice.getAccount().getHref(), "https://api.recurly.com/v2/accounts/1"); Assert.assertEquals(invoice.getUuid(), "421f7b7d414e4c6792938e7c49d552e9"); Assert.assertEquals(invoice.getState(), "open"); Assert.assertEquals((int) invoice.getInvoiceNumber(), 1005); Assert.assertEquals(invoice.getPoNumber(), "abc-123"); Assert.assertNull(invoice.getVatNumber()); Assert.assertEquals((int) invoice.getSubtotalInCents(), 1200); Assert.assertEquals((int) invoice.getTaxInCents(), 0); Assert.assertEquals((int) invoice.getTotalInCents(), 1200); Assert.assertEquals(invoice.getCurrency(), "USD"); Assert.assertEquals(invoice.getCreatedAt(), new DateTime("2011-08-25T12:00:00Z")); Assert.assertNotNull(invoice.getLineItems()); Assert.assertEquals(invoice.getLineItems().size(), 1); Assert.assertEquals(invoice.getTransactions().size(), 0); Assert.assertEquals(invoice.getAttemptNextCollectionAt(), new DateTime("2017-08-31T00:00:00Z")); Assert.assertEquals(invoice.getRecoveryReason(), "Reason"); Assert.assertNull(invoice.getTaxType());
final Invoice invoiceData = new Invoice(); invoiceData.setCollectionMethod("automatic"); Assert.assertEquals(invoice.getTotalInCents(), new Integer(200)); Invoice updatedInvoice = new Invoice(); updatedInvoice.setAddress(address); updatedInvoice.setPoNumber("9876"); updatedInvoice.setTermsAndConditions("T&C"); updatedInvoice.setCustomerNotes("Some notes"); recurlyClient.updateInvoice(invoice.getId(), updatedInvoice); refundOptions.setExternalRefund(true); refundOptions.setPaymentMethod("credit_card"); final Invoice refundInvoice = recurlyClient.refundInvoice(invoice.getId(), refundOptions); Assert.assertEquals(refundInvoice.getTotalInCents(), new Integer(-100)); Assert.assertEquals(refundInvoice.getSubtotalInCents(), new Integer(-100)); Assert.assertEquals(refundInvoice.getTransactions().get(0).getAction(), "refund"); final Invoices originalInvoices = recurlyClient.getOriginalInvoices(refundInvoice.getId()); Assert.assertEquals(originalInvoices.get(0).getId(), invoice.getId()); } finally { recurlyClient.closeAccount(accountData.getAccountCode());
final Invoice invoiceData = new Invoice(); invoiceData.setCollectionMethod("manual"); invoiceData.setLineItems(null); final Invoice invoice = recurlyClient.postAccountInvoice(accountData.getAccountCode(), invoiceData).getChargeInvoice(); Assert.assertNotNull(invoice); InputStream pdfInputStream = recurlyClient.getInvoicePdf(invoice.getId()); Assert.assertNotNull(pdfInputStream); Assert.assertTrue(pdfString.contains("Invoice # " + invoice.getId())); Assert.assertTrue(pdfString.contains("Subtotal $" + 1.5)); final Invoice closedInvoice = recurlyClient.markInvoiceSuccessful(invoice.getId()); Assert.assertEquals(closedInvoice.getState(), "paid", "Invoice not closed successfully");
final Invoice invoiceData = new Invoice(); invoiceData.setCollectionMethod("automatic"); Assert.assertEquals(invoice.getTotalInCents(), new Integer(200)); invoice = recurlyClient.getInvoice(invoice.getId()); final AdjustmentRefund adjustmentRefund = invoice.getLineItems().get(0).toAdjustmentRefund(); refundOptions.setRefundMethod(RefundMethod.transaction_first); refundOptions.setLineItems(lineItems); final Invoice refundInvoice = recurlyClient.refundInvoice(invoice.getId(), refundOptions); Assert.assertEquals(refundInvoice.getTotalInCents(), new Integer(-100)); Assert.assertEquals(refundInvoice.getSubtotalInCents(), new Integer(-100)); Assert.assertEquals(refundInvoice.getTransactions().get(0).getAction(), "refund"); Assert.assertEquals(refundInvoice.getLineItems().size(), 1); final Adjustment lineItem = refundInvoice.getLineItems().get(0); Assert.assertEquals(lineItem.getQuantity(), new Integer(1)); } finally {
Assert.assertEquals(found.getInvoice().getAccount().getAccountCode(), accountData.getAccountCode()); Assert.assertEquals(found.getInvoice().getAccount().getFirstName(), accountData.getFirstName()); Assert.assertEquals(found.getInvoice().getTotalInCents(), (Integer) 15); Assert.assertEquals(found.getInvoice().getCurrency(), CURRENCY); Assert.assertEquals(invoices.get(0).getTotalInCents(), t.getAmountInCents(), "Amount in cents is not the same"); Assert.assertEquals(invoices.get(1).getTotalInCents(), subscriptionData.getUnitAmountInCents(), "Amount in cents is not the same"); } finally {
/** * For use with RecurlyClient.getOriginalInvoices(). Check if an invoice had an <original_invoices> link * in the XML from the API. * * @return true if there are original invoices associated with this invoice */ public Boolean hasOriginalInvoices() { return originalInvoices != null && originalInvoices.getHref() != null && !originalInvoices.getHref().isEmpty(); }
final Invoice invoiceData = new Invoice(); invoiceData.setLineItems(null); final InvoiceCollection collection = recurlyClient.postAccountInvoice(accountData.getAccountCode(), invoiceData); Assert.assertNotNull(collection.getChargeInvoice()); final Invoice failInvoiceData = new Invoice(); failInvoiceData.setLineItems(null); final Invoice invoiceFail = recurlyClient.postAccountInvoice(accountData.getAccountCode(), failInvoiceData).getChargeInvoice(); Assert.assertNotNull(invoiceFail);
public void setDueOn(final Object dueOn) { this.dueOn = dateTimeOrNull(dueOn); }
@Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final InvoiceCollection collection = (InvoiceCollection) o; if (chargeInvoice != null ? !chargeInvoice.equals(collection.chargeInvoice) : collection.chargeInvoice != null) { return false; } if (creditInvoices != null ? !creditInvoices.equals(collection.creditInvoices) : collection.creditInvoices != null) { return false; } return true; }
public void setTaxRate(final Object taxRate) { this.taxRate = bigDecimalOrNull(taxRate); }
public Account getAccount() { if (account != null && account.getCreatedAt() == null) { account = fetch(account, Account.class); } return account; }
Assert.assertEquals(invoice.getAccount().getHref(), "https://api.recurly.com/v2/accounts/1"); Assert.assertTrue(invoice.hasOriginalInvoices()); Assert.assertEquals(invoice.getUuid(), "421f7b7d414e4c6792938e7c49d552e9"); Assert.assertEquals(invoice.getState(), "open"); Assert.assertEquals((int) invoice.getInvoiceNumber(), 1402); Assert.assertEquals(invoice.getPoNumber(), "abc-123"); Assert.assertEquals(invoice.getVatReverseChargeNotes(), "Some reverse charge notes"); Assert.assertEquals(invoice.getCustomerNotes(), "Some notes"); Assert.assertEquals(invoice.getTermsAndConditions(), "t and c"); Assert.assertEquals((int) invoice.getNetTerms(), 0); Assert.assertNull(invoice.getVatNumber()); Assert.assertEquals(invoice.getGatewayCode(), "Some Gateway Code"); Assert.assertEquals((int) invoice.getSubtotalInCents(), 9900); Assert.assertEquals((int) invoice.getTaxInCents(), 0); Assert.assertEquals((int) invoice.getTotalInCents(), 9900); Assert.assertEquals(invoice.getCurrency(), "USD"); Assert.assertEquals(invoice.getTaxType(), "usst"); Assert.assertEquals(invoice.getTaxRegion(), "CA"); Assert.assertEquals(invoice.getTaxRate(), new BigDecimal("0.0875")); Assert.assertEquals(invoice.getCreatedAt(), new DateTime("2011-08-25T12:00:00Z")); Assert.assertEquals(invoice.getUpdatedAt(), new DateTime("2011-08-25T12:00:00Z")); Assert.assertEquals(invoice.getClosedAt(), new DateTime("2011-08-25T12:00:00Z")); Assert.assertNotNull(invoice.getLineItems()); Assert.assertEquals(invoice.getLineItems().size(), 1); Assert.assertEquals(invoice.getInvoiceNumberPrefix(), "FR"); Assert.assertEquals(invoice.getId(), "FR1402"); final Adjustment adjustment = invoice.getLineItems().get(0); Assert.assertEquals(adjustment.getDescription(), "Charge for extra bandwidth");
final Invoice invoice = new Invoice(); invoice.setAccount(createRandomAccount(seed)); invoice.setUuid(randomAlphaNumericString(20, seed)); invoice.setState("open"); invoice.setInvoiceNumber(randomInteger(10000, seed)); invoice.setPoNumber(randomNumericString(5, seed)); invoice.setVatNumber(randomAlphaNumericString(5, seed)); invoice.setSubtotalInCents(randomInteger(1000, seed)); invoice.setTaxInCents(randomInteger(1000, seed)); invoice.setTotalInCents(randomInteger(1000, seed)); invoice.setCurrency(randomCurrency(seed)); invoice.setCreatedAt(NOW); invoice.setCollectionMethod("credit_card"); invoice.setNetTerms(randomInteger(100, seed)); invoice.setCustomerNotes("Customer Notes " + randomAlphaString(20, seed)); invoice.setTermsAndConditions("Terms and Conditions " + randomAlphaString(20, seed)); invoice.setVatReverseChargeNotes("VAT Reverse Charge Notes " + randomAlphaString(20, seed)); adjustments.add(createRandomAdjustment(seed + i)); invoice.setLineItems(adjustments); transactions.add(createRandomTransaction(seed + i)); invoice.setTransactions(transactions);