Directa 24 Java client library
The official Directa 24 Java client library.
Installation
Requirements
- Java 1.8 or later
Gradle users
Add this dependency to your project's build file:
implementation "com.directa24:cashin-java-sdk:1.0.13"
Maven users
Add this dependency to your project's POM:
<dependency>
<groupId>com.directa24</groupId>
<artifactId>cashin-java-sdk</artifactId>
<version>1.0.13</version>
</dependency>
Documentation
Please see the Java API docs for the most up-to-date documentation.
Usage
Deposit Credentials
String depositKeySbx = "1955f2d";
String secretKeySbx = "4lph0ns3";
Directa24 directa24Sandbox = new Directa24.Sandbox(depositKeySbx, secretKeySbx);
Read Only Credentials
String readOnlyKeySbx = "EgIECaVuyW";
Directa24 directa24Sandbox = new Directa24.Sandbox(readOnlyKeySbx);
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("+598 99730878")
.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
}
}
}
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
}
}
}
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
}
}
}
For more examples see the bundled tests.
Dependencies
The library uses Project Lombok. While it is not a requirement, you might want to install a plugin for your favorite IDE to facilitate development.
JUnit 4 and Wiremock library are needed to run the bundled tests.