From 5529fcbfb524e243878c62e8081841a05a76c5ac Mon Sep 17 00:00:00 2001 From: Paulo Souza Date: Wed, 9 Jul 2025 17:24:48 -0300 Subject: [PATCH] Added credit note pdf method --- CHANGELOG.md | 2 + src/main/java/com/starkinfra/CreditNote.java | 67 ++++++++++++++++++++ src/test/java/TestCreditNote.java | 48 ++++++++++++++ 3 files changed, 117 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 903c296..cfc3add 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ Given a version number MAJOR.MINOR.PATCH, increment: ## [Unreleased] +### Added +- CreditNote pdf and payment methods ## [0.17.0] - 2025-06-27 ### Added diff --git a/src/main/java/com/starkinfra/CreditNote.java b/src/main/java/com/starkinfra/CreditNote.java index c7912ae..af72824 100644 --- a/src/main/java/com/starkinfra/CreditNote.java +++ b/src/main/java/com/starkinfra/CreditNote.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.Objects; import java.util.ArrayList; +import java.io.InputStream; import java.lang.reflect.Type; import com.google.gson.*; @@ -1364,4 +1365,70 @@ public Description(Map data) throws Exception { } } } + + /** + * Retrieve a specific CreditNote pdf file + *

+ * Receive a single CreditNote pdf file generated in the Stark Infra API by passing its id. + *

+ * Parameters: + * @param id [string]: object unique id. ex: "5656565656565656" + *

+ * Return: + * @return CreditNote pdf file + * @throws Exception error in the request + */ + public static InputStream pdf(String id) throws Exception { + return pdf(id, null); + } + + /** + * Retrieve a specific CreditNote pdf file + *

+ * Receive a single CreditNote pdf file generated in the Stark Infra API by passing its id. + *

+ * Parameters: + * @param id [string]: object unique id. ex: "5656565656565656" + * @param user [Organization/Project object]: Organization or Project object. Not necessary if starkbank.User.defaultUser was set before function call + *

+ * Return: + * @return CreditNote pdf file + * @throws Exception error in the request + */ + public static InputStream pdf(String id, User user) throws Exception { + return Rest.getContent(data, id, "pdf", user, new HashMap<>()); + } + + /** + * Retrieve a specific CreditNote Transfer pdf file + *

+ * Receive a single CreditNote Transfer pdf file generated in the Stark Infra API by passing its id. + *

+ * Parameters: + * @param id [string]: object unique id. ex: "5656565656565656" + *

+ * Return: + * @return CreditNote Transfer pdf file + * @throws Exception error in the request + */ + public static InputStream payment(String id) throws Exception { + return payment(id, null); + } + + /** + * Retrieve a specific CreditNote Transfer pdf file + *

+ * Receive a single CreditNote Transfer pdf file generated in the Stark Infra API by passing its id. + *

+ * Parameters: + * @param id [string]: object unique id. ex: "5656565656565656" + * @param user [Organization/Project object]: Organization or Project object. Not necessary if starkbank.User.defaultUser was set before function call + *

+ * Return: + * @return CreditNote Transfer pdf file + * @throws Exception error in the request + */ + public static InputStream payment(String id, User user) throws Exception { + return Rest.getContent(data, id, "payment/pdf", user, new HashMap<>()); + } } diff --git a/src/test/java/TestCreditNote.java b/src/test/java/TestCreditNote.java index aad8305..7b4a638 100644 --- a/src/test/java/TestCreditNote.java +++ b/src/test/java/TestCreditNote.java @@ -4,6 +4,10 @@ import java.util.ArrayList; import java.time.LocalDate; +import java.io.File; +import java.io.InputStream; +import java.nio.file.StandardCopyOption; + import org.junit.Test; import org.junit.Assert; @@ -200,4 +204,48 @@ static List exampleWithObject() throws Exception { public static String getDateString(int delta) { return LocalDate.now().plusDays(delta).toString(); } + + @Test + public void testCreditNotePdfGet() throws Exception { + Settings.user = utils.User.defaultProject(); + + HashMap params = new HashMap<>(); + params.put("limit", 1); + params.put("status", "success"); + + Generator notes = CreditNote.query(params); + for (CreditNote note : notes) { + String noteId = note.id; + InputStream pdf = CreditNote.pdf(noteId); + Assert.assertNotNull(pdf); + java.nio.file.Files.copy( + pdf, + new File("note.pdf").toPath(), + StandardCopyOption.REPLACE_EXISTING + ); + System.out.println(note); + } + } + + @Test + public void testCreditNotePaymentPdfGet() throws Exception { + Settings.user = utils.User.defaultProject(); + + HashMap params = new HashMap<>(); + params.put("limit", 1); + params.put("status", "success"); + + Generator notes = CreditNote.query(params); + for (CreditNote note : notes) { + String noteId = note.id; + InputStream pdf = CreditNote.payment(noteId); + Assert.assertNotNull(pdf); + java.nio.file.Files.copy( + pdf, + new File("payment.pdf").toPath(), + StandardCopyOption.REPLACE_EXISTING + ); + System.out.println(note); + } + } }