/** * Attempts to update the specified invoice entry in the associated FreeAgent account. * * @param invoice The populated Invoice instance. * @return True if the invoice has been updated successfully, otherwise false. */ public boolean updateInvoice(FreeAgentInvoice invoice) { if (invoice != null) { String invoiceId = extractIdentifier(invoice.getUrl()); if (invoiceId != null && !invoiceId.isEmpty()) { Response response = freeAgentServiceInstance.updateInvoice(new FreeAgentInvoiceWrapper(invoice), invoiceId); if (response.getStatus() == 200) { invoice.setUpdatedAt(dateFormat.format(new Date())); return true; } else { return false; } } } return false; }
/** * Attempts to import a new invoice into the associated FreeAgent account by deserialising the * specified JSON invoice information and requesting a new invoice be created. * * <p>NOTE: The import (creation within FreeAgent) will only be actioned if no URL property is * present or if the URL property is not populated. Otherwise null will be returned. * * @param invoiceJSON A string containing invoice information in FreeAgent friendly format. * @return The newly populated invoice instance that has been imported into FreeAgent or null. * @throws JsonSyntaxException If the format does not match the FreeAgent V2 Invoice format. */ public FreeAgentInvoice importInvoice(String invoiceJSON) throws JsonSyntaxException { if (invoiceJSON == null || invoiceJSON.isEmpty()) { return null; } FreeAgentInvoice invoice = buildInvoice(invoiceJSON); if (invoice != null && (invoice.getUrl() == null || invoice.getUrl().isEmpty())) { FreeAgentInvoiceWrapper invoiceWrapper = freeAgentServiceInstance.createInvoice(new FreeAgentInvoiceWrapper(invoice)); if (invoiceWrapper != null) { return invoiceWrapper.getInvoice(); } } return null; }
/** * Attempts to delete the specified invoice entry in the associated FreeAgent account. * * @param invoice The populated invoice instance. * @return True if the invoice has been deleted successfully, otherwise false. */ public boolean deleteInvoice(FreeAgentInvoice invoice) { if (invoice != null) { String invoiceId = extractIdentifier(invoice.getUrl()); if (invoiceId != null && !invoiceId.isEmpty()) { Response response = freeAgentServiceInstance.deleteInvoice(invoiceId); if (response.getStatus() == 200) { return true; } else { return false; } } } return false; }