Java 8 checkbox.in.ua api client
Automatically generated by the Swagger Codegen
- and a little fixed by me)*
Refer to the checkbox.in.ua official documentation
test checkbox API
- API version: 0.1.26
- Build date: 2021-11-02T14:34:29.121+02:00[Europe/Kiev]
Core API of Software Registrar of Settlement Operations
Building the API client library requires:
- Java 1.7+
- Maven/Gradle
To install the API client library to your local Maven repository, simply execute:
mvn clean install
To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:
mvn clean deploy
Refer to the OSSRH Guide for more information.
Add this dependency to your project's POM:
<dependency>
<groupId>checkbox-api-j8client</groupId>
<artifactId>checkbox-api-j8client</artifactId>
<version>0.0.1</version>
<scope>compile</scope>
</dependency>
At first generate the JAR by executing:
mvn clean package
Then manually install the following JARs:
target/checkbox-api-j8client-0.0.1.jar
target/lib/*.jar
Please follow the installation All of the methods described below work, but others may not.
import ua.checkbox.j8client.*;
import ua.checkbox.j8client.auth.*;
import ua.checkbox.j8client.model.*;
import ua.checkbox.j8client.api.DefaultApi;
import java.io.File;
import java.util.*;
public class DefaultApiExample {
public static void main(String[] args) {
ShiftModel shift;
DefaultApi apiClient = new DefaultApi("https://api.checkbox.in.ua"); // for test mode use https://dev-api.checkbox.in.ua
try {
apiClient.signIn("login", "password"));
//open shift
shift = apiClient.openShift("your License Key", null);
// check shift status
apiClient.getShiftById(shift.getId());
if(shift.getStatus() == ShiftStatus.OPEN)
System.out.println("shift is open");
// get open shifts (I think there should be one)
PaginatedResultShiftWithCashRegisterModel_ opennedShifts = apiClient.getActiveShifts();
if (!result.getResults().isEmpty())
shift = result.getResults().get(0);
// deposit cash, aka "службове внесення готівки" if value > 0,
// withdraw cash, aka "службове вилучення готівки" if value < 0,
// use hundredths of your value, i.e. if your value is 500.00UAH, use 50000 instead
ReceiptServicePayload cashBody = new ReceiptServicePayload()
.payment(new CashPaymentPayload().value((int) (500.0 * 100)));
apiClient.createServiceReceipt(cashBody);
// Create X-report
ReportModel x = apiClient.createXReport();
// Create Z-report, shift closing
ShiftWithCashierAndCashRegister z = apiClient.closeShift(null);
// sale (isReturnReceipt == false) or return (isReturnReceipt == true)
// assumed that goods, item and client values contains necessary fields and getters
// goods
List<GoodItemPayload> goodsList = new ArrayList<GoodItemPayload>();
for (FiscalReceiptProductDto item : goods) {
GoodItemPayload goodItem = new GoodItemPayload();
AllOfGoodItemPayloadGood good = new AllOfGoodItemPayloadGood();
good.code(String.valueOf(item.getId()));
good.setName(item.getName());
good.setPrice(Integer.valueOf((int) (item.getSellPrice() * 100))); // price in 1/100 of UAH)
goodItem.setGood(good);
goodItem.setQuantity(item.getQuantity() * 1000); // 1/1000 of item quantity: if you sell 5 pcs. place 5000 here
goodItem.setIsReturn(isReturnReceipt);
goodsList.add(goodItem);
}
// type of payment
List<AnyOfReceiptSellPayloadPaymentsItems> payments = new ArrayList<>();
if (cashSum > 0) {
// round to first decimal number, as required by the National Bank of Ukraine
payments.add(new CashPaymentPayload().value((int) (Math.round(cashSum * 10.0) * 10))); // 1/100 of UAH
}
if (creditCardSum > 0) {
payments.add(new CardPaymentPayload().value((int) (creditCardSum * 100))); // 1/100 of UAH
}
// Discounts
List<DiscountPayload> discounts = new ArrayList<>();
if (discountSum > 0) {
discounts.add(new DiscountPayload().mode(DiscountMode.VALUE).type(DiscountType.DISCOUNT)
.value((int) (discountSum * 100)));
}
// e-mails
DeliveryPayload sendTo = new DeliveryPayload();
for (String email : client.getEmails()) {
sendTo.addEmailsItem(email);
}
ReceiptSellPayload receipt = new ReceiptSellPayload()
.id(uuid) // place here you uuid or skip this step
.goods(goodsList)
.payments(payments)
.discounts(discounts)
.rounding(true)
.delivery(sendTo);
if (currentLocation != null)
receipt.departament(currentLocation.getName());
ReceiptModel receiptResponse = apiClient.createReceiptSell(receipt);
// Get receipt as HTML document
String html = apiClient.getReceiptHtml(uuid, true);
// Get receipt as pdf document
File pdf = apiClient.getReceiptPdf(uuid);
// Get receipt as QR-code
File qr = apiClient.getReceiptQrCodeImage(uuid);
// Get receipt as png document (default size) to print with thermal printer
File png = apiClient.getReceiptPng(uuid, null, null);
} catch (ApiException e) {
if (e.getResponseBody() != null) {
// error message from api
System.out.println(e.getResponseBody());
} else if (e.getCause() != null && e.getCause().getMessage() != null) {
System.out.println(e.getCause().getMessage());
}
}
}
}