Litego.io API Java Library https://litego.io
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/main/java/io/litego/api
.gitignore
README.md
pom.xml

README.md

litego-java

Simple Litego API wrapper class, in Java. Litego API documentation can be found here https://litego.io/documentation/

Requirements

Java 1.8 or later.

Dependencies

  • Gson Java library that can be used to convert Java Objects into their JSON representation.
  • OkHttp An HTTP & HTTP/2 client for Android and Java applications

Installation

To use litego-java as a dependency in your project, the easiest way right now is to clone and publish it locally. Simply run:

git clone https://github.com/litegoio/litego-java.git
cd litego-java
mvn install

and then add to pom.xml

<dependencies>
    <dependency>
        <groupId>io.litego</groupId>
        <artifactId>litego-java</artifactId>
        <version>0.2</version>
    </dependency>
</dependencies>

Examples

Creating an instance with test/live mode

Litego litego = new Litego(Mode.TEST_URL);

or

Litego litego = new Litego(Mode.LIVE_URL);

After registration on https://litego.io and getting secret key and merchant ID values try to authenticate (get auth token for other requests) Two ways how to get auth token:

  • secret key and merchant ID
  • refresh token (if exists).
AuthResponse authResponse = litego.authenticate(merchantId, secretKey);

or get new if expired

AuthTokenResponse tokenResponse = litego.refreshAuthToken(refreshToken);

You will get auth token and refresh token values. Auth token will be used then for other API requests. Refresh token should be saved for reauthentication when auth token is expired.

Create charge

ChargeResponse chargeResponse = litego.createCharge(authToken, description, amount_satoshi)

Charges list

ChargeListResponse chargeList = litego.chargesList(authToken, isPaid, page, pageSize);

Get charge

ChargeResponse charge = litego.getCharge(authToken, chargeId);

Get information about authenticated merchant

MerchantInfoResponse merchantInfo = getMerchantSummary(authToken);

Set withdrawal address

WithdrawalAddressResponse address = litego.setWithdrawalAddress(authToken, someAddress, Withdrawals.REGULAR_ADDRESS_TYPE);

Get withdrawal settings

WithdrawalSettingsResponse settingsResponse = litego.getWithdrawalSettings(authToken);

Request manual withdrawal

WithdrawalTransactionResponse transaction = litego.withdrawManually(authToken);

Withdrawals list

WithdrawalsListResponse withdrawalList = litego.getListWithdrawals(authToken);

Set webhook URL

NotificationResponse notification = litego.setNotificationUrl(authToken, "http://litego.io");

List responses from webhook

NotificationResponsesList responsesList = litego.getListOfNotificationResponses(authToken);

List referral payments

ReferralPaymentsResponse paymentsResponse = litego.getReferralPayments(authToken, page, pageSize);

Websocket subscriptions

You can subscribe to topics with payments of all your charges or a single charge by it's ID just registering event listeners, which are objects that implement an interface WebSocketListener.

Subscribe for payments

litego.addPaymentsEventSubscribeListener(Mode.TEST_URL, authToken, new WebSocketListener() {
    @Override
    public void onMessage(WebSocket webSocket, String text) {
        System.out.println("Receive: " + text);
    }
});

Subscribe for payment of single charge

litego.addPaymentsEventSubscribeListenerSingle(Mode.TEST_URL, authToken, "2f551fc0-1faa-11e9-90e2-df42b3b425c0", new WebSocketListener() {
    @Override
    public void onMessage(WebSocket webSocket, String text) {
        System.out.println("Receive: " + text);
    }
});