Welcome to the Stark Bank .NET SDK! This tool is made for .NET developers who want to easily integrate with our API. This SDK version is compatible with the Stark Bank API v2.
If you have no idea what Stark Bank is, check out our website and discover a world where receiving or making payments is as easy as sending a text message to your client!
- Introduction
- Setup
- Testing in Sandbox
- Usage
- Transactions: Account statement entries
- Balance: Account balance
- Transfers: Wire transfers (TED and manual Pix)
- DictKeys: Pix Key queries to use with Transfers
- Institutions: Instutitions recognized by the Central Bank
- Invoices: Reconciled receivables (dynamic Pix QR Codes)
- DynamicBrcode: Simplified reconciled receivables (dynamic Pix QR Codes)
- Deposits: Other cash-ins (static Pix QR Codes, DynamicBrcodes, manual Pix, etc)
- Boletos: Boleto receivables
- BoletoHolmes: Boleto receivables investigator
- BrcodePayments: Pay Pix QR Codes
- BoletoPayments: Pay Boletos
- UtilityPayments: Pay Utility bills (water, light, etc.)
- TaxPayments: Pay taxes
- DarfPayments: Pay DARFs
- PaymentPreviews: Preview all sorts of payments
- PaymentRequest: Request a payment approval to a cost center
- CorporateHolders: Manage cardholders
- CorporateCards: Create virtual and/or physical cards
- CorporateInvoices: Add money to your corporate balance
- CorporateWithdrawals: Send money back to your Workspace from your corporate balance
- CorporateBalance: View your corporate balance
- CorporateTransactions: View the transactions that have affected your corporate balance
- CorporateEnums: Query enums related to the corporate purchases, such as merchant categories, countries and card purchase methods
- Webhooks: Configure your webhook endpoints and subscriptions
- WebhookEvents: Manage webhook events
- WebhookEventAttempts: Query failed webhook event deliveries
- Workspaces: Manage your accounts
- Request: Send a custom request to Stark Bank. This can be used to access features that haven't been mapped yet.
- Handling errors
- Help and Feedback
This library supports the following .NET versions:
- .NET Standard 2.0+
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:
- MAJOR version when the API version is incremented. This may include backwards incompatible changes;
- MINOR version when breaking changes are introduced OR new functionalities are added in a backwards compatible manner;
- PATCH version when backwards compatible bug fixes are implemented.
StarkBank`s .NET SDK is available on NuGet as starkbank 2.13.0.
1.1 To install the Package Manager:
Install-Package starkbank -Version 2.13.0
1.2 To install the .NET CLI:
dotnet add package starkbank --version 2.13.0
1.3 To install by PackageReference:
<PackageReference Include="starkbank" Version="2.13.0" />
1.4 To install with Paket CLI:
paket add starkbank --version 2.13.0
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:
(string privateKey, string publicKey) = StarkBank.Key.Create();
# or, to also save .pem files in a specific path
(string privateKey, string publicKey) = StarkBank.Key.Create("file/keys");
NOTE: When you are creating a new integration user, 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.
- Projects are workspace-specific users, that is, they are bound to the workspaces they are created in. One workspace can have multiple Projects.
- Organizations are general users that control your entire organization. They can control all your Workspaces and even create new ones. The Organization is bound to your company's tax ID only. Since this user is unique in your entire organization, only one credential can be linked to it.
3.1. To create a Project in Sandbox:
3.1.1. Log into Starkbank Sandbox
3.1.2. Go to Menu > Integrations
3.1.3. Click on the "New Project" button
3.1.4. Create a Project: Give it a name and upload the public key you created in section 2
3.1.5. After creating the Project, get its Project ID
3.1.6. Use the Project ID and private key to create the object below:
// Get your private key from an environment variable or an encrypted database.
// This is only an example of a private key content. You should use your own key.
string privateKeyContent = "-----BEGIN EC PARAMETERS-----\nBgUrgQQACg==\n-----END EC PARAMETERS-----\n-----BEGIN EC PRIVATE KEY-----\nMHQCAQEEIMCwW74H6egQkTiz87WDvLNm7fK/cA+ctA2vg/bbHx3woAcGBSuBBAAK\noUQDQgAE0iaeEHEgr3oTbCfh8U2L+r7zoaeOX964xaAnND5jATGpD/tHec6Oe9U1\nIF16ZoTVt1FzZ8WkYQ3XomRD4HS13A==\n-----END EC PRIVATE KEY-----";
StarkBank.Project project = new StarkBank.Project(
environment: "sandbox",
id: "5656565656565656",
privateKey: privateKeyContent
);
3.2. To create Organization credentials in Sandbox:
3.2.1. Log into Starkbank Sandbox
3.2.2. Go to Menu > Integrations
3.2.3. Click on the "Organization public key" button
3.2.4. Upload the public key you created in section 2 (only a legal representative of the organization can upload the public key)
3.2.5. Click on your profile picture and then on the "Organization" menu to get the Organization ID
3.2.6. Use the Organization ID and private key to create the object below:
// Get your private key from an environment variable or an encrypted database.
// This is only an example of a private key content. You should use your own key.
string privateKeyContent = "-----BEGIN EC PARAMETERS-----\nBgUrgQQACg==\n-----END EC PARAMETERS-----\n-----BEGIN EC PRIVATE KEY-----\nMHQCAQEEIMCwW74H6egQkTiz87WDvLNm7fK/cA+ctA2vg/bbHx3woAcGBSuBBAAK\noUQDQgAE0iaeEHEgr3oTbCfh8U2L+r7zoaeOX964xaAnND5jATGpD/tHec6Oe9U1\nIF16ZoTVt1FzZ8WkYQ3XomRD4HS13A==\n-----END EC PRIVATE KEY-----";
StarkBank.Organization organization = new StarkBank.Organization(
environment: "sandbox",
id: "5656565656565656",
privateKey: privateKeyContent,
workspaceID: null // You only need to set the workspaceID when you are operating a specific workspaceID
);
// To dynamically use your organization credentials in a specific workspaceID,
// you can use the Organization.Replace() method:
StarkBank.Balance.Get(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 two kinds of users that can access our API: Project and Member.
Project
andOrganization
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:
StarkBank.Balance balance = StarkBank.Balance.Get(user: project); //or organization
4.2 Set it as a default user in the SDK:
StarkBank.Settings.User = project; //or organization
StarkBank.Balance balance = StarkBank.Balance.Get();
Just select the way of passing the user that is more convenient to you. On all following examples we will assume a default user has been set.
The error language can also be set in the same way as the default user:
StarkBank.Settings.Language = "en-US";
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.
- The
Query
function provides a straight forward way to efficiently iterate through all results that match the filters you inform, seamlessly retrieving the next batch of elements from the API only when you reach the end of the current batch. If you are not worried about data volume or processing time, this is the way to go.
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.Transaction> transactions = StarkBank.Transaction.Query(
after: DateTime.Today.Date.AddDays(-10),
before: DateTime.Today.Date.AddDays(-1)
);
foreach(StarkBank.Transaction transaction in transactions) {
Console.WriteLine(transaction);
}
- The
Page
function gives you full control over the API pagination. With each function call, you receive up to 100 results and the cursor to retrieve the next batch of elements. This allows you to stop your queries and pick up from where you left off whenever it is convenient. When there are no more elements to be retrieved, the returned cursor will benull
.
using System;
using System.Collections.Generic;
List<Transaction> page;
string cursor = null;
while (true)
{
(page, cursor) = StarkBank.Transaction.Page(cursor: cursor);
foreach (Transaction entity in page)
{
Console.WriteLine(entity);
}
if (cursor == null)
{
break;
}
}
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, check out the function or class docstring to get more info or go straight to our [API docs].
To send money between Stark Bank accounts, you can create transactions:
using System;
using System.Collections.Generic;
List<StarkBank.Transaction> transactions = StarkBank.Transaction.Create(
new List<StarkBank.Transaction> {
new StarkBank.Transaction(
amount: 100, // (R$ 1.00)
receiverID: "1029378109327810",
description: "Transaction to dear provider",
externalID: "12345", // so we can block anything you send twice by mistake
tags: new List<string> { "provider" }
),
new StarkBank.Transaction(
amount: 234, // (R$ 2.34)
receiverID: "2093029347820947",
description: "Transaction to the other provider",
externalID: "12346", // so we can block anything you send twice by mistake
tags: new List<string> { "provider" }
)
}
);
foreach(StarkBank.Transaction transaction in transactions) {
Console.WriteLine(transaction);
}
Note: Instead of using Transaction objects, you can also pass each transaction element in dictionary format
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.
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.Transaction> transactions = StarkBank.Transaction.Query(
after: DateTime.Today.Date.AddDays(-10),
before: DateTime.Today.Date.AddDays(-1)
);
foreach(StarkBank.Transaction transaction in transactions) {
Console.WriteLine(transaction);
}
You can get a specific transaction by its id:
using System;
StarkBank.Transaction transaction = StarkBank.Transaction.Get("5155165527080960");
Console.WriteLine(transaction);
To know how much money you have in your workspace, run:
using System;
StarkBank.Balance balance = StarkBank.Balance.Get();
Console.WriteLine(balance);
You can also create transfers in the SDK (TED/Pix) and configure transfer behavior according to its rules.
using System;
using System.Collections.Generic;
List<StarkBank.Transfer> transfers = StarkBank.Transfer.Create(
new List<StarkBank.Transfer> {
new StarkBank.Transfer(
amount: 100, // R$ 1,00
bankCode: "260", // TED
branchCode: "0001",
accountNumber: "10000-0",
taxID: "012.345.678-90",
name: "Tony Stark",
tags: new List<string> { "iron", "suit" }
),
new StarkBank.Transfer(
amount: 200, // R$ 2,00
bankCode: "20018183", // Pix
branchCode: "1234",
accountNumber: "123456-7",
accountType: "salary",
externalID: "my-internal-id-12345",
taxID: "012.345.678-90",
name: "Jon Snow",
scheduled: DateTime.Now.AddDays(1),
description: "Sword",
rules: new List<BrcodePayment.Rule>() {
new BrcodePayment.Rule(
key: "resendingLimit", // Set maximum number of retries if Transfer fails due to systemic issues at the receiver bank
value: 5 // Our resending limit is 10 by default
)
}
)
}
);
foreach(StarkBank.Transfer transfer in transfers) {
Console.WriteLine(transfer);
}
Note: Instead of using Transfer objects, you can also pass each transfer element in dictionary format
You can query multiple transfers according to filters.
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.Transfer> transfers = StarkBank.Transfer.Query(
after: DateTime.Today.Date.AddDays(-10),
before: DateTime.Today.Date.AddDays(-1)
);
foreach(StarkBank.Transfer transfer in transfers) {
Console.WriteLine(transfer.Name);
}
To get a single transfer by its id, run:
using System;
StarkBank.Transfer transfer = StarkBank.Transfer.Get("5155165527080960");
Console.WriteLine(transfer);
To cancel a single scheduled transfer by its id, run:
using System;
StarkBank.Transfer transfer = StarkBank.Transfer.Delete("5155165527080960");
Console.WriteLine(transfer);
A transfer PDF may also be retrieved by passing its id. This operation is only valid if the transfer status is "processing" or "success".
byte[] pdf = StarkBank.Transfer.Pdf("5155165527080960");
System.IO.File.WriteAllBytes("transfer.pdf", 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.
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.Transfer.Log> logs = StarkBank.Transfer.Log.Query(limit: 50);
foreach(StarkBank.Transfer.Log log in logs) {
Console.WriteLine(log);
}
You can also get a specific log by its id.
using System;
StarkBank.Transfer.Log log = StarkBank.Transfer.Log.Get("5155165527080960");
Console.WriteLine(log);
You can get Pix key's parameters by its id.
using System;
StarkBank.DictKey dictKey = DictKey.Get("[email protected]");
Console.WriteLine(dictKey);
To take a look at the Pix keys linked to your workspace, just run the following:
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.DictKey> dictKeys = StarkBank.DictKey.Query(
status: "registered",
type: "evp"
);
foreach(StarkBank.DictKey dictKey in dictKeys) {
Console.WriteLine(dictKey);
}
You can query institutions registered by the Brazilian Central Bank for Pix and TED transactions.
using System;
using System.Collections.Generic;
List<StarkBank.Institution> institutions = StarkBank.Institution.Query(search: "stark");
foreach(StarkBank.Institution.Log institution in institutions) {
Console.WriteLine(institution);
}
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.
# coding: utf-8
using System;
using System.Collections.Generic;
List<StarkBank.Invoice> invoices = StarkBank.Invoice.Create(
new List<StarkBank.Invoice> {
new StarkBank.Invoice(
amount: 248,
descriptions: new List<Dictionary<string, object>>() {
new Dictionary<string, object> {
{"key", "Arya"},
{"value", "Not today"}
}
},
discounts: new List<Dictionary<string, object>>() {
new Dictionary<string, object> {
{"percentage", 10},
{"due", new DateTime(2021, 4, 25, 13, 17, 15)}
}
},
due: new DateTime(2021, 5, 25, 13, 17, 15),
expiration: 123456789,
fine: 2.5,
interest: 1.3,
name: "Arya Stark",
taxID: "29.176.331/0001-69",
tags: new List<string> { "immediate" }
),
new StarkBank.Invoice(
amount: 248,
discounts: new List<Dictionary<string, object>>() {
new Dictionary<string, object> {
{"percentage", 10},
{"due", new DateTime(2021, 4, 25)}
}
},
due: new DateTime(2021, 5, 25),
expiration: 123456789,
fine: 2.5,
interest: 1.3,
name: "Arya Stark",
taxID: "29.176.331/0001-69",
tags: new List<string> { "scheduled" }
)
}
);
foreach(StarkBank.Invoice invoice in invoices) {
Console.WriteLine(invoice);
}
Note: Instead of using Invoice objects, you can also pass each invoice element in dictionary format
After its creation, information on an invoice may be retrieved by its id. Its status indicates whether it's been paid.
using System;
StarkBank.Invoice invoice = StarkBank.Invoice.Get("5715709195714560");
Console.WriteLine(invoice);
After its creation, an invoice QRCode may be retrieved by its id.
using System;
byte[] png = StarkBank.Invoice.Qrcode("5715709195714560");
System.IO.File.WriteAllBytes("qrcode.png", png);
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.
After its creation, an invoice PDF may be retrieved by its id.
using System;
byte[] pdf = StarkBank.Invoice.Pdf("5715709195714560");
System.IO.File.WriteAllBytes("invoice.pdf", 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 an invoice by its id. Note that this is not possible if it has been paid already.
using System;
StarkBank.Invoice invoice = StarkBank.Invoice.Update(
"6312789471657984",
status: "canceled"
);
Console.WriteLine(invoice);
You can update an invoice's amount, due date and expiration by its id.
If the invoice has already been paid, the amount can still be decreased, causing the payment to be reversed to the payer.
To fully reverse the invoice, pass amount: 0
.
using System;
StarkBank.Invoice invoice = StarkBank.Invoice.Update(
"6312789471657984",
amount: 0
);
Console.WriteLine(invoice);
You can get a list of created invoices given some filters.
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.Invoice> invoices = StarkBank.Invoice.Query(
after: new DateTime(2019, 4, 1),
before: new DateTime(2021, 4, 30)
);
foreach(StarkBank.Invoice invoice in invoices) {
Console.WriteLine(invoice);
}
Logs are pretty important to understand the life cycle of an invoice.
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.Invoice.Log> logs = StarkBank.Invoice.Log.Query(
after: new DateTime(2019, 4, 1),
before: new DateTime(2021, 4, 30)
);
foreach(StarkBank.Invoice.Log log in logs) {
Console.WriteLine(log);
}
You can get a single log by its id.
using System;
StarkBank.Invoice.Log log = StarkBank.Invoice.Log.Get("4701727546671104");
Console.WriteLine(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:
using System;
byte[] pdf = StarkBank.Invoice.Log.Pdf("4701727546671104");
System.IO.File.WriteAllBytes("invoice-log.pdf", 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 InvoicePayment sub-resource:
using System;
StarkBank.InvoicePayment payment = Invoice.Payment("5155165527080960");
Console.WriteLine(payment);
You can create simplified dynamic QR Codes to receive money using Pix transactions. When a DynamicBrcode is paid, a Deposit is created with the tags parameter containing the character “dynamic-brcode/” followed by the DynamicBrcode’s uuid "dynamic-brcode/{uuid}" for conciliation.
The differences between an Invoice and the DynamicBrcode are the following:
Invoice | DynamicBrcode | |
---|---|---|
Expiration | âś“ | âś“ |
Can only be paid once | âś“ | âś“ |
Due, fine and fee | âś“ | X |
Discount | âś“ | X |
Description | âś“ | X |
Can be updated | âś“ | X |
Note: In order to check if a BR code has expired, you must first calculate its expiration date (add the expiration to the creation date). Note: To know if the BR code has been paid, you need to query your Deposits by the tag "dynamic-brcode/{uuid}" to check if it has been paid.
using System;
List<DynamicBrcode> brcodes = StarkBank.DynamicBrcode.Create(
new List<DynamicBrcode>() {
new DynamicBrcode(
amount: 23571, // R$ 235,71
expiration: 3600
),
new DynamicBrcode(
amount: 23571, // R$ 235,71
expiration: 3600
)
}
)
foreach(StarkBank.DynamicBrcode brcode in brcodes) {
Console.WriteLine(brcode);
}
Note: Instead of using DynamicBrcode objects, you can also pass each brcode element in dictionary format
After its creation, information on a DynamicBrcode may be retrieved by its uuid.
using System;
StarkBank.DynamicBrcode brcode = StarkBank.DynamicBrcode.Get("bb9cd43ea6f4403391bf7ef6aa876600");
Console.WriteLine(brcode);
You can get a list of created DynamicBrcodes given some filters.
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.DynamicBrcode> brcodes = StarkBank.DynamicBrcode.Query(
after: new DateTime(2023, 4, 1),
before: new DateTime(2023, 4, 30)
);
foreach(StarkBank.DynamicBrcode brcode in brcodes) {
Console.WriteLine(brcode);
}
You can get a list of created deposits given some filters.
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.Deposit> deposits = StarkBank.Deposit.Query(
after: new DateTime(2019, 4, 1),
before: new DateTime(2021, 4, 30)
);
foreach(StarkBank.Deposit deposit in deposits) {
Console.WriteLine(deposit);
}
After its creation, information on a deposit may be retrieved by its id.
using System;
StarkBank.Deposit deposit = StarkBank.Deposit.Get("5715709195714560");
Console.WriteLine(deposit);
Logs are pretty important to understand the life cycle of a deposit.
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.Deposit.Log> logs = StarkBank.Deposit.Log.Query(
after: new DateTime(2019, 4, 1),
before: new DateTime(2021, 4, 30)
);
foreach(StarkBank.Deposit.Log log in logs) {
Console.WriteLine(log);
}
Update a deposit by passing its id to be partially or fully reversed.
using System;
StarkBank.Deposit deposit = StarkBank.Deposit.Update(
"5155165527080960",
amount: 0
);
Console.WriteLine(deposit);
You can get a single log by its id.
using System;
StarkBank.Deposit.Log log = StarkBank.Deposit.Log.Get("4701727546671104");
Console.WriteLine(log);
You can create boletos to charge customers or to receive money from accounts you have in other banks.
using System;
using System.Collections.Generic;
List<StarkBank.Boleto> boletos = StarkBank.Boleto.Create(
new List<StarkBank.Boleto> {
new StarkBank.Boleto(
amount: 23571, // R$ 235,71
name: "Buzz Aldrin",
taxID: "012.345.678-90",
streetLine1: "Av. Paulista, 200",
streetLine2: "10 andar",
district: "Bela Vista",
city: "SĂŁo Paulo",
stateCode: "SP",
zipCode: "01310-000",
due: DateTime.Today.Date.AddDays(30),
fine: 5, // 5%
interest: 2.5 // 2.5% per month
)
}
);
foreach (StarkBank.Boleto boleto in boletos) {
Console.WriteLine(boleto);
}
Note: Instead of using Boleto objects, you can also pass each boleto element in dictionary format
After its creation, information on a boleto may be retrieved by passing its id. Its status indicates whether it's been paid.
using System;
StarkBank.Boleto boleto = StarkBank.Boleto.Get("5155165527080960");
Console.WriteLine(boleto);
After its creation, a boleto PDF may be retrieved by passing its id.
byte[] pdf = StarkBank.Boleto.Pdf("5155165527080960", layout: "default");
System.IO.File.WriteAllBytes("boleto.pdf", 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.
using System;
StarkBank.Boleto boleto = StarkBank.Boleto.Delete("5155165527080960");
Console.WriteLine(boleto);
You can get a list of created boletos given some filters.
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.Boleto> boletos = StarkBank.Boleto.Query(
after: DateTime.Today.Date.AddDays(-10),
before: DateTime.Today.Date.AddDays(-1)
);
foreach(StarkBank.Boleto boleto in boletos) {
Console.WriteLine(boleto);
}
Logs are pretty important to understand the life cycle of a boleto.
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.Boleto.Log> logs = StarkBank.Boleto.Log.Query(limit: 150);
foreach(StarkBank.Boleto.Log log in logs) {
Console.WriteLine(log);
}
You can get a single log by its id.
using System;
StarkBank.Boleto.Log log = StarkBank.Boleto.Log.Get("5155165527080960");
Console.WriteLine(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.
using System;
using System.Collections.Generic;
List<StarkBank.BoletoHolmes> payments = StarkBank.BoletoHolmes.Create(
new List<StarkBank.BoletoHolmes> {
new StarkBank.BoletoHolmes(
boletoID: "5656565656565656",
),
new StarkBank.BoletoHolmes(
boletoID: "4848484848484848",
tags: new List<string> { "elementary" }
)
}
);
foreach(StarkBank.BoletoHolmes sherlock in holmes) {
Console.WriteLine(sherlock);
}
Note: Instead of using BoletoHolmes objects, you can also pass each payment element in dictionary format
To get a single Holmes by its id, run:
using System;
StarkBank.BoletoHolmes sherlock = StarkBank.BoletoHolmes.Get("5155165527080960");
Console.WriteLine(sherlock);
You can search for boleto Holmes using filters.
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.BoletoHolmes> holmes = StarkBank.BoletoHolmes.Query(
tags: new List<string> { "elementary" }
);
foreach(StarkBank.BoletoHolmes sherlock in holmes) {
Console.WriteLine(sherlock);
}
Searches are also possible with boleto holmes logs:
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.BoletoHolmes.Log> logs = StarkBank.BoletoHolmes.Log.Query(
holmesIds: new List<string> { "5155165527080960", "76551659167801921" }
);
foreach(StarkBank.BoletoHolmes.Log log in logs) {
Console.WriteLine(log);
}
You can also get a boleto holmes log by specifying its id.
using System;
StarkBank.BoletoHolmes.Log log = StarkBank.BoletoHolmes.Log.Get("5155165527080960");
Console.WriteLine(log);
Paying a BR Code is also simple. After extracting the BR Code encoded in the Pix QR Code, you can do the following:
using System;
using System.Collections.Generic;
List<StarkBank.BrcodePayment> payments = StarkBank.BrcodePayment.Create(
new List<StarkBank.BrcodePayment> {
new StarkBank.BrcodePayment(
brcode: "00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T'Challa6009Sao Paulo62090505123456304B14A",
taxID: "012.345.678-90",
scheduled: DateTime.Today.Date.AddDays(2),
description: "this will be fast",
tags: new List<string> { "pix", "qrcode" },
rules: new List<BrcodePayment.Rule>() {
new BrcodePayment.Rule(
key: "resendingLimit", // Set maximum number of retries if Payment fails due to systemic issues at the receiver bank
value: 5 // Our resending limit is 10 by default
)
}
)
}
);
foreach(StarkBank.BrcodePayment payment in payments) {
Console.WriteLine(payment);
}
Note: You can also configure payment behavior according to its rules Note: Instead of using BrcodePayment objects, you can also pass each payment element in dictionary format
To get a single BR Code payment by its id, run:
using System;
StarkBank.BrcodePayment payment = StarkBank.BrcodePayment.Get("19278361897236187236");
Console.WriteLine(payment);
After its creation, a BR Code payment PDF may be retrieved by passing its id.
byte[] pdf = StarkBank.BrcodePayment.Pdf("5155165527080960");
System.IO.File.WriteAllBytes("brcode_payment.pdf", 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 cancel a BR Code payment by changing its status to "canceled". Note that this is not possible if it has been processed already.
using System;
StarkBank.BrcodePayment payment = StarkBank.BrcodePayment.Update(
"6312789471657984",
status: "canceled"
);
Console.WriteLine(payment);
You can search for BR Code payments using filters.
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.BrcodePayment> payments = StarkBank.BrcodePayment.Query(
tags: new List<string> { "company_1", "company_2" }
);
foreach(StarkBank.BrcodePayment payment in payments) {
Console.WriteLine(payment);
}
Searches are also possible with BR Code payment logs:
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.BrcodePayment.Log> logs = StarkBank.BrcodePayment.Log.Query(
paymentIds: new List<string> { "5155165527080960", "76551659167801921" }
);
foreach(StarkBank.BrcodePayment.Log log in logs) {
Console.WriteLine(log);
}
You can also get a BR Code payment log by specifying its id.
using System;
StarkBank.BrcodePayment.Log log = StarkBank.BrcodePayment.Log.Get("5155165527080960");
Console.WriteLine(log);
Paying a boleto is also simple.
using System;
using System.Collections.Generic;
List<StarkBank.BoletoPayment> payments = StarkBank.BoletoPayment.Create(
new List<StarkBank.BoletoPayment> {
new StarkBank.BoletoPayment(
line: "34191.09008 64694.017308 71444.640008 1 96610000014500",
taxID: "012.345.678-90",
scheduled: DateTime.Today.Date.AddDays(2),
description: "take my money",
tags: new List<string> { "take", "my", "money" }
),
new StarkBank.BoletoPayment(
barCode: "34191972300000289001090064694197307144464000",
taxID: "012.345.678-90",
scheduled: DateTime.Today.Date.AddDays(1),
description: "take my money one more time",
tags: new List<string> { "again" }
)
}
);
foreach(StarkBank.BoletoPayment payment in payments) {
Console.WriteLine(payment);
}
Note: Instead of using BoletoPayment objects, you can also pass each payment element in dictionary format
To get a single boleto payment by its id, run:
using System;
StarkBank.BoletoPayment payment = StarkBank.BoletoPayment.Get("19278361897236187236");
Console.WriteLine(payment);
After its creation, a boleto payment PDF may be retrieved by passing its id.
byte[] pdf = StarkBank.BoletoPayment.Pdf("5155165527080960");
System.IO.File.WriteAllBytes("boleto_payment.pdf", 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.
using System;
StarkBank.BoletoPayment payment = StarkBank.BoletoPayment.Delete("5155165527080960");
Console.WriteLine(payment);
You can search for boleto payments using filters.
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.BoletoPayment> payments = StarkBank.BoletoPayment.Query(
tags: new List<string> { "company_1", "company_2" }
);
foreach(StarkBank.BoletoPayment payment in payments) {
Console.WriteLine(payment);
}
Searches are also possible with boleto payment logs:
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.BoletoPayment.Log> logs = StarkBank.BoletoPayment.Log.Query(
paymentIds: new List<string> { "5155165527080960", "76551659167801921" }
);
foreach(StarkBank.BoletoPayment.Log log in logs) {
Console.WriteLine(log);
}
You can also get a boleto payment log by specifying its id.
using System;
StarkBank.BoletoPayment.Log log = StarkBank.BoletoPayment.Log.Get("5155165527080960");
Console.WriteLine(log);
It"s also simple to pay utility bills (such as electricity and water bills) in the SDK.
using System;
using System.Collections.Generic;
List<StarkBank.UtilityPayment> payments = StarkBank.UtilityPayment.Create(
new List<StarkBank.UtilityPayment> {
new StarkBank.UtilityPayment(
line: "83680000001 7 08660138003 0 71070987611 8 00041351685 7",
scheduled: DateTime.Today.Date.AddDays(2),
description: "take my money",
tags: new List<string> { "take", "my", "money" }
),
new StarkBank.UtilityPayment(
barCode: "83600000001512801380037107172881100021296561",
scheduled: DateTime.Today.Date.AddDays(1),
description: "take my money one more time",
tags: new List<string> { "again" }
)
}
);
foreach(StarkBank.UtilityPayment payment in payments) {
Console.WriteLine(payment);
}
Note: Instead of using UtilityPayment objects, you can also pass each payment element in dictionary format
To search for utility payments using filters, run:
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.UtilityPayment> payments = StarkBank.UtilityPayment.Query(
tags: new List<string> { "electricity", "gas" }
);
foreach(StarkBank.UtilityPayment payment in payments) {
Console.WriteLine(payment);
}
You can get a specific bill by its id:
using System;
StarkBank.UtilityPayment payment = StarkBank.UtilityPayment.Get("5155165527080960");
Console.WriteLine(payment);
After its creation, a utility payment PDF may also be retrieved by passing its id.
byte[] pdf = StarkBank.UtilityPayment.Pdf("5155165527080960");
System.IO.File.WriteAllBytes("electricity_payment.pdf", 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.
using System;
StarkBank.UtilityPayment payment = StarkBank.UtilityPayment.Delete("5155165527080960");
Console.WriteLine(payment);
You can search for payments by specifying filters. Use this to understand the bills life cycles.
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.UtilityPayment.Log> logs = StarkBank.UtilityPayment.Log.Query(
paymentIds: new List<string> { "102893710982379182", "92837912873981273" }
);
foreach(StarkBank.UtilityPayment.Log log in logs) {
Console.WriteLine(log);
}
If you want to get a specific payment log by its id, just run:
using System;
StarkBank.UtilityPayment.Log log = StarkBank.UtilityPayment.Log.Get("1902837198237992");
Console.WriteLine(log);
It is also simple to pay taxes (such as ISS and DAS) using this SDK.
using System;
List<StarkBank.TaxPayment> payments = StarkBank.TaxPayment.Create(new List<StarkBank.TaxPayment>() {
new StarkBank.TaxPayment(
barCode: "85660000001549403280074119002551100010601813",
description: "fix the road",
tags: new List<string> { "take", "my", "money" },
scheduled: "2020-08-13"
),
new StarkBank.TaxPayment(
line: "85800000003 0 28960328203 1 56072020190 5 22109674804 0",
description: "build the hospital, hopefully",
tags: new List<string> { "expensive" },
scheduled: "2020-08-13"
)
});
foreach (StarkBank.TaxPayment payment in payments)
{
Console.WriteLine(payment);
}
Note: Instead of using TaxPayment objects, you can also pass each payment element in dictionary format
To search for tax payments using filters, run:
using System;
List<StarkBank.TaxPayment> payments = StarkBank.TaxPayment.Query(limit: 5).ToList();
foreach (StarkBank.TaxPayment payment in payments)
{
Console.WriteLine(payment);
}
You can get a specific tax payment by its id:
using System;
StarkBank.TaxPayment payment = StarkBank.TaxPayment.Get("5155165527080960");
Console.WriteLine(payment);
After its creation, a tax payment PDF may also be retrieved by its id.
using System;
byte[] pdf = StarkBank.TaxPayment.Pdf("5155165527080960");
System.IO.File.WriteAllBytes("taxPayment.pdf", 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.
using System;
StarkBank.TaxPayment payment = StarkBank.TaxPayment.Delete("5155165527080960");
Console.WriteLine(payment);
You can search for payment logs by specifying filters. Use this to understand each payment life cycle.
using System;
List<StarkBank.TaxPayment.Log> logs = StarkBank.TaxPayment.Log.Query(
limit: 5
).ToList();
foreach (StarkBank.TaxPayment.Log log in logs)
{
Console.WriteLine(log);
}
If you want to get a specific payment log by its id, just run:
using System;
StarkBank.TaxPayment.Log log = StarkBank.TaxPayment.Log.Get("1902837198237992");
Console.WriteLine(log);
Note: Some taxes can't be payed with bar codes. Since they have specific parameters, each one of them has its own resource and routes, which are all analogous to the TaxPayment resource. The ones we currently support are:
- DarfPayment, for DARFs
If you want to manually pay DARFs without barCodes, you may create DarfPayments:
using System;
List<StarkBank.DarfPayment> payments = StarkBank.DarfPayment.Create(
new List<StarkBank.DarfPayment>() {
new StarkBank.DarfPayment(
revenueCode: "1240",
taxId: "012.345.678-90",
competence: "2020-09-01",
referenceNumber: "2340978970",
nominalAmount: 1234,
fineAmount: 12,
interestAmount: 34,
due: DateTime.Today.Date.AddDays(30),
scheduled: DateTime.Today.Date.AddDays(30),
tags: new List<string> { "DARF", "making money" },
description: "take my money",
)
}
);
foreach (StarkBank.DarfPayment payment in payments)
{
Console.WriteLine(payment);
}
Note: Instead of using DarfPayment objects, you can also pass each payment element in dictionary format
To search for DARF payments using filters, run:
using System;
List<StarkBank.DarfPayment> payments = StarkBank.DarfPayment.Query(
tags: new List<string>{ "darf", "july" }
).ToList();
foreach (StarkBank.DarfPayment payment in payments)
{
Console.WriteLine(payment);
}
You can get a specific DARF payment by its id:
using System;
StarkBank.DarfPayment payment = StarkBank.DarfPayment.Get("5155165527080960");
Console.WriteLine(payment);
After its creation, a DARF payment PDF may also be retrieved by its id.
using System;
byte[] pdf = StarkBank.DarfPayment.Pdf("5155165527080960");
System.IO.File.WriteAllBytes("darfPayment.pdf", 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 DARF payment by its id. Note that this is not possible if it has been processed already.
using System;
StarkBank.DarfPayment payment = StarkBank.DarfPayment.Delete("5155165527080960");
Console.WriteLine(payment);
You can search for payment logs by specifying filters. Use this to understand each payment life cycle.
using System;
List<StarkBank.DarfPayment.Log> logs = StarkBank.DarfPayment.Log.Query(
limit: 5
).ToList();
foreach (StarkBank.DarfPayment.Log log in logs)
{
Console.WriteLine(log);
}
If you want to get a specific payment log by its id, just run:
using System;
StarkBank.DarfPayment.Log log = StarkBank.DarfPayment.Log.Get("1902837198237992");
Console.WriteLine(log);
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"
using System;
List<PaymentPreview> previews = PaymentPreview.Create(new List<PaymentPreview>
{
new PaymentPreview(id: "00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T'Challa6009Sao Paulo62090505123456304B14A", scheduled: DateTime.Today.Date.AddDays(3)),
new PaymentPreview(id: "34191.09008 61207.727308 71444.640008 5 81310001234321")
});
foreach (StarkBank.PaymentPreview preview in previews)
{
Console.WriteLine(preview);
}
Note: Instead of using PaymentPreview objects, you can also pass each request element in dictionary format
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 web banking and must be performed according to the rules specified in the cost center.
Note: The value of the centerID parameter can be consulted by logging into our web banking and going to the desired Cost Center page.
using System;
using System.Collections.Generic;
List<StarkBank.PaymentRequest> requests = StarkBank.PaymentRequest.Create(
new List<StarkBank.PaymentRequest> {
new StarkBank.PaymentRequest(
centerID: "5656565656565656",
due: DateTime.Today.Date.AddDays(2),
payment: new StarkBank.Transfer(
amount: 100, // R$ 1,00
bankCode: "033",
branchCode: "0001",
accountNumber: "10000-0",
taxID: "012.345.678-90",
name: "Master Yoda"
)
),
new StarkBank.PaymentRequest(
centerID: "5656565656565656",
payment: new StarkBank.BoletoPayment(
line: "34191.09008 64694.017308 71444.640008 1 96610000014500",
taxID: "012.345.678-90",
description: "Payment for spare droid parts"
),
tags: new List<string> { "rd2d", "invoice/1234" }
)
}
);
foreach(StarkBank.PaymentRequest request in requests) {
Console.WriteLine(request);
}
Note: Instead of using PaymentRequest objects, you can also pass each payment element in dictionary format
To search for payment requests, run:
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.PaymentRequest> requests = StarkBank.PaymentRequest.Query(
centerID: "5656565656565656",
after: DateTime.Today.Date.AddDays(-10),
before: DateTime.Today.Date.AddDays(-1)
);
foreach(StarkBank.PaymentRequest request in requests) {
Console.WriteLine(request);
}
You can create card holders to which your cards will be bound. They support spending rules that will apply to all underlying cards.
using System;
List<StarkBank> holders = StarkBank.CorporateHolder.Create(
new List<StarkBank.CorporateHolder> {
new StarkBank.CorporateHolder(
name: "Iron Bank S.A.",
tags: new List<string> { "Traveler Employee" },
rules: new List<StarkBank.CorporateRule>() {
new StarkBank.CorporateRule(
name: "General USD",
interval: "day",
amount: 100000,
currencyCode: "USD"
)
}
)
}
)
foreach (StarkBank.CorporateHolder holder in holders) {
Console.Write(holder);
}
Note: Instead of using CorporateHolder objects, you can also pass each element in dictionary format
You can query multiple holders according to filters.
using System;
using System.Collections.Generic;
using StarkBank;
IEnumerable<StarkBank.CorporateHolder> holders = StarkBank.CorporateHolder.Query(
after: new DateTime(2019, 1, 1),
before: new DateTime(2022, 3, 1)
);
foreach(StarkBank.CorporateHolder holder in holders)
{
Console.Write(holder);
}
To cancel a single Corporate Holder by its id, run:
using System;
using StarkBank;
StarkBank.CorporateHolder holder = StarkBank.CorporateHolder.Cancel("5353197895942144");
Console.Write(holder);
To get a single Corporate Holder by its id, run:
using System;
using StarkBank;
StarkBank.CorporateHolder holder = StarkBank.CorporateHolder.Get("5353197895942144");
Console.Write(holder);
You can query holder logs to better understand holder life cycles.
using System;
using System.Collections.Generic;
using StarkBank;
IEnumerable<StarkBank.CorporateHolder.Log> logs = StarkBank.CorporateHolder.Log.Query(limit: 10);
foreach (StarkBank.CorporateHolder.Log log in logs)
{
Console.Write(log);
}
You can also get a specific log by its id.
using System;
using StarkBank;
StarkBank.CorporateHolder.Log log = StarkBank.CorporateHolder.Log.Get("6299741604282368");
Console.Write(log);
You can issue cards with specific spending rules.
using System;
using System.Collections.Generic;
using StarkBank;
StarkBank.CorporateCard card = StarkBank.CorporateCard.Create(
new StarkBank.CorporateCard(
holderID: "5155165527080960"
)
);
Console.Write(card);
You can get a list of created cards given some filters.
using System;
using System.Collections.Generic;
using StarkBank;
IEnumerable<StarkBank.CorporateCard> cards = StarkBank.CorporateCard.Query(
after: new DateTime(2019, 1, 1),
before: new DateTime(2023, 3, 1)
);
foreach(StarkBank.CorporateCard card in cards)
{
Console.Write(card);
}
After its creation, information on a card may be retrieved by its id.
using System;
using StarkBank;
StarkBank.CorporateCard card = StarkBank.CorporateCard.Get("5353197895942144");
Console.Write(card);
You can update a specific card by its id.
using System;
using System.Collections.Generic;
using StarkBank;
Dictionary<string, object> patchData = new Dictionary<string, object> {
{ "status", "blocked" }
};
StarkBank.CorporateCard card = StarkBank.CorporateCard.Update("5353197895942144", patchData);
Console.Write(card);
You can also cancel a card by its id.
using System;
using StarkBank;
StarkBank.CorporateCard card = StarkBank.CorporateCard.Cancel("5353197895942144");
Console.Write(card);
Logs are pretty important to understand the life cycle of a card.
using System;
using System.Collections.Generic;
using StarkBank;
IEnumerable<StarkBank.CorporateCard.Log> logs = StarkBank.CorporateCard.Log.Query(limit: 10);
foreach (StarkBank.CorporateCard.Log log in logs)
{
Console.Write(log);
}
You can get a single log by its id.
using System;
using StarkBank;
StarkBank.CorporateCard.Log log = StarkBank.CorporateCard.Log.Get("6299741604282368");
Console.Write(log);
You can get a list of created purchases given some filters.
using System;
using System.Collections.Generic;
using StarkBank;
IEnumerable<StarkBank.CorporatePurchase> purchases = StarkBank.CorporatePurchase.Query(
after: new DateTime(2019, 1, 1),
before: new DateTime(2022, 3, 1)
);
foreach (StarkBank.CorporatePurchase purchase in purchases)
{
Console.Write(purchase);
}
After its creation, information on a purchase may be retrieved by its id.
using System;
using StarkBank;
StarkBank.CorporatePurchase purchase = StarkBank.CorporatePurchase.Get("5642359077339136");
Console.Write(purchase);
Logs are pretty important to understand the life cycle of a purchase.
using System;
using System.Collections.Generic;
using StarkBank;
IEnumerable<StarkBank.CorporatePurchase.Log> logs = StarkBank.CorporatePurchase.Log.Query(limit: 10);
foreach (StarkBank.CorporatePurchase.Log log in logs)
{
Console.Write(log);
}
You can get a single log by its id.
using System;
using StarkBank;
StarkBank.CorporatePurchase.Log log = StarkBank.CorporatePurchase.Log.Get("6428086769811456");
Console.Write(log);
You can create Pix invoices to transfer money from accounts you have in any bank to your Corporate balance, allowing you to run your corporate operation.
using System;
using StarkBank;
StarkBank.CorporateInvoice invoice = StarkBank.CorporateInvoice.Create(
new StarkBank.CorporateInvoice(
amount: 10000
)
);
Console.Write(invoice);
Note: Instead of using CorporateInvoice objects, you can also pass each element in dictionary format
You can get a list of created invoices given some filters.
using System;
using System.Collections.Generic;
using StarkBank;
IEnumerable<StarkBank.CorporateInvoice> invoices = StarkBank.CorporateInvoice.Query(
after: new DateTime(2019, 1, 1),
before: new DateTime(2022, 3, 1)
);
foreach (StarkBank.CorporateInvoice invoice in invoices)
{
Console.Write(invoice);
}
You can create withdrawals to send cash back from your Corporate balance to your Banking balance by using the Withdrawal resource.
using System;
using StarkBank;
StarkBank.CorporateWithdrawal withdrawal = StarkBank.CorporateWithdrawal.Create(
new StarkBank.CorporateWithdrawal(
amount: 10000,
externalID: "3257"
)
);
Console.Write(withdrawal);
Note: Instead of using CorporateWithdrawal objects, you can also pass each element in dictionary format
After its creation, information on a withdrawal may be retrieved by its id.
using System;
using StarkBank;
StarkBank.CorporateWithdrawal withdrawal = StarkBank.CorporateWithdrawal.Get("5440727945314304");
Console.Write(withdrawal);
You can get a list of created withdrawals given some filters.
using System;
using System.Collections.Generic;
using StarkBank;
IEnumerable<StarkBank.CorporateWithdrawal> withdrawals = StarkBank.CorporateWithdrawal.Query(
after: new DateTime(2019, 1, 1),
before: new DateTime(2022, 3, 1)
);
foreach (StarkBank.CorporateWithdrawal withdrawal in withdrawals)
{
Console.Write(withdrawal);
}
To know how much money you have available to run authorizations, run:
using System;
using StarkBank;
StarkBank.CorporateBalance balance = StarkBank.CorporateBalance.Get();
Console.Write(balance);
To understand your balance changes (corporate statement), you can query transactions. Note that our system creates transactions for you when you make purchases, withdrawals, receive corporate invoice payments, for example.
using System;
using System.Collections.Generic;
using StarkBank;
IEnumerable<StarkBank.CorporateTransaction> transactions = StarkBank.CorporateTransaction.Query(
after: new DateTime(2019, 1, 1),
before: new DateTime(2022, 3, 1)
);
foreach (StarkBank.CorporateTransaction transaction in transactions)
{
Console.Write(transaction);
}
You can get a specific transaction by its id:
using System;
using StarkBank;
StarkBank.CorporateTransaction transaction = StarkBank.CorporateTransaction.Get("6539944898068480");
Console.Write(transaction);
You can query any merchant categories using this resource. You may also use MerchantCategories to define specific category filters in CorporateRules. Either codes (which represents specific MCCs) or types (code groups) will be accepted as filters.
using System;
using System.Collections.Generic;
using StarkBank;
IEnumerable<StarkBank.MerchantCategory> categories = StarkBank.MerchantCategory.Query(
search: "food"
);
foreach (StarkBank.MerchantCategory category in categories)
{
Console.Write(category);
}
You can query any merchant countries using this resource. You may also use MerchantCountries to define specific country filters in CorporateRules.
using System;
using System.Collections.Generic;
using StarkBank;
IEnumerable<StarkBank.MerchantCountry> countries = StarkBank.MerchantCountry.Query(
search: "brazil"
);
foreach (StarkBank.MerchantCountry country in countries)
{
Console.Write(country);
}
You can query available card methods using this resource. You may also use CardMethods to define specific purchase method filters in CorporateRules.
using System;
using System.Collections.Generic;
using StarkBank;
IEnumerable<StarkBank.CardMethod> methods = StarkBank.CardMethod.Query(
search: "token"
);
foreach (StarkBank.CardMethod method in methods)
{
Console.Write(method);
}
To create a webhook subscription and be notified whenever an event occurs, run:
using System;
StarkBank.Webhook webhook = StarkBank.Webhook.Create(
url: "https://webhook.site/dd784f26-1d6a-4ca6-81cb-fda0267761ec",
subscriptions: new List<string> { "transfer", "invoice", "deposit", "brcode-payment", "boleto", "boleto-payment", "utility-payment", "tax-payment" }
);
Console.WriteLine(webhook);
To search for registered webhooks, run:
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.Webhook> webhooks = StarkBank.Webhook.Query();
foreach(StarkBank.Webhook webhook in webhooks) {
Console.WriteLine(webhook);
}
You can get a specific webhook by its id.
using System;
StarkBank.Webhook webhook = StarkBank.Webhook.Get("10827361982368179");
Console.WriteLine(webhook);
You can also delete a specific webhook by its id.
using System;
StarkBank.Webhook webhook = StarkBank.Webhook.Delete("10827361982368179");
Console.WriteLine(webhook);
It"s easy to process events that arrived in your webhook. Remember to pass the signature header so the SDK can make sure it's really StarkBank that sent you the event.
using System;
Response response = listen(); // this is the method you made to get the events posted to your webhook endpoint
StarkBank.Event parsedEvent = StarkBank.Event.Parse(
content: response.Content,
signature: response.Headers["Digital-Signature"]
);
if (parsedEvent.Subscription == "transfer") {
StarkBank.Transfer.Log log = parsedEvent.Log as StarkBank.Transfer.Log;
Console.WriteLine(log.Transfer);
}
else if (parsedEvent.Subscription == "invoice") {
StarkBank.Invoice.Log log = parsedEvent.Log as StarkBank.Invoice.Log;
Console.WriteLine(log.Invoice);
}
else if (parsedEvent.Subscription == "deposit") {
StarkBank.Deposit.Log log = parsedEvent.Log as StarkBank.Deposit.Log;
Console.WriteLine(log.Deposit);
}
else if (parsedEvent.Subscription == "brcode-payment") {
StarkBank.BrcodePayment.Log log = parsedEvent.Log as StarkBank.BrcodePayment.Log;
Console.WriteLine(log.Payment);
}
else if (parsedEvent.Subscription == "boleto-payment") {
StarkBank.BoletoPayment.Log log = parsedEvent.Log as StarkBank.BoletoPayment.Log;
Console.WriteLine(log.Payment);
}
else if (parsedEvent.Subscription == "utility-payment") {
StarkBank.UtilityPayment.Log log = parsedEvent.Log as StarkBank.UtilityPayment.Log;
Console.WriteLine(log.Payment);
}
To search for webhook events, run:
using System;
using System.Collections.Generic;
IEnumerable<StarkBank.Event> events = StarkBank.Event.Query(
after: DateTime.Today,
isDelivered: false
);
foreach(StarkBank.Event eventObject in events) {
Console.WriteLine(eventObject);
}
You can get a specific webhook event by its id.
using System;
StarkBank.Event eventObject = StarkBank.Event.Get("10827361982368179");
Console.WriteLine(eventObject);
You can also delete a specific webhook event by its id.
using System;
StarkBank.Event eventObject = StarkBank.Event.Delete("10827361982368179");
Console.WriteLine(eventObject);
This can be used in case you"ve lost events.
With this function, you can manually set events retrieved from the API as
"delivered" to help future event queries with isDelivered: false
.
using System;
StarkBank.Event eventObject = StarkBank.Event.Update("129837198237192", isDelivered: true);
Console.WriteLine(eventObject);
You can also get information on failed webhook event delivery attempts.
using System;
List<StarkBank.Event.Attempt> attempts = StarkBank.Event.Attempt.Query(after: "2020-03-20").ToList();
foreach(StarkBank.Event.Attempt attempt in attempts) {
Console.WriteLine(attempt);
}
To retrieve information on a single attempt, use the following function:
using System;
StarkBank.Event.Attempt attempt = Starkbank.Event.Attempt.Get("1616161616161616");
Console.WriteLine(attempt);
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 a null workspaceID.
using System;
StarkBank.Workspace workspace = StarkBank.Workspace.Create(
username: "iron-bank-workspace-1",
name: "Iron Bank Workspace 1",
user: organization
);
Console.WriteLine(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.
using System;
List<StarkBank.Workspace> workspaces = StarkBank.Workspace.Query(
limit: 30
).ToList();
foreach (StarkBank.Workspace workspace in workspaces)
{
Console.WriteLine(workspace);
}
You can get a specific Workspace by its id.
using System;
StarkBank.Workspace workspace = StarkBank.Workspace.Get("10827361982368179");
Console.WriteLine(workspace);
You can update a specific Workspace by its id.
using System;
using System.IO;
byte[] image = File.ReadAllBytes("../../../logo.png");
Workspace updatedWorkspace = Workspace.Update(
id: workspace.ID,
name: "Updated workspace test",
username: "new-username-test",
allowedTaxIds: new List<string>(new string[] { "359.536.680-82", "20.018.183/0001-80" }),
picture: image,
pictureType: "image/png",
user: Organization.Replace(organization, workspace.ID)
);
Console.WriteLine(updatedWorkspace);
You can also block a specific Workspace by its id.
using System;
Workspace updatedWorkspace = Workspace.Update(
id: workspace.ID,
status: "blocked",
user: Organization.Replace(organization, workspace.ID)
);
Console.WriteLine(updatedWorkspace);
This resource allows you to send HTTP requests to StarkBank routes.
You can perform a GET request to any StarkBank route.
It's possible to get a single resource using its id in the path.
using StarkBank;
string exampleId = "5155165527080960"
JObejct request = Request.Get(
path="/invoice/" + exampleId
).Json();
Console.WriteLine(request.ToString());
You can also get the specific resource log,
using StarkBank;
string exampleId = "5155165527080960";
JObejct request = Request.Get(
path="/invoice/log/" + exampleId
).Json();
Console.WriteLine(request.ToString());
This same method will be used to list all created items for the requested resource.
using StarkBank;
string after = "2024-01-01";
string before = "2024-02-01";
string cursor = "";
JObject request = Request.Get(
path="/invoice/",
query={
"after": after,
"before": before,
"cursor": cursor
}
).Json();
Console.WriteLine(request.ToString());
To list logs, you will use the same logic as for getting a single log.
using StarkBank;
string after = "2024-01-01";
string before = "2024-02-01";
string cursor = "";
JObject request = Request.Get(
path="/invoice/log",
query={
"after": after,
"before": before,
"cursor": cursor
}
).Json();
Console.WriteLine(request.ToString());
You can get a resource file using this method.
using StarkBank;
string exampleId = "5155165527080960";
[]byte pdf = Request.Get(
path="/invoice/" + exampleId + "/pdf",
).ByteContent;
System.IO.File.WriteAllBytes("request.pdf", pdf);
You can perform a POST request to any StarkBank route.
This will create an object for each item sent in your request
Note: It's not possible to create multiple resources simultaneously. You need to send separate requests if you want to create multiple resources, such as invoices and boletos.
using StarkBank;
Dictionary<string, object> data = new Dictionary<string, object>() {
{
"invoices", new List<Dictionary<string, object>>() { new Dictionary<string, object>()
{
{ "amount", 100 },
{ "name", "Iron Bank S.A." },
{ "taxId", "20.018.183/0001-80" }
},
}
}
};
JObject request = Request.Post(
path="/invoice",
body=data,
).Json();
Console.WriteLine(request.ToString())
You can perform a PATCH request to any StarkBank route.
It's possible to update a single item of a StarkBank resource.
using StarkBank;
string exampleId = "5155165527080960"
Dictionary<string, object> data = new Dictionary<string, object>() { { "amount", 0 } };
JObject request = Request.Patch(
path="/invoice/" + exampleId,
body=data,
).Json();
Console.WriteLine(request.ToString());
You can perform a PUT request to any StarkBank route.
It's possible to put a single item of a StarkBank resource.
using StarkBank;
Dictionary<string, object> data = new Dictionary<string, object>() {
{
"profiles", new List<Dictionary<string, object>>() {
new Dictionary<string, object>()
{
{ "interval", "day" },
{ "delay", 0 }
}
}
}
};
JObject request = Request.Put(
path="/split-profile",
body=data,
).Json();
Console.WriteLine(request.ToJson());
You can perform a DELETE request to any StarkBank route.
It's possible to delete a single item of a StarkBank resource.
using StarkBank;
string exampleId = "5155165527080960"
JObject request = Request.Delete(
path="/transfer/" + exampleId,
).Json();
Console.WriteLine(request.ToString());
The SDK may raise one of four types of errors: InputErrors, InternalServerError, UnknownError, InvalidSignatureError
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:
using System;
using System.Collections.Generic;
using StarkBank.Error;
try {
List<StarkBank.Transaction> transactions = StarkBank.Transaction.Create(
new List<StarkBank.Transaction> {
new StarkBank.Transaction(
amount: 99999999999999, // (R$ 999,999,999,999.99)
receiverID: "1029378109327810",
description: ".",
externalID: "12345", // so we can block anything you send twice by mistake
tags: new List<string> { "provider" }
)
}
);
} catch (InputErrors e) {
foreach (ErrorElement error in e.Errors) {
Console.WriteLine(error.Code);
Console.WriteLine(error.Message);
}
}
InternalServerError will be raised if the API runs into an internal error. If you ever stumble upon this one, rest assured that the development team is already rushing in to fix the mistake and get you back up to speed.
UnknownError will be raised if a request encounters an error that is neither InputErrors nor an InternalServerError, such as connectivity problems.
InvalidSignatureError 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: [email protected]