Stark Infra Ruby SDK Beta
Welcome to the Stark Infra Ruby SDK! This tool is made for Ruby developers who want to easily integrate with our API. This SDK version is compatible with the Stark Infra API v2.
Introduction
Index
- Introduction
- Supported Ruby versions
- API documentation
- Versioning
- Setup
- Install our SDK
- Create your Private and Public Keys
- Register your user credentials
- Setting up the user
- Setting up the error language
- Resource listing and manual pagination
- Testing in Sandbox
- Usage
- Issuing
- Products: View available sub-issuer card products (a.k.a. card number ranges or BINs)
- Holders: Manage card holders
- Cards: Create virtual and/or physical cards
- Design: View your current card or package designs
- EmbossingKit: View your current embossing kits
- Stock: View your current stock of a certain IssuingDesign linked to an Embosser on the workspace
- Restock: Create restock orders of a specific IssuingStock object
- EmbossingRequest: Create embossing requests
- Purchases: Authorize and view your past purchases
- Invoices: Add money to your issuing balance
- Withdrawals: Send money back to your Workspace from your issuing balance
- Balance: View your issuing balance
- Transactions: View the transactions that have affected your issuing balance
- Enums: Query enums related to the issuing purchases, such as merchant categories, countries and card purchase methods
- Pix
- PixRequests: Create Pix transactions
- PixReversals: Reverse Pix transactions
- PixBalance: View your account balance
- PixStatement: Request your account statement
- PixKey: Create a Pix Key
- PixClaim: Claim a Pix Key
- PixDirector: Create a Pix Director
- PixInfraction: Create Pix Infraction reports
- PixChargeback: Create Pix Chargeback requests
- PixDomain: View registered SPI participants certificates
- StaticBrcode: Create static Pix BR codes
- DynamicBrcode: Create dynamic Pix BR codes
- BrcodePreview: Read data from BR Codes before paying them
- Lending
- CreditNote: Create credit notes
- CreditPreview: Create credit previews
- CreditHolmes: Create credit holmes debt verification
- Identity
- IndividualIdentity: Create individual identities
- IndividualDocument: Create individual documents
- Webhook:
- Webhook: Configure your webhook endpoints and subscriptions
- WebhookEvents: Manage Webhook events
- WebhookEventAttempts: Query failed webhook event deliveries
- Request: Send a custom request to Stark Infra. This can be used to access features that haven't been mapped yet.
- Issuing
- Handling errors
- Help and Feedback
Supported Ruby Versions
This library supports the following Ruby versions:
- Ruby 2.3+
Stark Infra API documentation
Feel free to take a look at our API docs.
Versioning
This project adheres to the following versioning pattern:
Given a version number MAJOR.MINOR.PATCH, increment:
- MAJOR version when the API version is incremented. This may include backwards incompatible changes;
- MINOR version when breaking changes are introduced OR new functionalities are added in a backwards compatible manner;
- PATCH version when backwards compatible bug fixes are implemented.
Setup
1. Install our SDK
1.1 To install the package with gem, run:
gem install starkinfra1.2 Or just add this to your Gemfile:
gem('starkinfra', '~> 0.5.1')2. Create your Private and Public Keys
We use ECDSA. That means you need to generate a secp256k1 private key to sign your requests to our API, and register your public key with us, so we can validate those requests.
You can use one of the following methods:
2.1. Check out the options in our tutorial.
2.2. Use our SDK:
require('starkinfra')
privateKey, publicKey = StarkInfra::Key.create
# or, to also save .pem files in a specific path
# private_key, public_key = StarkInfra::Key.create('file/keys/')NOTE: When you are creating 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.
3. Register your user credentials
You can interact directly with our API using two types of users: Projects and Organizations.
- Projects are workspace-specific users, that is, they are bound to the workspaces they are created in. One workspace can have multiple Projects.
- Organizations are general users that control your entire organization. They can control all your Workspaces and even create new ones. The Organization is bound to your company's tax ID only. Since this user is unique in your entire organization, only one credential can be linked to it.
3.1. To create a Project in Sandbox:
3.1.1. Log into StarkInfra Sandbox
3.1.2. Go to Menu > Integrations
3.1.3. Click on the "New Project" button
3.1.4. Create a Project: Give it a name and upload the public key you created in section 2
3.1.5. After creating the Project, get its Project ID
3.1.6. Use the Project ID and private key to create the object below:
require('starkinfra')
# Get your private key from an environment variable or an encrypted database.
# This is only an example of a private key content. You should use your own key.
private_key_content = '
-----BEGIN EC PARAMETERS-----
BgUrgQQACg==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIMCwW74H6egQkTiz87WDvLNm7fK/cA+ctA2vg/bbHx3woAcGBSuBBAAK
oUQDQgAE0iaeEHEgr3oTbCfh8U2L+r7zoaeOX964xaAnND5jATGpD/tHec6Oe9U1
IF16ZoTVt1FzZ8WkYQ3XomRD4HS13A==
-----END EC PRIVATE KEY-----
'
project = StarkInfra::Project.new(
environment: 'sandbox',
id: '5656565656565656',
private_key: private_key_content
)3.2. To create Organization credentials in Sandbox:
3.2.1. Log into Starkinfra Sandbox
3.2.2. Go to Menu > Integrations
3.2.3. Click on the "Organization public key" button
3.2.4. Upload the public key you created in section 2 (only a legal representative of the organization can upload the public key)
3.2.5. Click on your profile picture and then on the "Organization" menu to get the Organization ID
3.2.6. Use the Organization ID and private key to create the object below:
require('starkinfra')
# Get your private key from an environment variable or an encrypted database.
# This is only an example of a private key content. You should use your own key.
private_key_content = '
-----BEGIN EC PARAMETERS-----
BgUrgQQACg==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIMCwW74H6egQkTiz87WDvLNm7fK/cA+ctA2vg/bbHx3woAcGBSuBBAAK
oUQDQgAE0iaeEHEgr3oTbCfh8U2L+r7zoaeOX964xaAnND5jATGpD/tHec6Oe9U1
IF16ZoTVt1FzZ8WkYQ3XomRD4HS13A==
-----END EC PRIVATE KEY-----
'
organization = StarkInfra::Organization.new(
environment: 'sandbox',
id: '5656565656565656',
private_key: private_key_content,
workspace_id: nil, # You only need to set the workspace_id when you are operating a specific workspace_id
)NOTE 1: Never hard-code your private key. Get it from an environment variable or an encrypted database.
NOTE 2: We support 'sandbox' and 'production' as environments.
NOTE 3: The credentials you registered in sandbox do not exist in production and vice versa.
4. Setting up the user
There are three kinds of users that can access our API: Organization, Project, and Member.
-
ProjectandOrganizationare designed for integrations and are the ones meant for our SDKs. -
Memberis 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 an argument in all functions:
require('starkinfra')
balance = StarkInfra::PixBalance.get(user: project) # or organization4.2 Set it as a default user in the SDK:
require('starkinfra')
StarkInfra::user = project # or organization
balance = StarkInfra::PixBalance.getJust select the way of passing the user that is more convenient to you. On all following examples, we will assume a default user has been set.
5. Setting up the error language
The error language can also be set in the same way as the default user:
require('starkinfra')
StarkInfra::language = 'en-US'Language options are 'en-US' for English and 'pt-BR' for Brazilian Portuguese. English is the default.
Resource listing and manual pagination
Almost all SDK resources provide a query and a page function.
- The
queryfunction provides a straightforward 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.
require('starkinfra')
requests = StarkInfra::PixRequest.query(limit=200)
requests.each do |request|
puts request
end- The
pagefunction 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 benil.
require('starkinfra')
cursor = nil
while true
requests, cursor = StarkInfra::PixRequest.page(limit: 50, cursor: cursor)
requests.each do |request|
puts request
end
if cursor.nil?
break
end
endTo simplify the following SDK examples, we will only use the query function, but feel free to use page instead.
Testing in Sandbox
Your initial balance is zero. For many operations in Stark Infra, you'll need funds in your account, which can be added to your balance by creating a StarkBank::Invoice.
In the Sandbox environment, most of the created Invoices will be automatically paid, so there's nothing else you need to do to add funds to your account. Just create a few StarkBank::Invoices and wait around a bit.
In Production, you (or one of your clients) will need to actually pay this StarkBank::Invoice for the value to be credited to your account.
Usage
Here are a few examples on how to use the SDK. If you have any doubts, check out the function or class docstring to get more info or go straight to our API docs.
Issuing
Query IssuingProducts
To take a look at the sub-issuer card products available to you, just run the following:
require('starkinfra')
products = StarkInfra::IssuingProduct.query()
products.each do |product|
puts product
endThis will tell which card products and card number prefixes you have at your disposal.
Create IssuingHolders
You can create card holders to which your cards will be bound. They support spending rules that will apply to all underlying cards.
require('starkinfra')
holders = StarkInfra::IssuingHolder.create([
StarkInfra::IssuingHolder.new(
name: "Iron Bank S.A.",
external_id: '1234',
tax_id: '0000',
tags: ['012.345.678-90'],
rules: [StarkInfra::IssuingRule.new(
name: "General USD",
interval: "day",
amount: 100000,
currency_code: "USD"
)]
)
])
holders.each do |holder|
puts holder
endNote: Instead of using IssuingHolder objects, you can also pass each element in hash format
Query IssuingHolders
You can query multiple holders according to filters.
require('starkinfra')
holders = StarkInfra::IssuingHolder.query()
holders.each do |holder|
puts holder
endCancel an IssuingHolder
To cancel a single Issuing Holder by its id, run:
require('starkinfra')
holder = StarkInfra::IssuingHolder.cancel('5155165527080960')
puts holderGet an IssuingHolder
To get a single Issuing Holder by its id, run:
require('starkinfra')
holder = StarkInfra::IssuingHolder.get('5155165527080960')
puts holderQuery IssuingHolder logs
You can query holder logs to better understand holder life cycles.
require('starkinfra')
logs = StarkInfra::IssuingHolder::Log.query(
limit: 50,
after: '2022-01-01',
before: '2022-01-20',
)
logs.each do |log|
puts log
endGet an IssuingHolder log
You can also get a specific log by its id.
require('starkinfra')
log = StarkInfra::IssuingHolder::Log.get('5155165527080960')
puts logCreate IssuingCards
You can issue cards with specific spending rules.
require('starkinfra')
cards = StarkInfra::IssuingCard.create([
StarkInfra::IssuingCard.new(
holder_name: "Developers",
holder_tax_id: "012.345.678-90",
holder_external_id: "1234",
rules: [
StarkInfra::IssuingRule.new(
name: "General USD",
interval: "day",
amount: 100000,
currency_code: "USD"
)
]
)
])
cards.each do |card|
puts card
endQuery IssuingCards
You can get a list of created cards given some filters.
require('starkinfra')
cards = StarkInfra::IssuingCard.query(
limit: 10,
after: '2022-01-01',
before: '2022-01-20',
)
cards.each do |card|
puts card
endGet an IssuingCard
After its creation, information on a card may be retrieved by its id.
require('starkinfra')
card = StarkInfra::IssuingCard.get('5155165527080960')
puts cardUpdate an IssuingCard
You can update a specific card by its id.
require('starkinfra')
card = StarkInfra::IssuingCard.update(
'5155165527080960',
status: 'blocked'
)
puts cardCancel an IssuingCard
You can also cancel a card by its id.
require('starkinfra')
card = StarkInfra::IssuingCard.cancel('5155165527080960')
puts cardQuery IssuingCard logs
Logs are pretty important to understand the life cycle of a card.
require('starkinfra')
logs = StarkInfra::IssuingCard::Log.query(
limit: 50,
after: '2022-01-01',
before: '2022-01-20',
)
logs.each do |log|
puts log
endGet an IssuingCard log
You can get a single log by its id.
require('starkinfra')
log = StarkInfra::IssuingCard::Log.get('5155165527080960')
puts logQuery IssuingDesigns
You can get a list of available designs given some filters.
require('starkinfra')
designs = StarkInfra::IssuingDesign.query(
limit: 1
)
designs.each do |design|
puts design
endGet an IssuingDesign
Information on a design may be retrieved by its id.
require('starkinfra')
design = StarkInfra::IssuingDesign.get("5747368922185728")
puts designQuery IssuingEmbossingKits
You can get a list of created embossing kits given some filters.
require('starkinfra')
kits = StarkInfra::IssuingEmbossingKit.query(
limit: 10,
after: '2022-01-01',
before: '2022-01-20',
)
kits.each do |kit|
puts kit
endGet an IssuingEmbossingKit
After its creation, information on an embossing kit may be retrieved by its id.
require('starkinfra')
kit = StarkInfra::IssuingEmbossingKit.get("5792731695677440")
puts kitQuery IssuingStocks
You can get a list of available stocks given some filters.
require('starkinfra')
stocks = StarkInfra::IssuingStock.query(
limit: 10,
after: '2022-01-01',
before: '2022-01-20',
)
stocks.each do |stock|
puts stock
endGet an IssuingStock
Information on a stock may be retrieved by its id.
require('starkinfra')
stock = StarkInfra::IssuingStock.get("5792731695677440")
puts stockQuery IssuingStock logs
Logs are pretty important to understand the life cycle of a stock.
require('starkinfra')
logs = StarkInfra::IssuingStock::Log.query(limit: 50)
logs.each do |log|
puts log
endGet an IssuingStock log
You can get a single log by its id.
require('starkinfra')
log = StarkInfra::IssuingStock::Log.get("5809977331548160")
puts logCreate IssuingRestocks
You can order restocks for a specific IssuingStock.
require('starkinfra')
restocks = StarkInfra::IssuingRestock.create([
StarkInfra::IssuingRestock.new(
count: 100,
stock_id: "5136459887542272"
)
])
restocks.each do |restock|
puts restock
endQuery IssuingRestocks
You can get a list of created restocks given some filters.
require('starkinfra')
restocks = StarkInfra::IssuingRestock.query(
after: '2022-01-01',
before: '2022-01-20',
)
restocks.each do |restock|
puts restock
endGet an IssuingRestock
After its creation, information on a restock may be retrieved by its id.
require('starkinfra')
restock = StarkInfra::IssuingRestock.get("5664445921492992")
puts restockQuery IssuingRestock logs
Logs are pretty important to understand the life cycle of a restock.
require('starkinfra')
logs = StarkInfra::IssuingRestock::Log.query(limit: 50)
logs.each do |log|
puts log
endGet an IssuingRestock log
You can get a single log by its id.
require('starkinfra')
log = StarkInfra::IssuingRestock::Log.get('6310318875607040')
puts logCreate IssuingEmbossingRequests
You can create a request to emboss a physical card.
require('starkinfra')
requests = StarkInfra::IssuingEmbossingRequest.create([
StarkInfra::IssuingEmbossingRequest.new(
kit_id: "5648359658356736",
card_id: "5714424132272128",
display_name_1: "Antonio Stark",
shipping_city: "Sao Paulo",
shipping_country_code: "BRA",
shipping_district: "Bela Vista",
shipping_service: "loggi",
shipping_state_code: "SP",
shipping_street_line_1: "Av. Paulista, 200",
shipping_street_line_2: "10 andar",
shipping_tracking_number: "My_custom_tracking_number",
shipping_zip_code: "12345-678",
embosser_id: "5746980898734080"
)
])
requests.each do |request|
puts request
endQuery IssuingEmbossingRequests
You can get a list of created embossing requests given some filters.
require('starkinfra')
requests = StarkInfra::IssuingEmbossingRequest.query(
after: '2022-01-01',
before: '2022-01-20',
)
requests.each do |request|
puts request
endGet an IssuingEmbossingRequest
After its creation, information on an embossing request may be retrieved by its id.
require('starkinfra')
request = StarkInfra::IssuingEmbossingRequest.get('5191752558313472')
puts requestQuery IssuingEmbossingRequest logs
Logs are pretty important to understand the life cycle of an embossing request.
require('starkinfra')
logs = StarkInfra::IssuingEmbossingRequest::Log.query(limit: 150)
logs.each do |log|
puts log
endGet an IssuingEmbossingRequest log
You can get a single log by its id.
require('starkinfra')
log = StarkInfra::IssuingEmbossingRequest::Log.get("6724771005857792")
puts logProcess Purchase authorizations
It's easy to process purchase authorizations delivered to your endpoint. Remember to pass the signature header so the SDK can make sure it's StarkInfra that sent you the event. If you do not approve or decline the authorization within 2 seconds, the authorization will be denied.
require('starkinfra')
authorization = listen_authorizations() # this is your handler to listen for purchase authorization
authorization = StarkInfra::IssuingPurchase.parse(
content: authorization.body.read,
signature: authorization.headers['Digital-Signature']
)
send_response( # you should also implement this method
StarkInfra::IssuingPurchase.response( # this optional method just helps you build the response JSON
status: 'accepted',
amount: authorization.amount,
tags: ['my-purchase-id/123']
)
)
# or
send_response(
StarkInfra::IssuingPurchase.response(
status: 'denied',
reason: 'other',
tags: ['my-other-id/456']
)
)Query IssuingPurchases
You can get a list of created purchases given some filters.
require('starkinfra')
purchases = StarkInfra::IssuingPurchase.query(
limit: 10,
after: '2022-01-01',
before: '2022-01-20',
)
purchases.each do |purchase|
puts purchase
endGet an IssuingPurchase
After its creation, information on a purchase may be retrieved by its id.
require('starkinfra')
purchase = StarkInfra::IssuingPurchase.get('5155165527080960')
puts purchaseQuery IssuingPurchase logs
Logs are pretty important to understand the life cycle of a purchase.
require('starkinfra')
logs = StarkInfra::IssuingPurchase::Log.query(
limit: 50,
after: '2022-01-01',
before: '2022-01-20',
)
logs.each do |log|
puts log
endGet an IssuingPurchase log
You can get a single log by its id.
require('starkinfra')
log = StarkInfra::IssuingPurchase::Log.get('5155165527080960')
puts logCreate IssuingInvoices
You can create Pix invoices to transfer money from accounts you have in any bank to your Issuing balance, allowing you to run your issuing operation.
require('starkinfra')
invoice = StarkInfra::IssuingInvoice.create(
StarkInfra::IssuingInvoice.new(
amount: 1000
)
)
puts invoiceNote: Instead of using IssuingInvoice objects, you can also pass each invoice element in hash format
Get an IssuingInvoice
After its creation, information on an invoice may be retrieved by its id. Its status indicates whether it's been paid.
require('starkinfra')
invoice = StarkInfra::IssuingInvoice.get('5155165527080960')
puts invoiceQuery IssuingInvoices
You can get a list of created invoices given some filters.
require('starkinfra')
invoices = StarkInfra::IssuingInvoice.query(
limit: 10,
after: '2022-01-01',
before: '2022-01-20',
)
invoices.each do |invoice|
puts invoice
endQuery IssuingInvoice logs
Logs are pretty important to understand the life cycle of an invoice.
require('starkinfra')
logs = StarkInfra::IssuingInvoice::Log.query(
limit: 50,
after: '2022-01-01',
before: '2022-01-20',
)
logs.each do |log|
puts log
endGet an IssuingInvoice log
You can get a single log by its id.
require('starkinfra')
log = StarkInfra::IssuingInvoice::Log.get('5155165527080960')
puts logCreate IssuingWithdrawals
You can create withdrawals to send cash back from your Issuing balance to your Banking balance by using the Withdrawal resource.
require('starkinfra')
withdrawal = StarkInfra::IssuingWithdrawal.create(
StarkInfra::IssuingWithdrawal.new(
amount: 10_000,
external_id: '123',
description: 'Sending back'
)
)
puts withdrawalNote: Instead of using IssuingWithdrawal objects, you can also pass each element in dictionary format
Get an IssuingWithdrawal
After its creation, information on a withdrawal may be retrieved by its id.
require('starkinfra')
withdrawal = StarkInfra::IssuingWithdrawal.get('5155165527080960')
puts withdrawalQuery IssuingWithdrawals
You can get a list of created withdrawals given some filters.
require('starkinfra')
withdrawals = StarkInfra::IssuingWithdrawal.query(
limit: 10,
after: '2022-01-01',
before: '2022-01-20',
)
withdrawals.each do |withdrawal|
puts withdrawal
endGet your IssuingBalance
To know how much money you have available to run authorizations, run:
require('starkinfra')
balance = StarkInfra::IssuingBalance.get()
puts balanceQuery IssuingTransactions
To understand your balance changes (issuing statement), you can query transactions. Note that our system creates transactions for you when you make purchases, withdrawals, receive issuing invoice payments, for example.
require('starkinfra')
transactions = StarkInfra::IssuingTransaction.query(
limit: 10,
after: '2022-01-01',
before: '2022-01-20',
)
transactions.each do |transaction|
puts transaction
endGet an IssuingTransaction
You can get a specific transaction by its id:
require('starkinfra')
transaction = StarkInfra::IssuingTransaction.get('5155165527080960')
puts transactionIssuing Enums
Query MerchantCategories
You can query any merchant categories using this resource. You may also use MerchantCategories to define specific category filters in IssuingRules. Either codes (which represents specific MCCs) or types (code groups) will be accepted as filters.
require('starkinfra')
categories = StarkInfra::MerchantCategory.query(
search: 'food'
)
categories.each do |category|
puts category
endQuery MerchantCountries
You can query any merchant countries using this resource. You may also use MerchantCountries to define specific country filters in IssuingRules.
require('starkinfra')
countries = StarkInfra::MerchantCountry.query(
search: 'brazil'
)
countries.each do |country|
puts country
endQuery CardMethods
You can query available card methods using this resource. You may also use CardMethods to define specific purchase method filters in IssuingRules.
require('starkinfra')
methods = StarkInfra::CardMethod.query(
search: 'token',
)
methods.each do |method|
puts method
endPix
Create PixRequests
You can create a Pix request to transfer money from one of your users to anyone else:
require('starkinfra')
requests = StarkInfra::PixRequest.create(
[
StarkInfra::PixRequest.new(
amount: 100, # (R$ 1.00)
external_id: '141234121', # so we can block anything you send twice by mistake
sender_branch_code: '0000',
sender_account_number: '00000-0',
sender_account_type: 'checking',
sender_name: 'Tyrion Lannister',
sender_tax_id: '012.345.678-90',
receiver_bank_code: '00000001',
receiver_branch_code: '0001',
receiver_account_number: '00000-1',
receiver_account_type: 'checking',
receiver_name: 'Jamie Lannister',
receiver_tax_id: '45.987.245/0001-92',
end_to_end_id: 'E20018183202201201450u34sDGd19lz',
description: 'For saving my life',
),
StarkInfra::PixRequest.new(
amount: 200, # (R$ 2.00)
external_id: '2135613462', # so we can block anything you send twice by mistake
sender_account_number: '00000-0',
sender_branch_code: '0000',
sender_account_type: 'checking',
sender_name: 'Arya Stark',
sender_tax_id: '012.345.678-90',
receiver_bank_code: '00000001',
receiver_account_number: '00000-1',
receiver_branch_code: '0001',
receiver_account_type: 'checking',
receiver_name: 'John Snow',
receiver_tax_id: '012.345.678-90',
end_to_end_id: 'E20018183202201201450u34sDGd19lz',
tags: ['Needle', 'sword'],
)
]
)
requests.each do |request|
puts request
endNote: Instead of using PixRequest objects, you can also pass each element in hash format
Query PixRequests
You can query multiple Pix requests according to filters.
require('starkinfra')
requests = StarkInfra::PixRequest.query(
after: '2022-01-01',
before: '2022-01-10'
)
requests.each do |request|
puts request
endGet a PixRequest
After its creation, information on a Pix request may be retrieved by its id. Its status indicates whether it has been paid.
require('starkinfra')
request = StarkInfra::PixRequest.get('5155165527080960')
puts requestProcess inbound PixRequest authorizations
It's easy to process authorization requests that arrived at your endpoint. Remember to pass the signature header so the SDK can make sure it's StarkInfra that sent you the event. If you do not approve or decline the authorization within 1 second, the authorization will be denied.
require('starkinfra')
request = listen_requests() # this is your handler to listen for authorization requests
pix_request = StarkInfra::PixRequest.parse(
content: request.body.read,
signature: request.headers['Digital-Signature']
)
puts pix_request
send_response( # you should also implement this method
StarkInfra::PixRequest.response( # this optional method just helps you build the response JSON
status: "approved"
)
)
# or
send_response( # you should also implement this method
StarkInfra::PixRequest.response( # this optional method just helps you build the response JSON
status: "denied",
reason: "orderRejected"
)
)Query PixRequest logs
You can query Pix request logs to better understand Pix request life cycles.
require('starkinfra')
logs = StarkInfra::PixRequest::Log.query(
limit: 50,
after: '2022-01-01',
before: '2022-01-20',
)
logs.each do |log|
puts log
endGet a PixRequest log
You can also get a specific log by its id.
require('starkinfra')
log = StarkInfra::PixRequest::Log.get('5155165527080960')
puts logCreate PixReversals
You can reverse a PixRequest either partially or totally using a PixReversal.
require('starkinfra')
reversal = StarkInfra::PixReversal.create([
StarkInfra::PixReversal.new(
amount: 100,
end_to_end_id: 'E00000000202201060100rzsJzG9PzMg',
external_id: 'my_external_id',
reason: 'bankError',
)
])
puts reversalQuery PixReversals
You can query multiple Pix reversals according to filters.
require('starkinfra')
reversals = StarkInfra::PixReversal.query(
limit: 50,
after: '2022-01-01',
before: '2022-01-20',
)
reversals.each do |reversal|
puts reversal
endGet a PixReversal
After its creation, information on a Pix reversal may be retrieved by its id. Its status indicates whether it has been successfully processed.
require('starkinfra')
reversal = StarkInfra::PixReversal.get('5155165527080960')
puts reversalProcess inbound PixReversal authorizations
It's easy to process authorization requests that arrived at your endpoint. Remember to pass the signature header so the SDK can make sure it's StarkInfra that sent you the event. If you do not approve or decline the authorization within 1 second, the authorization will be denied.
require('starkinfra')
reversal = listen_reversals() # this is your handler to listen for authorization reversals
pix_reversal = StarkInfra::PixReversal.parse(
content: reversal.body.read,
signature: reversal.headers['Digital-Signature']
)
puts pix_reversal
send_response( # you should also implement this method
StarkInfra::PixReversal.response( # this optional method just helps you build the response JSON
status: "approved"
)
)
# or
send_response( # you should also implement this method
StarkInfra::PixReversal.response( # this optional method just helps you build the response JSON
status: "denied",
reason: "orderRejected"
)
)Query PixReversal logs
You can query Pix reversal logs to better understand Pix reversal life cycles.
require('starkinfra')
logs = StarkInfra::PixReversal::Log.query(
limit: 50,
after: '2022-01-01',
before: '2022-01-20',
)
logs.each do |log|
puts log
endGet a PixReversal log
You can also get a specific log by its id.
require('starkinfra')
log = StarkInfra::PixReversal::Log.get('5155165527080960')
puts logGet your PixBalance
To know how much money you have in your workspace, run:
require('starkinfra')
balance = StarkInfra::PixBalance.get()
puts balanceCreate a PixStatement
Statements are generated directly by the Central Bank and are only available for direct participants. To create a statement of all the transactions that happened on your account during a specific day, run:
require('starkinfra')
statement = StarkInfra::PixStatement.create([
StarkInfra::PixStatement.new(
after: '2022-01-01', # This is the date that you want to create a statement.
before: '2022-01-01', # After and before must be the same date.
type: 'transaction' # Options are 'interchange', 'interchangeTotal', 'transaction'.
)
])
puts statementQuery PixStatements
You can query multiple Pix statements according to filters.
require('starkinfra')
statements = StarkInfra::PixStatement.query(
limit: 50,
)
statements.each do |statement|
puts statement
endGet a PixStatement
Statements are only available for direct participants. To get a Pix statement by its id:
require('starkinfra')
statement = StarkInfra::PixStatement.get('5155165527080960')
puts statementGet a PixStatement .csv file
To get the .csv file corresponding to a Pix statement using its id, run:
require('starkinfra')
csv = StarkInfra::PixStatement.csv('5155165527080960')
File.binwrite('statement.zip', csv)Create a PixKey
You can create a Pix Key to link a bank account information to a key id:
require('starkinfra')
key = StarkInfra::PixKey.create(
StarkInfra::PixKey.new(
account_created: '2022-02-01T00:00:00.00',
account_number: '00000',
account_type: 'savings',
branch_code: '0000',
name: 'Jamie Lannister',
tax_id: '012.345.678-90',
id: '+5511989898989',
)
)
puts keyQuery PixKeys
You can query multiple Pix keys you own according to filters.
require('starkinfra')
keys = StarkInfra::PixKey.query(
limit: 1,
after: '2022-01-01',
before: '2022-01-12',
status: 'registered',
tags: ['iron', 'bank'],
ids: ['+5511989898989'],
type: 'phone'
)
keys.each do |key|
puts key
endGet a PixKey
Information on a Pix key may be retrieved by its id and the tax ID of the consulting agent. An endToEndId must be informed so you can link any resulting purchases to this query, avoiding sweep blocks by the Central Bank.
require('starkinfra')
key = StarkInfra::PixKey.get(
'5155165527080960',
payer_id: '012.345.678-90',
end_to_end_id: StarkInfra::EndToEndId.create('20018183'),
)
puts keyUpdate a PixKey
Update the account information linked to a Pix Key.
require('starkinfra')
key = StarkInfra::PixKey.update(
'+5511989898989',
reason: 'branchTransfer',
name: 'Jamie Lannister'
)
puts keyCancel a PixKey
Cancel a specific Pix Key using its id.
require('starkinfra')
key = StarkInfra::PixKey.cancel('5155165527080960')
puts keyQuery PixKey logs
You can query PixKey logs to better understand a Pix key life cycle.
require('starkinfra')
logs = StarkInfra::PixKey::Log.query(
limit: 50,
ids: ['5729405850615808'],
after: '2022-01-01',
before: '2022-01-20',
types: ['created'],
key_ids: ['+5511989898989']
)
logs.each do |log|
puts log
endGet a PixKey log
You can also get a specific log by its id.
require('starkinfra')
log = StarkInfra::PixKey::Log.get('5155165527080960')
puts logCreate a PixClaim
You can create a Pix claim to request the transfer of a Pix key from another bank to one of your accounts:
require('starkinfra')
claim = StarkInfra::PixClaim.create(
StarkInfra::PixClaim.new(
account_created: '2022-02-01T00:00:00.00',
account_number: '5692908409716736',
account_type: 'checking',
branch_code: '0000',
name: 'testKey',
tax_id: '012.345.678-90',
key_id: '+5511989898989'
)
)
puts claimQuery PixClaims
You can query multiple Pix claims according to filters.
require('starkinfra')
claims = StarkInfra::PixClaim.query(
limit: 1,
after: '2022-01-01',
before: '2022-01-12',
status: 'registered',
ids: ['5729405850615808'],
type: 'ownership',
agent: 'claimed',
key_type: 'phone',
key_id: '+5511989898989'
)
claims.each do |claim|
puts claim
endGet a PixClaim
After its creation, information on a Pix claim may be retrieved by its id.
require('starkinfra')
claim = StarkInfra::PixClaim.get('5155165527080960')
puts claimUpdate a PixClaim
A Pix claim can be confirmed or canceled by patching its status. A received Pix claim must be confirmed by the donor to be completed. Ownership Pix claims can only be canceled by the donor if the reason is "fraud". A sent Pix claim can also be canceled.
require('starkinfra')
claim = StarkInfra::PixClaim.update(
'5155165527080960',
status: 'confirmed'
)
puts claimQuery PixClaim logs
You can query Pix claim logs to better understand Pix claim life cycles.
require('starkinfra')
logs = StarkInfra::PixClaim::Log.query(
limit: 50,
ids: ['5729405850615808'],
after: '2022-01-01',
before: '2022-01-20',
types: ['registered'],
claim_ids: ['5719405850615809']
)
logs.each do |log|
puts log
endGet a PixClaim log
You can also get a specific log by its id.
require('starkinfra')
log = StarkInfra::PixClaim::Log.get('5155165527080960')
puts logCreate a PixDirector
To register the Pix director contact information at the Central Bank, run the following:
require('starkinfra')
director = StarkInfra::PixDirector.create(
StarkInfra::PixDirector.new(
name: 'Edward Stark',
tax_id: '03.300.300/0001-00',
phone: '+5511999999999',
email: 'ned.stark@company.com',
password: '12345678',
team_email: 'pix.team@company.com',
team_phones: ['+5511988889999', '+5511988889998']
)
)
puts directorCreate PixInfractions
Pix Infraction reports are used to report transactions that raise fraud suspicion, to request a refund or to reverse a refund. Infraction reports can be created by either participant of a transaction.
require('starkinfra')
infractions = StarkInfra::PixInfraction.create([
StarkInfra::PixInfraction.new(
reference_id: 'E20018183202201201450u34sDGd19lz',
type: 'fraud',
)
])
infractions.each do |infraction|
puts infraction
endQuery PixInfractions
You can query multiple infraction reports according to filters.
require('starkinfra')
infractions = StarkInfra::PixInfraction.query(
limit: 1,
after: '2022-01-01',
before: '2022-01-12',
status: 'delivered',
ids: ['5155165527080960']
)
infractions.each do |infraction|
puts infraction
endGet a PixInfraction
After its creation, information on a Pix infraction may be retrieved by its id.
require('starkinfra')
infraction = StarkInfra::PixInfraction.get('5155165527080960')
puts infractionUpdate a PixInfraction
A received Pix infraction can be confirmed or declined by patching its status. After a Pix infraction is patched, its status changes to closed.
require('starkinfra')
infraction = StarkInfra::PixInfraction.update(
id: '5155165527080960',
result: 'agreed'
)
puts infractionCancel a PixInfraction
Cancel a specific Pix Infraction using its id.
require('starkinfra')
infraction = StarkInfra::PixInfraction.cancel('5155165527080960')
puts infractionQuery PixInfraction logs
You can query infraction report logs to better understand their life cycles.
require('starkinfra')
logs = StarkInfra::PixInfraction::Log.query(
limit: 50,
ids: ['5729405850615808'],
after: '2022-01-01',
before: '2022-01-20',
types: ['created'],
infraction_ids: ['5155165527080960']
)
logs.each do |log|
puts log
endGet a PixInfraction log
You can also get a specific log by its id.
require('starkinfra')
log = StarkInfra::PixInfraction::Log.get('5155165527080960')
puts log Create PixChargebacks
A Pix chargeback can be created when fraud is detected on a transaction or a system malfunction results in an erroneous transaction.
require('starkinfra')
chargebacks = StarkInfra::PixChargeback.create([
StarkInfra::PixChargeback.new(
amount: 100,
reference_id: 'E20018183202201201450u34sDGd19lz',
reason: 'fraud',
)
])
chargebacks.each do |chargeback|
puts chargeback
endQuery PixChargebacks
You can query multiple Pix chargebacks according to filters.
require('starkinfra')
chargebacks = StarkInfra::PixChargeback.query(
limit: 1,
after: '2022-01-01',
before: '2022-01-12',
status: 'registered',
ids: ['5155165527080960']
)
chargebacks.each do |chargeback|
puts chargeback
endGet a PixChargeback
After its creation, information on a Pix Chargeback may be retrieved by its.
require('starkinfra')
chargeback = StarkInfra::PixChargeback.get('5155165527080960')
puts chargebackUpdate a PixChargeback
A received Pix Chargeback can be accepted or rejected by patching its status. After a Pix Chargeback is patched, its status changes to closed.
require('starkinfra')
chargeback = StarkInfra::PixChargeback.update(
'5155165527080960',
result: 'accepted',
reversal_reference_id: StarkInfra::ReturnId.create('20018183'),
)
puts chargebackCancel a PixChargeback
Cancel a specific Pix Chargeback using its id.
require('starkinfra')
chargeback = StarkInfra::PixChargeback.cancel('5155165527080960')
puts chargebackQuery PixChargeback logs
You can query Pix chargeback logs to better understand Pix chargeback life cycles.
require('starkinfra')
logs = StarkInfra::PixChargeback::Log.query(
limit: 50,
ids: ['5729405850615808'],
after: '2022-01-01',
before: '2022-01-20',
types: ['created'],
chargeback_ids: ['5155165527080960']
)
logs.each do |log|
puts log
endGet a PixChargeback log
You can also get a specific log by its id.
require('starkinfra')
log = StarkInfra::PixChargeback::Log.get('5155165527080960')
puts logQuery PixDomains
Here you can list all Pix Domains registered at the Brazilian Central Bank. The Pix Domain object displays the domain name and the QR Code domain certificates of registered Pix participants able to issue dynamic QR Codes.
require('starkinfra')
domains = StarkInfra::PixDomain.query()
domains.each do |domain|
puts domain
endCreate StaticBrcodes
StaticBrcodes store account information via a BR Code or an image (QR code) that represents a PixKey and a few extra fixed parameters, such as an amount and a reconciliation ID. They can easily be used to receive Pix transactions.
require('starkinfra')
brcodes = StarkInfra::StaticBrcode.create(
StarkInfra::StaticBrcode.new(
name: "Jamie Lannister",
key_id: "+5511988887777",
amount: 0,
reconciliation_id: "123",
city: "São Paulo"
)
)
brcodes.each do |brcode|
puts brcode
endQuery StaticBrcodes
You can query multiple StaticBrcodes according to filters.
require('starkinfra')
brcodes = StarkInfra::StaticBrcode.query(
limit: 4,
after: '2022-01-01',
before: '2022-01-20',
)
brcodes.each do |brcode|
puts brcode
endGet a StaticBrcodes
After its creation, information on a StaticBrcode may be retrieved by its UUID.
require('starkinfra')
brcode = StarkInfra::StaticBrcode.get("5ddde28043a245c2848b08cf315effa2")
puts brcodeCreate DynamicBrcodes
BR Codes store information represented by Pix QR Codes, which are used to send or receive Pix transactions in a convenient way. DynamicBrcodes represent charges with information that can change at any time, since all data needed for the payment is requested dynamically to an URL stored in the BR Code. Stark Infra will receive the GET request and forward it to your registered endpoint with a GET request containing the UUID of the BR Code for identification.
require('starkinfra')
brcodes = StarkInfra::DynamicBrcode.create([
StarkInfra::DynamicBrcode.new(
name: "Jamie Lannister",
city: "Rio de Janeiro",
external_id: "my-external-id/1234",
type: "instant"
)
])
brcodes.each do |brcode|
puts brcode
endQuery DynamicBrcodes
You can query multiple DynamicBrcodes according to filters.
require('starkinfra')
brcodes = StarkInfra::DynamicBrcode.query(
limit: 4,
after: '2022-01-01',
before: '2022-02-01',
uuids: %w[68a6af231c594a40bd11a80cb980c400 ba989316ffeb4500a60c3636eca90d7e],
)
brcodes.each do |brcode|
puts brcode
endGet a DynamicBrcode
After its creation, information on a DynamicBrcode may be retrieved by its UUID.
require('starkinfra')
brcode = StarkInfra::DynamicBrcode.get("ac7caa14e601461dbd6b12bf7e4cc48e")
puts brcodeVerify a DynamicBrcode read
When a DynamicBrcode is read by your user, a GET request will be made to the your regitered URL to retrieve additional information needed to complete the transaction. Use this method to verify the authenticity of a GET request received at your registered endpoint. If the provided digital signature does not check out with the StarkInfra public key, a stark.exception.InvalidSignatureException will be raised.
require('starkinfra')
request = listen() # this is the method you made to get the read requests posted to your registered endpoint
uuid = StarkInfra::Dynamicbrcode.verify(
signature=request.headers["Digital-Signature"],
uuid=get_uuid(request.url) # you should implement this method to extract the UUID from the request's URL
)
puts uuidAnswer to a Due DynamicBrcode read
When a Due DynamicBrcode is read by your user, a GET request containing the BR Code UUID will be made to your registered URL to retrieve additional information needed to complete the transaction.
The GET request must be answered in the following format within 5 seconds and with an HTTP status code 200.
require('starkinfra')
request = listen() # this is the method you made to get the read requests posted to your registered endpoint
uuid = StarkInfra::DynamicBrcode.verify(
signature: request.headers["Digital-Signature"],
content: get_uuid(request.url) # you should implement this method to extract the UUID from the request's URL
)
invoice = get_my_invoice(uuid) # you should implement this method to get the information of the BR Code from its uuid
send_response( # you should also implement this method to respond the read request
StarkInfra::DynamicBrcode.response_due(
version: invoice.version,
created: invoice.created,
due: invoice.due,
key_id: invoice.key_id,
status: invoice.status,
reconciliation_id: invoice.reconciliation_id,
nominal_amount: invoice.nominal_amount,
sender_name: invoice.sender_name,
sender_tax_id: invoice.sender_tax_id,
receiver_name: invoice.receiver_name,
receiver_tax_id: invoice.receiver_tax_id,
receiver_street_line: invoice.receiver_street_line,
receiver_city: invoice.receiver_city,
receiver_state_code: invoice.receiver_state_code,
receiver_zip_code: invoice.receiver_zip_code,
)
)Answer to an Instant DynamicBrcode read
When an Instant DynamicBrcode is read by your user, a GET request containing the BR Code UUID will be made to your registered URL to retrieve additional information needed to complete the transaction.
The get request must be answered in the following format within 5 seconds and with an HTTP status code 200.
require('starkinfra')
request = listen() # this is the method you made to get the read requests posted to your registered endpoint
uuid = StarkInfra::DynamicBrcode.verify(
signature: request.headers["Digital-Signature"],
content: get_uuid(request.url) # you should implement this method to extract the UUID from the request's URL
)
invoice = get_my_invoice(uuid) # you should implement this method to get the information of the BR Code from its uuid
send_response( # you should also implement this method to respond the read request
StarkInfra::DynamicBrcode.response_instant(
version: invoice.version,
created: invoice.created,
key_id: invoice.key_id,
status: invoice.status,
reconciliation_id: invoice.reconciliation_id,
amount: invoice.amount,
cashier_type: invoice.cashier_type,
cashier_bank_code: invoice.cashier_bank_code,
cash_amount: invoice.cash_amount,
)
)Create BrcodePreviews
You can create BrcodePreviews to preview BR Codes before paying them.
require('starkinfra')
previews = StarkInfra::BrcodePreview.create([
StarkInfra::BrcodePreview.new(
id: "00020126420014br.gov.bcb.pix0120nedstark@hotmail.com52040000530398654075000.005802BR5909Ned Stark6014Rio de Janeiro621605126674869738606304FF71",
payer_id: "123.456.789-10"
)
])
previews.each do |preview|
puts preview
endLending
If you want to establish a lending operation, you can use Stark Infra to create a CCB contract. This will enable your business to lend money without requiring a banking license, as long as you use a Credit Fund or Securitization company.
The required steps to initiate the operation are:
- Have funds in your Credit Fund or Securitization account
- Request the creation of an Identity Check for the credit receiver (make sure you have their documents and express authorization)
- (Optional) Create a Credit Simulation with the desired installment plan to display information for the credit receiver
- Create a Credit Note with the desired installment plan
Create CreditNotes
For lending operations, you can create a CreditNote to generate a CCB contract.
Note that you must have recently created an identity check for that same Tax ID before being able to create a credit operation for them.
require('starkinfra')
notes = StarkInfra::CreditNote.create([
StarkInfra::CreditNote.new(
template_id: '0123456789101112',
name: 'Jamie Lannister',
tax_id: '012.345.678-90',
nominal_amount: 100000,
scheduled: '2022-04-28',
invoices: [
StarkInfra::CreditNote::Invoice.new(
due: '2023-06-25',
amount: 120000,
fine: 10,
interest: 2,
tax_id: '012.345.678-90',
name: 'Jamie Lannister'
)
],
payment: StarkInfra::CreditNote::Transfer.new(
bank_code: '00000000',
branch_code: '1234',
account_number: '129340-1',
name: 'Jamie Lannister',
tax_id: '012.345.678-90',
amount: 100000,
),
payment_type: 'transfer',
signers: [
StarkInfra::CreditNote::Signer.new(
name: 'Jamie Lannister',
contact: 'jamie.lannister@gmail.com',
method: 'link'
)
],
external_id: '1234',
street_line_1: 'Rua ABC',
street_line_2: 'Ap 123',
district: 'Jardim Paulista',
city: 'São Paulo',
state_code: 'SP',
zip_code: '01234-567'
)
])
notes.each do |note|
puts note
endNote: Instead of using CreditNote objects, you can also pass each element in hash format
Query CreditNotes
You can query multiple credit notes according to filters.
require('starkinfra')
notes = StarkInfra::CreditNote.query(
limit: 10,
after: DateTime.new(2020, 1, 1),
before: DateTime.new(2020, 4, 1),
status: 'success',
tags: %w[iron, suit]
)
notes.each do |note|
puts note
endGet a CreditNote
After its creation, information on a credit note may be retrieved by its id.
require('starkinfra')
note = StarkInfra::CreditNote.get('5155165527080960')
puts noteCancel a CreditNote
You can cancel a credit note if it has not been signed yet.
require('starkinfra')
note = StarkInfra::CreditNote.cancel('5155165527080960')
puts noteQuery CreditNote logs
You can query credit note logs to better understand credit note life cycles.
require('starkinfra')
logs = StarkInfra::CreditNote::Log.query(
limit: 50,
after: '2022-01-01',
before: '2022-01-20'
)
logs.each do |log|
puts log
endGet a CreditNote log
You can also get a specific log by its id.
require('starkinfra')
log = StarkInfra::CreditNote::Log.get('5155165527080960')
puts logCreate CreditPreviews
You can preview a credit operation before creating them (Currently we only have CreditNote / CCB previews):
require('starkinfra')
previews = StarkInfra::CreditPreview.create([
StarkInfra::CreditPreview.new(
credit: StarkInfra::CreditNotePreview.new(
type: "price",
nominal_amount: 100000,
scheduled: '2022-07-10',
tax_id: "20.018.183/0001-80",
initial_due: '2022-07-10',
nominal_interest: 15,
count: 15,
interval: "year",
rebate_amount: 900,
),
type: "credit-note"
),
StarkInfra::CreditPreview.new(
credit: StarkInfra::CreditNotePreview.new(
type: "bullet",
nominal_amount: 100000,
scheduled: '2022-07-10',
tax_id: "20.018.183/0001-80",
initial_due: '2022-07-10',
nominal_interest: 15,
rebate_amount: 0,
),
type: "credit-note",
),
StarkInfra::CreditPreview.new(
credit: StarkInfra::CreditNotePreview.new(
type: "price",
nominal_amount: 100000,
scheduled: '2022-07-10',
tax_id: "20.018.183/0001-80",
initial_due: '2022-07-10',
nominal_interest: 15,
count: 15,
interval: "year",
rebate_amount: 900,
),
type: "credit-note",
),
StarkInfra::CreditPreview.new(
credit: StarkInfra::CreditNotePreview.new(
type: "american",
nominal_amount: 100000,
scheduled: '2022-07-10',
tax_id: "20.018.183/0001-80",
initial_due: '2022-07-10',
nominal_interest: 15,
count: 5,
interval: "month",
rebate_amount: 900,
)
)]
)
previews.each do |preview|
puts preview
endNote: Instead of using CreditPreview objects, you can also pass each element in dictionary format
Create CreditHolmes
Before you request a credit operation, you may want to check previous credit operations the credit receiver has taken.
For that, open up a CreditHolmes investigation to receive information on all debts and credit operations registered for that individual or company inside the Central Bank's SCR.
require('starkinfra')
holmes = StarkInfra::CreditHolmes.create([
StarkInfra::CreditHolmes.new(
tax_id: "123.456.789-00",
competence: "2022-09"
),
StarkInfra::CreditHolmes.new(
tax_id: "123.456.789-00",
competence: "2022-08"
),
StarkInfra::CreditHolmes.new(
tax_id: "123.456.789-00",
competence: "2022-07"
)
])
holmes.each do |sherlock|
print(sherlock)
endQuery CreditHolmes
You can query multiple credit holmes according to filters.
require('starkinfra')
holmes = StarkInfra::CreditHolmes.query(
after: "2022-06-01",
before: "2022-10-30",
status: "success"
)
holmes.each do |sherlock|
print(sherlock)
endGet a CreditHolmes
After its creation, information on a credit holmes may be retrieved by its id.
require('starkinfra')
holmes = StarkInfra::CreditHolmes.get("5657818854064128")
puts holmesQuery CreditHolmes logs
You can query credit holmes logs to better understand their life cycles.
require('starkinfra')
logs = StarkInfra::CreditHolmes::Log.query(
limit: 50,
ids: ["5729405850615808"],
after: "2022-01-01",
before: "2022-01-20",
types: ["created"]
)
logs.each do |log|
puts log
endGet a CreditHolmes log
You can also get a specific log by its id.
require('starkinfra')
log = StarkInfra::CreditHolmes::Log.get("5155165527080960")
puts logIdentity
Several operations, especially credit ones, require that the identity of a person or business is validated beforehand.
Identities are validated according to the following sequence:
- The Identity resource is created for a specific Tax ID
- Documents are attached to the Identity resource
- The Identity resource is updated to indicate that all documents have been attached
- The Identity is sent for validation and returns a webhook notification to reflect the success or failure of the operation
Create IndividualIdentities
You can create an IndividualIdentity to validate a document of a natural person
require('starkinfra')
identities = StarkInfra::IndividualIdentity.create([
StarkInfra::IndividualIdentity.new(
name: 'Walter White',
tax_id: '012.345.678-90',
tags: ['breaking', 'bad']
)
])
identities.each do |identity|
puts identity
endNote: Instead of using IndividualIdentity objects, you can also pass each element in dictionary format
Query IndividualIdentity
You can query multiple individual identities according to filters.
require('starkinfra')
identities = StarkInfra::IndividualIdentity.query(
limit: 10,
after: '2020-01-01',
before: '2020-04-01',
status: 'success',
tags: ['breaking', 'bad'],
)
identities.each do |identity|
puts identity
endGet an IndividualIdentity
After its creation, information on an individual identity may be retrieved by its id.
require('starkinfra')
identity = StarkInfra::IndividualIdentity.get('5155165527080960')
puts identityUpdate an IndividualIdentity
You can update a specific identity status to "processing" for send it to validation.
require('starkinfra')
identity = StarkInfra::IndividualIdentity.update('5155165527080960', status: 'processing')
puts identityNote: Before sending your individual identity to validation by patching its status, you must send all the required documents using the create method of the CreditDocument resource. Note that you must reference the individual identity in the create method of the CreditDocument resource by its id.
Cancel an IndividualIdentity
You can cancel an individual identity before updating its status to processing.
require('starkinfra')
identity = StarkInfra::IndividualIdentity.cancel('5155165527080960')
puts identityQuery IndividualIdentity logs
You can query individual identity logs to better understand individual identity life cycles.
require('starkinfra')
logs = StarkInfra::IndividualIdentity::Log.query(
limit: 50,
after: '2022-01-01',
before: '2022-01-20',
)
logs.each do |log|
puts log
endGet an IndividualIdentity log
You can also get a specific log by its id.
require('starkinfra')
log = StarkInfra::IndividualIdentity::Log.get('5155165527080960')
print(log)Create IndividualDocuments
You can create an individual document to attach images of documents to a specific individual Identity. You must reference the desired individual identity by its id.
require('starkinfra')
documents = StarkInfra::IndividualDocument.create([
StarkInfra::IndividualDocument.new(
type: 'identity-front',
content: 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD...',
identity_id: '5155165527080960',
tags: ['breaking', 'bad']
),
StarkInfra::IndividualDocument.new(
type: 'identity-back',
content: 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD...',
identity_id: '5155165527080960',
tags: ['breaking', 'bad']
),
StarkInfra::IndividualDocument.new(
type: 'selfie',
content: 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD...',
identity_id: '5155165527080960',
tags: ['breaking', 'bad']
)
])
documents.each do |document|
puts document
endNote: Instead of using IndividualDocument objects, you can also pass each element in dictionary format
Query IndividualDocuments
You can query multiple individual documents according to filters.
require('starkinfra')
documents = StarkInfra::IndividualIdentity.query(
limit: 10,
after: '2020-01-01',
before: '2020-04-01',
status: 'success',
tags: ['breaking', 'bad'],
)
documents.each do |document|
puts document
endGet an IndividualDocument
After its creation, information on an individual document may be retrieved by its id.
require('starkinfra')
document = StarkInfra::IndividualDocument.get('5155165527080960')
puts documentQuery IndividualDocument logs
You can query individual document logs to better understand individual document life cycles.
require('starkinfra')
logs = StarkInfra::IndividualDocument::Log.query(
limit=50,
after='2022-01-01',
before='2022-01-20',
)
logs.each do |log|
puts log
endGet an IndividualDocument log
You can also get a specific log by its id.
require('starkinfra')
log = StarkInfra::IndividualDocument::Log.get('5155165527080960')
puts logWebhook
Create a webhook subscription
To create a webhook subscription and be notified whenever an event occurs, run:
require('starkinfra')
webhook = StarkInfra::Webhook.create(
StarkInfra::Webhook.new(
url: 'https://webhook.site/dd784f26-1d6a-4ca6-81cb-fda0267761ec',
subscriptions: %w[pix-infraction pix-chargeback]
)
)
puts webhookQuery webhooks
To search for registered webhooks, run:
require('starkinfra')
webhooks = StarkInfra::Webhook.query()
webhooks.each do |webhook|
puts webhook
endGet a webhook
You can get a specific webhook by its id.
require('starkinfra')
webhook = StarkInfra::Webhook.get('1082736198236817')
puts webhookDelete a webhook
You can also delete a specific webhook by its id.
require('starkinfra')
webhook = StarkInfra::Webhook.delete('1082736198236817')
puts webhookProcess webhook events
It's easy to process events that arrived in your webhook. Remember to pass the signature header so the SDK can make sure it's StarkInfra that sent you the event.
require('starkinfra')
response = listen() # this is the method you made to get the events posted to your webhook endpoint
event = StarkInfra::Event.parse(
content: response.data.decode('utf-8'),
signature: response.headers['Digital-Signature'],
)
if event.subscription.include? 'pix-request'
puts event.log.request
elsif event.subscription.include? 'pix-reversal'
puts event.log.reversal
elsif event.subscription == 'pix-key'
puts event.log.key
elsif event.subscription == 'pix-claim'
puts event.log.claim
elsif event.subscription == 'pix-infraction'
puts event.log.infraction
elsif event.subscription == 'pix-chargeback'
puts event.log.chargeback
elsif event.subscription == 'credit-note'
puts event.log.note
elsif event.subscription == 'issuing-card'
puts event.log.card
elsif event.subscription == 'issuing-invoice'
puts event.log.invoice
elsif event.subscription == 'issuing-purchase'
puts event.log.purchase
endQuery webhook events
To search for webhook events, run:
require('starkinfra')
events = StarkInfra::Event.query(after: '2020-03-20', is_delivered: false)
events.each do |event|
puts event
endGet a webhook event
You can get a specific webhook event by its id.
require('starkinfra')
event = StarkInfra::Event.get('4828869076975616')
puts eventDelete a webhook event
You can also delete a specific webhook event by its id.
require('starkinfra')
event = StarkInfra::Event.delete('4828869076975616')
puts eventSet webhook events as delivered
This can be used in case you've lost events.
With this function, you can manually set events retrieved from the API as
"delivered" to help future event queries with is_delivered: false.
require('starkinfra')
event = StarkInfra::Event.update('5892075044208640', is_delivered: true)
puts eventQuery failed webhook event delivery attempts information
You can also get information on failed webhook event delivery attempts.
require('starkinfra')
attempts = StarkInfra::Event::Attempt.query(after: '2020-03-20')
attempts.each do |attempt|
puts attempt
endGet a failed webhook event delivery attempt information
To retrieve information on a single attempt, use the following function:
require('starkinfra')
attempt = StarkInfra::Event::Attempt.get('1616161616161616')
puts attemptRequest
This resource allows you to send HTTP requests to StarkInfra routes.
GET
You can perform a GET request to any StarkInfra route.
It's possible to get a single resource using its id in the path.
require('starkinfra')
example_id = "5155165527080960"
request = StarkInfra::Request.get(
path: "/pix-request/#{example_id}"
).json
puts requestYou can also get the specific resource log,
require('starkinfra')
example_id = "5699165527090460"
request = StarkInfra::Request.get(
path: "/pix-request/log/#{example_id}",
).json
puts requestThis same method will be used to list all created items for the requested resource.
require('starkinfra')
after = "2024-01-01"
before = "2024-02-01"
cursor = nil
request = StarkInfra::Request.get(
path: '/pix-request/',
query: {
"after": after,
"before": before,
"cursor": cursor
}
).json
puts requestTo list logs, you will use the same logic as for getting a single log.
require('starkinfra')
after = "2024-01-01"
before = "2024-02-01"
cursor = nil
request = StarkInfra::Request.get(
path: '/pix-request/log',
query: {
"after": after,
"before": before,
"cursor": cursor
}
).json
puts requestPOST
You can perform a POST request to any StarkInfra 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.
require('starkinfra')
data = {
"holders": [
{
"name": "Jaime Lannister",
"externalId": "my_external_id",
"taxId": "012.345.678-90"
}
]
}
request = StarkInfra::Request.post(
path: "/issuing-holder",
payload: data,
).json
puts requestPATCH
You can perform a PATCH request to any StarkInfra route.
It's possible to update a single item of a StarkInfra resource.
require('starkinfra')
example_id = "5155165527080960"
request = StarkInfra::Request.patch(
path: "/issuing-holder/#{example_id}",
body: {
"tags": ["Arya", "Stark"]
}
).json
puts requestDELETE
You can perform a DELETE request to any StarkInfra route.
It's possible to delete items of StarkInfra resource.
require('starkinfra')
example_id = "5155165527080960"
request = StarkInfra::Request.delete(
path="/issuing-holder/#{example_id}"
).json
puts request Handling errors
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:
require('starkinfra')
begin
reversal = StarkInfra::PixReversal.create(
[
StarkInfra::PixReversal.new(
amount: 100,
end_to_end_id: 'E00000000202201060100rzsJzG9PzMg',
external_id: 'my_external_id',
reason: 'bankError',
)
])
rescue StarkInfra::Error::InputErrors => e
e.errors.each do |error|
puts error.code
puts error.message
end
endInternalServerError 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 StarkInfra::Event.parse() when the provided content and signature do not check out with the Stark Infra public key.
Help and Feedback
If you have any questions about our SDK, just send us an email. We will respond you quickly, pinky promise. We are here to help you integrate with us ASAP. We also love feedback, so don't be shy about sharing your thoughts with us.
Email: help@starkbank.com