Skip to content

Commit

Permalink
INVD-3805 fixed customer taxes request (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
andriy-invoiced authored Jan 29, 2024
1 parent 0476c72 commit d573fff
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/main/java/com/invoiced/entity/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,4 +371,16 @@ public EntityList<PaymentSource> listPaymentSources() throws EntityException {
source.setEndpointBase(this.getEndpoint(true));
return source.listAll();
}

public String[] getTaxes() {
if (this.taxes == null) {
return null;
}
String[] ids = new String[this.taxes.length];
for (int i = 0; i < this.taxes.length; i++) {
ids[i] = this.taxes[i].toString();
}

return ids;
}
}
13 changes: 9 additions & 4 deletions src/main/java/com/invoiced/entity/TaxRate.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,19 @@ protected String getEntityId() {
@Override
@JsonIgnore
protected String[] getCreateExclusions() {
return new String[] {"object", "created_at"};
return new String[]{"object", "created_at"};
}

@Override
@JsonIgnore
protected String[] getSaveExclusions() {
return new String[] {
"id", "object", "currency", "value", "inclusive", "is_percent", "created_at"
return new String[]{
"id", "object", "currency", "value", "inclusive", "is_percent", "created_at"
};
}
}

@Override
public String toString() {
return id;
}
}
21 changes: 21 additions & 0 deletions src/test/java/com/invoiced/entity/CustomerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,25 @@ public void testNewNote() {
fail(e.getMessage());
}
}

@Test
public void testTaxes() {
//src/test/resources/mappings/customers_edit_3.json
//src/test/resources/mappings/tax_rates_retrieve_2.json

Connection conn = new Connection("api_key", "http://localhost:8080");

try {
Customer cust = conn.newCustomer().retrieve(11);
TaxRate taxRate1 = conn.newTaxRate().retrieve("vat");
TaxRate taxRate2 = conn.newTaxRate().retrieve("vat2");
cust.taxes = new TaxRate[] { taxRate1, taxRate2 };
cust.save();
assertTrue("Customer Tax is incorrect", cust.taxes[0].toString().equals("vat"));
assertTrue("Customer Tax is incorrect", cust.taxes[1].toString().equals("vat2"));

} catch (Exception e) {
fail(e.getMessage());
}
}
}
18 changes: 18 additions & 0 deletions src/test/resources/mappings/customers_edit_3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"request": {
"method": "PATCH",
"url": "/customers/11",
"bodyPatterns": [
{
"equalToJson": "{\"name\":\"Customer testRetrieve\",\"number\":\"0111\",\"email\":\"[email protected]\",\"autopay\":false,\"payment_terms\":\"NET 90\",\"type\":\"company\",\"city\":\"Austin\",\"country\":\"US\",\"taxes\":[\"vat\",\"vat2\"]}"
}
]
},
"response": {
"status": 200,
"body": "{\"name\":\"Customer testRetrieve\",\"number\":\"0111\",\"email\":\"[email protected]\",\"autopay\":false,\"payment_terms\":\"NET 90\",\"type\":\"company\",\"city\":\"Austin\",\"country\":\"US\",\"taxes\":[{\"created_at\":1477418268,\"currency\":null,\"id\":\"vat\",\"inclusive\":false,\"is_percent\":true,\"metadata\":{},\"name\":\"VAT_2\",\"object\":\"tax_rate\",\"value\":5},{\"created_at\":1477418268,\"currency\":null,\"id\":\"vat2\",\"inclusive\":false,\"is_percent\":true,\"metadata\":{},\"name\":\"VAT_2\",\"object\":\"tax_rate\",\"value\":15}]}",
"headers": {
"Content-Type": "application/json"
}
}
}
13 changes: 13 additions & 0 deletions src/test/resources/mappings/tax_rates_retrieve_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"request": {
"method": "GET",
"url": "/tax_rates/vat2"
},
"response": {
"status": 200,
"body": "{\"created_at\":1477418268,\"currency\":null,\"id\":\"vat2\",\"inclusive\":false,\"is_percent\":true,\"metadata\":{},\"name\":\"VAT_2\",\"object\":\"tax_rate\",\"value\":15}",
"headers": {
"Content-Type": "application/json"
}
}
}

0 comments on commit d573fff

Please sign in to comment.