Closed dimaloop closed 2 years ago
also added related_receipt_id and previous_receipt_id fields to ReceiptSellPayload according docs
[+] getReportTextById method for text report view [+] getReportXMLById method for xml report view [+] getForString private service method for getting content without json mapper update version to 1.10.7
[+] getReceiptTextById method for text receipt view [+] getReceiptPdfById method for pdf receipt view
Fix getReceiptPdfById method to work with byte[] instead String:
There were only methods for working with string body: HttpResponse.BodyHandlers.ofString()
I added a method to work with bytes
Perhaps other committers will have ideas for unification of getForObjectImpl - I will gladly accept ideas!
[+] getReceiptPngById method for PNG receipt view with optional paper/content width [+] getReceiptQRCodeById method for QRCode of receipt (png image) [+] added getters with defaults settings
Thank you for the new features!!! There is the only recommendation, as mentioned in the Abstract principle:
Each significant piece of functionality in a program should be implemented in just one place in the source code. Where similar functions are carried out by distinct pieces of code, it is generally beneficial to combine them into one by abstracting out the varying parts.
so I'd prefer to have the only one getForObjectImpl()
with
HttpResponse<byte[]> response = httpClient.send(request.build(), HttpResponse.BodyHandlers.ofByteArray());
instead of both getForObjectImpl()
and getForBytesImpl()
as they are pretty the same. To use this HttpResponse<byte[]>
instead of HttpResponse<String>
you have to change several parent methods, but this changes are simple.
And, please, use code formatting. For example it's better to have spaces in such peaces of code for better reading:
id+"/text"+(width>=10 && width<=250?"?width="+width:""
and also I'd prefer to assign optional param to a variable instead of a long string:
public String getReportTextById(String id,int width)
{
return getForString(URI.create(apiPrefix + REPORTS_PATH + "/" + id+"/text"+(width>=10 && width<=250?"?width="+width:"")));
}
use something like this:
public String getReportTextById(String id,int width)
{
String widthParam =
width >= MIN_WIDTH && width <= MAX_WIDTH
? "?width=" + width
: "";
return getForString(URI.create(apiPrefix + REPORTS_PATH + "/" + id + "/text" + widthParam));
}
and of cause no magic numbers use constants please
And one more thing )
Please, pay attention to getReceiptTextById(String id)
as it recursively calls itself (looks like it shouldn't).
And one more thing ) Please, pay attention to
getReceiptTextById(String id)
as it recursively calls itself (looks like it shouldn't).
Fixed, thank you
And, please, use code formatting.
changed
instead of both
getForObjectImpl()
andgetForBytesImpl()
as they are pretty the same. To use thisHttpResponse<byte[]>
instead ofHttpResponse<String>
you have to change several parent methods, but this changes are simple.
Can you provide code example? have no glue how to get responseFunction's type and implement instanceOf generic type
Sure, I'm sharing my implementations
Tested, works as expected! Thank you!
I guess it's just a typo, but should be fixed:
MAX_CHARS_PNG_RECEIPT <= 100
hard day, sorry. Thank you for your attention
According to the docs - CARD type deprecated, so removed