コード例 #1
0
 /**
  * Attempts to create a new invoice entry in the associated FreeAgent account.
  *
  * <p>Will return null if the invoice instance provided is null or cannot be saved into the
  * account.
  *
  * @param invoice The populated invoice instance.
  * @return The updated invoice instance or null.
  */
 public FreeAgentInvoice createInvoice(FreeAgentInvoice invoice) {
   if (invoice != null) {
     FreeAgentInvoiceWrapper invoiceWrapper =
         freeAgentServiceInstance.createInvoice(new FreeAgentInvoiceWrapper(invoice));
     if (invoiceWrapper != null) {
       return invoiceWrapper.getInvoice();
     }
   }
   return null;
 }
コード例 #2
0
  /**
   * 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;
  }