Skip to content

KamikotoTkach/CryptoCloud4j

Repository files navigation

CryptoCloud4j

SDK for CryptoCloud based on HttpWrapper
Currently wrapping all v2 requests

Usage:

Add to pom:

<dependency>
    <groupId>ru.cwcode.tkach.cryptocloud4j</groupId>
    <artifactId>CryptoCloud4j</artifactId>
    <version>1.0.1</version>
</dependency>

Create client

ServiceClient client = new ServiceClient(new OkHttpClient(), new Gson(), "https://api.cryptocloud.plus/");
client.addHeader("Authorization", "Token YOUR-SHOP-TOKEN");

Create bill:

CreateBillRequest request = new CreateBillRequest();
request.shopId("YOUR-SHOP-ID");
request.amount(200.0);
request.orderId("testid"); // <-- Your order ID, not required
    
client.sendRequest(request).thenAccept(response -> {
    response.getHandler()
        .ifMatch(200, BillCreatedResponse.class, billCreated -> {
            System.out.println("Bill created");
            System.out.println(billCreated);
          })
        .ifMatch(400, BadRequestResponse.class, badRequest -> {
            System.out.println("Bad request");
            System.out.println(badRequest);
          })
    });

Listening for postback:

Add to pom:

<dependency>
    <groupId>ru.cwcode.tkach.cryptocloud4j</groupId>
    <artifactId>CryptoCloud4jListener</artifactId>
    <version>1.0.0</version>
</dependency>

Create listener:

new PostbackListener("/your/notify/url", "YOUR-SHOP-SECRET", (int) port, (postbackRequest, token) -> { // <-- is called only if the JWT token is valid
    System.out.printf("""
                      Bill status updated:
                      Invoice id %s
                      Order id %s
                      Status %s
                      """,
                      postbackRequest.invoiceId(),
                      postbackRequest.orderId(),
                      postbackRequest.status());
    return PostbackListener.Status.HANDLED;
    });

Releases

No releases published

Packages

No packages published

Languages