Skip to content

AbacatePay/abacatepay-java-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🥑 AbacatePay Java SDK

Readme Version Status License

Contributors Last Commit

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. 🍃

Imagem

📋 Table of Contents

  1. 📖Introduction
  2. 🛠️ Components
  3. 💻 Code Example

Introduction

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.


Repository Structure

  • Package Director: Contains the core of the SDK, including the main modules such as clients, model and the main class AbacatePay.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


Main Packages

main package

  • 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.

billing package

Scripts related to billing, such as creation and listing.

  • Example: Structures for billing data (e.g. CreateBillingData) and API responses (e.g. CreateBillingResponse).

clients package

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:

Installation

  1. Java: Make sure you have JDK 8 or higher installed on your system.

  2. 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 maven

or

choco install maven -y
  1. 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>
  1. 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 AbacatePay class:
AbacatePay avocadoPay = new AbacatePay("YOUR_API_KEY");

Code Example

Below, we explain the main points of the SDK code example:

Code:

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();
}
}

Code Explanation:

  1. Base URL Configuration:
  • The API URL (https://api.abacatepay.com/v1) is stored in API_BASE_URL for easy reuse.
  1. Authentication and Headers:
  • A RequestInterceptor automatically adds Authorization (with the API key), Content-Type and other headers to each request. 3. AbacatePay Client (AbacatePayClient):

  • Created from a factory (AbacatePayClientFactory), provides methods for calls such as create and list.

  1. Creating a Bill (createBilling):
  • Sends the billing data (CreateBillingData) and returns the response.
  1. Listing Billings (listBillings):
  • Makes a request to list billings.

About

AbacatePay Java SDK for you to start receiving payments in seconds

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages