Welcome to the Stark Bank Clojure SDK! This tool is made for Clojure 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!
This library supports Clojure versions 1.10+.
Feel free to take a look at our API docs.
This project adheres to the following versioning pattern:
Given a version number MAJOR.MINOR.PATCH, increment:
1.1 Manually download the desired SDK version JARs found in our
GitHub page
and add it to your project.clj
as :resource-paths ["resources/starkbank-2.5.2.jar"]
.
1.2 Using Leiningen/Boot:
[starkbank/sdk "2.5.2"]
1.3 Using Clojure CLI/deps.edn:
starkbank/sdk {:mvn/version "2.5.2"}
1.4 Using Gradle:
compile 'starkbank:sdk:2.5.2'
1.5 Using Maven:
<dependency>
<groupId>starkbank</groupId>
<artifactId>sdk</artifactId>
<version>2.5.2</version>
</dependency>
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:
(ns my-lib.core
(:use starkbank.core))
(def key-pair (starkbank.key/create))
(def private-key (:private-key key-pair))
(def public-key (:public-key key-pair))
;or, to also save .pem files in a specific path
(def key-pair (starkbank.key/create "file/keys/"))
(def private-key (:private-key key-pair))
(def public-key (:public-key key-pair))
NOTE: When you are creating new credentials, 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.
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 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:
(ns my-lib.core
(:use starkbank.core))
;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.
(def 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-----
")
(def project (starkbank.user/project
"sandbox"
"5671398416568321"
private-key-content
))
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:
(ns my-lib.core
(:use starkbank.core))
;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.
(def 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-----
")
(def organization (starkbank.user/organization
"sandbox"
"5671398416568321"
private-key-content
nil; You only need to set the workspace-id when you are operating a specific workspace-id
))
;To dynamically use your organization credentials in a specific workspace-id,
;you can use the user/organization-replace function:
(starkbank.balance/get (starkbank.user/organization-replace organization "4848484848484848"))
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.
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 as the last argument:
(ns my-lib.core
(:use starkbank.core))
(def user (starkbank.user/project; or organization
"sandbox"
"5671398416568321"
private-key-content))
(def balance (starkbank.balance/get user))
4.2 Set it as a default user in the SDK:
(ns my-lib.core
(:use starkbank.core))
(def user (starkbank.user/project; or organization
"sandbox"
"5671398416568321"
private-key-content))
(starkbank.settings/user user)
(def balance (starkbank.balance/get))
Just select the way of passing the project user that is more convenient to you.
On all following examples we will assume a default user has been set in the configs.
We will also assume you are using (:use starkbank.core)
on your code ns calls to
expose the starkbank SDK namespaces.
The error language can also be set in the same way as the default user:
(:require [starkbank.settings :as settings])
(settings/language "pt-BR")
Language options are "en-US" for english and "pt-BR" for brazilian portuguese. English is default.
Almost all SDK resources provide a query
and a page
function.
query
function provides a straight forward way retrieve results that match the filters you inform, seamlessly retrieving all the filtered elements from the API.
If you are not worried about data volume or processing time, this is the way to go.(def transactions
(starkbank.transaction/query
{
:after "2020-03-20"
:before "2020-03-30"
:limit 10
}))
(println transactions)
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 nil
.(defn get-page
[iterations, cursor]
(when (> iterations 0)
(def page (transaction/page {:limit 2}))
(def new-cursor (get page :cursor))
(def new-entities (get page :transactions))
(concat new-entities (get-page (- iterations 1) new-cursor))))
(println (get-page 3 nil))
To simplify the following SDK examples, we will only use the query
function, but feel free to use page
instead.
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.
Here are a few examples on how to use the SDK. If you have any doubts, use the built-in
doc
function to get more info on the desired functionality
(for example: (doc starkbank.boleto)
)
To send money between Stark Bank accounts, you can create transactions:
(def transactions
(starkbank.transaction/create
[
{
:amount 100; (R$ 1,00)
:receiver-id "5768064935133184"
:description "Transaction to dear provider"
:external-id "12345"; so we can block anything you send twice by mistake
:tags ["provider"]
}
{
:amount 234; (R$ 2,34)
:receiver-id "5768064935133184"
:description "Transaction to the other provider"
:external-id "12346"; so we can block anything you send twice by mistake
:tags ["provider"]
}
]))
(println 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.
(def transactions
(starkbank.transaction/query
{
:after "2020-03-20"
:before "2020-03-30"
:limit 10
}))
(println transactions)
You can get a specific transaction by its id:
(def transaction (starkbank.transaction/get "6677396233125888"))
(println transaction)
To know how much money you have in your workspace, run:
(def balance (starkbank.balance/get))
(println (double (/ (:amount balance) 100)))
You can also create transfers in the SDK (TED/Pix).
(def transfers
(starkbank.transfer/create
[
{
:amount 100
:bank-code "20018183"; Pix
:branch-code "0001"
:account-number "10000-0"
:account-type "checking"
:external-id "my-internal-id-12345"
:tax-id "012.345.678-90"
:name "Tony Stark"
:tags ["iron" "suit"]
}
{
:amount 200
:bank-code "341"; TED
:branch-code "1234"
:account-number "123456-7"
:tax-id "012.345.678-90"
:name "Jon Snow"
}
]))
(println transfers)
You can query multiple transfers according to filters.
(def transfers
(starkbank.transfer/query
{
:after "2020-11-01"
:before "2020-12-01"
:limit 10
}))
(println transfers)
To get a single transfer by its id, run:
(def transfer (starkbank.transfer/get "4882890932355072"))
(println transfer)
A transfer PDF may also be retrieved by passing its id. This operation is only valid for transfers with "processing" or "success" status.
(clojure.java.io/copy
(starkbank.transfer/pdf "4882890932355072")
(clojure.java.io/file "transfer.pdf"))
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.
You can query transfer logs to better understand transfer life cycles.
(def logs
(starkbank.transfer.log/query
{
:limit 50
}))
(println logs)
You can also get a specific log by its id.
(def log (starkbank.transfer.log/get "6610264099127296"))
(println log)
You can get Pix key's parameters by its id.
(def dict-key (starkbank.dict-key/get "tony@starkbank.com"))
(println dict-key)
To take a look at the Pix keys linked to your workspace, just run the following:
(def dict-keys (starkbank.dict-key/query {:limit 5}))
(doseq [dict-key dict-keys]
(printn dict-key))
You can query institutions registered by the Brazilian Central Bank for Pix and TED transactions.
(def institutions (institution/query {:search "stark"}))
(println institutions)
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.
(def invoices (starkbank.invoice/create
[{
:tags [ "immediate" ]
:amount 400000
:due "2020-12-25T19:32:35.418698+00:00"
:tax-id "012.345.678-90"
:name "Iron Bank S.A."
:expiration 123456789
:fine 2.5
:interest 1.3
:descriptions [
{
:key "Product X"
:value "big"
}
]
}
{
:tags [ "scheduled" ]
:amount 23571
:due "2021-11-28"
:taxId "012.345.678-90"
:name "Buzz Aldrin"
:expiration 123456789
:fine 5
:interest 2.5
:discounts [
{
:percentage 5
:due "2021-11-27"
}
]
}]))
(doseq [invoice invoices]
(println invoice))
After its creation, information on an invoice may be retrieved by its id. Its status indicates whether it's been paid.
(def invoice (starkbank.invoice/get "6750458353811456"))
(println invoice)
After its creation, an invoice PDF may be retrieved by its id.
(clojure.java.io/copy
(starkbank.invoice/pdf "6750458353811456")
(clojure.java.io/file "invoice.pdf"))
After its creation, an Invoice QR Code may be retrieved by its id.
(clojure.java.io/copy
(starkbank.invoice/qrcode "6750458353811456")
(clojure.java.io/file "invoice.png"))
Be careful not to accidentally enforce any encoding on the raw png content, as it may yield abnormal results in the final file.
You can also cancel an invoice by its id. Note that this is not possible if it has been paid already.
(def invoice (starkbank.invoice/update "6750458353811456"))
{
:status "canceled"
}))
(println invoice)
You can update an invoice's amount, due date and expiration by its id. Note that this is not possible if it has been paid already.
(def invoices (starkbank.invoice/update "6750458353811456"))
{
:amount 10
:expiration 600
:due "2020-12-20T19:32:35.418698+00:00"
})))
(doseq [invoice invoices]
(println invoice))
You can get a list of created invoices given some filters.
(def invoices (starkbank.invoice/query
{
:limit 5
:status "created"
}))
(doser [invoice invoices]
(println invoice))
Logs are pretty important to understand the life cycle of an invoice.
(def logs (starkbank.invoice.log/query
{
:limit 5
}))
(doseq [log logs]
(println log))
You can get a single log by its id.
(def log (starkbank.invoice.log/get "6288576484474880"))
(println log)
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:
(clojure.java.io/copy
(starkbank.invoice.log/pdf "6750458353811456")
(clojure.java.io/file "invoice-log.pdf"))
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.
Once an invoice has been paid, you can get the payment information using the Invoice.Payment sub-resource:
(def payment (starkbank.invoice/payment "4187263519823719"))
(println payment)
You can get a list of created deposits given some filters.
(def deposits (starkbank.deposit/query
{
:limit 5
}))
(doseq [deposit deposits]
(println deposit))
Logs are pretty important to understand the life cycle of a deposit.
(def logs (starkbank.deposit.log/query
{
:limit 10
}))
(doseq [log logs]
(println log))
You can get a single log by its id.
(def log (starkbank.deposit.log/get "6532638269505536"))
(println log)
You can create boletos to charge customers or to receive money from accounts you have in other banks.
(def boletos (starkbank.boleto/create [{
:amount 23571; R$ 235,71
:name "Buzz Aldrin"
:tax-id "012.345.678-90"
:street-line-1 "Av. Paulista 200"
:street-line-2 "10 andar"
:district "Bela Vista"
:city "São Paulo"
:state-code "SP"
:zip-code "01310-000"
:due "2020-05-20"
:fine 5; 5%
:interest 2.5; 2.5% per month
}]))
(println boletos)
After its creation, information on a boleto may be retrieved by passing its id. Its status indicates whether it's been paid.
(def boleto (starkbank.boleto/get "6750458353811456"))
(println boleto)
After its creation, a boleto PDF may be retrieved by passing its id.
(clojure.java.io/copy
(starkbank.boleto/pdf "6750458353811456")
(clojure.java.io/file "boleto.pdf"))
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.
You can also cancel a boleto by its id. Note that this is not possible if it has been processed already.
(def boleto (starkbank.boleto/delete "5202697619767296"))
(println boleto)
You can get a stream of created boletos given some filters.
(def boletos
(starkbank.boleto/query
{
:after "2020-09-05"
:before "2020-10-02"
:limit 10
}))
(println boletos)
Logs are pretty important to understand the life cycle of a boleto.
(def logs
(starkbank.boleto.log/query
{
:boleto-ids ["6750458353811456"]
}))
(println logs)
You can get a single log by its id.
(def log (starkbank.boleto.log/get "6288576484474880"))
(println log)
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.
(def holmes (starkbank.boleto-holmes/create
[{
:boleto-id "5656565656565656"
:tags ["investigating product x"]
}]))
(doseq [sherlock holmes]
(println sherlock))
To get a single boleto holmes by its id, run:
(def sherlock (starkbank.boleto-holmes/get "5656565656565656"))
(println sherlock)
You can search for boleto holmes using filters.
(def holmes (starkbank.boleto-holmes/query {
:limit 10
:after "2020-11-01"
:before "2020-12-01"
}))
(doseq [sherlock holmes]
(println sherlock))
Searches are also possible with boleto holmes logs:
(def logs (starkbank.boleto-holmes.log/query
{
:limit 10
:type "solved"
}))
(doseq [log logs]
(println log))
You can also get a boleto holmes log by specifying its id.
(def log (starkbank.boleto-holmes.log/get "5656565656565656"))
(println log)
Paying a BR Code is also simple.
(def payments (starkbank.brcode-payment/create
[{
:brcode "00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T'Challa6009Sao Paulo62090505123456304B14A"
:tax-id "20.018.183/0001-80"
:description "Tony Stark's Suit"
:amount 123456
:scheduled "2020-12-20T19:32:35.418698+00:00"
:tags ["Stark" "Suit"]
}]))
(doseq [payment payments]
(println payment))
You can search for brcode payments using filters.
(def payments (starkbank.brcode-payment/query
{
:limit 10
}))
(doseq [payment payments]
(println payment))
To get a single BR Code payment by its id, run:
(def payment (starkbank.brcode-payment/get "6532638269505536"))
(println 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.
(def payment (starkbank.brcode-payment/update "6532638269505536"
{
:status "canceled"
}))
(println payment)
After its creation, a boleto payment PDF may be retrieved by its id.
(clojure.java.io/copy
(starkbank.brcode-payment/pdf "6750458353811456")
(clojure.java.io/file "payment.pdf"))
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.
Searches are also possible with BR Code payment logs:
(def logs (starkbank.brcode-payment.log/query
{
:limit 10
}))
(doseq [log logs]
(println log))
You can also get a BR Code payment log by specifying its id.
(def log (starkbank.brcode-payment.log/get "6532638269505536"))
(println log)
Paying a boleto is also simple.
(def payments
(starkbank.boleto-payment/create
[
{
:line "34191.09008 64694.017308 71444.640008 1 96610000014500"
:tax-id "012.345.678-90"
:scheduled "2020-05-07"
:description "take my money"
:tags ["take" "my" "money"]
}
{
:bar-code "34191972300000289001090064694197307144464000"
:tax-id "012.345.678-90"
:scheduled "2020-06-10"
:description "take my money one more time"
:tags ["again"]
}
]))
(println payments)
To get a single boleto payment by its id, run:
(def payment (starkbank.boleto-payment/get "5629412477239296"))
(println payment)
After its creation, a boleto payment PDF may be retrieved by passing its id.
(clojure.java.io/copy
(starkbank.boleto-payment/pdf "6497770399596544")
(clojure.java.io/file "boleto-payment.pdf"))
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.
You can also cancel a boleto payment by its id. Note that this is not possible if it has been processed already.
(def payment (starkbank.boleto-payment/delete "5629412477239296"))
(println payment)
You can search for boleto payments using filters.
(def payments
(starkbank.boleto-payment/query
{
:tags ["company_1", "company_2"]
:limit 10
}))
(println payments)
Searches are also possible with boleto payment logs:
(def logs
(starkbank.boleto-payment.log/query
{
:payment-ids ["5629412477239296" "5199478290120704"]
}))
(println logs)
You can also get a boleto payment log by specifying its id.
(def log (starkbank.boleto-payment.log/get "5391671273455616"))
(println log)
It's also simple to pay utility bills (such as electricity and water bills) in the SDK.
(def payments
(starkbank.utility-payment/create
[
{
:bar-code "83600000001522801380037107172881100021296561"
:scheduled "2020-04-11"
:description "paying some bills"
:tags ["take" "my" "money"]
}
{
:line "83680000001 7 08430138003 0 71070987611 8 00041351685 7"
:scheduled "2020-05-11"
:description "never ending bills"
:tags ["again"]
}
]))
(println payments)
To search for utility payments using filters, run:
(def payments
(starkbank.utility-payment/query
{
:tags ["electricity" "gas"]
:limit 10
}))
(println payments)
You can get a specific bill by its id:
(def payment (starkbank.utility-payment/get "6619425641857024"))
(println payment)
After its creation, a utility payment PDF may also be retrieved by passing its id.
(clojure.java.io/copy
(starkbank.utility-payment/pdf "4663663059271680")
(clojure.java.io/file "utility-payment.pdf"))
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.
You can also cancel a utility payment by its id. Note that this is not possible if it has been processed already.
(def payment (starkbank.utility-payment/delete "6619425641857024"))
(println payment)
You can search for payments by specifying filters. Use this to understand the bills life cycles.
(def logs
(starkbank.utility-payment.log/query
{
:payment-ids ["6619425641857024" "5738969660653568"]
}))
(println logs)
If you want to get a specific payment log by its id, just run:
(def log (starkbank.utility-payment.log/get "6197807794880512"))
(println log)
It is also simple to pay taxes (such as ISS and DAS) using this SDK.
(def payments
(starkbank.tax-payment/create
[
{
:bar-code "85660000001549403280074119002551100010601813"
:scheduled "2021-07-13"
:description "paying some bills"
:tags ["take" "my" "money"]
}
{
:line "85800000003 0 28960328203 1 56072020190 5 22109674804 0"
:scheduled "2021-07-13"
:description "build the hospital, hopefully"
:tags ["expensive"]
}
]))
(println payments)
To search for tax payments using filters, run:
(def payments
(starkbank.tax-payment/query
{ :limit 10 }))
(println payments)
You can get a specific tax payment by its id:
(def payment (starkbank.tax-payment/get "5155165527080960"))
(println payment)
After its creation, a tax payment PDF may also be retrieved by its id.
(clojure.java.io/copy
(starkbank.tax-payment/pdf "5155165527080960")
(clojure.java.io/file "tax-payment.pdf"))
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.
You can also cancel a tax payment by its id. Note that this is not possible if it has been processed already.
(def payment (starkbank.tax-payment/delete "5155165527080960"))
(println payment)
You can search for payment logs by specifying filters. Use this to understand each payment life cycle.
(def logs
(starkbank.tax-payment.log/query
{ :limit 10 }))
(println logs)
If you want to get a specific payment log by its id, just run:
(def log (starkbank.tax-payment.log/get "1902837198237992"))
(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:
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"
(def previews
[
{:id "00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T'Challa6009Sao Paulo62090505123456304B14A" :scheduled "2021-08-10" }
{:id "34191.09008 61207.727308 71444.640008 5 81310001234321" }
])
(def payment-previews (payment-preview/create previews))
(doseq [preview payment-previews]
(println preview))
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 also gives time to load your account with the required amount before the payments take place. The approvals can be granted at our website and must be performed according to the rules specified in the cost center.
Note: The value of the center-id parameter can be consulted by logging into our website and going to the desired cost center page.
(def payment {
:amount 200
:name "Dumlocks von z'Blurbows"
:tax-id "012.345.678-90"
:bank-code "60701190"
:branch-code "0001"
:account-number "00000-0"
:tags ["testing" "clojure"]
})
(def requests (starkbank.payment-request/create
[{
:type type
:payment payment
:center-id "5656565656565656"
:tags ["testing" "clojure"]
:due "2020-12-11"
}]))
(doseq [request requests]
(println request))
To search for payment requests, run:
(def requests (starkbank.payment-request/query {
:limit 3
:status ["success"]
:center-id "5656565656565656")})
(doseq [request requests]
(println request))
To create a webhook subscription and be notified whenever an event occurs, run:
(def webhook
(starkbank.webhook/create
{
:url "https://webhook.site/dd784f26-1d6a-4ca6-81cb-fda0267761ec"
:subscriptions ["transfer" "boleto" "boleto-payment" "utility-payment"]
}))
(println webhook)
To search for registered webhooks, run:
(def webhooks (starkbank.webhook/query))
(println webhooks)
You can get a specific webhook by its id.
(def webhook (starkbank.webhook/get "6178044066660352"))
(println webhook)
You can also delete a specific webhook by its id.
(def webhook (starkbank.webhook/delete "5083659757420544"))
(println webhook)
It's easy to process events that have arrived in your webhook. Remember to pass the signature header so the SDK can make sure it's really StarkBank that has sent you the event.
(def response (listen)); this is the function you made to get the events posted to your webhook
(def event
(starkbank.event/parse
(:content response)
(:Digital-Signature (:headers response))))
(println event)
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.
To search for webhooks events, run:
(def events
(starkbank.event/query
{
:after "2020-03-20"
:is-delivered false
:limit 10
}))
(println events)
You can get a specific webhook event by its id.
(def event (starkbank.event/get "6597859067559936"))
(println event)
You can also delete a specific webhook event by its id.
(def event (starkbank.event/delete "4568139664719872"))
(println event)
You can also get information on failed webhook event delivery attempts.
(def attempts (starkbank.event.attempt/query {:after ["2020-03-20"]}))
(printn attempts)
To retrieve information on a single attempt, use the following function:
(def attempt (starkbank.event.attempt/get "1616161616161616"))
(print attempt)
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
.
(def event (starkbank.event/update "5764442407043072"
{
:is-delivered true
}))
(println event)
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 :workspace-id nil
.
(def workspace
(starkbank.workspace/create
{
:username "iron-bank-workspace-1"
:name "Iron Bank Workspace 1"
}))
(println workspace)
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.
(def workspaces (starkbank.workspace/query))
(println workspaces)
You can get a specific Workspace by its id.
(def workspace (starkbank.workspace/get "6178044066660352"))
(println workspace)
You can update a specific Workspace by its id.
(def workspace (starkbank.workspace/update
"6178044066660352"
{
:username "new-username-test"
:name "Updated workspace test"
:allowed-tax-ids ["359.536.680-82", "20.018.183/0001-80"]
}))
(print workspace)
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:
(try
(starkbank.transaction/create [
{
:amount -200
:receiver-id "123"
:description "."
:external-id "repeated id"
:tags ["error" "example"]
}
])
(catch com.starkbank.error.InputErrors e
(map
(fn [element] (str "error-code: " (.code element) "\nerror-message: " (.message element)))
(.errors e))))
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.
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: developers@starkbank.com
Can you improve this documentation? These fine people already did:
Caio Dottori, Felipe Sueto, vidalmatheus, vidalstark & cdottoriEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close