Skip to content

Commit 4d4f9d9

Browse files
thomasatwikeyclaudekoen-serry
authored
Add custom attribute support to CreateInvoiceRequest (#8)
* Add custom attribute support to CreateInvoiceRequest Allow passing one or more custom attributes directly in the invoice object via setExtra(Map<String, String>). Each entry is serialized as a top-level key-value pair in the JSON request body. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Add test for custom attribute support in CreateInvoiceRequest Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Update InvoiceGatewayTest.java * Update InvoiceGatewayTest.java --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Koen Serry <482723+koen-serry@users.noreply.github.com>
1 parent f9bad72 commit 4d4f9d9

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/main/java/com/twikey/modal/InvoiceRequests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class CreateInvoiceRequest {
5353
private String ct;
5454
private Boolean manual;
5555
private List<LineItem> lines;
56+
private Map<String, String> extra;
5657

5758
public CreateInvoiceRequest(String number, Double amount, String date, String duedate, DocumentRequests.Customer customer) {
5859
this.number = number;
@@ -138,6 +139,11 @@ public CreateInvoiceRequest setLines(List<LineItem> lines) {
138139
return this;
139140
}
140141

142+
public CreateInvoiceRequest setExtra(Map<String, String> extra) {
143+
this.extra = extra;
144+
return this;
145+
}
146+
141147
/**
142148
* Converts this request to a Map suitable for API submission.
143149
*/
@@ -180,6 +186,9 @@ public JSONObject toRequest() {
180186
for (LineItem line : lines) lineMaps.add(line.toMap());
181187
map.put("lines", lineMaps.toString());
182188
}
189+
if (extra != null) {
190+
extra.forEach(map::put);
191+
}
183192
return map;
184193
}
185194

src/test/java/com/twikey/InvoiceGatewayTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,19 @@ public void testCreateInvoice() throws IOException, TwikeyClient.UserException {
7676
api.invoice().action(actionRequest);
7777
}
7878

79-
8079
@Test
80+
public void testCreateInvoiceWithCustomAttribute() throws IOException, TwikeyClient.UserException {
81+
Assume.assumeTrue("APIKey is set", apiKey != null);
82+
String number = "Inv-CustomAttr-" + System.currentTimeMillis();
83+
InvoiceRequests.CreateInvoiceRequest request = new InvoiceRequests.CreateInvoiceRequest(
84+
number, 50.0, LocalDate.now().toString(), LocalDate.now().plusMonths(1).toString(), customer)
85+
.setExtra(Map.of("myCustomAttribute", "BMW 3-Series"));
86+
InvoiceResponse.Invoice response = api.invoice().create(request);
87+
assertNotNull("Invoice Id", response.getId());
88+
System.out.printf("Created invoice %s with custom attribute%n", response.getId());
89+
}
90+
91+
@Test
8192
public void testUpdateInvoiceWithCustomAttribute() throws IOException, TwikeyClient.UserException {
8293
Assume.assumeTrue("APIKey is set", apiKey != null);
8394
String number = "Inv-UpdateAttr-" + System.currentTimeMillis();

0 commit comments

Comments
 (0)