Git Product home page Git Product logo

xendit-java's Introduction

Xendit Java Library

Download from JCenter

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", "[email protected]");
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", "[email protected]");
params.put("interval", "MONTH");
params.put("interval_count", 1);
params.put("description", "Test desc");
params.put("amount", 100000);

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 protected]")
        .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"
);

Back to top

Contributing

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

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.

xendit-java's People

Contributors

afahmip avatar candrasaputra avatar ervanadetya avatar hakiemaul avatar javiersuweijie avatar kevindavee avatar stanleynguyen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.