Skip to content

SDK to facilitate Java integrations with the Stark Bank API

License

Notifications You must be signed in to change notification settings

starkbank/sdk-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stark Bank Java SDK

Welcome to the Stark Bank Java SDK! This tool is made for Java developers who want to easily integrate with our API. This SDK version is compatible with the Stark Bank API v2.

If you have no idea what Stark Bank is, check out our website and discover a world where receiving or making payments is as easy as sending a text message to your client!

Introduction

Index

Supported Java Versions

This library supports the following Java versions:

  • Java 8+

If you have specific version demands for your projects, feel free to contact us.

Stark Bank API documentation

If you want to take a look at our API, follow this link.

Versioning

This project adheres to the following versioning pattern:

Given a version number MAJOR.MINOR.PATCH, increment:

  • MAJOR version when the API version is incremented. This may include backwards incompatible changes;
  • MINOR version when breaking changes are introduced OR new functionalities are added in a backwards compatible manner;
  • PATCH version when backwards compatible bug fixes are implemented.

Setup

1. Install our SDK

Manually download the desired SDK version with the JAR found in our GitHub page and add it to your project.

1.1 If you are using Gradle, add this line to your dependencies in build.gradle:

dependencies {
  implementation 'com.starkbank:sdk:2.19.0'
}

1.2 If you are using Maven, add this dependency to your pom.xml:

<dependency>
  <groupId>com.starkbank</groupId>
  <artifactId>sdk</artifactId>
  <version>2.19.0</version>
</dependency>

Note: If you are using Android, don't forget to add the compileOptions to your build.gradle:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

2. Create your Private and Public Keys

We use ECDSA. That means you need to generate a secp256k1 private key to sign your requests to our API, and register your public key with us so we can validate those requests.

You can use one of following methods:

2.1. Check out the options in our tutorial.

2.2. Use our SDK:

import com.starkbank.*;

Key key = Key.create();

String privatePem = key.privatePem;
String publicPem = key.publicPem;

System.out.print(privatePem);
System.out.print(publicPem);

// or, to also save .pem files in a specific path
Key key = Key.create("file/keys/");

String privatePem = key.privatePem;
String publicPem = key.publicPem;

System.out.print(privatePem);
System.out.print(publicPem);

3. Create a Project

3. Register your user credentials

You can interact directly with our API using two types of users: Projects and Organizations.

  • Projects are workspace-specific users, that is, they are bound to the workspaces they are created in. One workspace can have multiple Projects.
  • Organizations are general users that control your entire organization. They can control all your Workspaces and even create new ones. The Organization is bound to your company's tax ID only. Since this user is unique in your entire organization, only one credential can be linked to it.

3.1. To create a Project in Sandbox:

3.1.1. Log into Starkbank Sandbox

3.1.2. Go to Menu > Integrations

3.1.3. Click on the "New Project" button

3.1.4. Create a Project: Give it a name and upload the public key you created in section 2

3.1.5. After creating the Project, get its Project ID

3.1.6. Use the Project ID and private key to create the object below:

import com.starkbank.*;

// Get your private key from an environment variable or an encrypted database.
// This is only an example of a private key content. You should use your own key.
String privateKeyContent = "-----BEGIN EC PARAMETERS-----\nBgUrgQQACg==\n-----END EC PARAMETERS-----\n-----BEGIN EC PRIVATE KEY-----\nMHQCAQEEIMCwW74H6egQkTiz87WDvLNm7fK/cA+ctA2vg/bbHx3woAcGBSuBBAAK\noUQDQgAE0iaeEHEgr3oTbCfh8U2L+r7zoaeOX964xaAnND5jATGpD/tHec6Oe9U1\nIF16ZoTVt1FzZ8WkYQ3XomRD4HS13A==\n-----END EC PRIVATE KEY-----";

Project project = new Project(
    "sandbox",
    "5656565656565656",
    privateKeyContent
);

3.2. To create Organization credentials in Sandbox:

3.2.1. Log into Starkbank Sandbox

3.2.2. Go to Menu > Integrations

3.2.3. Click on the "Organization public key" button

3.2.4. Upload the public key you created in section 2 (only a legal representative of the organization can upload the public key)

3.2.5. Click on your profile picture and then on the "Organization" menu to get the Organization ID

3.2.6. Use the Organization ID and private key to create the object below:

import com.starkbank.*;

// Get your private key from an environment variable or an encrypted database.
// This is only an example of a private key content. You should use your own key.
String privateKeyContent = """
-----BEGIN EC PARAMETERS-----
BgUrgQQACg==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIMCwW74H6egQkTiz87WDvLNm7fK/cA+ctA2vg/bbHx3woAcGBSuBBAAK
oUQDQgAE0iaeEHEgr3oTbCfh8U2L+r7zoaeOX964xaAnND5jATGpD/tHec6Oe9U1
IF16ZoTVt1FzZ8WkYQ3XomRD4HS13A==
-----END EC PRIVATE KEY-----
""";

Organization organization = new Organization(
    "sandbox",
    "5656565656565656",
    privateKeyContent,
    null, // You only need to set the workspaceId when you are operating a specific workspaceId
);

// To dynamically use your organization credentials in a specific workspaceId,
// you can use the Organization.replace() method:
Balance balance = Balance.get(Organization.replace(organization, "4848484848484848"));
System.out.println(balance);

NOTE 1: Never hard-code your private key. Get it from an environment variable or an encrypted database.

NOTE 2: We support 'sandbox' and 'production' as environments.

NOTE 3: The credentials you registered in sandbox do not exist in production and vice versa.

4. Setting up the user

There are three kinds of users that can access our API: Organization, Project and Member.

  • Project and Organization are designed for integrations and are the ones meant for our SDKs.
  • Member is the one you use when you log into our webpage with your e-mail.

There are two ways to inform the user to the SDK:

4.1 Passing the user as argument in all functions:

import com.starkbank.*;

Balance balance = Balance.get(project); // or organization

4.2 Set it as a default user in the SDK:

import com.starkbank.*;

Settings.user = project; // or organization

Balance balance = Balance.get();

Just select the way of passing the user that is more convenient to you. On all following examples we will assume a default user has been set.

5. Setting up the error language

The error language can also be set in the same way as the default user:

import com.starkbank.*;

Settings.language = "en-US";

Language options are "en-US" for english and "pt-BR" for brazilian portuguese. English is default.

6. Resource listing and manual pagination

Almost all SDK resources provide a query and a page function.

  • The query function provides a straight forward way to efficiently iterate through all results that match the filters you inform, seamlessly retrieving the next batch of elements from the API only when you reach the end of the current batch. If you are not worried about data volume or processing time, this is the way to go.
import com.starkbank.*;
import com.starkbank.utils.Generator;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("limit", 200);
Generator<Transaction> transactions = Transaction.query(params);

for (Transaction transaction : transactions){
    System.out.println(transaction);
}
  • The page function gives you full control over the API pagination. With each function call, you receive up to 100 results and the cursor to retrieve the next batch of elements. This allows you to stop your queries and pick up from where you left off whenever it is convenient. When there are no more elements to be retrieved, the returned cursor will be None.
import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("limit", 50);
params.put("cursor", null);

while (true) {
    Transaction.Page page = Transaction.page(params);
    for (Transaction transaction: page.transactions) {
        System.out.println(transaction);
    }
    if (page.cursor == null) {
        break;
    }
    params.put("cursor", page.cursor);
}

To simplify the following SDK examples, we will only use the query function, but feel free to use page instead.

Testing in Sandbox

Your initial balance is zero. For many operations in Stark Bank, you'll need funds in your account, which can be added to your balance by creating an Invoice or a Boleto.

In the Sandbox environment, most of the created Invoices and Boletos will be automatically paid, so there's nothing else you need to do to add funds to your account. Just create a few Invoices and wait around a bit.

In Production, you (or one of your clients) will need to actually pay this Invoice or Boleto for the value to be credited to your account.

Usage

Here are a few examples on how to use the SDK. If you have any doubts, use the built-in help() function to get more info on the desired functionality (for example: help(starkbank.boleto.create))

Create transactions

To send money between Stark Bank accounts, you can create transactions:

import com.starkbank.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

List<Transaction> transactions = new ArrayList<>();
HashMap<String, Object> data = new HashMap<>();
data.put("amount", 10000);
data.put("receiverId", "5651751147405412");
data.put("description", "A Lannister always pays his debts");
data.put("externalId", "my_unique_id");
data.put("tags", new String[]{"lannister", "debts"});
transactions.add(new Transaction(data));

transactions = Transaction.create(transactions);

for (Transaction transaction : transactions){
    System.out.println(transaction);
}

Note: Instead of using UtilityPayment objects, you can also pass each payment element in HashMap format

Query transactions

To understand your balance changes (bank statement), you can query transactions. Note that our system creates transactions for you when you receive boleto payments, pay a bill or make transfers, for example.

import com.starkbank.*;
import com.starkbank.utils.Generator;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("after", "2020-04-01");
params.put("before", "2020-04-30");
Generator<Transaction> transactions = Transaction.query(params);

for (Transaction transaction : transactions){
    System.out.println(transaction);
}

Get a transaction

You can get a specific transaction by its id:

import com.starkbank.*;

Transaction transaction = Transaction.get("5155966664310784");

System.out.println(transaction);

Get balance

To know how much money you have in your workspace, run:

import com.starkbank.*;

Balance balance = Balance.get();

System.out.println(balance);

Create transfers

You can also create transfers in the SDK (TED/Pix) and configure transfer behavior according to its rules.

import com.starkbank.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

List<Transfer> transfers = new ArrayList<>();
HashMap<String, Object> data1 = new HashMap<>();
data1.put("amount", 100000000);
data1.put("bankCode", "341"); // TED
data1.put("branchCode", "2201");
data1.put("accountNumber", "76543-8");
data1.put("taxId", "594.739.480-42");
data1.put("name", "Daenerys Targaryen Stormborn");
data1.put("scheduled", "2020-12-11");
data1.put("description", "Transaction to dear provider");
data1.put("tags", new String[]{"daenerys", "invoice/1234"});
transfers.add(new Transfer(data1));

List<Transfer.Rule> rules = new ArrayList<>();
rules.add(
    new Transfer.Rule(
        "resendingLimit",   // Set maximum number of retries if Payment fails due to systemic issues at the receiver bank
        5                   // Our resending limit is 10 by default
    )
);

HashMap<String, Object> data2 = new HashMap<>();
data2.put("amount", 100000000);
data2.put("bankCode", "20018183"); // Pix
data2.put("branchCode", "2201");
data2.put("accountNumber", "76543-8");
data2.put("accountType", "checking");
data2.put("externalId", "my-internal-id-12345");
data2.put("taxId", "594.739.480-42");
data2.put("name", "Daenerys Targaryen Stormborn");
data2.put("scheduled", "2020-11-11T15:01:39.903667+00:00");
data2.put("tags", new String[]{"daenerys", "invoice/1234"});
data2.put("rules", rules);
transfers.add(new Transfer(data2));

transfers = Transfer.create(transfers);

for (Transfer transfer : transfers){
    System.out.println(transfer);
}

Note: Instead of using Transfer objects, you can also pass each transfer element in HashMap format

Query transfers

You can query multiple transfers according to filters.

import com.starkbank.*;
import com.starkbank.utils.Generator;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("after", "2020-04-01");
params.put("before", "2020-04-30");
Generator<Transfer> transfers = Transfer.query(params);

for (Transfer transfer : transfers){
    System.out.println(transfer);
}

Get a transfer

To get a single transfer by its id, run:

import com.starkbank.*;

Transfer transfer = Transfer.get("6532638269505536");

System.out.println(transfer);

Cancel a scheduled transfer

To cancel a scheduled transfer by its id, run:

import com.starkbank.*;

Transfer transfer = Transfer.delete("6532638269505536");

System.out.println(transfer);

Get a transfer PDF

After its creation, a transfer PDF may also be retrieved by passing its id.

import java.io.File;
import java.io.InputStream;
import java.nio.file.StandardCopyOption;
import com.starkbank.*;

InputStream pdf = Transfer.pdf("6266195376340992");

java.nio.file.Files.copy(
    pdf,
    new File("transfer.pdf").toPath(),
    StandardCopyOption.REPLACE_EXISTING
);

Be careful not to accidentally enforce any encoding on the raw pdf content, as it may yield abnormal results in the final file, such as missing images and strange characters.

Query transfer logs

You can query transfer logs to better understand transfer life cycles.

import com.starkbank.*;
import com.starkbank.utils.Generator;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("after", "2020-04-01");
params.put("before", "2020-04-30");
Generator<Transfer.Log> logs = Transfer.Log.query(params);

for (Transfer.Log log : logs){
    System.out.println(log);
}

Get a transfer log

You can also get a specific log by its id.

import com.starkbank.*;

Transfer.Log log = Transfer.Log.get("6532638269505536");

System.out.println(log);

Get DICT key

You can get Pix key's parameters by its id.

import com.starkbank.*;

DictKey dictKey = DictKey.get("[email protected]");

System.out.println(dictKey);

Query your DICT keys

To take a look at the Pix keys linked to your workspace, just run the following:

import com.starkbank.*;
import java.util.HashMap;
import com.starkbank.utils.Generator;

HashMap<String, Object> params = new HashMap<>();
params.put("status", "registered");
params.put("limit", 1);
params.put("type", "evp");

Generator<DictKey> dictKeys = DictKey.query(params);
for (DictKey dictKey : dictKeys) {
    System.out.println(dictKey);
}

Query Bacen institutions

You can query institutions registered by the Brazilian Central Bank for Pix and TED transactions.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("search", "stark");

Generator<Institution> institutions = Institution.query(params);

for (Institution institution : institutions) {
   System.out.println(institution);
}

Create invoices

You can create dynamic QR Code invoices to charge customers or to receive money from accounts you have in other banks.

Since the banking system only understands value modifiers (discounts, fines and interest) when dealing with dates (instead of datetimes), these values will only show up in the end user banking interface if you use dates in the "due" and "discounts" fields.

If you use datetimes instead, our system will apply the value modifiers in the same manner, but the end user will only see the final value to be paid on his interface.

Also, other banks will most likely only allow payment scheduling on invoices defined with dates instead of datetimes.

import com.starkbank.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

List<Invoice> invoices = new ArrayList<>();

List<HashMap<String, Object>> descriptions = new ArrayList<>();
HashMap<String, Object> description = new HashMap<String, Object>(){{
    put("key", "Some supplies");
    put("value", "100000");
}};
descriptions.add(description);

List<Invoice.Rule> rules = new ArrayList<>();
rules.add(
    new Invoice.Rule(
        "allowedTaxIds",                        // Set TaxIds allowed to receive this Invoice
        new String[] { "012.345.678-90" }
    )
);

invoices.add(new Invoice(new HashMap<String, Object>(){{
    put("tags", new String[]{"immediate"});
    put("amount", 23571);
    put("due", "2021-11-28T17:59:26.249976+00:00");
    put("taxId", "012.345.678-90");
    put("name", "Buzz Aldrin");
    put("expiration", 123456789);
    put("fine", 5);
    put("interest", 2.5);
    put("rules", rules);
    put("descriptions", descriptions);
}}));

List<HashMap<String, Object>> discounts = new ArrayList<>();
HashMap<String, Object> discount = new HashMap<String, Object>(){{
    put("due", "2021-11-27");
    put("percentage", 2.5);
}};
discounts.add(discount);

invoices.add(new Invoice(new HashMap<String, Object>(){{
    put("tags", new String[]{"scheduled"});
    put("amount", 23571);
    put("due", "2021-11-28");
    put("taxId", "012.345.678-90");
    put("name", "Buzz Aldrin");
    put("expiration", 123456789);
    put("fine", 5);
    put("interest", 2.5);
    put("discounts", discounts);
}}));

invoices = Invoice.create(invoices);

for (Invoice invoice : invoices) {
    System.out.println(invoice);
}

Note: Instead of using Invoice objects, you can also pass each invoice element in map format

Get an invoice

After its creation, information on an invoice may be retrieved by its id. Its status indicates whether it's been paid.

import com.starkbank.*;

Invoice invoice = Invoice.get("5155165527080960");

System.out.println(invoice);

Get an invoice QR Code

After its creation, an invoice QR Code png file may be retrieved by its id.

import com.starkbank.*;
import java.io.File;
import java.io.InputStream;
import java.nio.file.StandardCopyOption;
import java.util.HashMap;

HashMap<String, Object> options = new HashMap<>();
InputStream png = Invoice.qrcode("5155165527080960");

java.nio.file.Files.copy(
    png,
    new File("qrcode.png").toPath(),
    StandardCopyOption.REPLACE_EXISTING
);

Get an invoice PDF

After its creation, an invoice PDF may be retrieved by its id.

import com.starkbank.*;
import java.io.File;
import java.io.InputStream;
import java.nio.file.StandardCopyOption;
import java.util.HashMap;

HashMap<String, Object> options = new HashMap<>();
options.put("layout", "booklet");
InputStream pdf = Invoice.pdf("5155165527080960", options);

java.nio.file.Files.copy(
    pdf,
    new File("invoice.pdf").toPath(),
    StandardCopyOption.REPLACE_EXISTING
);

Be careful not to accidentally enforce any encoding on the raw pdf content, as it may yield abnormal results in the final file, such as missing images and strange characters.

Cancel an invoice

You can also cancel an invoice by its id. Note that this is not possible if it has been paid already.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> patchData = new HashMap<>();
patchData.put("status", "canceled");
Invoice invoice = Invoice.update("5155165527080960", patchData);

System.out.println(invoice);

Update an invoice

You can update an invoice's amount, due date and expiration by its id. If the invoice has already been paid, only the amount can be decreased, which will result in a payment reversal. To fully reverse the invoice, pass amount with a value of 0.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> patchData = new HashMap<>();
patchData.put("status", "canceled");
patchData.put("amount", 999999);
patchData.put("due", "2020-11-02T23:06:42.924000+00:00");
patchData.put("expiration", 123456789);
Invoice invoice = Invoice.update("5155165527080960", patchData);

System.out.println(invoice);

Query invoices

You can get a list of created invoices given some filters.

import com.starkbank.*;
import java.util.HashMap;
import com.starkbank.utils.Generator;

HashMap<String, Object> params = new HashMap<>();
params.put("status", "created");
params.put("limit", 1);
params.put("after", "2019-04-01");
params.put("before", "2030-04-30");

Generator<Invoice> invoices = Invoice.query(params);
for (Invoice invoice : invoices) {
    System.out.println(invoice);
}

Query invoice logs

Logs are pretty important to understand the life cycle of an invoice.

import com.starkbank.*;
import java.util.HashMap;
import com.starkbank.utils.Generator;

HashMap<String, Object> params = new HashMap<>();
params.put("limit", 3);
params.put("after", "2019-04-01");
params.put("before", "2030-04-30");
Generator<Invoice.Log> logs = Invoice.Log.query(params);

for (Invoice.Log log : logs) {
    System.out.println(log);
}

Get an invoice log

You can get a single log by its id.

import com.starkbank.*;

Invoice.Log log = Invoice.Log.get("5155165527080960");

System.out.println(log);

Get a reversed invoice log PDF

Whenever an Invoice is successfully reversed, a reversed log will be created. To retrieve a specific reversal receipt, you can request the corresponding log PDF:

import com.starkbank.*;

InputStream pdf = Invoice.Log.pdf("5155165527080960");
java.nio.file.Files.copy(
   pdf,
   new File("invoice.pdf").toPath(),
   StandardCopyOption.REPLACE_EXISTING
);

Be careful not to accidentally enforce any encoding on the raw pdf content, as it may yield abnormal results in the final file, such as missing images and strange characters.

Get an invoice payment information

Once an invoice has been paid, you can get the payment information using the Invoice.Payment sub-resource:

import com.starkbank.*;

Invoice.Payment payment = Invoice.payment("5155165527080960");

System.out.println(payment);

Create DynamicBrcodes

You can create simplified dynamic QR Codes to receive money using Pix transactions. When a DynamicBrcode is paid, a Deposit is created with the tags parameter containing the character “dynamic-brcode/” followed by the DynamicBrcode’s uuid "dynamic-brcode/{uuid}" for conciliation.

The differences between an Invoice and the DynamicBrcode are the following:

Invoice DynamicBrcode
Expiration âś“ âś“
Can only be paid once âś“ âś“
Due, fine and fee âś“ X
Discount âś“ X
Description âś“ X
Can be updated âś“ X

Note: In order to check if a BR code has expired, you must first calculate its expiration date (add the expiration to the creation date). Note: To know if the BR code has been paid, you need to query your Deposits by the tag "dynamic-brcode/{uuid}" to check if it has been paid.

import com.starkbank.*;

List<DynamicBrcode> brcodes = new ArrayList<>();

HashMap<String, Object> data = new HashMap<>();
data.put("amount", 23571);  // R$ 235,71 
data.put("expiration", 4000);
brcodes.add(new DynamicBrcode(data));

data = new HashMap<>();
data.put("amount", 23571);  // R$ 235,71 
data.put("expiration", 4000);
brcodes.add(new DynamicBrcode(data));

brcodes = DynamicBrcode.create(brcodes);

for (DynamicBrcode brcode : brcodes) {
    System.out.println(brcode);
}

Note: Instead of using DynamicBrcode objects, you can also pass each brcode element in map format

Get a DynamicBrcode

After its creation, information on a DynamicBrcode may be retrieved by its uuid.

import com.starkbank.*;

DynamicBrcode brcode = DynamicBrcode.get("4035a21a211d400e8c3335417090639f");

System.out.println(brcode);

Query DynamicBrcodes

You can get a list of created DynamicBrcodes given some filters.

import com.starkbank.*;

HashMap<String, Object> params = new HashMap<>();
params.put("after", "2023-01-01");
params.put("before", "2023-01-30");

Generator<DynamicBrcode> brcodes = DynamicBrcode.query(params);

for (DynamicBrcode brcode : brcodes) {
    System.out.println(brcode);
}

Query deposits

You can get a list of created deposits given some filters.

import com.starkbank.*;
import com.starkbank.utils.Generator;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("after", "2020-04-01");
params.put("before", "2020-04-30");
Generator<Deposit> deposits = Deposit.query(params);

for (Deposit deposit : deposits){
    System.out.println(deposit);
}

Get a deposit

After its creation, information on a deposit may be retrieved by its id.

import com.starkbank.*;

Deposit deposit = Deposit.get("5730174175805440");

System.out.println(deposit);

Update a deposit

Update a deposit by passing its id to be partially or fully reversed.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> patchData = new HashMap<>();
patchData.put("amount", 0);
Deposit deposit = Deposit.update("5155165527080960", patchData);

System.out.println(deposit);

Query deposit logs

Logs are pretty important to understand the life cycle of a deposit.

import com.starkbank.*;
import com.starkbank.utils.Generator;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("after", "2020-04-01");
params.put("before", "2020-04-30");
Generator<Deposit.Log> logs = Deposit.Log.query(params);

for (Deposit.Log log : logs){
    System.out.println(log);
}

Get a deposit log

You can get a single log by its id.

import com.starkbank.*;

Deposit.Log log = Deposit.Log.get("6532638269505536");

System.out.println(log);

Create boletos

You can create boletos to charge customers or to receive money from accounts you have in other banks.

import com.starkbank.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

List<Boleto> boletos = new ArrayList<>();
HashMap<String, Object> data = new HashMap<>();
data.put("amount", 400000);
data.put("name", "Iron Bank S.A.");
data.put("taxId", "20.018.183/0001-80");
data.put("streetLine1", "Av. Faria Lima, 1844");
data.put("streetLine2", "CJ 13");
data.put("district", "Itaim Bibi");
data.put("city", "SĂŁo Paulo");
data.put("stateCode", "SP");
data.put("zipCode", "01500-000");
data.put("due", "2021-05-20");
data.put("fine", 2.5);
data.put("interest", 1.3);
data.put("overdueLimit", 5);
data.put("tags", new String[]{"War supply", "Invoice #1234"});

List<Boleto.Description> descriptions = new ArrayList<>();
descriptions.add(new Boleto.Description("taxes", 3000));
descriptions.add(new Boleto.Description("this will be an incredible payment"));
data.put("descriptions", descriptions);

List<Boleto.Discount> discounts = new ArrayList<>();
discounts.add(new Boleto.Discount("2020-05-17", 2.5));
discounts.add(new Boleto.Discount("2020-05-18", 2.0));
data.put("discounts", discounts);

boletos.add(new Boleto(data));

boletos = Boleto.create(boletos);

for (Boleto boleto : boletos){
    System.out.println(boleto);
}

Note: Instead of using Boleto objects, you can also pass each boleto element in HashMap format

Query boletos

You can get a list of created boletos given some filters.

import com.starkbank.*;
import com.starkbank.utils.Generator;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("after", "2020-04-01");
params.put("before", "2020-04-30");
Generator<Boleto> boletos = Boleto.query(params);

for (Boleto boleto : boletos){
    System.out.println(boleto);
}

Get a boleto

After its creation, information on a boleto may be retrieved by passing its id. Its status indicates whether it's been paid.

import com.starkbank.*;

Boleto boleto = Boleto.get("5730174175805440");

System.out.println(boleto);

Get a boleto PDF

After its creation, a boleto PDF may be retrieved by passing its id.

import java.io.File;
import java.io.InputStream;
import java.nio.file.StandardCopyOption;
import com.starkbank.*;

HashMap<String, Object> options = new HashMap<>();
options.put("layout", "booklet");

InputStream pdf = Boleto.pdf("5915632394567680", options);

java.nio.file.Files.copy(
    pdf,
    new File("boleto.pdf").toPath(),
    StandardCopyOption.REPLACE_EXISTING
);

Be careful not to accidentally enforce any encoding on the raw pdf content, as it may yield abnormal results in the final file, such as missing images and strange characters.

Delete a boleto

You can also cancel a boleto by its id. Note that this is not possible if it has been processed already.

import com.starkbank.*;

Boleto boleto = Boleto.delete("5669456873259008");

System.out.println(boleto);

Query boleto logs

Logs are pretty important to understand the life cycle of a boleto.

import com.starkbank.*;
import com.starkbank.utils.Generator;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("after", "2020-04-01");
params.put("before", "2020-04-30");
Generator<Boleto.Log> logs = Boleto.Log.query(params);

for (Boleto.Log log : logs){
    System.out.println(log);
}

Get a boleto log

You can get a single log by its id.

import com.starkbank.*;

Boleto.Log log = Boleto.Log.get("6532638269505536");

System.out.println(log);

Investigate a boleto

You can discover if a StarkBank boleto has been recently paid before we receive the response on the next day. This can be done by creating a BoletoHolmes object, which fetches the updated status of the corresponding Boleto object according to CIP to check, for example, whether it is still payable or not. The investigation happens asynchronously and the most common way to retrieve the results is to register a "boleto-holmes" webhook subscription, although polling is also possible.

import com.starkbank;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;

List<BoletoHolmes> holmes = new ArrayList<>();
HashMap<String, Object> dataHolmes = new HashMap<>(); 
dataHolmes.put("boletoId", "5976467733217280");
holmes.add(new BoletoHolmes(dataHolmes));

holmes = BoletoHolmes.create(holmes);

for (BoletoHolmes sherlock : holmes){
    System.out.println(sherlock);
}

Note: Instead of using BoletoHolmes objects, you can also pass each payment element in map format

Get a boleto holmes

To get a single Holmes by its id, run:

import com.starkbank.*;

sherlock = BoletoHolmes.get("6093880533450752")

System.out.println(sherlock)

Query boleto holmes

You can search for boleto Holmes using filters.

import com.starkbank.*;
import com.starkbank.utils.Generator;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("limit", 3);
params.put("after", "2019-04-01");
params.put("before", "2030-04-30");
Generator<BoletoHolmes> holmes = BoletoHolmes.query(params);

for (BoletoHolmes sherlock : holmes){
    System.out.println(sherlock);
}

Query boleto holmes logs

Searches are also possible with boleto holmes logs:

import com.starkbank.*;
import com.starkbank.utils.Generator;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("limit", 3);
params.put("after", "2019-04-01");
params.put("before", "2030-04-30");
Generator<BoletoHolmes.Log> logs = BoletoHolmes.Log.query(params);

for (BoletoHolmes.Log log : logs){
    System.out.println(log);
}

Get a boleto holmes log

You can also get a boleto holmes log by specifying its id.

import com.starkbank.*;

log = BoletoHolmes.Log.get("5350990148534272")

System.out.println(log);

Pay a BR Code

Paying a BR Code is also simple.

import com.starkbank.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

List<BrcodePayment> payments = new ArrayList<>();

List<BrcodePayment.Rule> rules = new ArrayList<>();
rules.add(
    new BrcodePayment.Rule(
        "resendingLimit",   // Set maximum number of retries if Payment fails due to systemic issues at the receiver bank
        5                   // Our resending limit is 10 by default
    )
);

HashMap<String, Object> data = new HashMap<>();
data.put("brcode", "00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T'Challa6009Sao Paulo62090505123456304B14A");
data.put("taxId", "012.345.678-90");
data.put("scheduled", "2020-03-13");
data.put("description", "This will be fast");
data.put("tags", new String[]{"pix", "qrcode"});
data.put("rules", rules);
payments.add(new BrcodePayment(data));

payments = BrcodePayment.create(payments);

for (BrcodePayment payment : payments){
    System.out.println(payment);
}

Note: You can also configure payment behavior according to its rules Note: Instead of using BrcodePayment objects, you can also pass each payment element in map format

Query BR Code payments

You can search for brcode payments using filters.

import com.starkbank.*;
import com.starkbank.utils.Generator;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("after", "2020-04-01");
params.put("before", "2020-04-30");
Generator<BrcodePayment> payments = BrcodePayment.query(params);

for (BrcodePayment payment : payments){
    System.out.println(payment);
}

Get a BR Code payment

To get a single BR Code payment by its id, run:

import com.starkbank.*;

BrcodePayment payment = BrcodePayment.get("6532638269505536");

System.out.println(payment);

Cancel a BR Code payment

You can cancel a BR Code payment by changing its status to "canceled". Note that this is not possible if it has been processed already.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> patchData = new HashMap<>();
patchData.put("status", "canceled");
BrcodePayment payment = BrcodePayment.update("5155165527080960", patchData);

System.out.println(payment);

Get a BR Code payment PDF

After its creation, a boleto payment PDF may be retrieved by its id.

import java.io.File;
import java.io.InputStream;
import java.nio.file.StandardCopyOption;
import com.starkbank.*;

InputStream pdf = BrcodePayment.pdf("6311252829667328");

java.nio.file.Files.copy(
    pdf,
    new File("brcode-payment.pdf").toPath(),
    StandardCopyOption.REPLACE_EXISTING
);

Be careful not to accidentally enforce any encoding on the raw pdf content, as it may yield abnormal results in the final file, such as missing images and strange characters.

Query BR Code payment logs

Searches are also possible with BR Code payment logs:

import com.starkbank.*;
import com.starkbank.utils.Generator;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("paymentIds", "4785987200745472");
Generator<BrcodePayment.Log> logs = BrcodePayment.Log.query(params);

for (BrcodePayment.Log log : logs){
    System.out.println(log);
}

Get a BR Code payment log

You can also get a BR Code payment log by specifying its id.

import com.starkbank.*;

BrcodePayment.Log log = BrcodePayment.Log.get("6532638269505536");

System.out.println(log);

Pay a boleto

Paying boletos is also simple.

import com.starkbank.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

List<BoletoPayment> payments = new ArrayList<>();
HashMap<String, Object> data = new HashMap<>();
data.put("line", "34191.09107 05447.947309 71444.640008 8 84660000011631");
data.put("taxId", "38.435.677/0001-25");
data.put("scheduled", "2020-04-11");
data.put("description", "Payment for killing white walkers");
data.put("tags", new String[]{"little girl", "no one"});
payments.add(new BoletoPayment(data));

payments = BoletoPayment.create(payments);

for (BoletoPayment payment : payments){
    System.out.println(payment);
}

Note: Instead of using BoletoPayment objects, you can also pass each payment element in HashMap format

Query boleto payments

You can search for boleto payments using filters.

import com.starkbank.*;
import com.starkbank.utils.Generator;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("after", "2020-04-01");
params.put("before", "2020-04-30");
Generator<BoletoPayment> payments = BoletoPayment.query(params);

for (BoletoPayment payment : payments){
    System.out.println(payment);
}

Get a boleto payment

To get a single boleto payment by its id, run:

import com.starkbank.*;

BoletoPayment payment = BoletoPayment.get("6532638269505536");

System.out.println(payment);

Get a boleto payment PDF

After its creation, a boleto payment PDF may be retrieved by passing its id.

import java.io.File;
import java.io.InputStream;
import java.nio.file.StandardCopyOption;
import com.starkbank.*;

InputStream pdf = BoletoPayment.pdf("6311252829667328");

java.nio.file.Files.copy(
    pdf,
    new File("boleto-payment.pdf").toPath(),
    StandardCopyOption.REPLACE_EXISTING
);

Be careful not to accidentally enforce any encoding on the raw pdf content, as it may yield abnormal results in the final file, such as missing images and strange characters.

Delete a boleto payment

You can also cancel a boleto payment by its id. Note that this is not possible if it has been processed already.

import com.starkbank.*;

BoletoPayment payment = BoletoPayment.delete("5669456873259008");

System.out.println(payment);

Query boleto payment logs

Searches are also possible with boleto payment logs:

import com.starkbank.*;
import com.starkbank.utils.Generator;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("paymentIds", "4785987200745472");
Generator<BoletoPayment.Log> logs = BoletoPayment.Log.query(params);

for (BoletoPayment.Log log : logs){
    System.out.println(log);
}

Get a boleto payment log

You can also get a boleto payment log by specifying its id.

import com.starkbank.*;

BoletoPayment.Log log = BoletoPayment.Log.get("6532638269505536");

System.out.println(log);

Create utility payments

Its also simple to pay utility bills (such electricity and water bills) in the SDK.

import com.starkbank.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

List<UtilityPayment> payments = new ArrayList<>();
HashMap<String, Object> data = new HashMap<>();
data.put("line", "83640000001 1 07540138007 0 61053026111 0 08067159411 9");
data.put("scheduled", "2020-04-11");
data.put("description", "Electricity for the Long Night");
data.put("tags", new String[]{"Energy", "Winterfell"});
payments.add(new UtilityPayment(data));

payments = UtilityPayment.create(payments);

for (UtilityPayment payment : payments){
    System.out.println(payment);
}

Query utility payments

To search for utility payments using filters, run:

import com.starkbank.*;
import com.starkbank.utils.Generator;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("after", "2020-04-01");
params.put("before", "2020-04-30");
Generator<UtilityPayment> payments = UtilityPayment.query(params);

for (UtilityPayment payment : payments){
    System.out.println(payment);
}

Get a utility payment

You can get a specific bill by its id:

import com.starkbank.*;

UtilityPayment payment = UtilityPayment.get("6532638269505536");

System.out.println(payment);

Get a utility payment PDF

After its creation, a utility payment PDF may also be retrieved by passing its id.

import java.io.File;
import java.io.InputStream;
import java.nio.file.StandardCopyOption;
import com.starkbank.*;

InputStream pdf = UtilityPayment.pdf("6565645839761408");

java.nio.file.Files.copy(
    pdf,
    new File("utility-payment.pdf").toPath(),
    StandardCopyOption.REPLACE_EXISTING
);

Be careful not to accidentally enforce any encoding on the raw pdf content, as it may yield abnormal results in the final file, such as missing images and strange characters.

Delete a utility payment

You can also cancel a utility payment by its id. Note that this is not possible if it has been processed already.

import com.starkbank.*;

UtilityPayment payment = UtilityPayment.delete("5669456873259008");

System.out.println(payment);

Query utility payment logs

You can search for payment logs by specifying filters. Use this to understand the bills life cycles.

import com.starkbank.*;
import com.starkbank.utils.Generator;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("paymentIds", "6683343345156096");
Generator<UtilityPayment.Log> logs = UtilityPayment.Log.query(params);

for (UtilityPayment.Log log : logs){
    System.out.println(log);
}

Get a utility payment log

If you want to get a specific payment log by its id, just run:

import com.starkbank.*;

UtilityPayment.Log log = UtilityPayment.Log.get("6532638269505536");

System.out.println(log);

Create tax payment

It is also simple to pay taxes (such as ISS and DAS) using this SDK.

import com.starkbank.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

List<TaxPayment> payments = new ArrayList<>();

HashMap<String, Object> data = new HashMap<>();
data.put("barCode", "83660000001084301380074119002551100010601813");
data.put("description", "fix the road");
data.put("tags", new String[]{"take", "my", "money"});

payments.add(new TaxPayment(data));

payments = TaxPayment.create(payments);

for (TaxPayment payment : payments) {
    System.out.println(payment);
}

Note: Instead of using TaxPayment objects, you can also pass each payment element in dictionary format

Query tax payments

To search for tax payments using filters, run:

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("limit", 3);
params.put("after", "2019-04-01");
params.put("before", "2030-04-30");
params.put("status", "success");

Generator<TaxPayment> payments = TaxPayment.query(params);

for (TaxPayment payment : payments) {
    System.out.println(payment);
}

Get tax payment

You can get a specific tax payment by its id:

import com.starkbank.*;

TaxPayment payment = TaxPayment.get("5155165527080960");
System.out.println(payment);

Get tax payment PDF

After its creation, a tax payment PDF may also be retrieved by its id.

import com.starkbank.*;
import java.io.File;
import java.io.InputStream;
import java.nio.file.StandardCopyOption;


InputStream pdf = TaxPayment.pdf("5155165527080960");
java.nio.file.Files.copy(
    pdf,
    new File("tax-payment.pdf").toPath(),
    StandardCopyOption.REPLACE_EXISTING
);

Be careful not to accidentally enforce any encoding on the raw pdf content, as it may yield abnormal results in the final file, such as missing images and strange characters.

Delete tax payment

You can also cancel a tax payment by its id. Note that this is not possible if it has been processed already.

import com.starkbank.*;

TaxPayment payment = TaxPayment.delete("5155165527080960");
System.out.println(payment);

Query tax payment logs

You can search for payment logs by specifying filters. Use this to understand each payment life cycle.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("limit", 3);
params.put("after", "2019-04-01");
params.put("before", "2030-04-30");

Generator<TaxPayment.Log> logs = TaxPayment.Log.query(params);

for (TaxPayment.Log log : logs) {
    System.out.println(log);
}

Get tax payment log

If you want to get a specific payment log by its id, just run:

import com.starkbank.*;

TaxPayment.Log log = TaxPayment.Log.get("1902837198237992");
System.out.println(log);

Note: Some taxes can't be payed with bar codes. Since they have specific parameters, each one of them has its own resource and routes, which are all analogous to the TaxPayment resource. The ones we currently support are:

  • DarfPayment, for DARFs

Create DARF payment

If you want to manually pay DARFs without barCodes, you may create DarfPayments:

import com.starkbank.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

HashMap<String, Object> data = new HashMap<>();
data.put("revenueCode", "1240");
data.put("taxId", "012.345.678-90");
data.put("competence", "2023-04-03");
data.put("nominalAmount", "1234");
data.put("fineAmount", 12);
data.put("interestAmount", 34);
data.put("due", LocalDate.from(LocalDate.now().plusDays(30)).toString());
data.put("tags", new String[]{"DARF", "making money"});
data.put("description", "take my money");

List<DarfPayment> payments = new ArrayList<>();
payments.add(new DarfPayment(data));

payments = DarfPayment.create(payments);

for (DarfPayment payment : payments) {
    System.out.println(payment);
}

Note: Instead of using DarfPayment objects, you can also pass each payment element in dictionary format

Query DARF payments

To search for DARF payments using filters, run:

import com.starkbank.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

HashMap<String, Object> params = new HashMap<>();
params.put("tags", new String[]{"darf", "july"});

Generator<DarfPayment> payments = DarfPayment.query(params);

for (DarfPayment payment : payments) {
    System.out.println(payment)
}

Get DARF payment

You can get a specific DARF payment by its id:

import com.starkbank.*;

DarfPayment payment = DarfPayment.get("5155165527080960");

System.out.println(payment);

Get DARF payment PDF

After its creation, a DARF payment PDF may also be retrieved by its id.

import com.starkbank.*;
import java.io.File;
import java.io.InputStream;
import java.nio.file.StandardCopyOption;


InputStream pdf = DarfPayment.pdf("5155165527080960");
java.nio.file.Files.copy(
    pdf,
    new File("darf-payment.pdf").toPath(),
    StandardCopyOption.REPLACE_EXISTING
);

Be careful not to accidentally enforce any encoding on the raw pdf content, as it may yield abnormal results in the final file, such as missing images and strange characters.

Delete DARF payment

You can also cancel a DARF payment by its id. Note that this is not possible if it has been processed already.

import com.starkbank.*;

DarfPayment payment = DarfPayment.delete("5155165527080960");

System.out.println(payment);

Query DARF payment logs

You can search for payment logs by specifying filters. Use this to understand each payment life cycle.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("limit", 10);

Generator<DarfPayment.Log> logs = DarfPayment.Log.query(params);

for (DarfPayment.Log log : logs) {
    System.out.println(log);
}

Get DARF payment log

If you want to get a specific payment log by its id, just run:

import com.starkbank.*;

DarfPayment.Log log = DarfPayment.Log.get("1902837198237992");

System.out.println(log);

Preview payment information before executing the payment

You can preview multiple types of payment to confirm any information before actually paying. If the "scheduled" parameter is not informed, today will be assumed as the intended payment date. Right now, the "scheduled" parameter only has effect on BrcodePreviews. This resource is able to preview the following types of payment: "brcode-payment", "boleto-payment", "utility-payment" and "tax-payment"

import com.starkbank.*;

List<PaymentPreview> previews = new ArrayList<>();
previews.add(new PaymentPreview(new HashMap<String, Object>(){{
    put("id", "00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T'Challa6009Sao Paulo62090505123456304B14A");
    put("scheduled", "2021-02-10");
}}));
previews.add(new PaymentPreview(new HashMap<String, Object>(){{
    put("id", "34191.09008 61207.727308 71444.640008 5 81310001234321");
}}));

previews = (List<PaymentPreview>) PaymentPreview.create(previews);

for (PaymentPreview preview : previews) {
    System.out.println(preview);
}

Note: Instead of using PaymentPreview objects, you can also pass each request element in dictionary format

Create payment requests to be approved by authorized people in a cost center

You can also request payments that must pass through a specific cost center approval flow to be executed. In certain structures, this allows double checks for cash-outs and gives time to load your account with the required amount before the payments take place. The approvals can be granted at our web banking and must be performed according to the rules specified in the cost center.

Note: The value of the centerId parameter can be consulted by logging into our web banking and going to the desired cost center page.

import com.starkbank.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

HashMap<String, Object> paymentData = new HashMap<>();
paymentData.put("amount", 100000000);
paymentData.put("bankCode", "341");
paymentData.put("branchCode", "2201");
paymentData.put("accountNumber", "76543-8");
paymentData.put("taxId", "594.739.480-42");
paymentData.put("name", "Daenerys Targaryen Stormborn");
Transfer payment = new Transfer(paymentData);

List<PaymentRequest> requests = new ArrayList<>();
HashMap<String, Object> data = new HashMap<>();
data.put("centerId", "5967314465849344");
data.put("payment", payment);
data.put("due", "2020-04-11");
data.put("tags", new String[]{"daenerys", "invoice/1234"});
requests.add(new PaymentRequest(data));

requests = PaymentRequest.create(requests);

for (PaymentRequest request : requests){
    System.out.println(request);
}

Note: Instead of using PaymentRequest objects, you can also pass each request element in HashMap format

Query payment requests

To search for payment requests, run:

import com.starkbank.*;
import com.starkbank.utils.Generator;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("centerId", "5967314465849344");
params.put("after", "2020-04-01");
params.put("limit", 10);
Generator<PaymentRequest> requests = PaymentRequest.query(params);

for (PaymentRequest request : requests){
    System.out.println(request);
}

Corporate

Create CorporateHolders

You can create card holders to which your cards will be bound. They support spending rules that will apply to all underlying cards.

import com.starkbank.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

List<CorporateHolder> holders = new ArrayList<>();
HashMap<String, Object> data = new HashMap<>();
data.put("name", "Iron Bank S.A.");
data.put("tags", new String[]{"Traveler Employee"});

HashMap<String, Object> rule = new HashMap<>();
rule.put("name", "General USD");
rule.put("interval", "day");
rule.put("amount", 100000);
rule.put("currencyCode", "USD");
data.put("rules", new CorporateRule[]{new CorporateRule(rule)});
holders.add(new CorporateHolder(data));

holders = CorporateHolder.create(holders);

for (CorporateHolder holder : holders) {
    System.out.println(holder);
}

Note: Instead of using CorporateHolder objects, you can also pass each element in dictionary format

Query CorporateHolders

You can query multiple holders according to filters.

import com.starkbank.*;
import com.starkbank.utils.Generator;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("limit", 10);
Generator<CorporateHolder> holders = CorporateHolder.query(params);

for (PaymentRequest holder : holders){
    System.out.println(holder);
}

Cancel a CorporateHolder

To cancel a single Corporate Holder by its id, run:

import com.starkbank.*;

CorporateHolder holder = CorporateHolder.cancel("1902837198237992");

System.out.println(holder);

Get a CorporateHolder

To get a single Corporate Holder by its id, run:

import com.starkbank.*;

CorporateHolder holder = CorporateHolder.get("1902837198237992");

System.out.println(holder);

Query CorporateHolder logs

You can query holder logs to better understand holder life cycles.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("limit", 10);

Generator<CorporateHolder.Log> logs = CorporateHolder.Log.query(params);

for (CorporateHolder.Log log : logs) {
    System.out.println(log);
}

Get a CorporateHolder log

You can also get a specific log by its id.

import com.starkbank.*;

CorporateHolder.Log log = CorporateHolder.Log.get("1902837198237992");

System.out.println(log);

Create CorporateCard

You can issue cards with specific spending rules.

import com.starkbank.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

HashMap<String, Object> data = new HashMap<>();
data.put("holderId", "5155165527080960");

CorporateCard card = CorporateCard.create(new CorporateCard(data));

System.out.println(card);

Query CorporateCards

You can get a list of created cards given some filters.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("limit", 10);

Generator<CorporateCard> cards = CorporateCard.query(params);

for (CorporateCard card : cards) {
    System.out.println(card);
}

Get a CorporateCard

After its creation, information on a card may be retrieved by its id.

import com.starkbank.*;

CorporateCard card = CorporateCard.get("1902837198237992");

System.out.println(card);

Update a CorporateCard

You can update a specific card by its id.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> patchData = new HashMap<>();
patchData.put("status", "blocked");

CorporateCard card = CorporateCard.update("5155165527080960", patchData);

System.out.println(card);

Cancel a CorporateCard

You can also cancel a card by its id.

import com.starkbank.*;

CorporateCard card = CorporateCard.cancel("1902837198237992");

System.out.println(card);

Query CorporateCard logs

Logs are pretty important to understand the life cycle of a card.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("limit", 10);

Generator<CorporateCard.Log> logs = CorporateCard.Log.query(params);

for (CorporateCard.Log log : logs) {
    System.out.println(log);
}

Get a CorporateCard log

You can get a single log by its id.

import com.starkbank.*;

CorporateCard.Log log = CorporateCard.Log.get("1902837198237992");

System.out.println(log);

Query CorporatePurchases

You can get a list of created purchases given some filters.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("limit", 10);

Generator<CorporatePurchase> purchases = CorporatePurchase.query(params);

for (CorporatePurchase purchase : purchases) {
    System.out.println(purchase);
}

Get a CorporatePurchase

After its creation, information on a purchase may be retrieved by its id.

import com.starkbank.*;

CorporatePurchase purchase = CorporatePurchase.get("1902837198237992");

System.out.println(purchase);

Query CorporatePurchase logs

Logs are pretty important to understand the life cycle of a purchase.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("limit", 10);

Generator<CorporatePurchase.Log> logs = CorporatePurchase.Log.query(params);

for (CorporatePurchase.Log log : logs) {
    System.out.println(log);
}

Get a CorporatePurchase log

You can get a single log by its id.

import com.starkbank.*;

CorporatePurchase.Log log = CorporatePurchase.Log.get("1902837198237992");

System.out.println(log);

Create CorporateInvoice

You can create Pix invoices to transfer money from accounts you have in any bank to your Corporate balance, allowing you to run your corporate operation.

import com.starkbank.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

HashMap<String, Object> data = new HashMap<>();
data.put("amount", 1000);

CorporateInvoice invoice = CorporateInvoice.create(new CorporateInvoice(data));

System.out.println(invoice);

Note: Instead of using CorporateInvoice objects, you can also pass each element in dictionary format

Query CorporateInvoices

You can get a list of created invoices given some filters.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("limit", 10);

Generator<CorporateInvoice> invoices = CorporateInvoice.query(params);

for (CorporateInvoice invoice : invoices) {
    System.out.println(invoice);
}

Create CorporateWithdrawal

You can create withdrawals to send cash back from your Corporate balance to your Banking balance by using the Withdrawal resource.

import com.starkbank.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

HashMap<String, Object> data = new HashMap<>();
data.put("amount", 1000);
data.put("externalId", "123");
data.put("description", "Sending back");

CorporateWithdrawal withdrawal = CorporateWithdrawal.create(new CorporateWithdrawal(data));

System.out.println(withdrawal);

Note: Instead of using CorporateWithdrawal objects, you can also pass each element in dictionary format

Get a CorporateWithdrawal

After its creation, information on a withdrawal may be retrieved by its id.

import com.starkbank.*;

CorporateWithdrawal withdrawal = CorporateWithdrawal.get("1902837198237992");

System.out.println(withdrawal);

Query CorporateWithdrawals

You can get a list of created withdrawals given some filters.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("limit", 10);

Generator<CorporateWithdrawal> withdrawals = CorporateWithdrawal.query(params);

for (CorporateWithdrawal withdrawal : withdrawals) {
    System.out.println(withdrawal);
}

Get your CorporateBalance

To know how much money you have available to run authorizations, run:

import com.starkbank.*;

CorporateBalance balance = CorporateBalance.get();

System.out.println(balance);

Query CorporateTransactions

To understand your balance changes (corporate statement), you can query transactions. Note that our system creates transactions for you when you make purchases, withdrawals, receive corporate invoice payments, for example.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("limit", 10);

Generator<CorporateTransaction> transactions = CorporateTransaction.query(params);

for (CorporateTransaction transaction : transactions) {
    System.out.println(transaction);
}

Get a CorporateTransaction

You can get a specific transaction by its id:

import com.starkbank.*;

CorporateTransaction transaction = CorporateTransaction.get("5155165527080960");

System.out.println(transaction);

Corporate Enums

Query MerchantCategories

You can query any merchant categories using this resource. You may also use MerchantCategories to define specific category filters in CorporateRules. Either codes (which represents specific MCCs) or types (code groups) will be accepted as filters.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("search", "food");

Generator<MerchantCategory> categories = MerchantCategory.query(params);

for (MerchantCategory category : categories) {
    System.out.println(category);
}

Query MerchantCountries

You can query any merchant countries using this resource. You may also use MerchantCountries to define specific country filters in CorporateRules.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("search", "brazil");

Generator<MerchantCountry> countries = MerchantCountry.query(params);

for (MerchantCountry country : countries) {
    System.out.println(country);
}

Query CardMethods

You can query available card methods using this resource. You may also use CardMethods to define specific purchase method filters in CorporateRules.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("search", "token");

Generator<CardMethod> methods = CardMethod.query(params);

for (CardMethod method : methods) {
    System.out.println(method);
}

Split

Split an Invoice between different receivers.

Query Splits

You can get a list of created Splits given some filters.

import com.starkbank.*;
import java.util.Map;
import java.util.HashMap;

Map<String, Object> params = new HashMap<>();
params.put("limit", 10);

Generator<Split> splits = Split.query(params);

for (Split split : splits) {
    System.out.println(split);
}

Get a Split

To get a single Split by its id, run:

import com.starkbank.*;

Split split = Split.get("5155165527080960");

System.out.println(split);

Query Split Logs

You can query Split Logs to check additional information.

import com.starkbank.*;
import java.util.Map;
import java.util.HashMap;

Map<String, Object> params = new HashMap<>();
params.put("limit", 10);

Generator<Split.Log> logs = Split.Log.query(params);

for (Split.Log log : logs) {
    System.out.println(log);
}

Get a Split Log

You can also get a Split Log by specifying its id.

import com.starkbank.*;

Split.Log log = Split.Log.get("5155165527080960");

System.out.println(log);

Create SplitReceivers

You can create receivers to an Invoice Split by using the SplitReceiver resource.

import com.starkbank.*;
import java.util.Map;
import java.util.List;
import java.util.HashMap;
import java.util.ArrayList;

Map<String, Object> data = new HashMap<>();
data.put("name", "Daenerys Targaryen Stormborn");
data.put("taxId", "594.739.480-42");
data.put("bankCode", "341");
data.put("branchCode", "2201");
data.put("accountNumber", "76543-8");
data.put("accountType", "salary");

SplitReceiver receiver = SplitReceiver.create(new SplitReceiver(data));

System.out.println(receiver);

Query SplitReceivers

You can get a list of created SplitReceivers given some filters.

import com.starkbank.*;
import java.util.Map;
import java.util.HashMap;

Map<String, Object> params = new HashMap<>();
params.put("limit", 10);

Generator<SplitReceiver> receivers = SplitReceiver.query(params);

for (SplitReceiver receiver : receivers) {
    System.out.println(receiver);
}

Get a SplitReceiver

To get a single SplitReceiver by its id, run:

import com.starkbank.*;

SplitReceiver receiver = SplitReceiver.get("5155165527080960");

System.out.println(receiver);

Query SplitReceiver Logs

You can query SplitReceiver Logs to check additional information.

import com.starkbank.*;
import java.util.Map;
import java.util.HashMap;

Map<String, Object> params = new HashMap<>();
params.put("limit", 10);

Generator<SplitReceiver.Log> logs = SplitReceiver.Log.query(params);

for (Split.Log log : logs) {
    System.out.println(log);
}

Get a SplitReceiver Log

You can also get a SplitReceiver Log by specifying its id.

import com.starkbank.*;

SplitReceiver.Log log = SplitReceiver.Log.get("5155165527080960");

System.out.println(log);

Create a webhook subscription

To create a webhook subscription and be notified whenever an event occurs, run:

import com.starkbank.*;
import java.util.Map;
import java.util.HashMap;

Map<String, Object> data = new HashMap<>();
data.put("url", "https://winterfell.westeros.gov/events-from-stark-bank");
data.put("subscriptions", new String[]{"boleto", "boleto-payment", "transfer", "utility-payment", "tax-payment", "boleto-holmes", "brcode-payment", "deposit", "invoice"});
Webhook webhook = Webhook.create(data);

System.out.println(webhook);

Note: Instead of using Transaction objects, you can also pass each transaction element in HashMap format

Query webhooks

To search for registered webhooks, run:

import com.starkbank.*;
import com.starkbank.utils.Generator;

Generator<Webhook> webhooks = Webhook.query();

for (Webhook webhook : webhooks){
    System.out.println(webhook);
}

Get a webhook

You can get a specific webhook by its id.

import com.starkbank.*;

Webhook webhook = Webhook.get("5730174175805440");

System.out.println(webhook);

Delete a webhook

You can also delete a specific webhook by its id.

import com.starkbank.*;

Webhook webhook = Webhook.delete("6699417864241152");

System.out.println(webhook);

Process webhook events

It's easy to process events that arrived in your webhook. Remember to pass the signature header so the SDK can make sure it's really StarkBank that sent you the event.

import com.starkbank.*;

Request request = Listener.listen(); // this is the method you made to get the events posted to your webhook

String content = request.content.toString();
String signature = request.headers.get("Digital-Signature");

Event event = Event.parse(content, signature);
switch (event.subscription) {
    case "transfer": {
        Transfer.Log log = ((Event.TransferEvent) event).log;
        System.out.println(log.transfer);
        break;
    }
    case "boleto": {
        Boleto.Log log = ((Event.BoletoEvent) event).log;
        System.out.println(log.boleto);
        break;
    }
    case "boleto-payment": {
        BoletoPayment.Log log = ((Event.BoletoPaymentEvent) event).log;
        System.out.println(log.payment);
        break;
    }
    case "utility-payment": {
        UtilityPayment.Log log = ((Event.UtilityPaymentEvent) event).log;
        System.out.println(log.payment);
        break;
    }
    case "tax-payment": {
        TaxPayment.Log log = ((Event.TaxPaymentEvent) event).log;
        System.out.println(log.payment);
        break;
    }
    case "boleto-holmes": {
        BoletoHolmes.Log log = ((Event.BoletoHolmesEvent) event).log;
        System.out.println(log.payment);
        break;
    }
    case "brcode-payment": {
        BrcodePayment.Log log = ((Event.BrcodePaymentEvent) event).log;
        System.out.println(log.payment);
        break;
    }
    case "deposit": {
        Deposit.Log log = ((Event.DepositEvent) event).log;
        System.out.println(log.payment);
        break;
    }
    case "invoice": {
        Invoice.Log log = ((Event.InvoiceEvent) event).log;
        System.out.println(log.payment);
        break;
    }
}

Query webhook events

To search for webhooks events, run:

import com.starkbank.*;
import com.starkbank.utils.Generator;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("isDelivered", false);
params.put("after", "2020-04-01");
params.put("before", "2020-04-30");
Generator<Event> events = Event.query(params);

for (Event event : events){
    System.out.println(event);
}

Get a webhook event

You can get a specific webhook event by its id.

import com.starkbank.*;

Event event = Event.get("5730174175805440");

System.out.println(event);

Delete a webhook event

You can also delete a specific webhook event by its id.

import com.starkbank.*;

Event event = Event.delete("6312789471657984");

System.out.println(event);

Set webhook events as delivered

This can be used in case you've lost events. With this function, you can manually set events retrieved from the API as "delivered" to help future event queries with isDelivered=false.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("isDelivered", true);
Event event = Event.update("5824181711142912", params);

System.out.println(event);

Query failed webhook event delivery attempts information

You can also get information on failed webhook event delivery attempts.

import com.starkbank.*;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("after", "2020-03-20");
Generator<Event.Attempt> attempts = Event.Attempt.query(params);

for (Event.Attempt attempt: attempts) {
    System.out.println(attempt);
}

Get a failed webhook event delivery attempt information

To retrieve information on a single attempt, use the following function:

import com.starkbank.*;

Event.Attempt attempt = Event.Attempt.get("1616161616161616");

System.out.println(attempt);

Create a new Workspace

The Organization user allows you to create new Workspaces (bank accounts) under your organization. Workspaces have independent balances, statements, operations and users. The only link between your Workspaces is the Organization that controls them.

Note: This route will only work if the Organization user is used with workspaceId=null.

import com.starkbank.*;
import java.util.HashMap;

Workspace workspace = Workspace.create(
    "iron-bank-workspace-1",
    "Iron Bank Workspace 1",
    organization,
);

System.out.println(workspace);

List your Workspaces

This route lists Workspaces. If no parameter is passed, all the workspaces the user has access to will be listed, but you can also find other Workspaces by searching for their usernames or IDs directly.

import com.starkbank.*;

HashMap<String, Object> params = new HashMap<>();
params.put("limit", 30);
Generator<Workspace> workspaces = Workspace.query(params);

for (Workspace workspace : workspaces) {
    System.out.println(workspace);
}

Get a Workspace

You can get a specific Workspace by its id.

import com.starkbank.*;

Workspace workspace = Workspace.get("10827361982368179")

System.out.println(workspace)

Update a Workspace

You can update a specific Workspace by its id.

import com.starkbank.*;
import java.awt.image.BufferedImage;
import java.io.File;

BufferedImage image = ImageIO.read(new File("path/to/picture.png"));

Map<String, Object> patchData = new HashMap<>();
patchData.put("name", "Updated workspace test");
patchData.put("username", "new-username-test");
patchData.put("allowedTaxIds", new String[]{"35953668082", "88889288043"});
patchData.put("picture", image);
patchData.put("pictureType", "image/png");

Workspace workspace = Workspace.update(workspace.id, patchData, Organization.replace(organization, workspace.id));
System.out.println(workspace);

You can also block a specific Workspace by its id.

import com.starkbank.*;

Map<String, Object> patchData = new HashMap<>();
patchData.put("name", "new-name");
patchData.put("username", "new-username-test");
patchData.put("status", "blocked");

Workspace workspace = Workspace.update(workspace.id, patchData, Organization.replace(organization, workspace.id));
System.out.println(workspace);

Request

This resource allows you to send HTTP requests to StarkBank routes.

GET

You can perform a GET request to any StarkBank route.

It's possible to get a single resource using its id in the path.

import com.starkbank.*;

String path = "/invoice" + "/" + "5699165527090460";

String request = Request.get(path).content();

System.out.println(request);

You can also get the specific resource log,

import com.starkbank.*;

String path = "/invoice" + "/log/" + "5699165527090460";

String request = Request.get(path).content();

System.out.println(request);

This same method will be used to list all created items for the requested resource.

import com.starkbank.*;

String path = "/invoice";
Map<String, Object> query = new HashMap<>();
query.put("limit", 10);
String request = Request.get(path, query).content();

System.out.println(request);

To list logs, you will use the same logic as for getting a single log.

import com.starkbank.*;

String path = "/invoice/log";
Map<String, Object> query = new HashMap<>();
query.put("limit", 10);
String request = Request.get(path, query).content();

System.out.println(request);

POST

You can perform a POST request to any StarkBank route.

This will create an object for each item sent in your request

Note: It's not possible to create multiple resources simultaneously. You need to send separate requests if you want to create multiple resources, such as invoices and boletos.

import com.starkbank.*;

String path = "/invoice";
Map<String, Object> payload = new HashMap<>();
payload.put("name", "Jaime Lannister" + UUID.randomUUID().toString());
payload.put("amout", 100);
payload.put("taxId", "20.018.183/0001-80");

List<Object> invoices = new ArrayList<Object>();
invoices.add(payload);

Map<String, Object> data = new HashMap<>();
data.put("invoices", invoices);

String request = Request.post(path, data).content();

System.out.println(request);

PATCH

You can perform a PATCH request to any StarkBank route.

It's possible to update a single item of a StarkBank resource.

import com.starkbank.*;

String path = "invoice" + "/" + "5155165527080960";

HashMap<String, Object> data = new HashMap<>();;
data.put("amount", 0);

request = Request.patch(path, data).content();

System.out.println(request);

DELETE

You can perform a DELETE request to any StarkBank route.

It's possible to delete a single item of a StarkBank resource.

import com.starkbank.*;

String path = "/invoice" + "/" + "5155165527080960";

request = Request.delete(path).content();

System.out.println(request);

Handling errors

The SDK may raise one of four types of errors: InputErrors, InternalServerError, UnknownException, InvalidSignatureException

InputErrors will be raised whenever the API detects an error in your request (status code 400). If you catch such an error, you can get its elements to verify each of the individual errors that were detected in your request by the API.

For example:

import com.starkbank.*;
import com.starkbank.error.InputErrors;
import com.starkbank.error.ErrorElement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

List<Transaction> transactions = new ArrayList<>();
HashMap<String, Object> data = new HashMap<>();
data.put("amount", -200);
data.put("receiverId", "5651751147405412");
data.put("description", ".");
data.put("externalId", "repeated_id");
data.put("tags", new String[]{"Error", "Example"});
transactions.add(new Transaction(data));

try {
    Transaction.create(transactions);
} catch (InputErrors e) {
    for (ErrorElement error : e.errors){
        System.out.println(error.code);
        System.out.println(error.message);
    }
}

InternalServerError will be raised if the API runs into an internal error. If you ever stumble upon this one, rest assured that the development team is already rushing in to fix the mistake and get you back up to speed.

UnknownException will be raised if a request encounters an error that is neither InputErrors nor an InternalServerError, such as connectivity problems.

InvalidSignatureException will be raised specifically by starkbank.event.parse() when the provided content and signature do not check out with the Stark Bank public key.

Help and Feedback

If you have any questions about our SDK, just send us an email. We will respond you quickly, pinky promise. We are here to help you integrate with us ASAP. We also love feedback, so don't be shy about sharing your thoughts with us.

Email: [email protected]

About

SDK to facilitate Java integrations with the Stark Bank API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages