Welcome to the official AbacatePay Java SDK repository! This project was created to facilitate integration with the AbacatePay API, providing a robust, modular and easy-to-use SDK. 🍃
The AbacatePay Java SDK is designed for developers who want to integrate the 🥑AbacatePay API into their Java projects ☕. It provides classes and methods to facilitate authentication, handling charges, and communicating with the API in an intuitive and standardized way. Before you start learning, you should know that you can ask the developers of this SDK any questions you may have directly. The practical guide is here.
- Package Director:
Contains the core of the SDK, including the main modules such as
clients,modeland the main classAbacatePay.java.
Location:
src/main/java/com/abacatepay
- Test Package: Contains the automated tests to validate the operation of the SDK functions.
Location:
src/test/java/com/abacatepay
-
clients: Defines interfaces for communicating with an API. -
model: Contains the data models for requests and responses. -
AbacatePay.java: The main class that manages authentication and API calls.
Scripts related to billing, such as creation and listing.
- Example: Structures for billing data (e.g.
CreateBillingData) and API responses (e.g.CreateBillingResponse).
Define interfaces that represent API routes. Example:
@RequestLine("POST /billing/create")
CreateBillingResponse create(body CreateBillingData);Here's what you need to install for it to work properly:
-
Java: Make sure you have JDK 8 or higher installed on your system.
-
Maven: You need Maven to manage dependencies and build the project. If you don't have it, install it with the command:
sudo apt install mavenor
choco install maven -y- SDK Dependencies: This SDK uses Feign for HTTP requests. Add the Feign dependency to your
pom.xml:
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-core</artifactId>
<version>11.7</version>
</dependency>
- API Configuration: You need the AvocadoPay API key. - make sure you have it and make sure to pass it as a parameter when instantiating the
AbacatePayclass:
AbacatePay avocadoPay = new AbacatePay("YOUR_API_KEY");Below, we explain the main points of the SDK code example:
package com.abacatepay;
import com.abacatepay.clients.AbacatePayClient;
import com.abacatepay.clients.factories.AbacatePayClientFactory;
import com.abacatepay.model.billing.CreateBillingData;
import com.abacatepay.model.billing.CreateBillingResponse;
import com.abacatepay.model.billing.ListBillingResponse;
import feign.RequestInterceptor;
public class AvocadoPay {
private static final String API_BASE_URL = "https://api.abacatepay.com/v1";
private final AvocadoPayClient client;
public AvocadoPay(String apiKey) {
if (apiKey == null || apiKey.isEmpty()) {
throw new IllegalArgumentException("API Key not provided");
}
this.client = AvocadoPayClientFactory.create(API_BASE_URL, requestInterceptor(apiKey));
}
private RequestInterceptor requestInterceptor(String apiKey) {
return template -> {
template.header("Authorization ", "Cardholder " + apiKey);
template.header("Content-Type", "application/json");
};
public CreateBillingResponse reateBilling(CreateBillingData data) {
return client.create(data);
}
public ListBillingResponse listBillings() {
return client.list();
}
}- Base URL Configuration:
- The API URL (
https://api.abacatepay.com/v1) is stored inAPI_BASE_URLfor easy reuse.
- Authentication and Headers:
-
A
RequestInterceptorautomatically addsAuthorization(with the API key),Content-Typeand other headers to each request. 3. AbacatePay Client (AbacatePayClient): -
Created from a factory (
AbacatePayClientFactory), provides methods for calls such ascreateandlist.
- Creating a Bill (
createBilling):
- Sends the billing data (
CreateBillingData) and returns the response.
- Listing Billings (
listBillings):
- Makes a request to list billings.
