Skip to content
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 67 additions & 0 deletions src/main/java/com/starkinfra/CreditNote.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -1364,4 +1365,70 @@ public Description(Map<String, Object> data) throws Exception {
}
}
}

/**
* Retrieve a specific CreditNote pdf file
* <p>
* Receive a single CreditNote pdf file generated in the Stark Infra API by passing its id.
* <p>
* Parameters:
* @param id [string]: object unique id. ex: "5656565656565656"
* <p>
* 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
* <p>
* Receive a single CreditNote pdf file generated in the Stark Infra API by passing its id.
* <p>
* 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
* <p>
* 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
* <p>
* Receive a single CreditNote Transfer pdf file generated in the Stark Infra API by passing its id.
* <p>
* Parameters:
* @param id [string]: object unique id. ex: "5656565656565656"
* <p>
* 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
* <p>
* Receive a single CreditNote Transfer pdf file generated in the Stark Infra API by passing its id.
* <p>
* 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
* <p>
* 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<>());
}
}
48 changes: 48 additions & 0 deletions src/test/java/TestCreditNote.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -200,4 +204,48 @@ static List<CreditNote> 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<String, Object> params = new HashMap<>();
params.put("limit", 1);
params.put("status", "success");

Generator<CreditNote> 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<String, Object> params = new HashMap<>();
params.put("limit", 1);
params.put("status", "success");

Generator<CreditNote> 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);
}
}
}