LogoLogo
Document ValidationsPayment Methods
Latest
Latest
  • D24 APIs
  • Getting Started with D24
  • API Documentation
    • Deposits API
      • Technical and Security Aspects
        • Calculating the Signature
      • Endpoints
        • Deposit Creation Endpoint
          • Notifications
        • PCI Deposit Creation Endpoint
        • Deposit Status Endpoint
        • Payment Methods Endpoint
        • Currency Exchange Endpoint
        • Crypto Exchange Endpoint
        • Country States Codes Endpoint
        • Refund Creation Endpoint
          • Notifications
        • Refund Status Endpoint
      • Payment Methods
        • 🌎America
          • 🇦🇷Argentina
          • 🇧🇴Bolivia
          • 🇧🇷Brazil
          • 🇨🇱Chile
          • 🇨🇦Canada
          • 🇨🇴Colombia
          • 🇪🇨Ecuador
          • 🇬🇹Guatemala
          • 🇲🇽Mexico
          • 🇵🇾Paraguay
          • 🇵🇪Peru
        • 🌍Africa
          • 🇧🇼Botswana
          • 🇨🇲Cameroon
          • 🇨🇬Congo Brazzaville
          • 🇨🇩Congo DRC
          • 🇪🇬Egypt
          • 🇬🇦Gabon
          • 🇬🇭Ghana
          • 🇨🇮Ivory Coast
          • 🇰🇪Kenya
          • 🇳🇬Nigeria
          • 🇲🇼Malawi
          • 🇷🇼Rwanda
          • 🇿🇦South Africa
          • 🇺🇬Uganda
          • 🇿🇲Zambia
          • 🇹🇿Tanzania
        • 🌏Asia
          • 🇧🇩Bangladesh
          • 🇨🇳China
          • 🇭🇰Hong Kong
          • 🇮🇳India
          • 🇮🇩Indonesia
          • 🇯🇵Japan
          • 🇲🇾Malaysia
          • 🇵🇰Pakistan
          • 🇹🇭Thailand
          • 🇹🇷Turkey
          • 🇻🇳Vietnam
      • API Codes
    • Cashouts API
      • Technical and Security Aspects
        • Calculating the Payload-Signature
      • Endpoints
        • Cashout Creation Endpoint
          • Notifications
        • Cashout Status Endpoint
        • Cashout Update Status Endpoint
        • Cashout Cancellation Endpoint
        • Cashout Bank Codes
      • Countries Validations
        • American Countries
          • 🇧🇴Bolivia
          • 🇧🇷Brazil
          • 🇨🇦Canada
          • 🇨🇱Chile
          • 🇨🇴Colombia
          • 🇪🇨Ecuador
          • 🇲🇽Mexico
          • 🇵🇪Peru
          • 🇦🇷Argentina
          • 🇵🇾Paraguay
        • African Countries
          • 🇧🇼Botwsana
          • 🇨🇲Cameroon
          • 🇨🇬Congo Brazzaville
          • 🇨🇩Congo DRC
          • 🇪🇬Egypt
          • 🇬🇦Gabon
          • 🇬🇭Ghana
          • 🇰🇪Kenya
          • 🇲🇼Malawi
          • 🇳🇬Nigeria
          • 🇷🇼Rwanda
          • 🇿🇦SOUTH AFRICA
          • 🇿🇲Zambia
        • Asian Countries
          • 🇧🇩Bangladesh
          • 🇨🇳China
          • 🇮🇳India
          • 🇮🇩Indonesia
          • 🇯🇵Japan
          • 🇲🇾Malaysia
          • 🇹🇭Thailand
          • 🇹🇷Turkey
          • 🇵🇰Pakistan
          • 🇻🇳Vietnam
        • Oceania Countries
          • 🇦🇺Australia
      • API Codes
    • Subscriptions API
      • Technical and Security Aspects
        • Calculating the Signature
      • Subscription Creation Endpoints
        • OneShot Subscription Creation
        • PCI Subscription Creation Endpoint
        • Notifications
      • Subscription Cancellation Endpoint
      • Subscription Status Endpoint
    • Bank Accounts Validation API
      • Technical and Security Aspects
        • Calculating the Signature
      • Endpoints
        • Bank Account Validation Endpoint
        • Pix Key Validation Endpoint
      • API Codes
    • KYC API
      • Technical and Security Aspects
        • Calculating the Signature
      • KYC Endpoint
      • API Codes
    • Reconciliation API
      • Technical and Security Aspects
      • Endpoints
      • API Codes
    • Quickpay
      • Endpoints
        • Deposit creation endpoint
          • Notifications
        • Deposit Status Endpoint
    • Tools for Platforms
      • Technical and Security Aspects
        • Calculating the Signature
      • SubMerchant Creation
        • Notifications
      • SubMerchant Status Endpoint
      • Commission Update Endpoint
  • PLUGINS
    • Shopify
      • Installation
      • Onboarding
      • Customer flow
      • Admin Flow
      • Tutorials
      • FAQ
    • WooCommerce
      • Installation
      • Configuration
  • Deposits Tools
    • Cards SDK
      • With User Interface
        • 🚀Color Customization
      • Without User Interface
    • Java SDK
    • PHP SDK
  • Knowledge Base
    • Countries Specifications
    • Deposits with Cards SDK
      • With User Interface
      • Without User Interface
    • Deposits with 3DS Authentication
    • Deposits with Installments
  • v1 Developers Guide
  • Status Page
Powered by GitBook
On this page
  • Introduction
  • Installation
  • Requirements
  • Gradle Users
  • Maven Users
  • Dependencies
  • Usage
  • Deposit Credentials
  • Read-Only Credentials
  • Classes
  • Create Deposit
  • Deposit Status
  • Payment Methods
  • Exchange Rates
  • Create Refund
  • Refund Status

Was this helpful?

  1. Deposits Tools

Java SDK

Learn how to use our SDK in Java to facilitate even further the integration with our Deposits APIs

PreviousWithout User InterfaceNextPHP SDK

Last updated 1 year ago

Was this helpful?

Introduction

The Deposits Java SDK (Software Development Kit) is a software package you can download and add to your existing code facilitating the integration by having pre-defined classes and functions you can call to integrate the .

Review and download the source code from GitHub by clicking on the button below

Installation

Requirements

  • Java 1.8 or later

Gradle Users

Add this dependency to your project's build file:

Java Gradle Dependency
implementation "com.directa24:cashin-java-sdk:1.0.13"

Maven Users

Add this dependency to your project's POM:

Java Maven dependency
<dependency>
  <groupId>com.directa24</groupId>
  <artifactId>cashin-java-sdk</artifactId>
  <version>1.0.13</version>
</dependency>

Dependencies

Usage

Begin by initializing your credentials

Deposit Credentials

String depositKeySbx = "fUEhPEKrUt";
String secretKeySbx = "wSHTfsMMdNskTppilncuZPEklgLmdUAOg";

Directa24 directa24Sandbox = new Directa24.Sandbox(depositKeySbx, secretKeySbx);

Read-Only Credentials

String readOnlyKeySbx = "EKiFOWiHnI";

Directa24 directa24Sandbox = new Directa24.Sandbox(readOnlyKeySbx);

Make sure you have whitelisted your servers IPs on our Merchant Panel by going to Settings -> API Access.

As soon as you are ready with the integration and you have the production credentials, replace the credentials for the production ones.

Classes

Create Deposit

public class CreateDepositExample {

   public static void main(String[] args) {

      Address address = Address.builder()
                               .street("Rua Dr. Franco Ribeiro, 52")
                               .city("Rio Branco")
                               .state("AC")
                               .zipCode("11600-234")
                               .build();

      Payer payer = Payer
            .builder()
            .id("4-9934519")
            .address(address)
            .document("21329039050")
            .documentType("CPF")
            .email("[email protected]")
            .firstName("Ricardo")
            .lastName("Carlos")
            .phone("+59899000878")
            .build();

      BankAccount bankAccount = BankAccount
            .builder()
            .bankCode("01")
            .accountNumber("3242342")
            .accountType("SAVING")
            .beneficiary("Ricardo Carlos")
            .branch("12")
            .build();

      CreateDepositRequest createDepositRequest = CreateDepositRequest
            .builder()
            .invoiceId("108")
            .amount(new BigDecimal(100))
            .country("BR")
            .currency("BRL")
            .payer(payer)
            .paymentMethod("BB")
            .paymentType("BANK_TRANSFER")
            .bankAccount(bankAccount)
            .earlyRelease(false)
            .feeOnPayer(false)
            .surchargeOnPayer(false)
            .bonusAmount(BigDecimal.ONE)
            .bonusRelative(false)
            .strikethroughPrice(BigDecimal.ONE)
            .description("Test")
            .clientIp("186.51.171.84")
            .language("es")
            .deviceId("00000000-00000000-01234567-89ABCDEF")
            .backUrl("https://yoursite.com/deposit/108/cancel")
            .successUrl("https://yoursite.com/deposit/108/confirm")
            .errorUrl("https://yoursite.com/deposit/108/error")
            .notificationUrl("https://yoursite.com/ipn")
            .logo("https://yoursite.com/logo.png")
            .test(true)
            .mobile(false)
            .idempotency("")
            .build();

      try {
         CreateDepositResponse createDepositResponse = directa24Sandbox.client.createDeposit(createDepositRequest);
         
         // Handle response

      } catch (Directa24Exception e) {
         // Handle errors
      }
   }
}

CreateDepositRequest.amount and CreateDepositRequest.country are the only mandatory fields for a successful request. The rest of the fields needs to be sent depending on the flow you have chosen as those will be collected by us if not sent.

Deposit Status

public class DepositStatusExample {

   public static void main(String[] args) {
      DepositStatusRequest depositStatusRequest = DepositStatusRequest
                                                  .builder()
                                                  .id(300000001)
                                                  .build();
      try {
         DepositStatusResponse depositStatusResponse = directa24Sandbox.client.depositStatus(depositStatusRequest);
      
         // Handle response

      } catch (Directa24Exception e) {
         // Handle errors
      }
   }
}

Make sure you are adding the deposit_id received on your notification_url in the field DepositStatusRequest.id.

Payment Methods

public class PaymentMethodsExample {

   public static void main(String[] args) {
      PaymentMethodRequest paymentMethodRequest = PaymentMethodRequest
                                                  .builder()
                                                  .country("BR")
                                                  .build();
      try {
         List<PaymentMethodResponse> paymentMethodResponse = directa24Sandbox.client.paymentMethods(paymentMethodRequest);
      
         // Handle response

      } catch (Directa24Exception e) {
         // Handle errors
      }
   }
}

Exchange Rates

public class ExchangeRateExample {

   public static void main(String[] args) {
      ExchangeRateRequest exchangeRatesRequest = ExchangeRateRequest
                                                 .builder()
                                                 .country("BR")
                                                 .amount(BigDecimal.TEN)
                                                 .build();
      try {
         ExchangeRateResponse exchangeRateResponse = directa24Test.client.exchangeRates(exchangeRateRequest);
         
         // Handle response

      } catch (Directa24Exception e) {
         // Handle errors
      }
   }
}

Create Refund

In order to create a refund, you need to send the deposit_id, merchant_invoice_id, and the bank_account object (only for non-cc payments, otherwise, it is optional).

public class CreateRefundTest extends AbstractDirecta24Test {

   @Before
   public void createMocks() {

      stubFor(post(urlMatching("/v3/refunds"))
            .withHeader("X-Login", equalTo(DEPOSIT_KEY))
            .withHeader("Content-Type", equalTo("application/json"))
            .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody("{\"refund_id\": 1000043\n}")));

   }

   @Test
   public void createRefundTest() throws Directa24Exception {

      Directa24 directa24Test = new Directa24.Test(DEPOSIT_KEY, SECRET_KEY);

      BankAccount bankAccount = BankAccount
            .builder()
            .bankCode("01")
            .accountNumber("3242342")
            .accountType("SAVING")
            .beneficiary("Ricardo Carlos")
            .branch("12")
            .build();

      CreateRefundRequest createRefundRequest = CreateRefundRequest
            .builder()
            .depositId(9999)
            .invoiceId("1234")
            .amount(new BigDecimal(100))
            .bankAccount(bankAccount)
            .comments("Test")
            .notificationUrl("https://yoursite.com/ipn")
            .idempotency("")
            .build();

      CreateRefundResponse createRefundResponse = directa24Test.client.createRefund(createRefundRequest);

      assertTrue(createRefundResponse != null && createRefundResponse.getRefundId() != null);

      verify(postRequestedFor(urlEqualTo("/v3/refunds")).withHeader("Content-Type", equalTo("application/json")));
   }

}

Refund Status

public class RefundStatusTest extends AbstractDirecta24Test {

   @Before
   public void createMocks() {

      stubFor(get(urlMatching("/v3/refunds/123456"))
            .withHeader("X-Login", equalTo(DEPOSIT_KEY))
            .withHeader("Content-Type", equalTo("application/json"))
            .willReturn(aResponse()
                  .withStatus(200)
                  .withHeader("Content-Type", "application/json")
                  .withBody(
                        "{\"deposit_id\": 300537729,\"merchant_invoice_id\": \"postmanTest971574817\",\"status\": \"PENDING\",\"amount\": 1000.00}")));

      stubFor(get(urlMatching("/v3/refunds/999999"))
            .withHeader("X-Login", equalTo(DEPOSIT_KEY))
            .withHeader("Content-Type", equalTo("application/json"))
            .willReturn(aResponse().withStatus(404).withHeader("Content-Type", "application/json")));
   }

   @Test
   public void refundStatusTest() throws Directa24Exception {

      Directa24 directa24Test = new Directa24.Test(DEPOSIT_KEY, SECRET_KEY);

      RefundStatusRequest refundStatusRequest = RefundStatusRequest.builder() //
                                                                   .id(123456) //
                                                                   .build();

      RefundStatusResponse refundStatusResponse = directa24Test.client.refundStatus(refundStatusRequest);

      assertTrue(refundStatusResponse != null);
      assertEquals(refundStatusResponse.getStatus(), "PENDING");

      verify(getRequestedFor(urlEqualTo("/v3/refunds/" + 123456)).withHeader("Content-Type", equalTo("application/json")));
   }

   @Test
   public void refundNotFoundTest() {

      Directa24 directa24Test = new Directa24.Test(DEPOSIT_KEY, SECRET_KEY);

      RefundStatusRequest refundStatusRequest = RefundStatusRequest.builder() //
                                                                   .id(999999) //
                                                                   .build();

      RefundStatusResponse refundStatusResponse = null;
      try {
         refundStatusResponse = directa24Test.client.refundStatus(refundStatusRequest);
         fail("Refund doesn't exists");
      } catch (Directa24Exception e) {
      }

      assertTrue(refundStatusResponse == null);
   }

The library uses . While it is not a requirement, you might want to install a for your favorite IDE to facilitate development.

and library are needed to run the bundled tests.

for more information about the API Keys.

Once the credentials and the IPs have been properly set-up, you are ready to start using the classes the SDK provides. Each Class can be used to execute the functionalities of its respective

Make sure you take a look at the to review how the integration of each of them works, the validations and the responses formats.

heck the respective to see the format of the responses, fields requirements and validations.

Every time you need to create a deposit, you will need to invoke the CreateDepositRequest Class with all the objects containing the information required to be sent. The amount of information required depends on the flow you have chosen, either the or the

As soon as the deposit is created and you have received the notification in your notification_url, you will want to invoke the DepositStatusRequest Class to retrieve the of the deposit.

Click here to see the

For the best user experience, we recommend integrating our to automatically retrieve the of payment methods name, logos, types and more that your account has available.

In order to do that, invoke the PaymentMethodRequest Class containing the of the country you need the payment methods from in the field PaymentMethodRequest.country

If you need to know the Exchange Rate of a given currency, you can do so by invoking ExchangeRateRequest with the of the origin and the amount you want to convert to USD.

Project Lombok
plugin
JUnit 4
Wiremock
Deposit Endpoint.
Deposit Endpoints here
Endpoint Page
Payment Methods Endpoint
list
Deposits Endpoints
Click here
deposits status flow.
Hosted Checkout Experience
ONE SHOT Experience.
Open in GitHub
Country's ISO code
Country's ISO code
status