Skip to content

BasicEx Java SDK

License: MITMaven Central

This Java SDK fully implements the RESTful interface of BasicEx payment gateway.

Installation

Prerequisites

  • Java 1.8 or higher.

Gradle Usage

Add this dependency to your project's build file:

groovy
implementation "com.basicex:basicex-java:1.0.3"

Maven Usage

Add this dependency to your project's pom.xml file:

xml
<dependency>
    <groupId>com.basicex</groupId>
    <artifactId>basicex-java</artifactId>
    <version>1.0.3</version>
</dependency>

Documentation

Usage

Configure SDK Connection Timeout

Set SDK connection and read timeout globally:

java
BasicExClient client = new BasicExClient(configPath, BasicExConfig.builder()
                .connectTimeout(30 * 1000)
                .readTimeout(30 * 1000)
                .build());

Configure SDK Automatic Retry

BasicEx Java SDK can be configured to automatically retry a specified number of times when a request fails due to reasons such as network connection timeout:

java
BasicExClient client = new BasicExClient(configPath, BasicExConfig.builder()
                .maxNetworkRetries(2)
                .build());

Configure SDK Proxy

BasicEx Java SDK supports setting up a proxy for situations where your server needs a proxy to access the internet:

java
BasicExClient client = new BasicExClient(configPath, BasicExConfig.builder()
                .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 1080)), new PasswordAuthentication("user", "password".toCharArray()))
                .build());

Create a New Invoice

java
import com.basicex.sdk.BasicExClient;
import com.basicex.sdk.exception.BasicexException;
import com.basicex.sdk.model.InvoiceObject;
import com.basicex.sdk.model.params.InvoiceCreateParams;
import com.basicex.sdk.model.params.constant.AmountType;

import java.io.IOException;
import java.math.BigDecimal;
import java.security.cert.CertificateException;
import java.util.UUID;

public class BasicExTest{
    private static String configPath = "~/4d1ebd88-8154-4ca1-b1c6-051b7d28c204/config.json";
    public static void main(String[] args) throws CertificateException, IOException, BasicexException {
        BasicExClient client = new BasicExClient(configPath);
        InvoiceObject invoiceObject = client.invoices().create(InvoiceCreateParams.builder()
                .redirectUrl("https://basicex.com")
                .notificationUrl("https://basicex.com/notify")
                .currency("USDT")
                .amount(new BigDecimal("10.25"))
                .amountType(AmountType.COIN_AMOUNT)
                .orderId(UUID.randomUUID().toString())
                .description("Hello, BasicEx")
                .build());

        String cashierUrl = invoiceObject.getCashierUrl();
        System.out.println(cashierUrl);
    }
}

Create a Payout Request:

java
import com.basicex.sdk.BasicExClient;
import com.basicex.sdk.exception.BasicexException;
import com.basicex.sdk.model.InvoiceObject;
import com.basicex.sdk.model.PayoutObject;
import com.basicex.sdk.model.params.InvoiceCreateParams;
import com.basicex.sdk.model.params.PayoutCreateParams;
import com.basicex.sdk.model.params.constant.AmountType;
import com.basicex.sdk.model.params.constant.NetWorkType;

import java.io.IOException;
import java.math.BigDecimal;
import java.security.cert.CertificateException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class BasicExPayoutsTest {
    private static String configPath = "~/4d1ebd88-8154-4ca1-b1c6-051b7d28c204/config.json";
    public static void main(String[] args) throws CertificateException, IOException, BasicexException {
        BasicExClient client = new BasicExClient(configPath);
        PayoutService payout = client.payouts();
        Map<String, String> map = new HashMap<>();
       	map.put("desc", "Hello,BasicEx");

        PayoutCreateParams params = PayoutCreateParams.builder()
                .amount(new BigDecimal(5))
                .currency("USDT")
                .notificationUrl("https://basicex.com/notify")
                .description("TEST PAYOUT SDK")
                .metadata(map)
                .physical(Boolean.TRUE)
                .targetType("ADDRESS")
                .target("0x682D39Ea8d26510BE379d30807AF61e5eF9E2XXX")
                .network(NetWorkType.ERC20.code)
                .merOrderNo(UUID.randomUUID().toString().replace("-", ""))
                .build();
        PayoutObject payoutObject = payout.create(params);
        System.out.println(payoutObject);
    }
}