Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INVD-3805 fixed customer taxes request #31

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}
}
Loading