Skip to content

Xendit REST API Client for Java - Card, Virtual Account, Invoice, Disbursement, Recurring Payments, Payout, EWallet, Balance, Retail Outlets Services

License

Notifications You must be signed in to change notification settings

glendaesutanto/xendit-java

 
 

Repository files navigation

Xendit Java Library

Download

This library is the abstraction of Xendit API for access from applications written with Java.

Table of Contents

API Documentation

Please check Xendit API Reference.

Requirements

JDK 1.7 or later.

Installation

Maven

Add these lines of code in your pom.xml

<dependency>
    <groupId>com.xendit</groupId>
    <artifactId>xendit-java-lib</artifactId>
    <version>SELECTED_VERSION</version>
</dependency>

<repositories>
    <repository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>bintray-xendit-android</id>
        <name>bintray</name>
        <url>https://dl.bintray.com/xendit/android</url>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>bintray-xendit-android</id>
        <name>bintray-plugins</name>
        <url>https://dl.bintray.com/xendit/android</url>
    </pluginRepository>
</pluginRepositories>

Gradle

Add these lines in your build.gradle

...
repositories {
	maven {
		url  "https://dl.bintray.com/xendit/android"
	}
}
...
compile 'com.xendit:xendit-java-lib:{SELECTED_VERSION}'

More information: https://bintray.com/xendit/android/xendit-java-lib

Usage

You need to use secret API key in order to use functionality in this library. The key can be obtained from your Xendit Dashboard.

import com.xendit.Xendit;

public class Example {
    public static void main(String[] args) {
        Xendit.apiKey = "PUT YOUR API KEY HERE";
    }
}

Example: Create a disbursement

import com.xendit.Xendit;
import com.xendit.exception.XenditException;
import com.xendit.model.Disbursement;

import java.util.HashMap;
import java.util.Map;

public class ExampleCreateDisbursement {
    public static void main(String[] args) {
        Xendit.apiKey = "xnd_development_...";

        try {
            Map<String, Object> params = new HashMap<>();
            params.put("external_id", "my_external_id");
            params.put("bank_code", "BCA");
            params.put("account_holder_name", "John Doe");
            params.put("account_number", "123456789");
            params.put("description", "My Description");
            params.put("amount", "90000");

            Disbursement disbursement = Disbursement.create(params);
        } catch (XenditException e) {
            e.printStackTrace();
        }
    }
}

There are some examples provided for you here.

Disbursement Services

Create a disbursement

You can choose whether want to put the attributes as parameters or to put in inside a Map object.

Disbursement.create(
    String externalId,
    String bankCode,
    String accountHolderName,
    String accountNumber,
    String description,
    BigInteger amount,
    String[] emailTo,
    String[] emailCc,
    String[] emailBcc
);
Disbursement.create(
    Map<String, Object> params
);
Map<String, Object> params = new HashMap<>();
params.put("external_id", "my_external_id");
params.put("bank_code", "BCA");
params.put("account_holder_name", "John Doe");
params.put("account_number", "123456789");
params.put("description", "My Description");
params.put("amount", "90000");

Disbursement disbursement = Disbursement.create(params);

Get banks with available disbursement service

AvailableBank[] banks = Disbursement.getAvailableBanks();

Get a disbursement by external ID

Disbursement disbursement = Disbursement.getByExternalId("EXAMPLE_ID");

Get a disbursement by ID

Disbursement disbursement = Disbursement.getById("EXAMPLE_ID");

Back to top

Invoice services

Create an invoice

You can choose whether want to put the attributes as parameters or to put in inside a Map object.

Invoice.create(
    String externalId,
    Number amount,
    String payerEmail,
    String description
);
Invoice.create(
    Map<String, Object> params
);
Map<String, Object> params = new HashMap<>();
params.put("external_id", "my_external_id");
params.put("amount", 1800000);
params.put("payer_email", "customer@domain.com");
params.put("description", "Invoice Demo #123");

Invoice invoice = Invoice.create(params);

Get an invoice by ID

Invoice invoice = Invoice.getById("EXAMPLE_ID");

Get all invoices

Map<String, Object> params = new HashMap<>();
params.put("limit", 3);
params.put("statuses", "[\"SETTLED\",\"EXPIRED\"]");

Invoice[] invoices = Invoice.getAll(params);

Expire an invoice

Invoice invoice = Invoice.expire("EXAMPLE_ID");

Back to top

Virtual Account Services

Create a fixed virtual account

You can choose whether want to put the attributes as parameters or to put in inside a Map object.

Closed virtual account
FixedVirtualAccount.createClosed(
    String externalId,
    String bankCode,
    String name,
    Long expectedAmount,
    Map<String, Object> additionalParam
);
FixedVirtualAccount.createClosed(
    Map<String, Object> params
);
Opened virtual account
FixedVirtualAccount.createOpen(
    String externalId,
    String bankCode,
    String name,
    Map<String, Object> additionalParam
);
FixedVirtualAccount.createOpen(
    Map<String, Object> params
);
Map<String, Object> params = new HashMap<>();
params.put("external_id", "my_external_id");
params.put("bank_code", BankCode.BNI.getText());
params.put("name", "John Doe");

FixedVirtualAccount virtualAccount = FixedVirtualAccount.createOpen(params);

Update a fixed virtual account by ID

Map<String, Object> params = new HashMap<>();
params.put("is_single_use", true);

FixedVirtualAccount fixedVirtualAccount = FixedVirtualAccount.update("EXAMPLE_ID", params);

Get banks with available virtual account service

AvailableBank[] availableBanks = FixedVirtualAccount.getAvailableBanks();

Get a fixed virtual account by ID

FixedVirtualAccount fpa = FixedVirtualAccount.getFixedVA("EXAMPLE_ID");

Get a fixed virtual account payment by payment ID

FixedVirtualAccountPayment payment = FixedVirtualAccount.getPayment("EXAMPLE_PAYMENT_ID");

Back to top

Retail Outlet Services

Create fixed payment code

You can choose whether want to put the attributes as parameters or to put in inside a Map object.

RetailOutlet.createFixedPaymentCode(
    String externalId,
    String retailOutletName,
    String name,
    Number expectedAmount
);
RetailOutlet.createFixedPaymentCode(
    Map<String, Object> params
);
params.put("external_id", "test");
params.put("retail_outlet_name", "ALFAMART");
params.put("name", "Rika Sutanto");
params.put("expected_amount", 10000);

FixedPaymentCode fpc = RetailOutlet.createFixedPaymentCode(params);

Get fixed payment code

FixedPaymentCode fpc = RetailOutlet.getFixedPaymentCode("EXAMPLE_ID");

Update fixed payment code

You can choose whether want to put the attributes as parameters or to put in inside a Map object.

RetailOutlet.updateFixedPaymentCode(
    String id,
    String name,
    Number expectedAmount,
    String expirationDate
);
RetailOutlet.updateFixedPaymentCode(
    String id,
    Map<String, Object> params
);
Map<String, Object> params = new HashMap<>();
params.put("name", "Lorem Ipsum");

FixedPaymentCode fpc = RetailOutlet.updateFixedPaymentCode("EXAMPLE_ID", params);

Back to top

Recurring Payment Services

Create a recurring payment

You can choose whether want to put the attributes as parameters or to put in inside a Map object.

RecurringPayment.create(
   String externalId,
   String payerEmail,
   String interval,
   Number intervalCount,
   String description,
   Number amount
);
RecurringPayment.create(
   Map<String, Object> params
);
Map<String , Object> params = new HashMap<>();
params.put("external_id", "recurring_31451441");
params.put("payer_email", "sample_email@xendit.co");
params.put("interval", "MONTH");
params.put("interval_count", 1);
params.put("description", "Test desc");
params.put("amount", 100000);
params.put("currency", "IDR"); //Optional param

RecurringPayment recurringPayment = RecurringPayment.create(params);

Get a recurring payment

RecurringPayment recurringPayment = RecurringPayment.get("5e2dd160f8a4d24146f5974c");

Edit a recurring payment

Map<String, Object> params = new HashMap<>();
params.put("amount", 987654);
params.put("interval", "WEEK");

RecurringPayment recurringPayment = RecurringPayment.edit("5e2dd55ef8a4d24146f59775", params);

Stop a recurring payment

RecurringPayment recurringPayment = RecurringPayment.stop("5e2dd160f8a4d24146f5974c");

Pause a recurring payment

RecurringPayment recurringPayment = RecurringPayment.pause("5e2dd55ef8a4d24146f59775");

Resume a recurring payment

RecurringPayment recurringPayment = RecurringPayment.resume("5e2dd55ef8a4d24146f59775");

List recurring payments by ID

Invoice[] invoices = RecurringPayment.getPaymentsById("5e2dd55ef8a4d24146f59775");

Back to top

Balance Service

Get balance

The accountType parameter is optional.

Balance.get();

Balance.get(String accountType);
Balance balance = Balance.get("CASH");

Back to top

Payout Services

Create a payout

You can choose whether want to put the attributes as parameters or to put in inside a Map object.

Payout.createPayout(
    String externalId,
    Number amount
);
Payout.createPayout(
    Map<String, Object> params
);
Map<String, Object> params = new HashMap<>();
params.put("external_id", "my_test_id");
params.put("amount", 100000);

Payout payout = Payout.createPayout(params);

Get a payout by ID

Payout payout = Payout.getPayout("EXAMPLE_ID");

Void a payout

Payout payout = Payout.voidPayout("EXAMPLE_ID");

Back to top

E-Wallet Services

Create a Linkaja payment

EWalletPayment.createLinkajaPayment(
    String externalId,
    Number amount,
    String phone,
    EWalletLinkajaItem[] items,
    String callbackUrl,
    String redirectUrl
);

Create a Dana payment

EWalletPayment.createDanaPayment(
    String externalId,
    Number amount,
    String phone,
    String expirationDate,
    String callbackUrl,
    String redirectUrl
);

Create an OVO payment

EWalletPayment.createOvoPayment(
    String externalId,
    Number amount,
    String phone
);

Get an e-wallet payment

EWalletPayment payment = EWalletPayment.getPaymentStatus("ovo-ewallet", EWalletPayment.EWalletType.OVO);

Back to top

Credit Card Services

Create an authorization

You can choose whether want to put the attributes as parameters or to put in inside a Map object.

CreditCardCharge.createAuthorization(
    String tokenId,
    String externalId,
    Number amount,
    String authenticationId,
    String cardCVN,
    Boolean capture
);
CreditCardCharge.createAuthorization(
    Map<String, Object> params
);
CreditCardCharge creditCardCharge = CreditCard.createAuthorization("...", "test_id", 75000, "...", "123", false);

Create a charge

You can choose whether want to put the attributes as parameters or to put in inside a Map object.

CreditCardCharge.createCharge(
    String tokenId,
    String externalId,
    Number amount,
    String authenticationId,
    String cardCVN,
    String descriptor
);
CreditCardCharge.createCharge(
    Map<String, Object> params
);
CreditCardCharge creditCardCharge = CreditCard.createCharge("...", "test_id", 75000, "...", "123", "lorem ipsum");

Reverse an authorization

CreditCard.reverseAuthorization(String chargeId, String externalId);

CreditCardReverseAuth creditCardReverseAuth = CreditCard.reverseAuthorization("1234567", "external_id");

Capture a charge

CreditCard.captureCharge(String chargeId, Number amount);

CreditCardCharge creditCardCharge = CreditCard.captureCharge("12345678", 55000);

Get a charge by ID

CreditCardCharge creditCardCharge = CreditCard.getCharge("1234567");

Create a refund

CreditCard.createRefund(String id, Number amount, String externalId);

CreditCardRefund creditCardRefund = CreditCard.createRefund("1234567", 50000, "external_id");

Back to top

Batch Disbursement Services

Batch disbursement item

BatchDisbursementItem item =
    BatchDisbursementItem.builder()
        .amount(10000)
        .bankCode("ABC")
        .bankAccountName("Lorem Ipsum")
        .bankAccountNumber("1234567890")
        .description("Lorem ipsum dolor sit amet")
        .externalId("test_id")
        .emailTo(["email1", "email2"])
        .emailCC(["email1", "email2"])
        .emailBcc(["email1", "email2"])
        .build();

Create a batch disbursement

BatchDisbursement.create(
    String reference,
    BatchDisbursementItem[] disbursements
);

Get banks with available disbursement service

AvailableBank[] banks = BatchDisbursement.getAvailableBanks();

Back to top

Cardless Credit Services

Cardless credit item

CardlessCreditItem item =
    CardlessCreditItem.builder()
        .id("123")
        .name("Phone Case")
        .price(200000)
        .type("Smartphone")
        .url("https://www.example.org")
        .quantity(1)
        .build();

Cardless credit customer details

CardlessCreditCustomer customer =
    CardlessCreditCustomer.builder()
        .firstName("Lorem")
        .lastName("Ipsum")
        .email("email@example.com")
        .phone("08129748247684")
        .build();

Cardless credit shipping address

CardlessCreditShippingAddress address =
    CardlessCreditShippingAddress.builder()
        .firstName("Lorem")
        .lastName("Ipsum")
        .address("Jalan teknologi")
        .city("Jakarta")
        .postalCode("12345")
        .countryCode("IDN")
        .phone("08129748247684")
        .build();

Create a cardless credit payment

You can choose whether want to put the attributes as parameters or to put in inside a Map object.

CardlessCredit.create(
    String cardlessCreditType,
    String externalId,
    Number amount,
    String paymentType,
    CardlessCreditItem[] items,
    CardlessCreditCustomer customerDetails,
    CardlessCreditShippingAddress shippingAddress,
    String redirectUrl,
    String callbackUrl
);
CardlessCredit.create(
    Map<String, Object> params
);
CardlessCredit cardlessCredit = CardlessCredit.create(
    "KREDIVO",
    "external_id",
    200000,
    CardlessCredit.PaymentType.THREE_MONTHS.getVal(),
    items,
    customer,
    address,
    "www.example.com",
    "www.example.com"
);

QR Code

Create QR Code

QRCode qrCode = QRCode.create(
    "external_id",
    QRCode.QRCodeType.DYNAMIC,
    "https://callback.site",
    10000
);

Get QR Code

QRCode qrCode = QRCode.getQRCode("external_id");

Back to top

Contributing

You can go to the contributing guidelines to learn on how to contribute this project.

Lint

Run ./gradlew spotlessApply to apply linter.

Tests

Make sure the the code passes all tests.

./gradlew test

Precommit

Before making any commits, please install pre-commit. To install pre-commit, follow the installation steps.

For any requests, bugs, or comments, please open an issue or submit a pull request.

About

Xendit REST API Client for Java - Card, Virtual Account, Invoice, Disbursement, Recurring Payments, Payout, EWallet, Balance, Retail Outlets Services

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • Java 100.0%