/omise-java

Omise Java Library

Primary LanguageJavaMIT LicenseMIT

OMISE-JAVA

Maven Central Circle CI Discourse Forum

This library has been updated to v3.0.0.

Omise-java provides a set of Java bindings to the Omise REST API. Please contact support@omise.co if you have any questions regarding this library and the functionality it provides.

INSTALLATION

Android

WARNING: Android users should check out our omise-android repository instead.

This library requires Java 8 and up and is meant to be used with Java server implementations.

Gradle/Maven

Adds to your build.gradle file.

dependencies {
    compile 'co.omise:omise-java:3.0.0'
}

Shadow JAR

If you have dependency conflicts with omise-java jar you can try using the shadowed JAR version which has the JAR dependencies relocated to the co.omise.dependencies package.

You can obtain a shadowed jar by manually cloning the project and running the shadowJar task:

$ git clone git://github.com/omise/omise-java
$ cd omise-java
$ gradle shadowJar
:compileJava
:processResources
:classes
:shadowJar

BUILD SUCCESSFUL

$ ls builds/libs
omise-java-3.0.0-all.jar

#MIGRATION TO v3.0.0

The alteration made in the v3.0.0 of omise-java are breaking changes and would require code changes from your side if you have already been using this library from previous versions. We have put together a guide to make this process easier by pointing the changes to you. You can find the complete v3.0.0 migration guide here.

USAGE

Obtain a set of API keys from the Omise Dashboard and create a Client object

Client client = new Client.Builder()
                        .publicKey("pkey_test_123")
                        .secretKey("skey_test_123")
                        .build();

Access the API by creating a Request and sending it through the Client, for example to get current Balance

Request<Balance> request = new Balance.GetRequestBuilder().build();
Balance balance = client.sendRequest(request);

long total = balance.getTotal();

Creating a charge from a token

Client client = new Client.Builder()
                        .publicKey("pkey_test_123")
                        .build();

Request<Charge> request =
                    new Charge.CreateRequestBuilder()
                            .amount(100000) // 1,000 THB
                            .currency("thb")
                            .card("card_test_4xtsoy2nbfs7ujngyyq")
                            .build();
Charge charge = client.sendRequest(request);
    
System.out.println("created charge: " + charge.getId());

LICENSE

MIT license