Stark Infra Elixir SDK Beta

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

Introduction

Index

Supported Elixir Versions

This library supports Elixir versions 1.9+.

Stark Infra API documentation

Feel free to take a look at our API docs.

Versioning

This project adheres to the following versioning pattern:

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

Setup

1. Install our SDK

To install the package with mix, add this to your deps and run mix deps.get:

def deps do
  [
  {:starkinfra, "~> 0.2.0"}
  ]
end

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:

{private_key, public_key} = StarkInfra.Key.create()

# or, to also save .pem files in a specific path
{private_key, public_key} = StarkInfra.Key.create("file/keys/")

Note: When you are creating a new Project, it is recommended that you create the keys inside the infrastructure that will use it, in order to avoid risky internet transmissions of your private-key. Then you can export the public-key alone to the computer where it will be used in the new Project creation.

3. Register your user credentials

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

3.1. To create a Project in Sandbox:

3.1.1. Log into StarkInfra 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 struct below:

# 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.
private_key_content = "
-----BEGIN EC PARAMETERS-----
BgUrgQQACg==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIMCwW74H6egQkTiz87WDvLNm7fK/cA+ctA2vg/bbHx3woAcGBSuBBAAK
oUQDQgAE0iaeEHEgr3oTbCfh8U2L+r7zoaeOX964xaAnND5jATGpD/tHec6Oe9U1
IF16ZoTVt1FzZ8WkYQ3XomRD4HS13A==
-----END EC PRIVATE KEY-----
"

project = StarkInfra.project(
  id: "5671398416568321",
  environment: :sandbox,
  private_key: private_key_content
)

3.2. To create Organization credentials in Sandbox:

3.2.1. Log into Starkinfra 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 struct below:

# 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.
private_key_content = """
-----BEGIN EC PARAMETERS-----
BgUrgQQACg==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIMCwW74H6egQkTiz87WDvLNm7fK/cA+ctA2vg/bbHx3woAcGBSuBBAAK
oUQDQgAE0iaeEHEgr3oTbCfh8U2L+r7zoaeOX964xaAnND5jATGpD/tHec6Oe9U1
IF16ZoTVt1FzZ8WkYQ3XomRD4HS13A==
-----END EC PRIVATE KEY-----
"""

organization = StarkInfra.Organization(
  environment: "sandbox",
  id: "5656565656565656",
  private_key: private_key_content,
  workspace_id: nil,  # You only need to set the workspace_id when you are operating a specific workspace_id
)

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.

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

4.1 Passing the user as argument in all functions using the user keyword:

balance = StarkInfra.PixBalance.get!(user: project)  # or organization

4.2 Set it as a default user in the config/config.exs file:

import Config

config :starkinfra,
  project: [
    environment: :sandbox,
    id: "9999999999999999",
    private_key: private_key_content
  ]

or

import Config

config :starkinfra,
  organization: [
    environment: :sandbox,
    id: "9999999999999999",
    private_key: private_key_content,
    workspace_id: "8888888888888888" # or nil
  ]

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 in the configs.

5. Setting up the error language

The error language can also be set in the config/config.exs file:

import Config

config :starkinfra,
  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.

notes = StarkInfra.CreditNote.query!(
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1)
) 
|> Enum.take(10) 
|> IO.inspect
defmodule CursorRecursion do
  def get!(iterations \\ 1, cursor \\ nil)  

  def get!(iterations, cursor) when iterations > 0 do
  {new_cursor, new_entities} = StarkInfra.CreditNote.page!(cursor: cursor)
  new_entities ++ get!(
    iterations - 1,
    new_cursor
  )
  end

  def get!(iterations, _cursor) do
    []
  end
end

transactions = CursorRecursion.get!(3) 
|> IO.inspect

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 Infra, you'll need funds in your account, which can be added to your balance by creating an StarkBank.Invoice or a StarkBank.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.

Here are a few examples on how to use the SDK. If you have any doubts, use the built-in h() function to get more info on the desired functionality (for example: StarkInfra.CreditNote |> h)

Note: Almost all SDK functions also provide a bang (!) version. To simplify the examples, they will be used the most throughout this README.

Issuing

Query IssuingProducts

To take a look at the sub-issuer BINs available to you, just run the following:

StarkInfra.IssuingProduct.query!() 
|> Enum.take(10) 
|> IO.inspect

This will tell which card products and card number prefixes you have at your disposal.

Create IssuingHolders

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

StarkInfra.IssuingHolder.create!(
  [
    %StarkInfra.IssuingHolder{
      name: "Iron Bank S.A.",
      tax_id: "012.345.678-90",
      external_id: "1234",
      tags: ["Traveler Employee"],
      rules: [
        %StarkInfra.IssuingRule{
          name: "General USD",
          interval: "day",
          amount: 100000,
          currency_code: "USD"
        }
      ]
    }
  ],
  expand: ["rules"]
) |> IO.inspect

Note: Instead of using IssuingHolder structs, you can also pass each transfer element in dictionary format

Query IssuingHolders

You can query multiple holders according to filters.

StarkInfra.IssuingHolder.query!() 
|> Enum.take(10) 
|> IO.inspect

Cancel an IssuingHolder

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

StarkInfra.IssuingHolder.cancel!("5155165527080960") 
|> IO.inspect

Get an IssuingHolder

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

StarkInfra.IssuingHolder.get!("5155165527080960") 
|> IO.inspect

Query IssuingHolder logs

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

StarkInfra.IssuingHolder.Log.query!(
  limit: 10,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1)
)
|> Enum.take(10) 
|> IO.inspect

Get an IssuingHolder log

You can also get a specific log by its id.

StarkInfra.IssuingHolder.Log.get!("5155165527080960")
|> IO.inspect

Create IssuingCards

You can issue cards with specific spending rules.

StarkInfra.IssuingCard.create!(
  [
    %StarkInfra.IssuingCard{
      holder_name: "Developers",
      holder_tax_id: "012.345.678-90",
      holder_external_id: "1234",
      rules: [
        %StarkInfra.IssuingRule{
          name: "General",
          interval: "week",
          amount: 100000,
          currency_code: "USD"
        }
      ]
    }
  ],
  expand: ["rules", "securityCode", "number", "expiration"]
) |> IO.inspect

Create IssuingCards without a holder

A physical card can be created without a holder and have one assigned later, while it is still "pending". Omit holder_name, holder_tax_id and holder_external_id (send all three or none of them). The API rejects virtual cards without a holder. The holder fields come back as empty strings.

StarkInfra.IssuingCard.create!(
  [
    %StarkInfra.IssuingCard{
      product_id: "52091969",
      type: "physical",
      tags: ["department: tech"]
    }
  ]
) |> IO.inspect

To assign a holder to a card created without one, send holder_name, holder_tax_id and holder_external_id (all three or none) while the card is still "pending". The holder can be assigned and the card activated in the same call by also sending status: "active" and the pin.

StarkInfra.IssuingCard.update!(
  "5155165527080960",
  holder_name: "Developers",
  holder_tax_id: "012.345.678-90",
  holder_external_id: "1234",
  status: "active",
  pin: "1234"
) |> IO.inspect

Update several IssuingCards at once

Holders can be assigned to several pending cards in a single request. The API applies the whole list or none of it. Each item takes the card id and the fields the API accepts in this route: status, rules, tags and the three holder fields (pin and display_name are accepted only when updating a single card). Build the items as maps, as below: every non-nil field of a struct is sent, so structs returned by get or query must not be reused.

StarkInfra.IssuingCard.update_multi!(
  [
    %{
      id: "5155165527080960",
      holder_name: "Developers",
      holder_tax_id: "012.345.678-90",
      holder_external_id: "1234"
    },
    %{
      id: "5656565656565656",
      holder_name: "Developers",
      holder_tax_id: "012.345.678-90",
      holder_external_id: "1234"
    }
  ]
) |> IO.inspect

Query IssuingCards

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

StarkInfra.IssuingCard.query!(
  limit: 10,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1),
) 
|> Enum.take(10)
|> IO.inspect

Get an IssuingCard

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

StarkInfra.IssuingCard.get!("5155165527080960") 
|> IO.inspect

Update an IssuingCard

You can update a specific card by its id.

StarkInfra.IssuingCard.update!(
  "5155165527080960", 
  status: "blocked"
) |> IO.inspect

Cancel an IssuingCard

You can also cancel a card by its id.

StarkInfra.IssuingCard.cancel!("5155165527080960")
|> IO.inspect

Query IssuingCard logs

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

StarkInfra.IssuingCard.Log.query!(
  limit: 10,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1)
) 
|> Enum.take(10) 
|> IO.inspect

Get an IssuingCard log

You can get a single log by its id.

StarkInfra.IssuingCard.Log.get!("5155165527080960") 
|> IO.inspect

Process Purchase authorizations

It's easy to process purchase authorizations delivered to your endpoint. If you do not approve or decline the authorization within 2 seconds, the authorization will be denied.

request = listen()  # this is the method you made to get the events posted to your webhook

{authorization, _cache_pid} = StarkInfra.IssuingPurchase.parse!(
  content: request.content,
  signature: request.headers["Digital-Signature"]
)

send_response(  # you should also implement this method
  StarkInfra.IssuingPurchase.response!(
      "approved",
      amount: authorization.amount,
      tags: ["my-purchase-id/123"]
  )
)

# or

send_response(
  StarkInfra.IssuingPurchase.response!(
      "denied",
      reason: "other",
      tags: ["other-id/456"]
  )
)

Query IssuingPurchases

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

StarkInfra.IssuingPurchase.query!(
  limit: 10,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1),
) 
|> Enum.take(10)
|> IO.inspect

Get an IssuingPurchase

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

StarkInfra.IssuingPurchase.get!("5155165527080960") 
|> IO.inspect

Update an IssuingPurchase

You can update a specific IssuingPurchase by its id.

StarkInfra.IssuingPurchase.update!(
  "5155165527080960",
  description: "Dinner",
  tags: ["customer-x", "reimbursement"]
) |> IO.inspect

Query IssuingPurchase logs

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

StarkInfra.IssuingPurchase.Log.query!(
  limit: 50,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1)
) 
|> Enum.take(50) 
|> IO.inspect

Get an IssuingPurchase log

You can get a single log by its id.

StarkInfra.IssuingPurchase.Log.get!("5155165527080960") 
|> IO.inspect

Create an IssuingTokenRequest

You can create a request that provides the required data you must send to the wallet app.

request = StarkInfra.IssuingTokenRequest.create!(
  %StarkInfra.IssuingTokenRequest{
    card_id: "5189831499972623",
    wallet_id: "google",
    method_code: "app"
  }
)

IO.inspect(request)

Process Token authorizations

It's easy to process token authorizations delivered to your endpoint. Remember to pass the signature header so the SDK can make sure it's StarkInfra that sent you the event. If you do not approve or decline the authorization within 2 seconds, the authorization will be denied.

{:ok, {authorization, _cache_pid}} = StarkInfra.IssuingToken.parse(
  content: content,
  signature: signature
)

response = StarkInfra.IssuingToken.response_authorization!(
  "approved",
  activation_methods: [
    %{"type" => "app", "value" => "com.subissuer.android"},
    %{"type" => "text", "value" => "** *****-5678"}
  ],
  design_id: "4584031664472031",
  tags: ["token", "user/1234"]
)

# or

response = StarkInfra.IssuingToken.response_authorization!(
  "denied",
  reason: "other"
)

Process Token activations

It's easy to process token activation notifications delivered to your endpoint. Remember to pass the signature header so the SDK can make sure it's Stark Infra that sent you the event.

{:ok, {activation, _cache_pid}} = StarkInfra.IssuingTokenActivation.parse(
  content: content,
  signature: signature
)

After that, you may generate the activation code and send it to the cardholder. The cardholder enters the received code in the wallet app. We'll receive and send it to tokenAuthorizationUrl for your validation, completing the provisioning process.

{:ok, {activation, _cache_pid}} = StarkInfra.IssuingToken.parse(
  content: content,
  signature: signature
)

response = StarkInfra.IssuingToken.response_activation!(
  "approved",
  tags: ["token", "user/1234"]
)

# or

response = StarkInfra.IssuingToken.response_activation!(
  "denied",
  reason: "other",
  tags: ["token", "user/1234"]
)

Get an IssuingToken

You can get a single token by its id.

StarkInfra.IssuingToken.get!("5749080709922816")
|> IO.inspect

Query IssuingTokens

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

StarkInfra.IssuingToken.query!(
  limit: 5,
  after: Date.utc_today |> Date.add(-100),
  before: Date.utc_today,
  status: "active",
  card_ids: ["5656565656565656", "4545454545454545"],
  external_ids: ["DSHRMC00002626944b0e3b539d4d459281bdba90c2588791", "DSHRMC00002626941c531164a0b14c66ad9602ee716f1e85"]
)
|> Enum.take(5)
|> IO.inspect

Update an IssuingToken

You can update a specific token by its id.

StarkInfra.IssuingToken.update!("5155165527080960", status: "blocked")
|> IO.inspect

Cancel an IssuingToken

You can also cancel a token by its id.

StarkInfra.IssuingToken.cancel!("5155165527080960")
|> IO.inspect

Get an IssuingTokenDesign

You can get a single design by its id.

StarkInfra.IssuingTokenDesign.get!("5749080709922816")
|> IO.inspect

Query IssuingTokenDesigns

You can get a list of available designs given some filters.

StarkInfra.IssuingTokenDesign.query!(limit: 5)
|> Enum.take(5)
|> IO.inspect

Get an IssuingTokenDesign PDF

A design PDF can be retrieved by its id.

pdf = StarkInfra.IssuingTokenDesign.pdf!("5155165527080960")

File.write!("design.pdf", pdf)

Create IssuingInvoices

Issuing invoices are requests to transfer money to your Issuing Balance. When an Issuing Invoice you created is paid, the amount will be added to your Issuing Balance.

StarkInfra.IssuingInvoice.create!([
  %StarkInfra.IssuingInvoice{
    amount: 1000
  }
]) |> IO.inspect

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

Get an IssuingInvoice

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

StarkInfra.IssuingInvoice.get!("5155165527080960") 
|> IO.inspect

Query IssuingInvoices

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

StarkInfra.IssuingInvoice.query!(
  limit: 10,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1),
) 
|> Enum.take(10) 
|> IO.inspect

Query IssuingInvoice logs

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

StarkInfra.IssuingInvoice.Log.query!(
  limit: 50,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1)
) 
|> Enum.take(10) 
|> IO.inspect

Get an IssuingInvoice log

You can get a single log by its id.

StarkInfra.IssuingInvoice.Log.get!("5155165527080960") 
|> IO.inspect

Create IssuingWithdrawals

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

StarkInfra.IssuingWithdrawal.create!(
  %StarkInfra.IssuingWithdrawal{
    amount: 10000,
    external_id: "123"
    description: "Sending back",
  }
) |> IO.inspect

Note: Instead of using Withdrawal structs, you can also pass each withdrawal element in dictionary format

Get an IssuingWithdrawal

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

StarkInfra.IssuingWithdrawal.get!("5155165527080960") 
|> IO.inspect

Query IssuingWithdrawals

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

StarkInfra.IssuingWithdrawal.query!(
  limit: 10,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1),
) 
|> Enum.take(10) 
|> IO.inspect

Get your IssuingBalance

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

StarkInfra.IssuingBalance.get!() 
|> IO.inspect

Query IssuingTransactions

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

StarkInfra.IssuingTransaction.query!(
  limit: 10,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1),
) 
|> Enum.take(10) 
|> IO.inspect

Get an IssuingTransaction

You can get a specific transaction by its id:

StarkInfra.IssuingTransaction.get!("5155165527080960") 
|> IO.inspect

Issuing Enums

Query MerchantCategories

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

StarkInfra.MerchantCategory.query!(search: "food")
|> Enum.take(10)
|> IO.inspect

Query MerchantCountries

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

StarkInfra.MerchantCountry.query!(search: "brazil")
|> Enum.take(10)
|> IO.inspect

Query CardMethods

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

StarkInfra.CardMethod.query!(search: "token")
|> Enum.take(10)
|> IO.inspect

Query IssuingBillingInvoices

To understand the amounts charged from your Workspace to cover the costs of your Issuing operations, you can query the invoices generated according to your billing plan.

StarkInfra.IssuingBillingInvoice.query!(
  limit: 10,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1),
  status: "paid"
)
|> Enum.take(10)
|> IO.inspect

Get an IssuingBillingInvoice

You can get a specific billing invoice by its id.

StarkInfra.IssuingBillingInvoice.get!("5155165527080960")
|> IO.inspect

Query IssuingBillingTransactions

You can query the transactions that compose a given IssuingBillingInvoice by filtering on its id.

StarkInfra.IssuingBillingTransaction.query!(
  limit: 10,
  invoice_id: "5155165527080960"
)
|> Enum.take(10)
|> IO.inspect

Query IssuingDesigns

To view the card and card package designs available to your Workspace, run:

StarkInfra.IssuingDesign.query!(limit: 10)
|> Enum.take(10)
|> IO.inspect

Get an IssuingDesign

You can get a specific design by its id.

StarkInfra.IssuingDesign.get!("5155165527080960")
|> IO.inspect

Get an IssuingDesign pdf

You can get the pdf file generated for a specific design by its id.

{:ok, pdf} = StarkInfra.IssuingDesign.pdf("5155165527080960")
file = File.open!("issuing_design.pdf", [:write])
IO.binwrite(file, pdf)
File.close(file)

Query IssuingEmbossingKits

To view the embossing kits available to your Workspace, run:

StarkInfra.IssuingEmbossingKit.query!(limit: 10)
|> Enum.take(10)
|> IO.inspect

Get an IssuingEmbossingKit

You can get a specific embossing kit by its id.

StarkInfra.IssuingEmbossingKit.get!("5155165527080960")
|> IO.inspect

Create IssuingEmbossingRequests

You can create embossing requests to emboss a physical IssuingCard using an IssuingEmbossingKit.

StarkInfra.IssuingEmbossingRequest.create!([
  %StarkInfra.IssuingEmbossingRequest{
    card_id: "5155165527080960",
    kit_id: "5157536855658496",
    display_name_1: "ANTHONY STARK",
    shipping_city: "SAO PAULO",
    shipping_country_code: "BRA",
    shipping_district: "VILA MADALENA",
    shipping_state_code: "SP",
    shipping_street_line_1: "AVENIDA FARIA LIMA",
    shipping_street_line_2: "Apto. 6",
    shipping_service: "loggi",
    shipping_tracking_number: "1234567890123456",
    shipping_zip_code: "05433-000"
  }
]) |> IO.inspect

Note: Instead of using IssuingEmbossingRequest structs, you can also pass each IssuingEmbossingRequest element in map format

Query IssuingEmbossingRequests

You can query multiple embossing requests according to filters.

StarkInfra.IssuingEmbossingRequest.query!(limit: 10)
|> Enum.take(10)
|> IO.inspect

Get an IssuingEmbossingRequest

After its creation, information on an embossing request may be retrieved by its id.

StarkInfra.IssuingEmbossingRequest.get!("5155165527080960")
|> IO.inspect

Query IssuingEmbossingRequest logs

You can query embossing request logs to better understand an IssuingEmbossingRequest life cycle.

StarkInfra.IssuingEmbossingRequest.Log.query!(limit: 10)
|> Enum.take(10)
|> IO.inspect

Get an IssuingEmbossingRequest log

You can also get a specific log by its id.

StarkInfra.IssuingEmbossingRequest.Log.get!("5155165527080960")
|> IO.inspect

Create IssuingRestocks

You can create restock orders to replenish a specific IssuingStock.

StarkInfra.IssuingRestock.create!([
  %StarkInfra.IssuingRestock{
    count: 100,
    stock_id: "5136459887542272",
    tags: ["card", "corporate"]
  }
]) |> IO.inspect

Note: Instead of using IssuingRestock structs, you can also pass each IssuingRestock element in map format

Query IssuingRestocks

You can query multiple restock orders according to filters.

StarkInfra.IssuingRestock.query!(limit: 10)
|> Enum.take(10)
|> IO.inspect

Get an IssuingRestock

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

StarkInfra.IssuingRestock.get!("5155165527080960")
|> IO.inspect

Query IssuingRestock logs

You can query restock logs to better understand an IssuingRestock life cycle.

StarkInfra.IssuingRestock.Log.query!(limit: 10)
|> Enum.take(10)
|> IO.inspect

Get an IssuingRestock log

You can also get a specific log by its id.

StarkInfra.IssuingRestock.Log.get!("5155165527080960")
|> IO.inspect

Query IssuingStocks

You can query the current stock of a certain IssuingDesign linked to an Embosser.

StarkInfra.IssuingStock.query!(limit: 10)
|> Enum.take(10)
|> IO.inspect

Get an IssuingStock

Information on an IssuingStock may be retrieved by its id.

StarkInfra.IssuingStock.get!("5155165527080960")
|> IO.inspect

Query IssuingStock logs

You can query stock logs to better understand an IssuingStock life cycle.

StarkInfra.IssuingStock.Log.query!(limit: 10)
|> Enum.take(10)
|> IO.inspect

Get an IssuingStock log

You can also get a specific log by its id.

StarkInfra.IssuingStock.Log.get!("5155165527080960")
|> IO.inspect

Create IssuingStockRules

You can create rules to be notified whenever a specific IssuingStock reaches a minimum balance.

StarkInfra.IssuingStockRule.create!([
  %StarkInfra.IssuingStockRule{
    minimum_balance: 10000,
    stock_id: "5136459887542272",
    emails: ["john.doe@enterprise.com"],
    phones: ["+55 (11) 91234 5678"]
  }
])
|> IO.inspect

Query IssuingStockRules

You can get a list of created stock rules given some filters.

StarkInfra.IssuingStockRule.query!(
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1)
)
|> Enum.take(10)
|> IO.inspect

Update an IssuingStockRule

You can update a specific IssuingStockRule by its id.

StarkInfra.IssuingStockRule.update!("5664445921492992", minimum_balance: 20000)
|> IO.inspect

Cancel an IssuingStockRule

You can also cancel a specific IssuingStockRule by its id.

StarkInfra.IssuingStockRule.cancel!("5664445921492992")
|> IO.inspect

Pix

Create PixRequests

You can create a Pix request to transfer money from one of your users to anyone else:

StarkInfra.PixRequest.create!([
  %StarkInfra.PixRequest{
    amount: 100,
    external_id: "141234121",
    sender_account_number: "00000-0",
    sender_branch_code: "0001",
    sender_account_type: "checking",
    sender_name: "Tyrion Lannister",
    sender_tax_id: "012.345.678-90",
    receiver_bank_code: "00000001",
    receiver_account_number: "00000-0",
    receiver_branch_code: "0001",
    receiver_account_type: "checking",
    receiver_name: "Jamie Lannister",
    receiver_tax_id: "012.345.678-90",
    end_to_end_id: StarkInfra.Utils.EndToEndId.generate("00000001") # Pass your bank code to create an end to end ID
  }
]) |> IO.inspect

Note: Instead of using PixRequest structs, you can also pass each element in dictionary format

Query PixRequests

You can query multiple Pix requests according to filters.

StarkInfra.PixRequest.query!(
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1),
  status: ["success"],
  tags: ["iron", "suit"],
  end_to_end_ids: ["E79457883202101262140HHX553UPqeq"]
) 
|> Enum.take(10) 
|> IO.inspect

Get a PixRequest

After its creation, information on a Pix request may be retrieved by its id. Its status indicates whether it has been paid.

StarkInfra.PixRequest.get!("5155165527080960") 
|> IO.inspect

Process inbound PixRequest authorizations

It's easy to process authorization requests that arrived at your endpoint. Remember to pass the signature header so the SDK can make sure it's StarkInfra that sent you the event. If you do not approve or decline the authorization within 1 second, the authorization will be denied.

request = listen()  # this is your handler to listen for authorization requests

{pix_request, _cache_pid} = StarkInfra.PixRequest.parse!(
  content: request.content,
  signature: request.headers["Digital-Signature"]
)

IO.inspect(pix_request)

send_response(  # you should also implement this method
  StarkInfra.PixRequest.response!(  # this optional method just helps you build the response JSON
    "approved"
  )
)

# or

send_response(
  StarkInfra.PixRequest.response!(
    "denied",
    reason: "orderRejected"
  )
)

Query PixRequest logs

You can query Pix request logs to better understand Pix request life cycles.

logs = StarkInfra.PixRequest.Log.query!(
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1)
) 
|> Enum.take(10)
|> IO.inspect

Get a PixRequest log

You can also get a specific log by its id.

StarkInfra.PixRequest.Log.get!("5155165527080960") |> IO.inspect

Create PixReversals

You can reverse a PixRequest either partially or totally using a PixReversal.

StarkInfra.PixReversal.create!([
  %StarkInfra.PixReversal{
    amount: 100,
    external_id: "my_unique_id",
    end_to_end_id: "E00000000202201060100rzsJzG9PzMg",
  }
]) |> IO.inspect

Query PixReversals

You can query multiple Pix reversals according to filters.

StarkInfra.PixReversal.query!(
  limit: 10,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1),
  status: ["created"],
  tags: ["iron", "suit"],
  return_ids: ["D20018183202202030109X3OoBHG74wo"]
) 
|> Enum.take(10) 
|> IO.inspect

Get a PixReversal

After its creation, information on a Pix reversal may be retrieved by its id. Its status indicates whether it has been successfully processed.

StarkInfra.PixReversal.get!("5155165527080960") 
|> IO.inspect

Process inbound PixReversal authorizations

It's easy to process authorization requests that arrived at your endpoint. Remember to pass the signature header so the SDK can make sure it's StarkInfra that sent you the event. If you do not approve or decline the authorization within 1 second, the authorization will be denied.

request = listen()  # this is your handler to listen for authorization requests

{pix_reversal, _cache_pid} = StarkInfra.PixReversal.parse!(
  content: request.content,
  signature: request.headers["Digital-Signature"]
)

IO.inspect(pix_reversal)

send_response(  # you should also implement this method
  StarkInfra.PixReversal.response!(  # this optional method just helps you build the response JSON
    "approved"
  )
)

# or

send_response(
  StarkInfra.PixReversal.response!(
    "denied",
    reason: "orderRejected"
  )
)

Query PixReversal logs

You can query Pix reversal logs to better understand their life cycles.

StarkInfra.PixReversal.Log.query!(
  limit: 50,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1)
)
|> Enum.take(10)
|> IO.inspect

Get a PixReversal log

You can also get a specific log by its id.

StarkInfra.PixReversal.Log.get!("5155165527080960") 
|> IO.inspect

Get your PixBalance

To see how much money you have in your account, run:

StarkInfra.PixBalance.get!() 
|> IO.inspect

Create a PixStatement

Statements are generated directly by the Central Bank and are only available for direct participants. To create a statement of all the transactions that happened on your account during a specific day, run:

statement = StarkInfra.PixStatement.create!(
  after: Date.utc_today |> Date.add(-1), # This is the date that you want to create a statement.
  before: Date.utc_today |> Date.add(-1), # After and before must be the same date.
  type: "transaction"  # Options are "interchange", "interchangeTotal", "transaction".
) |> IO.inspect

Query PixStatements

You can query multiple Pix statements according to filters.

statements = StarkInfra.PixStatement.query!(
  limit: 50,
)
|> Enum.take(10)
|> IO.inspect

Get a PixStatement

Statements are only available for direct participants. To get a Pix statement by its id:

statement = StarkInfra.PixStatement.get!("5674087007387648") 
|> IO.inspect

Get a PixStatement .csv file

To get the .csv file corresponding to a Pix statement using its id, run:

statement_csv = StarkInfra.PixStatement.get_csv!("5674087007387648")
file = File.open!("statement.zip", [:write])
IO.binwrite(file, statement_csv)
File.close(file)

Create a PixKey

You can create a Pix Key to link a bank account information to a key id:

key = StarkInfra.PixKey.create!(
  %StarkInfra.PixKey{
    key_id: "+5511989898989",
    bank_code: "34052649",
    account_number: "052649",
    branch_code: "0001",
    account_type: "checking",
    name: "Tyrion Lannister",
    tax_id: "012.345.678-90",
  }
) |> IO.inspect

Query PixKeys

You can query multiple Pix keys you own according to filters.

keys = StarkInfra.PixKey.query!(
  limit: 1,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1),
  status: ["registered"],
  tags: ["iron", "suit"],
  ids: ["+5511989898989"],
)
|> Enum.take(10) 
|> IO.inspect

Get a PixKey

Information on a Pix key may be retrieved by its id and the tax ID of the consulting agent. An endToEndId must be informed so you can link any resulting purchases to this query, avoiding sweep blocks by the Central Bank.

StarkInfra.PixKey.get!("+5511989898989", "012.345.678-90") 
|> IO.inspect

Update a PixKey

Update the account information linked to a Pix Key.

StarkInfra.PixKey.update!(
  "+5511989898989", 
  "reconciliation",
  name: "Tyrion Lannister"
) |> IO.inspect

Cancel a PixKey

Cancel a specific Pix Key using its id.

StarkInfra.PixKey.cancel!("+5511989898989") 
|> IO.inspect

Query PixKey logs

You can query Pix key logs to better understand a Pix key life cycle.

StarkInfra.PixKey.Log.query!(
  limit: 50,
  ids: ["5729405850615808"],
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1),
  types: ["created"],
  key_ids: ["+5511989898989"]
)
|> Enum.take(10)
|> IO.inspect

Get a PixKey log

You can also get a specific log by its id.

StarkInfra.PixKey.Log.get!("5729405850615808") 
|> IO.inspect

Create PixKeyHolmes

To investigate whether a Pix Key is registered in the Central Bank's DICT, open up a PixKeyHolmes for it:

StarkInfra.PixKeyHolmes.create!(
  [
    %StarkInfra.PixKeyHolmes{
      key_id: "+5511989898989"
    },
    %StarkInfra.PixKeyHolmes{
      key_id: "valid@sandbox.com",
      tags: ["sherlock"]
    }
  ]
)
|> IO.inspect

Query PixKeyHolmes

You can query multiple PixKeyHolmes according to filters.

StarkInfra.PixKeyHolmes.query!(
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1),
  status: ["solved"]
)
|> Enum.take(10)
|> IO.inspect

Get a PixKeyHolmes

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

StarkInfra.PixKeyHolmes.get!("5155165527080960")
|> IO.inspect

Query PixKeyHolmes logs

You can query PixKeyHolmes logs to better understand their life cycles.

StarkInfra.PixKeyHolmes.Log.query!(
  limit: 50,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1)
)
|> Enum.take(50)
|> IO.inspect

Get a PixKeyHolmes log

You can also get a specific log by its id.

StarkInfra.PixKeyHolmes.Log.get!("5155165527080960")
|> IO.inspect

Create a PixClaim

You can create a Pix claim to request the transfer of a Pix key from another bank to one of your accounts:

StarkInfra.PixClaim.create!(
  %StarkInfra.PixClaim{
    account_created: DateTime.utc_now(),
    account_number: "123456789",
    account_type: "checking",
    branch_code: "0001",
    name: "Jamie Lanister",
    tax_id: "012.345.678-90",
    key_id: "+5511933571793",
  }
) |> IO.inspect

Query PixClaims

You can query multiple Pix claims according to filters.

StarkInfra.PixClaim.query!(
  limit: 1,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1),
  status: ["registered"],
  type: "ownership",
  agent: "claimed",
  key_type: "phone",
  key_id: "+5511989898989"
)
|> Enum.take(10)
|> IO.inspect

Get a PixClaim

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

StarkInfra.PixClaim.get!("5729405850615808") 
|> IO.inspect

Update a PixClaim

A Pix Claim can be confirmed or canceled by patching its status. A received Pix Claim must be confirmed by the donor to be completed. Ownership Pix Claims can only be canceled by the donor if the reason is "fraud". A sent Pix Claim can also be canceled.

StarkInfra.PixClaim.update!(
  "5729405850615808", 
  status: "confirmed"
) |> IO.inspect

Query PixClaim logs

You can query Pix claim logs to better understand Pix claim life cycles.

logs = StarkInfra.PixClaim.Log.query!(
  limit: 50,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1),
  types: ["registered"],
  claim_ids: ["5719405850615809"]
)
|> Enum.take(10)
|> IO.inspect

Get a PixClaim log

You can also get a specific log by its id.

StarkInfra.PixClaim.Log.get!("5719405850615809") 
|> IO.inspect

Create a PixDirector

To register the Pix director contact information at the Central Bank, run the following:

StarkInfra.PixDirector.create!(
  %StarkInfra.PixDirector{
    name: "Tyrion Lannister",
    email: "tyrion@lannister.com",
    phone: "+5511989898989",
    tax_id: "012.345.678-90",
  }
) |> IO.inspect

Create PixInfractions

Creating Pix infractions through the SDK is deprecated: StarkInfra.PixInfraction.create/2 returns a deprecated error and create!/2 raises, without calling the API.

Query PixInfractions

You can query multiple Pix infractions according to filters.

StarkInfra.PixInfraction.query!(
  limit: 10,
  after: "2022-01-01",
  before: "2022-01-12",
  status: ["delivered"],
  ids: ["5729405850615808"],
)
|> Enum.take(10)
|> IO.inspect

Get a PixInfraction

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

StarkInfra.PixInfraction.get!("5155165527080960") |> IO.inspect

Update a PixInfraction

A received Pix Infraction can be confirmed or declined by patching its status. After a Pix Infraction is patched, its status changes to closed.

StarkInfra.PixInfraction.update!(
  "5155165527080960", 
  "agreed"
) |> IO.inspect

Cancel a PixInfraction

Cancel a specific Pix Infraction using its id.

StarkInfra.PixInfraction.cancel!("5155165527080960") 
|> IO.inspect

Query PixInfraction logs

You can query Pix infractions logs to better understand their life cycles.

StarkInfra.PixInfraction.Log.query!(
  limit: 50,
  ids: ["5729405850615808"],
  after: "2022-01-01",
  before: "2022-01-20",
  types: ["created"],
  infraction_ids: ["5155165527080960"]
)
|> Enum.take(50)
|> IO.inspect

Get a PixInfraction log

You can also get a specific log by its id.

StarkInfra.PixInfraction.Log.get!("5155165527080960") 
|> IO.inspect

Create a PixFraud

Pix Frauds can be created by either participant or automatically when a Pix Infraction is accepted.

StarkInfra.PixFraud.create!(
  [
    %StarkInfra.PixFraud{
      external_id: "my_external_id_1234",
      type: "mule",
      tax_id: "012.345.678-90"
    }
  ]
)
|> IO.inspect

Query PixFrauds

You can query multiple Pix frauds according to filters.

StarkInfra.PixFraud.query!(
  limit: 1,
  after: "2022-01-01",
  before: "2022-01-12",
  status: ["created"],
  ids: ["5155165527080960"]
)
|> Enum.take(1)
|> IO.inspect

Get a PixFraud

After its creation, information on a Pix Fraud may be retrieved by its ID.

StarkInfra.PixFraud.get!("5155165527080960") 
|> IO.inspect

Cancel a PixFraud

Cancel a specific Pix Fraud using its id.

StarkInfra.PixFraud.cancel!("5155165527080960") 
|> IO.inspect

Query PixFraud logs

You can query PixFraud logs to better understand their life cycles.

StarkInfra.PixFraud.Log.query!(
  limit: 50,
  after: "2022-01-01",
  before: "2022-01-20"
)
|> Enum.take(50)
|> IO.inspect

Get a PixFraud log

You can also get a specific log by its id.

StarkInfra.PixFraud.Log.get!("5155165527080960") 
|> IO.inspect

Get a PixUser

You can get a specific fraud statistics of a user with his taxId.

StarkInfra.PixUser.get!("01234567890")
|> IO.inspect

Create PixChargebacks

A Pix chargeback can be created when fraud is detected on a transaction or a system malfunction results in an erroneous transaction.

StarkInfra.PixChargeback.create!(
  %StarkInfra.PixChargeback{
    amount: 100,
    reference_id: "E20018183202201201450u34sDGd19lz",
    reason: "fraud",
  }
)
|> Enum.take(100)
|> IO.inspect

Query PixChargebacks

You can query multiple Pix chargebacks according to filters.

chargebacks = StarkInfra.PixChargeback.query!(
  limit: 1,
  after: "2022-01-01",
  before: "2022-01-12",
  status: ["registered"],
  ids: ["5155165527080960"]
)
|> Enum.take(1)
|> IO.inspect

Get a PixChargeback

After its creation, information on a Pix Chargeback may be retrieved by its.

StarkInfra.PixChargeback.get!("5155165527080960") 
|> IO.inspect

Update a PixChargeback

A received Pix Chargeback can be accepted or rejected by patching its status. After a Pix Chargeback is patched, its status changes to closed.

StarkInfra.PixChargeback.update!(
  "5155165527080960", 
  "accepted",
  reversal_reference_id: StarkInfra.Utils.ReturnId.create!("20018183")
) |> IO.inspect

Cancel a PixChargeback

Cancel a specific Pix Chargeback using its id.

StarkInfra.PixChargeback.cancel!("5155165527080960") 
|> IO.inspect

Query PixChargeback logs

You can query Pix chargeback logs to better understand Pix chargeback life cycles.

StarkInfra.PixChargeback.Log.query!(
  limit: 50,
  ids: ["5729405850615808"],
  after: "2022-01-01",
  before: "2022-01-20",
  types: ["created"],
  chargeback_ids: ["5155165527080960"]
)
|> Enum.take(50)
|> IO.inspect

Get a PixChargeback log

You can also get a specific log by its id.

StarkInfra.PixChargeback.Log.get!("5155165527080960") 
|> IO.inspect

Query PixDomains

You can query for domains of registered SPI participants able to issue dynamic QR Codes.

StarkInfra.PixDomain.query!() 
|> IO.inspect

Create BrcodePreviews

You can preview a BR Code before paying it by providing the BR Code string and the payer's tax id:

StarkInfra.BrcodePreview.create!([
  %StarkInfra.BrcodePreview{
    id: "00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T'Challa6009Sao Paulo62090505123456304B14A",
    payer_id: "20.018.183/0001-80"
  }
]) |> IO.inspect

Note: Instead of using BrcodePreview structs, you can also pass each BrcodePreview element in map format

Create StaticBrcodes

StaticBrcodes store account information via a BR code or an image (QR code) that represents a PixKey and a few extra fixed parameters, such as an amount and a reconciliation ID. They can easily be used to receive Pix transactions.

StarkInfra.StaticBrcode.create!([
  %StarkInfra.StaticBrcode{
    name: "Jamie Lannister",
    key_id: "+5511988887777",
    amount: 100,
    reconciliation_id: "123",
    city: "Rio de Janeiro"
  }
])
|> IO.inspect

Query StaticBrcodes

You can query multiple StaticBrcodes according to filters.

StarkInfra.StaticBrcode.query!(
  limit: 1,
  after: "2022-06-01",
  before: "2022-06-30",
  uuids: ["5ddde28043a245c2848b08cf315effa2"]
)
|> Enum.take(1)
|> IO.inspect

Get a StaticBrcode

After its creation, information on a StaticBrcode may be retrieved by its UUID.

StarkInfra.StaticBrcode.get!("5ddde28043a245c2848b08cf315effa2")
|> IO.inspect

Create DynamicBrcodes

BR codes store information represented by Pix QR Codes, which are used to send or receive Pix transactions in a convenient way. DynamicBrcodes represent charges with information that can change at any time, since all data needed for the payment is requested dynamically to an URL stored in the BR Code. Stark Infra will receive the GET request and forward it to your registered endpoint with a GET request containing the UUID of the BR code for identification.

StarkInfra.DynamicBrcode.create!([
  %StarkInfra.DynamicBrcode{
    name: "Jamie Lannister",
    city: "Rio de Janeiro",
    external_id: "my_unique_id_01",
    type: "instant"
  }
])
|> IO.inspect

Query DynamicBrcodes

You can query multiple DynamicBrcodes according to filters.

StarkInfra.DynamicBrcode.query!(
  limit: 1,
  after: "2022-06-01",
  before: "2022-06-30",
  uuids: ["ac7caa14e601461dbd6b12bf7e4cc48e"]
)
|> Enum.take(1)
|> IO.inspect

Get a DynamicBrcode

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

StarkInfra.DynamicBrcode.get!("ac7caa14e601461dbd6b12bf7e4cc48e")
|> IO.inspect

Verify a DynamicBrcode read

When a DynamicBrcode is read by your user, a GET request will be made to your registered URL to retrieve additional information needed to complete the transaction. Use this method to verify the authenticity of a GET request received at your registered endpoint. If the provided digital signature does not check out with the StarkInfra public key, the returned error will have code "invalidSignature".

request = listen() # this is the method you made to get the read requests posted to your registered endpoint

uuid = StarkInfra.DynamicBrcode.verify!(
  uuid: request.url.get_parameter("uuid"),
  signature: request.headers["Digital-Signature"]
)

Without a cache_pid, every call requests the Stark Infra public key from the API (/GET public-key). Since verify does not return a cache_pid, create one once and pass it on every call to reuse the key:

{:ok, cache_pid} = Agent.start_link(fn -> %{} end) # create it once, e.g. when your application starts

uuid = StarkInfra.DynamicBrcode.verify!(
  uuid: request.url.get_parameter("uuid"),
  signature: request.headers["Digital-Signature"],
  cache_pid: cache_pid
)

Answer to a Due DynamicBrcode read

When a Due DynamicBrcode is read by your user, a GET request containing the BR code UUID will be made to your registered URL to retrieve additional information needed to complete the transaction.

The GET request must be answered in the following format within 5 seconds and with an HTTP status code 200.

request = listen() # this is the method you made to get the read requests posted to your registered endpoint

uuid = StarkInfra.DynamicBrcode.verify!(
  uuid: request.url.get_parameter("uuid"),
  signature: request.headers["Digital-Signature"]
)

invoice = get_my_invoice(uuid) # you should implement this method to get the information of the BR code from its uuid

send_response( # you should also implement this method to respond the read request
  StarkInfra.DynamicBrcode.response_due!(
    version: invoice.version,
    created: invoice.created,
    due: invoice.due,
    key_id: invoice.key_id,
    status: invoice.status,
    reconciliation_id: invoice.reconciliation_id,
    nominal_amount: invoice.amount,
    sender_name: invoice.sender_name,
    sender_tax_id: invoice.sender_tax_id,
    receiver_name: invoice.receiver_name,
    receiver_tax_id: invoice.receiver_tax_id,
    receiver_street_line: invoice.receiver_street_line,
    receiver_city: invoice.receiver_city,
    receiver_state_code: invoice.receiver_state_code,
    receiver_zip_code: invoice.receiver_zip_code
  )
)

Answer to an Instant DynamicBrcode read

When an Instant DynamicBrcode is read by your user, a GET request containing the BR code UUID will be made to your registered URL to retrieve additional information needed to complete the transaction.

The get request must be answered in the following format within 5 seconds and with an HTTP status code 200.

request = listen() # this is the method you made to get the read requests posted to your registered endpoint

uuid = StarkInfra.DynamicBrcode.verify!(
  uuid: request.url.get_parameter("uuid"),
  signature: request.headers["Digital-Signature"]
)

invoice = get_my_invoice(uuid) # you should implement this method to get the information of the BR code from its uuid

send_response( # you should also implement this method to respond the read request
  StarkInfra.DynamicBrcode.response_instant!(
    version: invoice.version,
    created: invoice.created,
    key_id: invoice.key_id,
    status: invoice.status,
    reconciliation_id: invoice.reconciliation_id,
    amount: invoice.amount,
    cashier_type: invoice.cashier_type,
    cashier_bank_code: invoice.cashier_bank_code,
    cash_amount: invoice.cash_amount
  )
)

Create PixDisputes

Pix disputes can be created when a fraud is detected creating a chain of transactions in order to reverse the funds to the origin.

StarkInfra.PixDispute.create!([
  %StarkInfra.PixDispute{
    reference_id: "E20018183202512191914WcfANNEIYnt",
    method: "scam",
    operator_phone: "+5511999999999",
    operator_email: "operator@example.com"
  }
])
|> IO.inspect

Note: Instead of using PixDispute structs, you can also pass each element in map format

Query PixDisputes

You can query multiple PixDisputes according to filters.

StarkInfra.PixDispute.query!(
  limit: 10,
  after: "2020-01-01",
  before: "2020-04-01",
  status: "success",
  tags: ["iron", "suit"]
)
|> Enum.take(10)
|> IO.inspect

Get a PixDispute

After its creation, information on a PixDispute may be retrieved by its id. Its status indicates whether it has been paid.

StarkInfra.PixDispute.get!("5155165527080960") 
|> IO.inspect

Cancel a PixDispute

Cancel a specific PixDispute using its id.

StarkInfra.PixDispute.cancel!("5155165527080960") 
|> IO.inspect

Query PixDispute logs

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

StarkInfra.PixDispute.Log.query!(
  limit: 50, 
  after: "2022-01-01",
  before: "2022-01-20"
)
|> Enum.take(50)
|> IO.inspect

Get a PixDispute log

You can also get a specific log by its id.

StarkInfra.PixDispute.Log.get!("5155165527080960") 
|> IO.inspect

Create PixPullRequests

You can create PixPullRequests to trigger automatic debits against an active PixPullSubscription.

StarkInfra.PixPullRequest.create!([
  %StarkInfra.PixPullRequest{
    amount: 11234,
    due: ~U[2026-04-15 12:00:00Z],
    end_to_end_id: "E00002649202201172211u34srod19le",
    receiver_account_number: "876543-2",
    receiver_account_type: "checking",
    receiver_bank_code: "20018183",
    reconciliation_id: "cycle-202604",
    subscription_id: "5656565656565656",
    tags: ["monthly"]
  }
])
|> IO.inspect

Query PixPullRequests

StarkInfra.PixPullRequest.query!(
  limit: 10,
  after: "2026-01-01",
  before: "2026-04-30",
  status: ["created", "success"],
  subscription_ids: ["5656565656565656"]
)
|> Enum.take(10)
|> IO.inspect

Get a PixPullRequest

StarkInfra.PixPullRequest.get!("5656565656565656")
|> IO.inspect

Update a PixPullRequest

Change the status to "scheduled" or "denied". When denying, :reason is required.

StarkInfra.PixPullRequest.update!(
  "5656565656565656",
  "denied",
  reason: "senderAccountClosed"
)
|> IO.inspect

Cancel a PixPullRequest

StarkInfra.PixPullRequest.cancel!("5656565656565656", "senderUserRequested")
|> IO.inspect

Query PixPullRequest logs

StarkInfra.PixPullRequest.Log.query!(
  limit: 50,
  after: "2026-01-01",
  before: "2026-04-30",
  request_ids: ["5656565656565656"]
)
|> Enum.take(50)
|> IO.inspect

Get a PixPullRequest log

StarkInfra.PixPullRequest.Log.get!("5155165527080960")
|> IO.inspect

Create PixPullSubscriptions

You can create recurring Pix debit authorizations to allow a receiver to pull a series of Pix payments from a sender.

StarkInfra.PixPullSubscription.create!([
  %StarkInfra.PixPullSubscription{
    bacen_id: "RR2017032900000000000000003",
    external_id: "my-subscription-001",
    installment_start: ~U[2026-04-01 12:00:00.000000Z],
    interval: "month",
    receiver_name: "Edward Stark",
    receiver_tax_id: "20.018.183/0001-80",
    receiver_bank_code: "20018183",
    reference_code: "contract-202604",
    sender_account_number: "876543-2",
    sender_bank_code: "20018183",
    sender_branch_code: "1357-9",
    sender_city_code: "3550308",
    sender_tax_id: "012.345.678-90",
    type: "push",
    amount: 11234,
    description: "Monthly subscription",
    tags: ["employees", "monthly"]
  }
])
|> IO.inspect

Query PixPullSubscriptions

You can query multiple Pix pull subscriptions according to filters.

StarkInfra.PixPullSubscription.query!(
  limit: 10,
  after: "2026-01-01",
  before: "2026-04-30",
  status: ["active"],
  tags: ["monthly"]
)
|> Enum.take(10)
|> IO.inspect

Get a PixPullSubscription

After its creation, information on a Pix pull subscription may be retrieved by its id.

StarkInfra.PixPullSubscription.get!("5656565656565656")
|> IO.inspect

Update a PixPullSubscription

You can update a Pix pull subscription by passing its id.

When patching status to "confirmed", sender_city_code MUST be present in the patch.

StarkInfra.PixPullSubscription.update!(
  "5656565656565656",
  "confirmed",
  sender_city_code: "3550308"
)
|> IO.inspect

Cancel a PixPullSubscription

You can cancel a Pix pull subscription by passing its id and a reason. The reason is sent as a query parameter on the DELETE request.

StarkInfra.PixPullSubscription.cancel!(
  "5656565656565656",
  reason: "accountClosed"
)
|> IO.inspect

Query PixPullSubscription logs

You can query Pix pull subscription logs to better understand Pix pull subscription life cycles.

StarkInfra.PixPullSubscription.Log.query!(
  limit: 50,
  after: "2026-01-01",
  before: "2026-04-30",
  subscription_ids: ["5656565656565656"]
)
|> Enum.take(50)
|> IO.inspect

Get a PixPullSubscription log

You can also get a specific log by its id.

StarkInfra.PixPullSubscription.Log.get!("5155165527080960")
|> IO.inspect

Process inbound PixPullSubscription events

Inbound PixPullSubscription events will be POSTed at your registered endpoint. You can use the parse function to verify the digital signature and reconstruct the PixPullSubscription object.

{:ok, {subscription, cache_pid}} = StarkInfra.PixPullSubscription.parse(
  content: "{\"bacenId\": \"RR2017032900000000000000003\", ...}",
  signature: "MEUCIQC7FVhXdripx/aXg5yNLxmNoZlehpyvX3QYDXJ8o3PAZQIgVe1omKFh7Vd54ML4U1z7L+kpx+GHl+G2XLeFTLZeBJk="
)

IO.inspect(subscription)

Create PixInternalTransactionReports

Transactions that happen internally, outside of the SPI, must be reported to the Central Bank so they are reflected in your statements. You can do so by creating PixInternalTransactionReports:

StarkInfra.PixInternalTransactionReport.create!(
  [
    %StarkInfra.PixInternalTransactionReport{
      amount: 10000,
      created: ~U[2024-01-01 12:00:00Z],
      end_to_end_id: "E12345678202401011234567890123456",
      method: "manual",
      reference_type: "request",
      sender_account_number: "12345",
      sender_branch_code: "0001",
      sender_account_type: "checking",
      sender_bank_code: "12345678",
      sender_tax_id: "123.456.789-01",
      receiver_account_number: "67890",
      receiver_branch_code: "0001",
      receiver_account_type: "savings",
      receiver_bank_code: "87654321",
      receiver_tax_id: "987.654.321-00",
      receiver_key_id: "user@example.com"
    }
  ]
)
|> IO.inspect

Query PixInternalTransactionReports

You can query multiple PixInternalTransactionReports according to filters.

StarkInfra.PixInternalTransactionReport.query!(
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1),
  status: ["success"]
)
|> Enum.take(10)
|> IO.inspect

Get a PixInternalTransactionReport

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

StarkInfra.PixInternalTransactionReport.get!("5656565656565656")
|> IO.inspect

Query PixInternalTransactionReport logs

You can query PixInternalTransactionReport logs to better understand their life cycles.

StarkInfra.PixInternalTransactionReport.Log.query!(
  limit: 50,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1)
)
|> Enum.take(50)
|> IO.inspect

Get a PixInternalTransactionReport log

You can also get a specific log by its id.

StarkInfra.PixInternalTransactionReport.Log.get!("5155165527080960")
|> IO.inspect

Credit Note

Create CreditNotes

You can create a Credit Note to generate a CCB contract:

StarkInfra.CreditNote.create!([
  %StarkInfra.CreditNote{
    template_id: "5686220801703936",
    name: "Jamie Lannister",
    tax_id: "012.345.678-90",
    nominal_amount: 100000,
    scheduled: Date.add(Date.utc_today(), 1),
    invoices: [
      %StarkInfra.CreditNote.Invoice{
        due: Date.add(Date.utc_today(), 30),
        amount: 120000,
        fine: 10,
        interest: 2
      }
    ],
    tags: ["test", "testing"],
    payment: %StarkInfra.CreditNote.Transfer{
      bank_code: "00000000",
      branch_code: "1234",
      account_number: "129340-1",
      name: "Jamie Lannister",
      tax_id: "012.345.678-90"
    },
    payment_type: "transfer",
    signers: [
      %StarkInfra.CreditSigner{
        name: "Jamie Lannister",
        contact: "jamie.lannister@gmail.com",
        method: "link"
      }
    ],
    external_id: "my_unique_123",
    street_line_1: "Av. Paulista, 200",
    street_line_2: "10 andar",
    district: "Bela Vista",
    city: "Sao Paulo",
    state_code: "SP",
    zip_code: "01310-000",
    template_replacements: StarkInfra.CreditNote.TemplateReplacements.new(%{
      guarantor_name: "Jon Snow",
      guarantor_tax_id: "012.345.678-90",
      guarantor_address: "Av. Paulista, 200 - Bela Vista - Sao Paulo, SP"
    })
  }
]) |> IO.inspect

Note: template_replacements is optional and its keys depend on your contract template. Pass a StarkInfra.CreditNote.TemplateReplacements struct (built with TemplateReplacements.new/1) or a plain map: both send the same request. Write the keys in snake_case, as atoms or strings: they are sent in camelCase (guarantor_name becomes guarantorName). Keys already in camelCase are sent as written. Keys with nil values are not sent. Returned CreditNotes carry a TemplateReplacements struct with the string keys as the API sent them, in camelCase, readable as note.template_replacements["guarantorName"].

Note: Instead of using CreditNote structs, you can also pass each CreditNote element in map format

Query CreditNotes

You can query multiple credit notes according to filters.

StarkInfra.CreditNote.query!(
  limit: 10,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1),
  status: ["success"],
  tags: ["iron", "suit"]
)
|> Enum.take(10)
|> IO.inspect

Get a CreditNote

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

StarkInfra.CreditNote.get!("5155165527080960") 
|> IO.inspect

Cancel a CreditNote

You can cancel a credit note if it has not been signed yet.

StarkInfra.CreditNote.cancel!("5155165527080960") 
|> IO.inspect

Query CreditNote logs

You can query credit note logs to better understand credit note life cycles.

StarkInfra.CreditNote.Log.query!(
  limit: 10,
  after: "2020-11-01",
  before: "2020-11-02"
)
|> Enum.take(10)
|> IO.inspect

Get a CreditNote log

You can also get a specific log by its id.

StarkInfra.CreditNote.log.get!("5155165527080960") 
|> IO.inspect

Get a CreditNote pdf

You can get the CCB disbursement contract pdf associated with a CreditNote by its id.

{:ok, pdf} = StarkInfra.CreditNote.pdf("5155165527080960")
file = File.open!("credit_note.pdf", [:write])
IO.binwrite(file, pdf)
File.close(file)

Get a CreditNote payment pdf

You can also get the CCB disbursement payment receipt pdf by the CreditNote id.

{:ok, payment} = StarkInfra.CreditNote.payment("5155165527080960")
file = File.open!("credit_note_payment.pdf", [:write])
IO.binwrite(file, payment)
File.close(file)

CCB Token Resend

You can resend the CCB token to the signers in case they missed the original email or link.

note = StarkInfra.CreditNote.get!("5155165527080960")

for signer <- note.signers do
  StarkInfra.CreditSigner.resend_token!(signer.id)
end

Credit Holmes

Create CreditHolmes

Before you create a CreditHolmes, make sure you have your customer's express authorization to verify their information in the Central Bank's SCR.

StarkInfra.CreditHolmes.create!([
  %StarkInfra.CreditHolmes{
    tax_id: "012.345.678-90",
    competence: "2022-06"
  }
]) |> IO.inspect

Note: Instead of using CreditHolmes structs, you can also pass each CreditHolmes element in map format

Query CreditHolmes

You can query multiple CreditHolmes according to filters.

StarkInfra.CreditHolmes.query!(
  limit: 10,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1)
)
|> Enum.take(10)
|> IO.inspect

Get a CreditHolmes

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

StarkInfra.CreditHolmes.get!("5155165527080960")
|> IO.inspect

Query CreditHolmes logs

You can query CreditHolmes logs to better understand a CreditHolmes life cycle.

StarkInfra.CreditHolmes.Log.query!(
  limit: 10,
  after: "2020-11-01",
  before: "2020-11-02"
)
|> Enum.take(10)
|> IO.inspect

Get a CreditHolmes log

You can also get a specific log by its id.

StarkInfra.CreditHolmes.Log.get!("5155165527080960")
|> IO.inspect

Credit Preview

Create CreditPreviews

You can preview a credit note before taking it, to check whether its computed fields match what you expect.

StarkInfra.CreditPreview.create!([
  %StarkInfra.CreditPreview{
    type: "credit-note",
    credit: %StarkInfra.CreditPreview.CreditNotePreview{
      type: "sac",
      nominal_amount: 100000,
      scheduled: Date.utc_today |> Date.add(3) |> Date.to_string,
      tax_id: "012.345.678-90",
      initial_due: Date.utc_today |> Date.add(33) |> Date.to_string,
      nominal_interest: 10,
      count: 12,
      interval: "month"
    }
  }
]) |> IO.inspect

Note: Instead of using CreditPreview structs, you can also pass each CreditPreview element in map format

Ledger

Create Ledgers

You can create a Ledger to track the balance of a bank account, a digital wallet, an inventory product, etc:

StarkInfra.Ledger.create!([
  %StarkInfra.Ledger{
    external_id: "my-internal-id-123456",
    rules: [
      %StarkInfra.Ledger.Rule{key: "minimumBalance", value: 0}
    ],
    tags: ["account/123", "savings"],
    metadata: %{"accountId" => "123", "accountType" => "savings"}
  }
])
|> IO.inspect

Note: Instead of using Ledger structs, you can also pass each Ledger element in map format

Query Ledgers

You can query multiple Ledgers according to filters.

StarkInfra.Ledger.query!(
  limit: 10,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1),
  external_ids: ["my-internal-id-123456"],
  tags: ["savings"]
)
|> Enum.take(10)
|> IO.inspect

Get a Ledger

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

StarkInfra.Ledger.get!("5155165527080960")
|> IO.inspect

Update a Ledger

You can update the rules, tags or metadata of a Ledger by passing its id.

StarkInfra.Ledger.update!(
  "5155165527080960",
  rules: [%StarkInfra.Ledger.Rule{key: "minimumBalance", value: 0}]
)
|> IO.inspect

Query Ledger logs

You can query Ledger logs to better understand a Ledger's life cycle.

StarkInfra.Ledger.Log.query!(
  limit: 10,
  after: "2020-11-01",
  before: "2020-11-02"
)
|> Enum.take(10)
|> IO.inspect

Get a Ledger log

You can also get a specific log by its id.

StarkInfra.Ledger.Log.get!("5155165527080960")
|> IO.inspect

Create LedgerTransactions

You can create a LedgerTransaction to update a Ledger's balance:

StarkInfra.LedgerTransaction.create!([
  %StarkInfra.LedgerTransaction{
    amount: 11234,
    ledger_id: "5155165527080960",
    external_id: "my-internal-id-123456",
    source: "bank-transfer/123",
    tags: ["transfer/123", "savings"],
    metadata: %{"orderId" => "123", "orderType" => "purchase"}
  }
])
|> IO.inspect

Note: Instead of using LedgerTransaction structs, you can also pass each LedgerTransaction element in map format

Query LedgerTransactions

You can query multiple LedgerTransactions according to filters.

StarkInfra.LedgerTransaction.query!(
  limit: 10,
  ledger_id: "5155165527080960",
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1)
)
|> Enum.take(10)
|> IO.inspect

Get a LedgerTransaction

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

StarkInfra.LedgerTransaction.get!("5155165527080960")
|> IO.inspect

Identity

Individual identities run an end-to-end identity verification on a Brazilian individual, and individual account requests ask Stark Infra to open an account for a natural person.

Create IndividualIdentities

You can create an IndividualIdentity to run an end-to-end identity verification on a natural person. Stark Infra collects the requested proofs and delivers the result through the webhook subscription.

StarkInfra.IndividualIdentity.create!([
  %StarkInfra.IndividualIdentity{
    name: "Walter White",
    email: "walter.white@email.com",
    delivery_method: "automatic",
    proofs: ["identity"],
    tax_id: "012.345.678-90",
    tags: ["breaking", "bad"]
  }
])
|> IO.inspect

Note: Instead of using IndividualIdentity structs, you can also pass each element in map format

Query IndividualIdentity

You can query multiple individual identities according to filters.

StarkInfra.IndividualIdentity.query!(
  limit: 10,
  after: Date.utc_today |> Date.add(-100),
  before: Date.utc_today,
  status: "success",
  tags: ["breaking", "bad"]
)
|> Enum.take(10)
|> IO.inspect

Get an IndividualIdentity

After its creation, information on an individual identity may be retrieved by its id.

StarkInfra.IndividualIdentity.get!("5155165527080960")
|> IO.inspect

Update an IndividualIdentity

You can update the tax_id of an individual identity, useful when the CPF is unknown at creation time and is only collected during the proof submission flow.

StarkInfra.IndividualIdentity.update!("5155165527080960", tax_id: "012.345.678-90")
|> IO.inspect

Cancel an IndividualIdentity

You can cancel an individual identity while it is still in "created" or "pending" status.

StarkInfra.IndividualIdentity.cancel!("5155165527080960")
|> IO.inspect

Query IndividualIdentity logs

You can query individual identity logs to better understand individual identity life cycles.

StarkInfra.IndividualIdentity.Log.query!(
  limit: 50,
  after: Date.utc_today |> Date.add(-100),
  before: Date.utc_today
)
|> Enum.take(50)
|> IO.inspect

Get an IndividualIdentity log

You can also get a specific log by its id.

StarkInfra.IndividualIdentity.Log.get!("5155165527080960")
|> IO.inspect

Create IndividualAccountRequests

You can create an IndividualAccountRequest to request the opening of an account for a specific individual.

StarkInfra.IndividualAccountRequest.create!([
  %StarkInfra.IndividualAccountRequest{
    name: "Walter White",
    tax_id: "012.345.678-90",
    address: %StarkInfra.IndividualAccountRequest.Address{
      street: "Rua do Estilo Barroco",
      number: "648",
      neighborhood: "Santo Amaro",
      city: "Sao Paulo",
      state: "SP",
      zip_code: "05724005"
    },
    income: 1000000,
    birth_date: "1965-09-07",
    tags: ["breaking", "bad"]
  }
])
|> IO.inspect

Note: Instead of using IndividualAccountRequest structs, you can also pass each element in map format

Query IndividualAccountRequests

You can query multiple individual account requests according to filters.

StarkInfra.IndividualAccountRequest.query!(
  limit: 10,
  after: Date.utc_today |> Date.add(-100),
  before: Date.utc_today,
  status: "created",
  tags: ["breaking", "bad"]
)
|> Enum.take(10)
|> IO.inspect

Get an IndividualAccountRequest

After its creation, information on an individual account request may be retrieved by its id.

StarkInfra.IndividualAccountRequest.get!("5155165527080960")
|> IO.inspect

Update an IndividualAccountRequest

You can update a specific individual account request by passing its id. Send it to validation by patching its status to "processing" once the required documents have been attached.

StarkInfra.IndividualAccountRequest.update!("5155165527080960", status: "processing")
|> IO.inspect

Query IndividualAccountRequest logs

You can query individual account request logs to better understand individual account request life cycles.

StarkInfra.IndividualAccountRequest.Log.query!(
  limit: 50,
  after: Date.utc_today |> Date.add(-100),
  before: Date.utc_today
)
|> Enum.take(50)
|> IO.inspect

Get an IndividualAccountRequest log

You can also get a specific log by its id.

StarkInfra.IndividualAccountRequest.Log.get!("5155165527080960")
|> IO.inspect

Create IndividualAccountAttachments

You can create an IndividualAccountAttachment to attach images of documents to a specific IndividualAccountRequest. You must reference the desired IndividualAccountRequest by its id. Pass the raw image bytes and a MIME content type; the SDK encodes them as a data url before sending.

StarkInfra.IndividualAccountAttachment.create!([
  %StarkInfra.IndividualAccountAttachment{
    type: "identity-front",
    content: File.read!("identity-front.png"),
    content_type: "image/png",
    account_request_id: "5155165527080960",
    tags: ["breaking", "bad"]
  }
])
|> IO.inspect

Note: The API accepts a single attachment per create call. Instead of using an IndividualAccountAttachment struct, you can also pass the element in map format

Query IndividualAccountAttachments

You can query multiple individual account attachments according to filters.

StarkInfra.IndividualAccountAttachment.query!(
  limit: 10,
  after: Date.utc_today |> Date.add(-100),
  before: Date.utc_today,
  status: "created",
  tags: ["breaking", "bad"]
)
|> Enum.take(10)
|> IO.inspect

Get an IndividualAccountAttachment

After its creation, information on an individual account attachment may be retrieved by its id.

StarkInfra.IndividualAccountAttachment.get!("5155165527080960")
|> IO.inspect

Cancel an IndividualAccountAttachment

You can cancel an individual account attachment by passing its id. The returned struct has status "deleted".

StarkInfra.IndividualAccountAttachment.cancel!("5155165527080960")
|> IO.inspect

Query IndividualAccountAttachment logs

You can query individual account attachment logs to better understand individual account attachment life cycles.

StarkInfra.IndividualAccountAttachment.Log.query!(
  limit: 50,
  after: Date.utc_today |> Date.add(-100),
  before: Date.utc_today
)
|> Enum.take(50)
|> IO.inspect

Get an IndividualAccountAttachment log

You can also get a specific log by its id.

StarkInfra.IndividualAccountAttachment.Log.get!("5155165527080960")
|> IO.inspect

Create BusinessIdentities

You can create a BusinessIdentity to verify the identity of a company (PJ) by its tax ID (CNPJ).

StarkInfra.BusinessIdentity.create!([
  %StarkInfra.BusinessIdentity{
    tax_id: "20.018.183/0001-80",
    tags: ["onboarding-123"]
  }
])
|> IO.inspect

Note: Instead of using BusinessIdentity structs, you can also pass each element in map format

Query BusinessIdentities

You can query multiple business identities according to filters.

StarkInfra.BusinessIdentity.query!(
  limit: 10,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1),
  status: ["success"],
  tags: ["onboarding-123"]
)
|> Enum.take(10)
|> IO.inspect

Get a BusinessIdentity

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

StarkInfra.BusinessIdentity.get!("5155165527080960")
|> IO.inspect

Update a BusinessIdentity

You can update a specific business identity by passing its id. Send it to processing by passing "processing" in the status (the identity must have attachments).

StarkInfra.BusinessIdentity.update!("5155165527080960", status: "processing")
|> IO.inspect

Cancel a BusinessIdentity

You can cancel a business identity by passing its id, while it is in the "created" or "pending" status.

StarkInfra.BusinessIdentity.cancel!("5155165527080960")
|> IO.inspect

Query BusinessIdentity logs

You can query business identity logs to better understand business identity life cycles.

StarkInfra.BusinessIdentity.Log.query!(
  limit: 50,
  after: "2022-01-01",
  before: "2022-01-20"
)
|> Enum.take(50)
|> IO.inspect

Get a BusinessIdentity log

You can also get a specific log by its id.

StarkInfra.BusinessIdentity.Log.get!("5155165527080960")
|> IO.inspect

Create BusinessAttachments

You can create a BusinessAttachment to attach a document (e.g. articles of incorporation) to a specific BusinessIdentity. You must reference the desired business identity by its id. A BusinessIdentity accepts at most 2 attachments.

StarkInfra.BusinessAttachment.create!([
  %StarkInfra.BusinessAttachment{
    name: "articles-of-incorporation.pdf",
    content: "data:application/pdf;base64,JVBERi0xLjQ...",
    business_identity_id: "5155165527080960",
    tags: ["doc-principal"]
  }
])
|> IO.inspect

Note: Instead of using BusinessAttachment structs, you can also pass each element in map format

Query BusinessAttachments

You can query multiple business attachments according to filters.

StarkInfra.BusinessAttachment.query!(
  limit: 10,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1),
  status: ["approved"],
  tags: ["doc-principal"]
)
|> Enum.take(10)
|> IO.inspect

Get a BusinessAttachment

After its creation, information on a business attachment may be retrieved by its id. Pass expand: ["content"] to also retrieve the document content.

StarkInfra.BusinessAttachment.get!("5155165527080960", expand: ["content"])
|> IO.inspect

Cancel a BusinessAttachment

You can cancel a business attachment by passing its id, while it is in the "created" status.

StarkInfra.BusinessAttachment.cancel!("5155165527080960")
|> IO.inspect

Query BusinessAttachment logs

You can query business attachment logs to better understand business attachment life cycles.

StarkInfra.BusinessAttachment.Log.query!(
  limit: 50,
  after: "2022-01-01",
  before: "2022-01-20"
)
|> Enum.take(50)
|> IO.inspect

Get a BusinessAttachment log

You can also get a specific log by its id.

StarkInfra.BusinessAttachment.Log.get!("5155165527080960")
|> IO.inspect

Create BusinessAccountRequests

You can create a BusinessAccountRequest to request an account for a specific company, opening the account with identity verification by webview for each of its owners.

StarkInfra.BusinessAccountRequest.create!([
  %StarkInfra.BusinessAccountRequest{
    name: "Stark Bank S.A.",
    tax_id: "20.018.183/0001-80",
    address: %StarkInfra.BusinessAccountRequest.Address{
      street: "Av. Faria Lima",
      number: "2000",
      neighborhood: "Itaim Bibi",
      city: "Sao Paulo",
      state: "SP",
      zip_code: "04538-132",
      complement: "Sala 42"
    },
    revenue: 100000000,
    owners: [
      %StarkInfra.BusinessAccountRequest.Owner{
        tax_id: "012.345.678-90",
        name: "Jamie Lannister",
        role: "partner"
      },
      %StarkInfra.BusinessAccountRequest.Owner{
        tax_id: "812.531.960-36",
        name: "Cersei Lannister",
        role: "representative"
      }
    ]
  }
])
|> IO.inspect

Note: Instead of using BusinessAccountRequest, Address and Owner structs, you can also pass each element in map format

Query BusinessAccountRequests

You can query multiple business account requests according to filters.

StarkInfra.BusinessAccountRequest.query!(
  limit: 10,
  after: Date.utc_today |> Date.add(-30),
  before: Date.utc_today |> Date.add(-1),
  status: ["approved"],
  tags: ["breaking", "bad"]
)
|> Enum.take(10)
|> IO.inspect

Get a BusinessAccountRequest

After its creation, information on a business account request may be retrieved by its id. Use it to read the per-owner verification status.

request = StarkInfra.BusinessAccountRequest.get!("5155165527080960")

for owner <- request.owners do
  IO.inspect({owner.name, owner.status})
end

Each owner also carries a validator_link, the webview where that owner completes biometrics and document capture. Treat it as a credential: deliver it to its owner through a secure channel, and never log it or write it to disk.

Query BusinessAccountRequest logs

You can query business account request logs to better understand business account request life cycles.

StarkInfra.BusinessAccountRequest.Log.query!(
  limit: 50,
  after: "2020-01-01",
  before: "2020-01-20"
)
|> Enum.take(50)
|> IO.inspect

Get a BusinessAccountRequest log

You can also get a specific log by its id.

StarkInfra.BusinessAccountRequest.Log.get!("5155165527080960")
|> IO.inspect

Webhook

Create a Webhook subscription

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

StarkInfra.Webhook.create!(
  url: "https://webhook.site/dd784f26-1d6a-4ca6-81cb-fda0267761ec",
  subscriptions: ["contract", "credit-note", "signer", "issuing-card", "issuing-invoice", "issuing-purchase", "pix-request.in", "pix-request.out", "pix-reversal.in", "pix-reversal.out", "pix-claim", "pix-key", "pix-chargeback", "pix-infraction"]
) |> IO.inspect

Query Webhook subscriptions

To search for registered webhooks, run:

for webhook <- StarkInfra.Webhook.query!() do
  webhook |> IO.inspect
end

Get a Webhook subscription

You can get a specific webhook by its id.

StarkInfra.Webhook.get!("6178044066660352")
|> IO.inspect

Delete a Webhook subscription

You can also delete a specific webhook by its id.

StarkInfra.Webhook.delete!("6178044066660352")
|> IO.inspect

Webhook events

Process Webhook events

It's easy to process events delivered to your Webhook endpoint. Remember to pass the signature header so the SDK can make sure it was StarkInfra that sent you the event.

response = listen()  # this is the function you made to get the events posted to your webhook

{event, _cache_pid} = StarkInfra.Event.parse!(
  content: response.content,
  signature: response.headers["Digital-Signature"]
) |> IO.inspect

To avoid making unnecessary requests to the API (/GET public-key), you can pass the cache_pid (returned on all requests) on your next parse. The process referred by the PID cache_pid will store the latest Stark Bank public key and automatically refresh it if an inconsistency is found between the content, signature and current public key.

Note: If you don't send the cache_pid to the parser, a new cache process will be generated.

{event, _cache_pid} = StarkInfra.Event.parse!(
  content: response.content,
  signature: response.headers["Digital-Signature"],
  cache_pid: cache_pid
) |> IO.inspect

If the data does not check out with the Stark Bank public-key, the function will automatically request the key from the API and try to validate the signature once more. If it still does not check out, it will raise an error.

Query Webhook events

To search for webhooks events, run:

StarkInfra.Event.query!(
  after: "2020-03-20",
  is_delivered: false,
  limit: 10
) 
|> Enum.take(10)
|> IO.inspect

Get a Webhook event

You can get a specific webhook event by its id.

StarkInfra.Event.get!("4568139664719872")
|> IO.inspect

Delete a Webhook event

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

StarkInfra.Event.delete!("4568139664719872")
|> IO.inspect

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 is_delivered: false.

StarkInfra.Event.update!("5764442407043072", is_delivered: true)
|> IO.inspect

Query failed Webhook event delivery attempts information

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

for attempt <- StarkInfra.Event.Attempt.query!(after: "2020-03-20") do
  attempt |> IO.inspect attempt
end

Get a failed Webhook event delivery attempt information

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

StarkInfra.Event.Attempt.get("1616161616161616")
|> IO.inspect

Handling errors

The SDK may raise or return errors as the StarkInfra.Error struct, which contains the "code" and "message" attributes.

If you use bang functions, the list of errors will be converted into a string and raised. If you use normal functions, the list of error structs will be returned so you can better analyse them.

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: help@starkinfra.com