From 46cd0019ecb03e941350b17f8cf06737bbdc1fb0 Mon Sep 17 00:00:00 2001 From: Leandro Santos <> Date: Tue, 11 Apr 2023 11:51:50 -0300 Subject: [PATCH] Add new resources and attributes, fix parameters and remove deprecated resources --- CHANGELOG.md | 55 +- README.md | 1007 +++++++++++++++-- lib/brcode_preview/brcode_preview.ex | 147 +++ lib/card_method/card_method.ex | 87 ++ lib/credit_holmes/credit_holmes.ex | 264 +++++ lib/credit_holmes/credit_holmes_log.ex | 187 +++ lib/credit_note/credit_note.ex | 135 +-- lib/credit_note/credit_note_log.ex | 60 +- lib/credit_note/invoice/description.ex | 4 +- lib/credit_note/invoice/discount.ex | 2 +- lib/credit_note/invoice/invoice.ex | 42 +- lib/credit_note/signer.ex | 37 - lib/credit_note/transfer.ex | 76 +- lib/credit_preview/credit_note_preview.ex | 89 ++ lib/credit_preview/credit_preview.ex | 94 ++ lib/credit_signer/credit_signer.ex | 50 + lib/dynamic_brcode/dynamic_brcode.ex | 462 ++++++++ lib/error.ex | 6 +- lib/event/{event_attempt.ex => attempt.ex} | 61 +- lib/event/event.ex | 81 +- .../individual_document.ex | 261 +++++ .../individual_document_log.ex | 187 +++ .../individual_identity.ex | 333 ++++++ .../individual_identity_log.ex | 187 +++ .../issuing_authorization.ex | 221 ---- lib/issuing_balance/issuing_balance.ex | 16 +- lib/issuing_bin/issuing_bin.ex | 133 --- lib/issuing_card/issuing_card.ex | 187 +-- lib/issuing_card/issuing_card_log.ex | 72 +- lib/issuing_design/issuing_design.ex | 232 ++++ .../issuing_embossing_kit.ex | 209 ++++ .../issuing_embossing_request.ex | 319 ++++++ .../issuing_embossing_request_log.ex | 210 ++++ lib/issuing_holder/issuing_holder.ex | 132 +-- lib/issuing_holder/issuing_holder_log.ex | 77 +- lib/issuing_invoice/issuing_invoice.ex | 86 +- lib/issuing_invoice/issuing_invoice_log.ex | 78 +- lib/issuing_product/issuing_product.ex | 130 +++ lib/issuing_purchase/issuing_purchase.ex | 262 +++-- lib/issuing_purchase/issuing_purchase_log.ex | 80 +- lib/issuing_restock/issuing_restock.ex | 226 ++++ lib/issuing_restock/issuing_restock_log.ex | 205 ++++ lib/issuing_rule/issuing_rule.ex | 44 +- lib/issuing_stock/issuing_stock.ex | 225 ++++ lib/issuing_stock/issuing_stock_log.ex | 209 ++++ .../issuing_transaction.ex | 116 +- lib/issuing_withdrawal/issuing_withdrawal.ex | 86 +- lib/key.ex | 2 +- lib/merchant_category/merchant_category.ex | 93 ++ lib/merchant_country/merchant_country.ex | 89 ++ lib/pix_balance/pix_balance.ex | 14 +- lib/pix_chargeback/pix_chargeback.ex | 131 ++- lib/pix_chargeback/pix_chargeback_log.ex | 68 +- lib/pix_claim/pix_claim.ex | 148 +-- lib/pix_claim/pix_claim_log.ex | 84 +- lib/pix_director/pix_director.ex | 36 +- ...x_domain_certificate.ex => certificate.ex} | 4 +- lib/pix_domain/pix_domain.ex | 12 +- lib/pix_infraction/pix_infraction.ex | 132 ++- lib/pix_infraction/pix_infraction_log.ex | 77 +- lib/pix_key/pix_key.ex | 141 +-- lib/pix_key/pix_key_log.ex | 78 +- lib/pix_request/pix_request.ex | 170 +-- lib/pix_request/pix_request_log.ex | 74 +- lib/pix_reversal/pix_reversal.ex | 145 ++- lib/pix_reversal/pix_reversal_log.ex | 70 +- lib/pix_statement/pix_statement.ex | 72 +- lib/starkinfra.ex | 22 +- lib/static_brcode/static_brcode.ex | 269 +++++ lib/utils/api.ex | 12 +- lib/utils/case.ex | 16 +- lib/utils/checks.ex | 2 +- lib/utils/parse.ex | 37 +- lib/webhook/webhook.ex | 66 +- test/brcode_preview_test.exs | 28 + test/card_method_test.exs | 21 + test/credit_holmes_log_test.exs | 60 + test/credit_holmes_test.exs | 92 ++ test/credit_note_test.exs | 8 +- test/credit_preview_test.exs | 111 ++ test/dynamic_brcode_test.exs | 182 +++ test/individual_document_log_test.exs | 60 + test/individual_document_test.exs | 94 ++ test/individual_identity_log_test.exs | 60 + test/individual_identity_test.exs | 93 ++ test/issuing_authorization_test.exs | 85 -- test/issuing_bin_test.exs | 37 - test/issuing_design_test.exs | 60 + test/issuing_embossing_kit_test.exs | 60 + test/issuing_embossing_request_log_test.exs | 60 + test/issuing_embossing_request_test.exs | 60 + test/issuing_product_test.exs | 37 + test/issuing_restock_log_test.exs | 60 + test/issuing_restock_test.exs | 93 ++ test/issuing_stock_log_test.exs | 60 + test/issuing_stock_test.exs | 60 + test/merchant_category_test.exs | 21 + test/merchant_country_test.exs | 21 + test/pix_claim_test.exs | 24 +- test/pix_infraction_test.exs | 4 +- test/pix_key_test.exs | 2 +- test/static_brcode_test.exs | 101 ++ test/test_helper.exs | 24 +- test/utils/pix_reversal.exs | 2 +- 104 files changed, 9071 insertions(+), 2142 deletions(-) create mode 100644 lib/brcode_preview/brcode_preview.ex create mode 100644 lib/card_method/card_method.ex create mode 100644 lib/credit_holmes/credit_holmes.ex create mode 100644 lib/credit_holmes/credit_holmes_log.ex delete mode 100644 lib/credit_note/signer.ex create mode 100644 lib/credit_preview/credit_note_preview.ex create mode 100644 lib/credit_preview/credit_preview.ex create mode 100644 lib/credit_signer/credit_signer.ex create mode 100644 lib/dynamic_brcode/dynamic_brcode.ex rename lib/event/{event_attempt.ex => attempt.ex} (61%) create mode 100644 lib/individual_document/individual_document.ex create mode 100644 lib/individual_document/individual_document_log.ex create mode 100644 lib/individual_identity/individual_identity.ex create mode 100644 lib/individual_identity/individual_identity_log.ex delete mode 100644 lib/issuing_authorization/issuing_authorization.ex delete mode 100644 lib/issuing_bin/issuing_bin.ex create mode 100644 lib/issuing_design/issuing_design.ex create mode 100644 lib/issuing_embossing_kit/issuing_embossing_kit.ex create mode 100644 lib/issuing_embossing_request/issuing_embossing_request.ex create mode 100644 lib/issuing_embossing_request/issuing_embossing_request_log.ex create mode 100644 lib/issuing_product/issuing_product.ex create mode 100644 lib/issuing_restock/issuing_restock.ex create mode 100644 lib/issuing_restock/issuing_restock_log.ex create mode 100644 lib/issuing_stock/issuing_stock.ex create mode 100644 lib/issuing_stock/issuing_stock_log.ex create mode 100644 lib/merchant_category/merchant_category.ex create mode 100644 lib/merchant_country/merchant_country.ex rename lib/pix_domain/{pix_domain_certificate.ex => certificate.ex} (76%) create mode 100644 lib/static_brcode/static_brcode.ex create mode 100644 test/brcode_preview_test.exs create mode 100644 test/card_method_test.exs create mode 100644 test/credit_holmes_log_test.exs create mode 100644 test/credit_holmes_test.exs create mode 100644 test/credit_preview_test.exs create mode 100644 test/dynamic_brcode_test.exs create mode 100644 test/individual_document_log_test.exs create mode 100644 test/individual_document_test.exs create mode 100644 test/individual_identity_log_test.exs create mode 100644 test/individual_identity_test.exs delete mode 100644 test/issuing_authorization_test.exs delete mode 100644 test/issuing_bin_test.exs create mode 100644 test/issuing_design_test.exs create mode 100644 test/issuing_embossing_kit_test.exs create mode 100644 test/issuing_embossing_request_log_test.exs create mode 100644 test/issuing_embossing_request_test.exs create mode 100644 test/issuing_product_test.exs create mode 100644 test/issuing_restock_log_test.exs create mode 100644 test/issuing_restock_test.exs create mode 100644 test/issuing_stock_log_test.exs create mode 100644 test/issuing_stock_test.exs create mode 100644 test/merchant_category_test.exs create mode 100644 test/merchant_country_test.exs create mode 100644 test/static_brcode_test.exs diff --git a/CHANGELOG.md b/CHANGELOG.md index 2989902..211ad49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,9 +13,58 @@ Given a version number MAJOR.MINOR.PATCH, increment: ## [Unreleased] ### Added -- IssuingRule missing parameters -### Fixed -- query parameters in post requests +- StaticBrcode resource +- BrcodePreview resource +- DynamicBrcode resource +- IndividualDocument resource +- IndividualDocument.Log resource +- IndividualIdentity resource +- IndividualIdentity.Log resource +- CreditHolmes resource +- CreditHolmes.Log resource +- IssuingDesign resource +- IssuingEmbossingKit resource +- IssuingEmbossingRequest resource +- IssuingEmbossingRequest.Log resource +- IssuingRestock resource +- IssuingRestock.Log resource +- IssuingStock resource +- IssuingStock.Log resource +- CardMethod sub-resource +- MerchantCountry sub-resource +- MerchantCategory sub-resource +- CreditPreview sub-resource +- CreditNotePreview sub-resource +- flow attribute to PixChargeback and PixInfraction resources +- tags parameter to PixClaim, PixInfraction, PixChargeback resources +- tags parameter to query and page methods in PixChargeback, PixClaim and PixInfraction resources +- agent parameter to query and page methods in PixInfraction and PixChargeback resources +- expand parameter to create, get, query and page methods in IssuingHolder resource +- pin parameter to update method in IssuingCard resource +- nominal_interest attributes to return only in CreditNote resource +- code attribute to IssuingProduct resource +- parse method in IssuingPurchase resource +- response method in IssuingPurchas, PixRequest and PixReversal resources +- zip_code, is_partial_allowed, card_tags and holder_tags attributes to IssuingPurchase resource +- brcode, link and due attributes to IssuingInvoice resource +### Changed +- CreditNote.Signer to CreditSigner sub-resource +- PixDirector resource to sub-resource +- IssuingBin resource to IssuingProduct +- fine and interest attributes to return only in CreditNote.Invoice sub-resource +- expiration from returned-only attribute to optional parameter in the CreditNote resource +- settlement parameter to funding_type and client parameter to holder_type in Issuing Product resource +- bank_code parameter to claimer_bank_code in PixClaim resource +- agent parameter to flow in PixClaim and PixInfraction resources +- agent parameter to flow on query and page methods in PixClaim resource +- CreditNote.Signer sub-resource to CreditSigner resource +### Removed +- IssuingAuthorization resource +- category parameter from IssuingProduct resource +- bank_code attribute from PixReversal resource +- agent parameter from PixClaim.Log +- bacen_id attribute from PixChargeback and PixInfraction resources +- cardDesignId and envelopeDesignId to IssuingEmbossingRequest resource ## [0.1.0] - 2022-06-03 ### Added diff --git a/README.md b/README.md index 944ed6e..a29d0d1 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ This SDK version is compatible with the Stark Infra API v2. - [Introduction](#introduction) - [Supported Elixir versions](#supported-elixir-versions) - - [API documentation](#stark-bank-api-documentation) + - [API documentation](#stark-infra-api-documentation) - [Versioning](#versioning) - [Setup](#setup) - [Install our SDK](#1-install-our-sdk) @@ -18,18 +18,25 @@ This SDK version is compatible with the Stark Infra API v2. - [Register your user credentials](#3-register-your-user-credentials) - [Setting up the user](#4-setting-up-the-user) - [Setting up the error language](#5-setting-up-the-error-language) - - [Resource listing and manual pagination](#6-resource-listing-and-manual-pagination) +- [Resource listing and manual pagination](#6-resource-listing-and-manual-pagination) - [Testing in Sandbox](#testing-in-sandbox) - [Usage](#usage) - [Issuing](#issuing) - - [BINs](#query-issuingbins): View available sub-issuer BINs (a.k.a. card number ranges) + - [Products](#query-issuingproducts): View available sub-issuer card products (a.k.a. card number ranges or BINs) - [Holders](#create-issuingholders): Manage card holders - [Cards](#create-issuingcards): Create virtual and/or physical cards + - [Design](#query-issuingdesigns): View your current card or package designs + - [EmbossingKit](#query-issuingembossingkits): Create embossing kits + - [Stock](#query-issuingstocks): View your current stock of a certain IssuingDesign linked to an Embosser on the workspace + - [Restock](#create-issuingrestocks): Create restock orders of a specific IssuingStock object + - [EmbossingRequest](#create-issuingembossingrequests): Create embossing requests - [Purchases](#process-purchase-authorizations): Authorize and view your past purchases - [Invoices](#create-issuinginvoices): Add money to your issuing balance - [Withdrawals](#create-issuingwithdrawals): Send money back to your Workspace from your issuing balance - [Balance](#get-your-issuingbalance): View your issuing balance - - [Transactions](#query-issuingtransactions): View the transactions that have affected your issuing balance + - [Transactions](#query-issuingtransactions): View the transactions that have affected your issuing + balance + - [Enums](#issuing-enums): Query enums related to the issuing purchases, such as merchant categories, countries and card purchase methods - [Pix](#pix) - [PixRequests](#create-pixrequests): Create Pix transactions - [PixReversals](#create-pixreversals): Reverse Pix transactions @@ -41,11 +48,18 @@ This SDK version is compatible with the Stark Infra API v2. - [PixInfraction](#create-pixinfractions): Create Pix Infraction reports - [PixChargeback](#create-pixchargebacks): Create Pix Chargeback requests - [PixDomain](#query-pixdomains): View registered SPI participants certificates - - [Credit Note](#credit-note) - - [CreditNote](#create-creditnotes): Create credit notes + - [StaticBrcode](#create-staticbrcodes): Create static Pix BR codes + - [DynamicBrcode](#create-dynamicbrcodes): Create dynamic Pix BR codes + - [BrcodePreview](#create-brcodepreviews): Read data from BR Codes before paying them + - [Lending](#lending) + - [CreditNote](#create-creditnotes): Create credit notes + - [CreditPreview](#create-creditpreviews): Create credit previews + - [CreditHolmes](#create-creditholmes): Create credit holmes debt verification + - [Identity](#identity) + - [IndividualIdentity](#create-individualidentities): Create individual identities + - [IndividualDocument](#create-individualdocuments): Create individual documents - [Webhook](#webhook): - - [Webhook](#create-a-webhook-subscription): Configure your webhook endpoints and subscriptions - - [Webhook Events](#webhook-events): + - [Webhook](#create-a-webhook): Configure your webhook endpoints and subscriptions - [WebhookEvents](#process-webhook-events): Manage Webhook events - [WebhookEventAttempts](#query-failed-webhook-event-delivery-attempts-information): Query failed webhook event deliveries - [Handling errors](#handling-errors) @@ -57,7 +71,7 @@ This library supports Elixir versions 1.9+. # Stark Infra API documentation -Feel free to take a look at our [API docs](https://www.starkbank.com/docs/api). +Feel free to take a look at our [API docs](https://www.starkinfra.com/docs/api). # Versioning @@ -129,7 +143,7 @@ Since this user is unique in your entire organization, only one credential can b 3.1.5. After creating the Project, get its Project ID -3.1.6. Use the Project ID and private key to create the struct below: +3.1.6. Use the Project ID and private key to create the object below: ```elixir # Get your private key from an environment variable or an encrypted database. @@ -164,7 +178,7 @@ project = StarkInfra.project( 3.2.5. Click on your profile picture and then on the "Organization" menu to get the Organization ID -3.2.6. Use the Organization ID and private key to create the struct below: +3.2.6. Use the Organization ID and private key to create the object below: ```elixir # Get your private key from an environment variable or an encrypted database. @@ -203,7 +217,7 @@ There are three kinds of users that can access our API: **Organization**, **Proj There are two ways to inform the user to the SDK: -4.1 Passing the user as argument in all functions using the `user` keyword: +4.1 Passing the user as an argument in all functions: ```elixir balance = StarkInfra.PixBalance.get!(user: project) # or organization @@ -237,7 +251,7 @@ config :starkinfra, ``` Just select the way of passing the user that is more convenient to you. -On all following examples we will assume a default user has been set in the configs. +On all following examples, we will assume a default user has been set. ## 5. Setting up the error language @@ -250,13 +264,13 @@ config :starkinfra, language: "en-US" ``` -Language options are "en-US" for english and "pt-BR" for brazilian portuguese. English is default +Language options are "en-US" for english and "pt-BR" for brazilian portuguese. English is default. ## 6. Resource listing and manual pagination Almost all SDK resources provide a `query` and a `page` function. -- The `query` function provides a straight forward way to efficiently iterate through all results that match the filters you inform, +- The `query` function 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. @@ -299,14 +313,13 @@ To simplify the following SDK examples, we will only use the `query` function, b # Testing in Sandbox Your initial balance is zero. For many operations in Stark Infra, you'll need funds -in your account, which can be added to your balance by creating an StarkBank.Invoice -or a StarkBank.Boleto. +in your account, which can be added to your balance by creating an StarkBank.Invoice. -In the Sandbox environment, most of the created Invoices and Boletos will be automatically paid, +In the Sandbox environment, most of the created StarkBank.Invoice 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. +a few StarkBank.Invoice and wait around a bit. -In Production, you (or one of your clients) will need to actually pay this Invoice or Boleto +In Production, you (or one of your clients) will need to actually pay this Invoice for the value to be credited to your account. # Usage @@ -317,16 +330,14 @@ Here are a few examples on how to use the SDK. If you have any doubts, use the b `h()` function to get more info on the desired functionality (for example: `StarkInfra.CreditNote |> h`) -**Note**: Almost all SDK functions also provide a bang (!) version. To simplify the examples, they will be used the most throughout this README. - ## Issuing -### Query IssuingBins +### Query IssuingProducts -To take a look at the sub-issuer BINs available to you, just run the following: +To take a look at the sub-issuer card products available to you, just run the following: ```elixir -StarkInfra.IssuingBin.query!() +StarkInfra.IssuingProduct.query!() |> Enum.take(10) |> IO.inspect ``` @@ -360,7 +371,7 @@ StarkInfra.IssuingHolder.create!( ) |> IO.inspect ``` -**Note**: Instead of using IssuingHolder structs, you can also pass each transfer element in dictionary format +**Note**: Instead of using IssuingHolder objects, you can also pass each transfer element in dictionary format ### Query IssuingHolders @@ -374,7 +385,7 @@ StarkInfra.IssuingHolder.query!() ### Cancel an IssuingHolder -To cancel a single Issuing Holder by its id, run: +To cancel a specific IssuingHolder by its id, run: ```elixir StarkInfra.IssuingHolder.cancel!("5155165527080960") @@ -383,7 +394,7 @@ StarkInfra.IssuingHolder.cancel!("5155165527080960") ### Get an IssuingHolder -To get a single Issuing Holder by its id, run: +To get a specific IssuingHolder by its id, run: ```elixir StarkInfra.IssuingHolder.get!("5155165527080960") @@ -392,7 +403,7 @@ StarkInfra.IssuingHolder.get!("5155165527080960") ### Query IssuingHolder logs -You can query holder logs to better understand holder life cycles. +You can query IssuingHolder logs to better understand IssuingHolder life cycles. ```elixir StarkInfra.IssuingHolder.Log.query!( @@ -497,16 +508,234 @@ StarkInfra.IssuingCard.Log.query!( ### Get an IssuingCard log -You can get a single log by its id. +You can get a specific log by its id. ```elixir StarkInfra.IssuingCard.Log.get!("5155165527080960") |> IO.inspect ``` +### Query IssuingDesigns + +You can get a list of available designs given some filters. + + +```elixir +StarkInfra.IssuingDesign.query!( + limit: 10 +) +|> Enum.take(10) +|> IO.inspect +``` + +### Get an IssuingDesign + +Information on a design may be retrieved by its id. + +```elixir +StarkInfra.IssuingDesign.get!("5155165527080960") +|> IO.inspect +``` + +### Query IssuingEmbossingKits + +You can get a list of created embossing kits given some filters. + +```elixir +StarkInfra.IssuingEmbossingKit.query!( + limit: 10, + after: Date.utc_today |> Date.add(-30), + before: Date.utc_today |> Date.add(-1) +) +|> Enum.take(10) +|> IO.inspect +``` + +### Get an IssuingEmbossingKit + +After its creation, information on an embossing kit may be retrieved by its id. + +```elixir +StarkInfra.IssuingEmbossingKit.get!("5792731695677440") +|> IO.inspect +``` + +### Query IssuingStocks + +You can get a list of available stocks given some filters. + +```elixir +StarkInfra.IssuingStock.query!( + limit: 10, + after: Date.utc_today |> Date.add(-30), + before: Date.utc_today |> Date.add(-1) +) +|> Enum.take(10) +|> IO.inspect +``` + +### Get an IssuingStock + +Information on a stock may be retrieved by its id. + +```elixir +StarkInfra.IssuingStock.get!("5792731695677440") +|> IO.inspect +``` + +### Query IssuingStock logs + +Logs are pretty important to understand the life cycle of a stock. + +```elixir +StarkInfra.IssuingStock.Log.query!( + limit: 150 +) +|> Enum.take(150) +|> IO.inspect +``` + +### Get an IssuingStock log + +You can get a single log by its id. + +```elixir +StarkInfra.IssuingStock.Log.get!("5792731695677440") +|> IO.inspect +``` + +### Create IssuingRestocks + +You can order restocks for a specific IssuingStock. + +```elixir +StarkInfra.IssuingRestock.create!( + [ + %StarkInfra.IssuingRestock{ + count: 100, + stock_id: "5136459887542272" + } + ] +) |> IO.inspect +``` + +### Query IssuingRestocks + +You can get a list of created restocks given some filters. + +```elixir +StarkInfra.IssuingRestock.query!( + after: Date.utc_today |> Date.add(-30), + before: Date.utc_today |> Date.add(-1) +) +|> Enum.take(150) +|> IO.inspect +``` + +### Get an IssuingRestock + +After its creation, information on a restock may be retrieved by its id. + +```elixir +StarkInfra.IssuingRestock.get!("5792731695677440") +|> IO.inspect +``` + +### Query IssuingRestock logs + +Logs are pretty important to understand the life cycle of a restock. + +```elixir +StarkInfra.IssuingRestock.Log.query!( + limit: 150 +) +|> Enum.take(150) +|> IO.inspect +``` + +### Get an IssuingRestock log + +You can get a single log by its id. + +```elixir +StarkInfra.IssuingRestock.Log.get!("5792731695677440") +|> IO.inspect +``` + +### Create IssuingEmbossingRequests + +You can create a request to emboss a physical card. + +```elixir +StarkInfra.IssuingEmbossingRequest.create!( + [ + %StarkInfra.IssuingEmbossingRequest{ + card_design_id: "5648359658356736", + envelope_design_id: "5747368922185728", + 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" + } + ] +) |> IO.inspect +``` + +### Query IssuingEmbossingRequests + +You can get a list of created embossing requests given some filters. + +```elixir +StarkInfra.IssuingEmbossingRequest.query!( + after: Date.utc_today |> Date.add(-30), + before: Date.utc_today |> Date.add(-1) +) +|> Enum.take(150) +|> IO.inspect +``` + +### Get an IssuingEmbossingRequest + +After its creation, information on an embossing request may be retrieved by its id. + +```elixir +StarkInfra.IssuingEmbossingRequest.get!("5792731695677440") +|> IO.inspect +``` + +### Query IssuingEmbossingRequest logs + +Logs are pretty important to understand the life cycle of an embossing request. + +```elixir +StarkInfra.IssuingEmbossingRequest.Log.query!( + limit: 150 +) +|> Enum.take(150) +|> IO.inspect +``` + +### Get an IssuingEmbossingRequest log + +You can get a single log by its id. + +```elixir +StarkInfra.IssuingEmbossingRequest.Log.get!("5792731695677440") +|> IO.inspect +``` + ### Process 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. ```elixir @@ -552,7 +781,7 @@ StarkInfra.IssuingPurchase.query!( ### Get an IssuingPurchase -After its creation, information on a purchase may be retrieved by its id. +After its creation, information on a purchase may be retrieved by its id. ```elixir StarkInfra.IssuingPurchase.get!("5155165527080960") @@ -575,7 +804,7 @@ StarkInfra.IssuingPurchase.Log.query!( ### Get an IssuingPurchase log -You can get a single log by its id. +You can get a specific log by its id. ```elixir StarkInfra.IssuingPurchase.Log.get!("5155165527080960") @@ -584,7 +813,7 @@ StarkInfra.IssuingPurchase.Log.get!("5155165527080960") ### Create IssuingInvoices -Issuing invoices are requests to transfer money to your Issuing Balance. When an Issuing Invoice you created is paid, the amount will be added to your Issuing Balance. +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. ```elixir StarkInfra.IssuingInvoice.create!([ @@ -594,7 +823,7 @@ StarkInfra.IssuingInvoice.create!([ ]) |> IO.inspect ``` -**Note**: Instead of using Invoice structs, you can also pass each invoice element in dictionary format +**Note**: Instead of using IssuingInvoice objects, you can also pass each element in dictionary format ### Get an IssuingInvoice @@ -636,7 +865,7 @@ StarkInfra.IssuingInvoice.Log.query!( ### Get an IssuingInvoice log -You can get a single log by its id. +You can also get a specific log by its id. ```elixir StarkInfra.IssuingInvoice.Log.get!("5155165527080960") @@ -645,8 +874,7 @@ StarkInfra.IssuingInvoice.Log.get!("5155165527080960") ### Create IssuingWithdrawals -You can create withdrawals to send cash back from your Issuing balance to your Banking balance -by using the Withdrawal resource. +You can create withdrawals to send cash back from your Issuing balance to your Banking balance by using the IssuingWithdrawal resource. ```elixir StarkInfra.IssuingWithdrawal.create!( @@ -658,7 +886,7 @@ StarkInfra.IssuingWithdrawal.create!( ) |> IO.inspect ``` -**Note**: Instead of using Withdrawal structs, you can also pass each withdrawal element in dictionary format +**Note**: Instead of using IssuingWithdrawal objects, you can also pass each element in dictionary format ### Get an IssuingWithdrawal @@ -671,7 +899,7 @@ StarkInfra.IssuingWithdrawal.get!("5155165527080960") ### Query IssuingWithdrawals -You can get a list of created invoices given some filters. +You can create withdrawals to send cash back from your Issuing balance to your Banking balance by using the IssuingWithdrawal resource. ```elixir StarkInfra.IssuingWithdrawal.query!( @@ -717,6 +945,42 @@ StarkInfra.IssuingTransaction.get!("5155165527080960") |> IO.inspect ``` +### Issuing Enums + +#### Query MerchantCategories + +You can query any merchant categories using this resource. +You may also use MerchantCategories to define specific category filters in IssuingRules. +Either codes (which represents specific MCCs) or types (code groups) will be accepted as filters. + +```elixir +categories = StarkInfra.MerchantCategory.query!(search: "food") +|> Enum.take(10) +|> IO.inspect +``` + +#### Query MerchantCountries + +You can query any merchant countries using this resource. +You may also use MerchantCountries to define specific country filters in IssuingRules. + +```elixir +countries = StarkInfra.MerchantCountry.query!(search: "brazil") +|> Enum.take(10) +|> IO.inspect +``` + +#### Query CardMethods + +You can query available card methods using this resource. +You may also use CardMethods to define specific purchase method filters in IssuingRules. + +```elixir +methods = StarkInfra.CardMethod.query!(search: "token") +|> Enum.take(1) +|> IO.inspect +``` + ## Pix ### Create PixRequests @@ -744,11 +1008,11 @@ StarkInfra.PixRequest.create!([ ]) |> IO.inspect ``` -**Note**: Instead of using PixRequest structs, you can also pass each element in dictionary format +**Note**: Instead of using PixRequest objects, you can also pass each element in dictionary format ### Query PixRequests -You can query multiple Pix requests according to filters. +You can query multiple PixRequests according to filters. ```elixir StarkInfra.PixRequest.query!( @@ -764,16 +1028,47 @@ StarkInfra.PixRequest.query!( ### Get a PixRequest -After its creation, information on a Pix request may be retrieved by its id. Its status indicates whether it has been paid. +After its creation, information on a Pix request may be retrieved by its id. +Its status indicates whether it has been paid. ```elixir StarkInfra.PixRequest.get!("5155165527080960") |> IO.inspect ``` +### Process inbound PixRequest authorizations + +It's easy to process authorization requests that arrived at your endpoint. +Remember to pass the signature header so the SDK can make sure it's StarkInfra that sent you the event. +If you do not approve or decline the authorization within 1 second, the authorization will be denied. + +```elixir +request = listen() # this is the method you made to get the events posted to your webhook + +{pix_request, _cache_pid} = StarkInfra.PixRequest.parse!( + content: request.content, + signature: request.headers["Digital-Signature"] +) + +send_response( # you should also implement this method + StarkInfra.PixRequest.response!( + "approved" + ) +) + +# or + +send_response( + StarkInfra.PixRequest.response!( + "denied", + reason: "orderRejected" + ) +) +``` + ### Query PixRequest logs -You can query Pix request logs to better understand Pix request life cycles. +You can query Pix request logs to better understand Pix request life cycles. ```elixir logs = StarkInfra.PixRequest.Log.query!( @@ -808,7 +1103,7 @@ StarkInfra.PixReversal.create!([ ### Query PixReversals -You can query multiple Pix reversals according to filters. +You can query multiple Pix reversals according to filters. ```elixir StarkInfra.PixReversal.query!( @@ -833,9 +1128,39 @@ StarkInfra.PixReversal.get!("5155165527080960") |> IO.inspect ``` +### Process inbound PixReversal authorizations + +It's easy to process authorization requests that arrived at your endpoint. +Remember to pass the signature header so the SDK can make sure it's StarkInfra that sent you the event. +If you do not approve or decline the authorization within 1 second, the authorization will be denied. + +```elixir +request = listen() # this is the method you made to get the events posted to your webhook + +{reversal, _cache_pid} = StarkInfra.PixReversal.parse!( + content: request.content, + signature: request.headers["Digital-Signature"] +) + +send_response( # you should also implement this method + StarkInfra.PixReversal.response!( + "approved" + ) +) + +# or + +send_response( + StarkInfra.PixReversal.response!( + "denied", + reason: "orderRejected" + ) +) +``` + ### Query PixReversal logs -You can query Pix reversal logs to better understand their life cycles. +You can query Pix reversal logs to better understand their life cycles. ```elixir StarkInfra.PixReversal.Log.query!( @@ -880,7 +1205,7 @@ statement = StarkInfra.PixStatement.create!( ### Query PixStatements -You can query multiple Pix statements according to filters. +You can query multiple PixStatements according to filters. ```elixir statements = StarkInfra.PixStatement.query!( @@ -912,7 +1237,7 @@ File.close(file) ### Create a PixKey -You can create a Pix Key to link a bank account information to a key id: +You can create a Pix key to link a bank account information to a key id: ```elixir key = StarkInfra.PixKey.create!( @@ -930,7 +1255,7 @@ key = StarkInfra.PixKey.create!( ### Query PixKeys -You can query multiple Pix keys you own according to filters. +You can query multiple Pix keys according to filters. ```elixir keys = StarkInfra.PixKey.query!( @@ -956,7 +1281,7 @@ StarkInfra.PixKey.get!("+5511989898989", "012.345.678-90") |> IO.inspect ``` -### Patch a PixKey +### Update a PixKey Update the account information linked to a Pix Key. @@ -1023,7 +1348,7 @@ StarkInfra.PixClaim.create!( ### Query PixClaims -You can query multiple Pix claims according to filters. +You can query multiple PixClaims according to filters. ```elixir StarkInfra.PixClaim.query!( @@ -1049,7 +1374,7 @@ StarkInfra.PixClaim.get!("5729405850615808") |> IO.inspect ``` -### Patch a PixClaim +### Update a PixClaim A Pix Claim can be confirmed or canceled by patching its status. A received Pix Claim must be confirmed by the donor to be completed. @@ -1061,7 +1386,7 @@ StarkInfra.PixClaim.update!( "5729405850615808", status: "confirmed" ) |> IO.inspect -``` +``` ### Query PixClaim logs @@ -1105,8 +1430,7 @@ StarkInfra.PixDirector.create!( ### Create PixInfractions -Pix infractions are used to report transactions that raise fraud suspicion, to request a refund or to -reverse a refund. Pix infractions can be created by either participant of a transaction. +Pix infractions are used to report transactions that raise fraud suspicion, to request a refund or to reverse a refund. Pix infractions can be created by either participant of a transaction. ```elixir StarkInfra.PixInfraction.create!([ @@ -1119,7 +1443,7 @@ StarkInfra.PixInfraction.create!([ ### Query PixInfractions -You can query multiple Pix infractions according to filters. +You can query multiple infraction reports according to filters. ```elixir StarkInfra.PixInfraction.query!( @@ -1164,7 +1488,7 @@ StarkInfra.PixInfraction.cancel!("5155165527080960") ### Query PixInfraction logs -You can query Pix infractions logs to better understand their life cycles. +You can query infraction report logs to better understand their life cycles. ```elixir StarkInfra.PixInfraction.Log.query!( @@ -1190,8 +1514,7 @@ StarkInfra.PixInfraction.Log.get!("5155165527080960") ### Create PixChargebacks -A Pix chargeback can be created when fraud is detected on a transaction or a system malfunction -results in an erroneous transaction. +A Pix chargeback can be created when fraud is detected on a transaction or a system malfunction results in an erroneous transaction. ```elixir StarkInfra.PixChargeback.create!( @@ -1254,7 +1577,7 @@ StarkInfra.PixChargeback.cancel!("5155165527080960") ### Query PixChargeback logs -You can query Pix chargeback logs to better understand Pix chargeback life cycles. +You can query PixChargeback logs to better understand PixChargeback life cycles. ```elixir StarkInfra.PixChargeback.Log.query!( @@ -1279,18 +1602,223 @@ StarkInfra.PixChargeback.Log.get!("5155165527080960") ### Query PixDomains -You can query for domains of registered SPI participants able to issue dynamic QR Codes. +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. ```elixir StarkInfra.PixDomain.query!() |> IO.inspect ``` -## Credit Note +### Create StaticBrcodes + +StaticBrcodes store account information via a BR Code or an image (QR code) +that represents a PixKey and a few extra fixed parameters, such as an amount +and a reconciliation ID. They can easily be used to receive Pix transactions. + +```elixir +brcode = StarkInfra.StaticBrcode.create!( + [ + %StarkInfra.StaticBrcode { + name: "Jamie Lannister", + key_id: "+5511988887777", + amount: 10000, + reconciliation_id: "123", + city: "São Paulo" + } + ] +) +|> Enum.take(100) +|> IO.inspect +``` + +### Query StaticBrcodes + +You can query multiple StaticBrcodes according to filters. + +```elixir +brcodes = StarkInfra.StaticBrcode.query!(limit: 10) +|> Enum.take(1) +|> IO.inspect +``` + +### Get a StaticBrcode + +After its creation, information on a StaticBrcode may be retrieved by its UUID. + +```elixir +StarkInfra.StaticBrcode.Log.get!("5155165527080960") +|> IO.inspect +``` + + ### Create DynamicBrcodes + +BR codes store information represented by Pix QR Codes, which are used to send +or receive Pix transactions in a convenient way. +DynamicBrcodes represent charges with information that can change at any time, +since all data needed for the payment is requested dynamically to an URL stored +in the BR Code. Stark Infra will receive the GET request and forward it to your +registered endpoint with a GET request containing the UUID of the BR Code for +identification. + +```elixir +brcodes = StarkInfra.DynamicBrcode.create!( + [ + %StarkInfra.DynamicBrcode { + name: "Jamie Lannister", + city: "Rio de Janeiro", + external_id: "my-external-id-1!", + type: brcode.type + } + ] +) +|> Enum.take(10) +|> IO.inspect +``` + +### Query DynamicBrcodes + +You can query multiple DynamicBrcodes according to filters. + +```elixir +brcodes = StarkInfra.DynamicBrcode.query!(limit: 10) +|> Enum.take(1) +|> IO.inspect +``` + +### Get a DynamicBrcode + +After its creation, information on a DynamicBrcode may be retrieved by its UUID. + +```elixir +StarkInfra.DynamicBrcode.Log.get!("5155165527080960") +|> IO.inspect +``` + +### Verify a DynamicBrcode read + +When a DynamicBrcode is read by your user, a GET request will be made to your registered URL to retrieve additional information needed to complete the transaction. +Use this method to verify the authenticity of a GET request received at your registered endpoint. +If the provided digital signature does not check out with the StarkInfra public key, a Stark.Exception.InvalidSignatureException will be raised. + +```elixir +request = listen() # this is the method you made to get the read requests posted to your registered endpoint + +uuid = StarkInfra.DynamicBrcode.verify!( + content: request.url.get_parameter("uuid"), + signature: request.headers["Digital-Signature"], +) +|> IO.inspect +``` + +### Answer to a Due DynamicBrcode read + +When a Due DynamicBrcode is read by your user, a GET request containing +the BR Code UUID will be made to your registered URL to retrieve additional +information needed to complete the transaction. + +The GET request must be answered in the following format within 5 seconds +and with an HTTP status code 200. + +```elixir +request = listen() # this is the method you made to get the read requests posted to your registered endpoint + +uuid = StarkInfra.DynamicBrcode.verify!( + content: request.url.get_parameter("uuid"), + signature: request.headers["Digital-Signature"], +) + +invoice = get_my_invoice(uuid) # you should implement this method to get the information of the BR Code from its uuid + +send_response( # you should also implement this method to respond the read request + starkinfra.dynamicbrcode.response_due( + version=invoice.version, + created=invoice.created, + due=invoice.due, + key_id=invoice.key_id, + status=invoice.status, + reconciliation_id=invoice.reconciliation_id, + amount=invoice.amount, + sender_name=invoice.sender_name, + receiver_name=invoice.receiver_name, + 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. + +```elixir +request = listen() # this is the method you made to get the read requests posted to your registered endpoint + +uuid = StarkInfra.DynamicBrcode.verify!( + content: request.url.get_parameter("uuid"), + signature: request.headers["Digital-Signature"], +) + +invoice = get_my_invoice(uuid) # you should implement this method to get the information of the BR Code from its uuid + +send_response( # you should also implement this method to respond the read request + starkinfra.issuingpurchase.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. + +```elixir +StarkInfra.BrcodePreview.create([ + %StarkInfra.BrcodePreview{ + id: "00020126420014br.gov.bcb.pix0120nedstark@hotmail.com52040000530398654075000.005802BR5909Ned Stark6014Rio de Janeiro621605126674869738606304FF71" + }, + %StarkInfra.BrcodePreview{ + id: "00020126430014br.gov.bcb.pix0121aryastark@hotmail.com5204000053039865406100.005802BR5910Arya Stark6014Rio de Janeiro6216051262678188104863042BA4" + } +]) +|> IO.inspect +``` + +## Lending +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: + 1. Have funds in your Credit Fund or Securitization account + 2. Request the creation of an [Identity Check](#create-individualidentities) +for the credit receiver (make sure you have their documents and express authorization) + 3. (Optional) Create a [Credit Simulation](#create-creditpreviews) +with the desired installment plan to display information for the credit receiver + 4. Create a [Credit Note](#create-creditnotes) +with the desired installment plan ### Create CreditNotes -You can create a Credit Note to generate a CCB contract: +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. ```elixir StarkInfra.CreditNote.create!([ @@ -1334,11 +1862,11 @@ StarkInfra.CreditNote.create!([ ]) |> IO.inspect ``` -**Note**: Instead of using CreditNote structs, you can also pass each CreditNote element in map format +**Note**: Instead of using CreditNote objects, you can also pass each element in map format ### Query CreditNotes -You can query multiple credit notes according to filters. +You can query multiple CreditNotes according to filters. ```elixir StarkInfra.CreditNote.query!( @@ -1372,7 +1900,7 @@ StarkInfra.CreditNote.cancel!("5155165527080960") ### Query CreditNote logs -You can query credit note logs to better understand credit note life cycles. +You can query CreditNote logs to better understand CreditNote life cycles. ```elixir StarkInfra.CreditNote.Log.query!( @@ -1393,11 +1921,333 @@ StarkInfra.CreditNote.log.get!("5155165527080960") |> IO.inspect ``` +### Create CreditPreviews + +You can preview a credit operation before creating them (Currently we only have CreditNote / CCB previews): + +```elixir +previews = StarkInfra.CreditPreview.create!( + [ + %StarkInfra.CreditPreview{ + type: "credit-note", + credit: %StarkInfra.CreditNotePreview{ + tax_id: "012.345.678-90", + type: "sac", + nominal_amount: 100000, + rebate_amount: 1000, + nominal_interest: 2.5, + scheduled: "2023-04-28", + initial_due: "2023-12-28", + initial_amount: 9999, + interval: "month" + } + }, + %StarkInfra.CreditPreview{ + type: "credit-note", + credit: %StarkInfra.CreditNotePreview{ + tax_id: "012.345.678-90", + type: "bullet", + nominal_amount: 100000, + rebate_amount: 1000, + nominal_interest: 2.5, + scheduled: "2023-04-28", + initial_due: "2023-12-28", + } + }, + %StarkInfra.CreditPreview{ + type: "credit-note", + credit: %StarkInfra.CreditNotePreview{ + tax_id: "012.345.678-90", + type: "price", + nominal_amount: 100000, + rebate_amount: 1000, + nominal_interest: 2.5, + scheduled: "2023-04-28", + initial_due: "2023-12-28", + initial_amount: 9999, + interval: "month" + } + }, + %StarkInfra.CreditPreview{ + type: "credit-note", + credit: %StarkInfra.CreditNotePreview{ + tax_id: "012.345.678-90", + type: "american", + nominal_amount: 100000, + rebate_amount: 1000, + nominal_interest: 2.5, + scheduled: "2023-04-28", + initial_due: "2023-12-28", + count: 12, + interval: "year" + } + } + ] +) +|> IO.inspect +``` + +**Note**: 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. + +```elixir +previews = StarkInfra.CreditHolmes.create!( + [ + %StarkInfra.CreditHolmes{ + tax_id: "123.456.789-00", + competence: "2022-09" + }, + %StarkInfra.CreditHolmes{ + tax_id: "123.456.789-00", + competence: "2022-08" + }, + %StarkInfra.CreditHolmes{ + tax_id: "123.456.789-00", + competence: "2022-07" + } + ] +) +|> IO.inspect +``` + +### Query CreditHolmes + +You can query multiple credit holmes according to filters. + +```elixir +StarkInfra.CreditHolmes.query!( + status: "sucess", + after: "2020-11-01", + before: "2020-11-02" +) +|> Enum.take(10) +|> IO.inspect +``` + +### Get an CreditHolmes + +After its creation, information on a credit holmes may be retrieved by its id. + +```elixir +StarkInfra.CreditHolmes.get!("5155165527080960") +|> IO.inspect +``` + +### Query CreditHolmes logs + +You can query credit holmes logs to better understand their life cycles. + +```elixir +StarkInfra.CreditHolmes.Log.query!( + limit: 50, + id: ["5729405850615808"] + after: "2020-11-01", + before: "2020-11-02" + types: ["created"] +) +|> Enum.take(10) +|> IO.inspect +``` + +### Get an CreditHolmes log + +You can also get a specific log by its id. + +```elixir +StarkInfra.CreditHolmes.Log.get!("5155165527080960") +|> IO.inspect +``` + +## Identity +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: +1. The Identity resource is created for a specific Tax ID +2. Documents are attached to the Identity resource +3. The Identity resource is updated to indicate that all documents have been attached +4. 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 + +```elixir +previews = StarkInfra.IndividualIdentity.create!( + [ + %StarkInfra.IndividualIdentity{ + name: "Walter White", + tax_id: "123.456.789-00", + tags: ["breaking", "bad"] + } + ] +) +|> IO.inspect +``` + +**Note**: 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. + +```elixir +StarkInfra.IndividualIdentity.query!( + limit: 10, + after: "2020-11-01", + before: "2020-11-02", + before: "success", + tags: ["breaking", "bad"] +) +|> Enum.take(10) +|> IO.inspect +``` + +### Get an IndividualIdentity + +After its creation, information on an individual identity may be retrieved by its id. + +```elixir +StarkInfra.IndividualIdentity.get!("5155165527080960") +|> IO.inspect +``` + +### Update an IndividualIdentity + +You can update a specific identity status to "processing" for send it to validation. + +```elixir +StarkInfra.IndividualIdentity.update!("5155165527080960", status: "processing") +|> IO.inspect +``` + +**Note**: 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. + +```elixir +StarkInfra.IndividualIdentity.cancel!("5155165527080960") +|> IO.inspect +``` + +### Query IndividualIdentity logs + +You can query individual identity logs to better understand individual identity life cycles. + +```elixir +StarkInfra.IndividualIdentity.Log.query!( + limit: 50, + after: "2020-11-01", + before: "2020-11-02" +) +|> Enum.take(50) +|> IO.inspect +``` + +### Get an IndividualIdentity log + +You can also get a specific log by its id. + +```elixir +StarkInfra.IndividualIdentity.Log.get!("5155165527080960") +|> IO.inspect +``` + +### 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. + +```elixir +previews = StarkInfra.IndividualDocument.create!( + [ + %StarkInfra.IndividualDocument{ + type: "identity-front", + content: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD...", + identity_id: "5155165527080960", + tags: ["breaking", "bad"] + }, + %StarkInfra.IndividualDocument{ + type: "identity-back", + content: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD...", + identity_id: "5155165527080960", + tags: ["breaking", "bad"] + }, + %StarkInfra.IndividualDocument{ + type: "selfie", + content: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD...", + identity_id: "5155165527080960", + tags: ["breaking", "bad"] + } + ] +) +|> IO.inspect +``` + +**Note**: Instead of using IndividualDocument objects, you can also pass each element in dictionary format + +### Query IndividualDocument + +You can query multiple individual documents according to filters. + +```elixir +StarkInfra.IndividualDocument.query!( + limit: 10, + after: "2020-11-01", + before: "2020-11-02", + status: "success", + tags: ["breaking", "bad"] +) +|> Enum.take(10) +|> IO.inspect +``` + +### Get an IndividualDocument + +After its creation, information on an individual document may be retrieved by its id. + +```elixir +StarkInfra.IndividualDocument.get!("5155165527080960") +|> IO.inspect +``` + +### Query IndividualDocument logs + +You can query individual document logs to better understand individual document life cycles. + +```elixir +StarkInfra.IndividualDocument.Log.query!( + limit: 10, + after: "2020-11-01", + before: "2020-11-02" +) +|> Enum.take(10) +|> IO.inspect +``` + +### Get an IndividualDocument log + +You can also get a specific log by its id. + +```elixir +StarkInfra.IndividualDocument.Log.get!("5155165527080960") +|> IO.inspect +``` + ## Webhook -### Create a Webhook subscription +### Create a Webhook -To create a webhook subscription and be notified whenever an event occurs, run: +To create a Webhook and be notified whenever an event occurs, run: ```elixir StarkInfra.Webhook.create!( @@ -1416,7 +2266,7 @@ for webhook <- StarkInfra.Webhook.query!() do end ``` -### Get a Webhook subscription +### Get a Webhook You can get a specific webhook by its id. @@ -1425,7 +2275,7 @@ StarkInfra.Webhook.get!("6178044066660352") |> IO.inspect ``` -### Delete a Webhook subscription +### Delete a Webhook You can also delete a specific webhook by its id. @@ -1434,8 +2284,6 @@ StarkInfra.Webhook.delete!("6178044066660352") |> IO.inspect ``` -## Webhook events - ### Process Webhook events It's easy to process events delivered to your Webhook endpoint. @@ -1464,12 +2312,9 @@ and automatically refresh it if an inconsistency is found between the content, s ) |> IO.inspect ``` -If the data does not check out with the Stark Bank public-key, the function will automatically request the -key from the API and try to validate the signature once more. If it still does not check out, it will raise an error. - ### Query Webhook events -To search for webhooks events, run: +To search for Webhooks events, run: ```elixir StarkInfra.Event.query!( @@ -1483,7 +2328,7 @@ StarkInfra.Event.query!( ### Get a Webhook event -You can get a specific webhook event by its id. +You can get a specific Webhook event by its id. ```elixir StarkInfra.Event.get!("4568139664719872") @@ -1492,7 +2337,7 @@ StarkInfra.Event.get!("4568139664719872") ### Delete a Webhook event -You can also delete a specific webhook event by its id. +You can also delete a specific Webhook event by its id. ```elixir StarkInfra.Event.delete!("4568139664719872") @@ -1522,7 +2367,7 @@ end ### Get a failed Webhook event delivery attempt information -To retrieve information on a single attempt, use the following function: +To retrieve information on a specific attempt, use the following function: ```elixir StarkInfra.Event.Attempt.get("1616161616161616") @@ -1531,10 +2376,10 @@ StarkInfra.Event.Attempt.get("1616161616161616") # Handling errors -The SDK may raise or return errors as the StarkInfra.Error struct, which contains the "code" and "message" attributes. +The SDK may raise or return errors as the StarkInfra.Error object, which contains the "code" and "message" attributes. -If you use bang functions, the list of errors will be converted into a string and raised. -If you use normal functions, the list of error structs will be returned so you can better analyse them. +If you use bang functions, the list of errors will be converted into a binary and raised. +If you use normal functions, the list of error objects will be returned so you can better analyse them. # Help and Feedback diff --git a/lib/brcode_preview/brcode_preview.ex b/lib/brcode_preview/brcode_preview.ex new file mode 100644 index 0000000..dc6ada0 --- /dev/null +++ b/lib/brcode_preview/brcode_preview.ex @@ -0,0 +1,147 @@ +defmodule StarkInfra.BrcodePreview do + alias __MODULE__, as: BrcodePreview + alias StarkInfra.Error + alias StarkInfra.Utils.Rest + alias StarkInfra.User.Organization + + @moduledoc """ + Groups BrcodePreview related functions + """ + + @doc """ + The BrcodePreview object is used to preview information from a BR Code before paying it. + + When you initialize a BrcodePreview, the entity will not be automatically + created in the Stark Infra API. The 'create' function sends the objects + to the Stark Infra API and returns the created object. + + ## Parameters (required): + - `:id` [binary]: BR Code string for a Pix payment also the information directly encoded in a QR Code. ex: "00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T'Challa6009Sao Paulo62090505123456304B14A" + + ## Attributes (return-only): + - `:account_number` [binary]: Payment receiver account number. ex: "1234567" + - `:account_type` [binary]: Payment receiver account type. ex: "checking" + - `:amount` [integer]: Value in cents that this payment is expecting to receive. If 0, any value is accepted. ex: 123 (= R$1,23) + - `:amount_type` [binary]: amount type of the BR Code. If the amount type is "custom" the BR Code's amount can be changed by the sender at the moment of payment. ex: "fixed" or "custom" + - `:bank_code` [binary]: Payment receiver bank code. ex: "20018183" + - `:branch_code` [binary]: Payment receiver branch code. ex: "0001" + - `:cash_amount` [integer]: Amount to be withdrawn from the cashier in cents. ex: 1000 (= R$ 10.00) + - `:cashier_bank_code` [binary]: Cashier's bank code. ex: "20018183" + - `:cashier_type` [binary]: Cashier's type. ex: "merchant", "participant" and "other" + - `:discount_amount` [integer]: Discount value calculated over nominal_amount. ex: 3000 + - `:fine_amount` [integer]: Fine value calculated over nominal_amount. ex: 20000 + - `:interest_amount` [integer]: Interest value calculated over nominal_amount. ex: 10000 + - `:key_id` [binary]: Receiver's PixKey id. ex: "+5511989898989" + - `:name` [binary]: Payment receiver name. ex: "Tony Stark" + - `:nominal_amount` [integer]: Brcode emission amount, without fines, fees and discounts. ex: 1234 (= R$ 12.34) + - `:reconciliation_id` [binary]: Reconciliation ID linked to this payment. If the brcode is dynamic, the reconciliation_id will have from 26 to 35 alphanumeric characters, ex: "cd65c78aeb6543eaaa0170f68bd741ee". If the brcode is static, the reconciliation_id will have up to 25 alphanumeric characters "ah27s53agj6493hjds6836v49" + - `:reduction_amount` [integer]: Reduction value to discount from nominal_amount. ex: 1000 + - `:scheduled` [DateTime]: date of payment execution. ex: ~U[2020-3-10 10:30:0:0] + - `:status` [binary]: Payment status. ex: "active", "paid", "canceled" or "unknown" + - `:tax_id` [binary]: Payment receiver tax ID. ex: "012.345.678-90" + """ + @enforce_keys [ + :id + ] + defstruct [ + :id, + :account_number, + :account_type, + :amount, + :amount_type, + :bank_code, + :branch_code, + :cash_amount, + :cashier_bank_code, + :cashier_type, + :discount_amount, + :fine_amount, + :interest_amount, + :key_id, + :name, + :nominal_amount, + :reconciliation_id, + :reduction_amount, + :scheduled, + :status, + :tax_id, + ] + + @type t() :: %__MODULE__{} + + @doc """ + Process BR Codes before paying them. + + ## Parameters (required): + - `:previews` [list of BrcodePreview objects]: List of BrcodePreview objects to preview. ex: [StarkInfra.BrcodePreview("00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T'Challa6009Sao Paulo62090505123456304B14A")] + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of BrcodePreview objects with updated attributes + """ + @spec create( + [BrcodePreview.t() | map()], + user: Project.t() | Organization.t() | nil + ) :: + {:ok, [BrcodePreview.t()]} | + {:error, [Error.t()]} + def create(previews, options \\ []) do + Rest.post( + resource(), + previews, + options + ) + end + + @doc """ + Same as create(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec create!( + [BrcodePreview.t() | map()], + user: Project.t() | Organization.t() | nil + ) :: any + def create!(previews, options \\ []) do + Rest.post!( + resource(), + previews, + options + ) + end + + @doc false + def resource() do + { + "BrcodePreview", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %BrcodePreview{ + id: json[:id], + account_number: json[:account_number], + account_type: json[:account_type], + amount: json[:amount], + amount_type: json[:amount_type], + bank_code: json[:bank_code], + branch_code: json[:branch_code], + cash_amount: json[:cash_amount], + cashier_bank_code: json[:cashier_bank_code], + cashier_type: json[:cashier_type], + discount_amount: json[:discount_amount], + fine_amount: json[:fine_amount], + interest_amount: json[:interest_amount], + key_id: json[:key_id], + name: json[:name], + nominal_amount: json[:nominal_amount], + reconciliation_id: json[:reconciliation_id], + reduction_amount: json[:reduction_amount], + scheduled: json[:scheduled], + status: json[:status], + tax_id: json[:tax_id] + } + end +end diff --git a/lib/card_method/card_method.ex b/lib/card_method/card_method.ex new file mode 100644 index 0000000..144ec40 --- /dev/null +++ b/lib/card_method/card_method.ex @@ -0,0 +1,87 @@ +defmodule StarkInfra.CardMethod do + alias __MODULE__, as: CardMethod + alias StarkInfra.Error + alias StarkInfra.Utils.Rest + alias StarkInfra.User.Organization + + @moduledoc """ + Groups CardMethod related functions + """ + + @doc """ + CardMethod's codes are used to define methods filters in IssuingRules. + + ## Parameters (required): + - `:code` [binary]: method's code. ex: "chip", "token", "server", "manual", "magstripe", "contactless" + + ## Attributes (return-only): + - `:name` [binary]: method's name. ex: "token" + - `:number` [binary]: method's number. ex: "81" + """ + @enforce_keys [ + :code, + ] + defstruct [ + :code, + :name, + :number + ] + + @type t() :: %__MODULE__{} + + @doc """ + Receive a stream of CardMethod objects available in the Stark Infra API + + ## Parameters (optional): + - `:search` [binary, default nil]: keyword to search for code, name or number. ex: "token" + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - stream of CardMethod objects with updated attributes + """ + @spec query( + search: binary, + user: Project.t() | Organization.t() | nil + ) :: + ({:cont, {:ok, [CardMethod.t()]}} | + {:error, [Error.t()]} | + {:halt, any} | + {:suspend, any}, + any -> any) + def query(options \\ []) do + Rest.get_list(resource(), options) + end + + @doc """ + Same as query(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec query!( + search: binary, + user: Project.t() | Organization.t() | nil + ) :: + ({:cont, [CardMethod.t()]} | + {:error, [Error.t()]} | + {:halt, any} | + {:suspend, any}, + any -> any) + def query!(options \\ []) do + Rest.get_list!(resource(), options) + end + + @doc false + def resource() do + { + "CardMethod", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %CardMethod{ + code: json[:code], + name: json[:name], + number: json[:number] + } + end +end diff --git a/lib/credit_holmes/credit_holmes.ex b/lib/credit_holmes/credit_holmes.ex new file mode 100644 index 0000000..e8e00d2 --- /dev/null +++ b/lib/credit_holmes/credit_holmes.ex @@ -0,0 +1,264 @@ +defmodule StarkInfra.CreditHolmes do + alias __MODULE__, as: CreditHolmes + alias StarkInfra.Utils.Rest + alias StarkInfra.User.Project + alias StarkInfra.User.Organization + alias StarkInfra.Error + + @moduledoc """ + Groups CreditHolmes related functions + """ + + @doc """ + CreditHolmes are used to obtain debt information on your customers. + Before you create a CreditHolmes, make sure you have your customer's express + authorization to verify their information in the Central Bank's SCR. + + When you initialize a CreditHolmes, the entity will not be automatically + created in the Stark Infra API. The 'create' function sends the objects + to the Stark Infra API and returns the list of created objects. + + ## Parameters (required): + - `:tax_id` [binary]: customer's tax ID (CPF or CNPJ) for whom the credit operations will be verified. ex: "20.018.183/0001-80" + + ## Parameters (optional): + - `:competence` [binary, default 'two months before current date']: competence month of the operation verification, format: "YYYY-MM". ex: "2021-04" + - `:tags` [list of binaries]: list of binaries for reference when searching for CreditHolmes. ex: [credit", "operation"] + + ## Attributes (return-only): + - `:id` [binary]: unique id returned when CreditHolmes is created. ex: "5656565656565656" + - `:result` [binary]: result of the investigation after the case is solved. + - `:status` [binary]: current status of the CreditHolmes. ex: "created", "failed", "success" + - `:updated` [DateTime]: latest update DateTime for the CreditHolmes. ex: ~U[2020-3-10 10:30:0:0] + - `:created` [DateTime]: creation datetime for the CreditHolmes. ex: ~U[2020-03-10 10:30:0:0] + """ + + @enforce_keys [ + :tax_id + ] + defstruct [ + :tax_id, + :competence, + :tags, + :id, + :result, + :status, + :updated, + :created + ] + + @type t() :: %__MODULE__{} + + @doc """ + Send a list of CreditHolmes objects for creation in the Stark Infra API. + + ## Parameters (required): + - `:holmes` [list of CreditHolmes objects]: list of CreditHolmes objects to be created in the API + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of CreditHolmes objects with updated attributes + """ + @spec create( + [CreditHolmes.t() | map], + user: Organization.t() | Project.t() | nil + ) :: + {:ok, [CreditHolmes.t()]} | + {:error, [Error.t()]} + def create(holmes, options \\ []) do + Rest.post( + resource(), + holmes, + options + ) + end + + @doc """ + Same as create(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec create!( + [CreditHolmes.t() | map], + user: Organization.t() | Project.t() | nil + ) :: any + def create!(holmes, options \\ []) do + Rest.post!( + resource(), + holmes, + options + ) + end + + @doc """ + Receive a stream of CreditHolmes objects previously created in the Stark Infra API. + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:status` [binary, default nil]: filter for status of retrieved objects. ex: "created", "failed", "success" + - `:tags` [list of binaries, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - stream of CreditHolmes objects with updated attributes + """ + @spec query( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: binary, + tags: [binary], + ids: [binary], + user: (Organization.t() | Project.t() | nil) + ) :: + {:ok, [CreditHolmes.t()]} | + {:error, [Error.t()]} + def query(options \\ []) do + Rest.get_list( + resource(), + options + ) + end + + @doc """ + Same as query(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec query!( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: binary, + tags: [binary], + ids: [binary], + user: (Organization.t() | Project.t() | nil) + ) :: any + def query!(options \\ []) do + Rest.get_list!( + resource(), + options + ) + end + + @doc """ + Receive a list of up to 100 CreditHolmes objects previously created in the Stark Infra API and the cursor to the next page. + Use this function instead of query if you want to manually page your requests. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:status` [binary, default nil]: filter for status of retrieved objects. ex: "created", "failed", "success" + - `:tags` [list of binaries, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of CreditHolmes objects with updated attributes + - cursor to retrieve the next page of CreditHolmes objects + """ + @spec page( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: binary, + tags: [binary], + ids: [binary], + user: (Organization.t() | Project.t() | nil) + ) :: + {:ok, {binary, [CreditHolmes.t()]}} | + {:error, [Error.t()]} + def page(options \\ []) do + Rest.get_page( + resource(), + options + ) + end + + @doc """ + Same as page(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec page!( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: binary, + tags: [binary], + ids: [binary], + user: (Organization.t() | Project.t() | nil) + ) :: any + def page!(options \\ []) do + Rest.get_page!( + resource(), + options + ) + end + + @doc """ + Receive a single CreditHolmes object previously created in the Stark Infra API by its id. + + ## Parameters (required): + - `:id` [binary]: object unique id. ex: "5656565656565656" + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - CreditHolmes object with updated attributes + """ + @spec get( + id: binary, + user: (Organization.t() | Project.t() | nil) + ) :: + {:ok, CreditHolmes.t()} | + {:error, [Error.t()]} + def get(id, options \\ []) do + Rest.get_id( + resource(), + id, + options + ) + end + + @doc """ + Same as get(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec get!( + id: binary, + user: (Organization.t() | Project.t() | nil) + ) :: any + def get!(id, options \\ []) do + Rest.get_id!( + resource(), + id, + options + ) + end + + @doc false + def resource() do + { + "CreditHolmes", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %CreditHolmes{ + id: json[:id], + tax_id: json[:tax_id], + competence: json[:competence], + tags: json[:tags], + result: json[:result], + status: json[:status], + updated: json[:updated], + created: json[:created] + } + end +end diff --git a/lib/credit_holmes/credit_holmes_log.ex b/lib/credit_holmes/credit_holmes_log.ex new file mode 100644 index 0000000..77bcf6a --- /dev/null +++ b/lib/credit_holmes/credit_holmes_log.ex @@ -0,0 +1,187 @@ +defmodule StarkInfra.CreditHolmes.Log do + alias __MODULE__, as: Log + alias StarkInfra.Utils.Rest + alias StarkInfra.Utils.API + alias StarkInfra.Utils.Check + alias StarkInfra.CreditHolmes + alias StarkInfra.User.Project + alias StarkInfra.User.Organization + alias StarkInfra.Error + + @moduledoc """ + Groups CreditHolmes.Log related functions + """ + @doc """ + Every time an CreditHolmes entity is updated, a corresponding CreditHolmes.Log + is generated for the entity. This log is never generated by the user, but + it can be retrieved to check additional information on the CreditHolmes. + + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the log is created. ex: "5656565656565656" + - `:holmes` [CreditHolmes]: CreditHolmes entity to which the log refers to. + - `:errors` [list of binaries]: list of errors linked to this CreditHolmes event + - `:type` [binary]: type of the CreditHolmes event which triggered the log creation. ex: "created", "failed", "success" + - `:created` [DateTime, default nil]: creation DateTime for the Log. ex: ~U[2020-3-10 10:30:0:0] + """ + @enforce_keys [ + :id, + :holmes, + :errors, + :type, + :created + ] + defstruct [ + :id, + :holmes, + :errors, + :type, + :created + ] + + @type t() :: %__MODULE__{} + + @doc """ + Receive a single CreditHolmes.Log object previously created by the Stark Infra API by its id + + ## Parameters (required): + - `:id` [binary]: object unique id. ex: "5656565656565656" + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - CreditHolmes.Log object that corresponds to the given id. + """ + @spec get( + binary, + user: Project.t() | + Organization.t() | nil + ) :: + {:ok, [Log.t()]} | + {:error, [Error.t()]} + def get(id, options \\ []) do + Rest.get_id(resource(), id, options) + end + + @doc """ + Same as get(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec get!( + binary, + user: Project.t() | Organization.t() | nil + ) :: Log.t() + def get!(id, options \\ []) do + Rest.get_id!(resource(), id, options) + end + + @doc """ + Receive a stream of CreditHolmes.Log objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: datetime.date(2020, 3, 10) + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: datetime.date(2020, 3, 10) + - `:types` [list of strings, default nil]: filter for log event types. ex: ["canceled", "created", "expired", "failed", "refunded", "registered", "sending", "sent", "signed", "success"] + - `:holmes_ids` [list of strings, default nil]: list of CreditHolmes ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - stream of CreditHolmes.Log objects with updated attributes + """ + @spec query( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + holmes_ids: [binary], + user: Project.t() | Organization.t() + ) :: + ({:cont, {:ok, [Log.t()]}} | + {:error, [Error.t()]}, + any -> any) + def query(options \\ []) do + Rest.get_list(resource(), options) + end + + @doc """ + Same as query(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec query!( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + holmes_ids: [binary], + user: Project.t() | Organization.t() + ) :: [Log.t()] + def query!(options \\ []) do + Rest.get_list!(resource(), options) + end + + @doc """ + Receive a list of up to 100 CreditHolmes.Log objects previously created in the Stark Infra API and the cursor to the next page. + Use this function instead of query if you want to manually page your requests. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: datetime.date(2020, 3, 10) + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: datetime.date(2020, 3, 10) + - `:types` [list of strings, default nil]: filter for log event types. ex: ["canceled", "created", "expired", "failed", "refunded", "registered", "sending", "sent", "signed", "success"] + - `:holmes_ids` [list of strings, default nil]: list of CreditHolmes ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of CreditHolmes.Log objects with updated attributes + - cursor to retrieve the next page of CreditHolmes.Log objects + """ + @spec page( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + holmes_ids: [binary], + user: Project.t() | Organization.t() + ) :: + {:ok, {binary, [Invoice.t()]}} | + {:error, [Error.t()]} + def page(options \\ []) do + Rest.get_page(resource(), options) + end + + @doc """ + Same as page(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec page!( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + holmes_ids: [binary], + user: Project.t() | Organization.t() + ) :: + [Log.t()] + def page!(options \\ []) do + Rest.get_page!(resource(), options) + end + + @doc false + def resource() do + { + "CreditHolmesLog", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %Log{ + id: json[:id], + holmes: json[:holmes] |> API.from_api_json(&CreditHolmes.resource_maker/1), + created: json[:created] |> Check.datetime(), + type: json[:type], + errors: json[:errors] + } + end +end diff --git a/lib/credit_note/credit_note.ex b/lib/credit_note/credit_note.ex index 673752f..d312671 100644 --- a/lib/credit_note/credit_note.ex +++ b/lib/credit_note/credit_note.ex @@ -6,7 +6,7 @@ defmodule StarkInfra.CreditNote do alias StarkInfra.Utils.Check alias StarkInfra.User.Project alias StarkInfra.User.Organization - alias StarkInfra.CreditNote.Signer + alias StarkInfra.CreditSigner alias StarkInfra.CreditNote.Invoice alias StarkInfra.CreditNote.Transfer @@ -16,43 +16,45 @@ defmodule StarkInfra.CreditNote do @doc """ CreditNotes are used to generate CCB contracts between you and your customers. + When you initialize a CreditNote, the entity will not be automatically - created in the Stark Infra API. The 'create' function sends the structs - to the Stark Infra API and returns the list of created structs. + created in the Stark Infra API. The 'create' function sends the objects + to the Stark Infra API and returns the created object. ## Parameters (required): - - `:template_id` [string]: ID of the contract template on which the CreditNote will be based. ex: "0123456789101112" - - `:name` [string]: credit receiver's full name. ex: "Anthony Edward Stark" - - `:tax_id` [string]: credit receiver's tax ID (CPF or CNPJ). ex: "20.018.183/0001-80" + - `:template_id` [binary]: ID of the contract template on which the CreditNote will be based. ex: "0123456789101112" + - `:name` [binary]: credit receiver's full name. ex: "Anthony Edward Stark" + - `:tax_id` [binary]: credit receiver's tax ID (CPF or CNPJ). ex: "20.018.183/0001-80" - `:nominal_amount` [integer]: amount in cents transferred to the credit receiver, before deductions. ex: 11234 (= R$ 112.34) - - `:scheduled` [Date Datetime or string]: Date or datetime of transfer execution. ex: ~D[2020-03-10] - - `:invoices` [list of Invoice structs or maps]: list of Invoice structs to be created and sent to the credit receiver. ex: [%{ due: "2023-06-25", amount: 120000, fine: 10, interest: 2}] - - `:payment` [Transfer struct or map]: payment entity to be created and sent to the credit receiver. ex: %{ bankCode: "00000000", branchCode: "1234", accountNumber: "129340-1", name: "Jamie Lannister", taxId: "012.345.678-90"} - - `:signers` [list of Signer objects or maps]: name and e-mail of signers that sign the contract. ex: [%{"name": "Tony Stark", "contact": "tony@starkindustries.com", "method": "link"}] - - `:external_id` [string]: a string that must be unique among all your CreditNotes, used to avoid resource duplication. ex: “my-internal-id-123456” - - `:street_line_1` [string]: credit receiver main address. ex: "Av. Paulista, 200" - - `:street_line_2` [string]: credit receiver address complement. ex: "Apto. 123" - - `:district` [string]: credit receiver address district / neighbourhood. ex: "Bela Vista" - - `:city` [string]: credit receiver address city. ex: "Rio de Janeiro" - - `:state_code` [string]: credit receiver address state. ex: "GO" - - `:zip_code` [string]: credit receiver address zip code. ex: "01311-200" + - `:scheduled` [Date, Datetime or binary]: Date or datetime of transfer execution. ex: ~D[2020-03-10] + - `:invoices` [list of CreditNote.Invoice objects or maps]: list of Invoice objects to be created and sent to the credit receiver. ex: [%{ due: "2023-06-25", amount: 120000, fine: 10, interest: 2}] + - `:payment` [CreditNote.Transfer object or map]: payment entity to be created and sent to the credit receiver. ex: %{ bankCode: "00000000", branchCode: "1234", accountNumber: "129340-1", name: "Jamie Lannister", taxId: "012.345.678-90"} + - `:signers` [list of CreditSigner objects or maps]: name and e-mail of signers that sign the contract. ex: [%{"name": "Tony Stark", "contact": "tony@starkindustries.com", "method": "link"}] + - `:external_id` [binary]: a binary that must be unique among all your CreditNotes, used to avoid resource duplication. ex: “my-internal-id-123456” + - `:street_line_1` [binary]: credit receiver main address. ex: "Av. Paulista, 200" + - `:street_line_2` [binary]: credit receiver address complement. ex: "Apto. 123" + - `:district` [binary]: credit receiver address district / neighbourhood. ex: "Bela Vista" + - `:city` [binary]: credit receiver address city. ex: "Rio de Janeiro" + - `:state_code` [binary]: credit receiver address state. ex: "GO" + - `:zip_code` [binary]: credit receiver address zip code. ex: "01311-200" ## Parameters (conditionally required): - - `:payment_type` [string]: payment type, inferred from the payment parameter if it is not a dictionary. ex: "transfer" + - `:payment_type` [binary]: payment type, inferred from the payment parameter if it is not a dictionary. ex: "transfer" ## Parameters (optional): - `:rebate_amount` [integer, default 0]: credit analysis fee deducted from lent amount. ex: 11234 (= R$ 112.34) - - `:tags` [list of strings, default []]: list of strings for reference when searching for CreditNotes. ex: [\"employees\", \"monthly\"] + - `:tags` [list of binaries, default nil]: list of binaries for reference when searching for CreditNotes. ex: ["employees", "monthly"] + - `:expiration` [integer or DateTime, default 604800 (7 days)]: time interval in seconds between scheduled date and expiration date. ex 123456789 ## Attributes (return-only): - - `:id` [string]: unique id returned when the CreditNote is created. ex: "5656565656565656" + - `:id` [binary]: unique id returned when the CreditNote is created. ex: "5656565656565656" - `:amount` [integer]: CreditNote value in cents. ex: 1234 (= R$ 12.34) - - `:expiration` [integer]: time interval in seconds between due date and expiration date. ex 123456789 - - `:document_id` [string]: ID of the signed document to execute this CreditNote. ex: "4545454545454545" - - `:status` [string]: current status of the CreditNote. ex: "canceled", "created", "expired", "failed", "processing", "signed", "success" - - `:transaction_ids` [list of strings]: ledger transaction ids linked to this CreditNote. ex: [\"19827356981273\"] - - `:workspace_id` [string]: ID of the Workspace that generated this CreditNote. ex: "4545454545454545" + - `:document_id` [binary]: ID of the signed document to execute this CreditNote. ex: "4545454545454545" + - `:status` [binary]: current status of the CreditNote. ex: "canceled", "created", "expired", "failed", "processing", "signed", "success" + - `:transaction_ids` [list of binaries]: ledger transaction ids linked to this CreditNote. ex: ["19827356981273"] + - `:workspace_id` [binary]: ID of the Workspace that generated this CreditNote. ex: "4545454545454545" - `:tax_amount` [integer]: tax amount included in the CreditNote. ex: 100 + - `:nominal_interest` [float]: yearly nominal interest rate of the CreditNote, in percentage. ex: 11.5 - `:interest` [float]: yearly effective interest rate of the CreditNote, in percentage. ex: 12.5 - `:created` [DateTime]: creation DateTime for the CreditNote. ex: ~U[2020-3-10 10:30:0:0] - `:updated` [DateTime]: latest update DateTime for the CreditNote. ex: ~U[2020-3-10 10:30:0:0] @@ -93,10 +95,11 @@ defmodule StarkInfra.CreditNote do :payment_type, :rebate_amount, :tags, + :expiration, :id, :interest, + :nominal_interest, :amount, - :expiration, :document_id, :status, :transaction_ids, @@ -109,22 +112,22 @@ defmodule StarkInfra.CreditNote do @type t() :: %__MODULE__{} @doc """ - Send a list of CreditNote structs for creation in the Stark Infra API + Send a list of CreditNote objects for creation in the Stark Infra API ## Parameters (required): - - `:notes` [list of CreditNote structs]: list of CreditNote structs to be created in the API + - `:notes` [list of CreditNote objects]: list of CreditNote objects to be created in the API - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of CreditNote structs with updated attributes + - list of CreditNote objects with updated attributes """ @spec create( [CreditNote.t() | map()], user: Project.t() | Organization.t() | nil ) :: - { :ok, [CreditNote.t()]} | + {:ok, [CreditNote.t()]} | {:error, [Error.t()]} def create(notes, options \\ []) do Rest.post( @@ -137,7 +140,7 @@ defmodule StarkInfra.CreditNote do @doc """ Same as create(), but it will unwrap the error tuple and raise in case of errors. """ - @spec create( + @spec create!( [CreditNote.t() | map()], user: Project.t() | Organization.t() | nil ) :: any @@ -150,16 +153,16 @@ defmodule StarkInfra.CreditNote do end @doc """ - Receive a single CreditNote struct previously created in the Stark Infra API by its id + Receive a single CreditNote object previously created in the Stark Infra API by its id ## Parameters (required): - - `:id` [string]: struct's unique id. ex: "5656565656565656" + - `:id` [binary]: object's unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - CreditNote struct with updated attributes + - CreditNote object that corresponds to the given id. """ @spec get( binary, @@ -180,19 +183,19 @@ defmodule StarkInfra.CreditNote do end @doc """ - Receive a stream of CreditNote structs previously created in the Stark Infra API + Receive a stream of CreditNote objects previously created in the Stark Infra API - ## Options: - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil] date filter for structs created only after specified date. ex: ~D[2020, 3, 10] - - `:before` [Date or string, default nil] date filter for structs created only before specified date. ex: ~D[2020, 3, 10] - - `:status` [string, default nil]: filter for status of retrieved structs. Options: “canceled”, “created”, “expired”, “failed”, “processing”, “signed”, “success”. - - `:tags` [list of strings, default []]: tags to filter retrieved structs. ex: ["tony", "stark"] - - `:ids` [list of strings, default []]: list of ids to filter retrieved structs. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020, 3, 10] + - `:status` [binary, default nil]: filter for status of retrieved objects. ex: “canceled”, “created”, “expired”, “failed”, “processing”, “signed”, “success”. + - `:tags` [list of binaries, default []]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:ids` [list of binaries, default []]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of CreditNote structs with updated attributes + - stream of CreditNote objects with updated attributes """ @spec query( limit: integer, @@ -234,22 +237,22 @@ defmodule StarkInfra.CreditNote do end @doc """ - Receive a list of up to 100 CreditNote structs previously created in the Stark Infra API and the cursor to the next page. + Receive a list of up to 100 CreditNote objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your requests. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. It must be an integer between 1 and 100. ex: 50 - - `:after` [Date or string, default nil] Date filter for structs created only after specified date. ex: ~D[2020-3-10] - - `:before` [Date or string, default nil] Date filter for structs created only before specified date. ex: ~D(2020-3-10] - - `:status` [string, default nil]: filter for status of retrieved structs. Options: “canceled”, “created”, “expired”, “failed”, “processing”, “signed”, “success”. - - `:tags` [list of strings, default []]: tags to filter retrieved structs. ex: ["tony", "stark"] - - `:ids` [list of strings, default []]: list of ids to filter retrieved structs. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: Date filter for objects created only after specified date. ex: ~D[2020-3-10] + - `:before` [Date or binary, default nil]: Date filter for objects created only before specified date. ex: ~D(2020-3-10] + - `:status` [binary, default nil]: filter for status of retrieved objects. ex: “canceled”, “created”, “expired”, “failed”, “processing”, “signed”, “success”. + - `:tags` [list of binaries, default []]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:ids` [list of binaries, default []]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of CreditNote structs with updated attributes - - cursor to retrieve the next page of CreditNote structs + - list of CreditNote objects with updated attributes + - cursor to retrieve the next page of CreditNote objects """ @spec page( cursor: binary, @@ -289,13 +292,13 @@ defmodule StarkInfra.CreditNote do Cancel a CreditNote entity previously created in the Stark Infra API ## Parameters (required): - - `:id` [string]: id of the CreditNote to be canceled + - `:id` [binary]: CreditNote unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - canceled CreditNote struct + - canceled CreditNote object """ @spec cancel( binary, @@ -342,7 +345,7 @@ defmodule StarkInfra.CreditNote do nominal_amount: json[:nominal_amount], scheduled: json[:scheduled], invoices: json[:invoices] |> Enum.map(fn invoice -> API.from_api_json(invoice, &Invoice.resource_maker/1) end), - signers: json[:signers] |> Enum.map(fn signer -> API.from_api_json(signer, &Signer.resource_maker/1) end), + signers: json[:signers] |> Enum.map(fn signer -> API.from_api_json(signer, &CreditSigner.resource_maker/1) end), payment: parse_payment!(json[:payment], json[:payment_type]), payment_type: json[:payment_type], external_id: json[:external_id], @@ -353,8 +356,10 @@ defmodule StarkInfra.CreditNote do state_code: json[:state_code], zip_code: json[:zip_code], interest: json[:interest], + nominal_interest: json[:nominal_interest], rebate_amount: json[:rebate_amount], tags: json[:tags], + expiration: json[:expiration], created: json[:created] |> Check.datetime(), updated: json[:updated] |> Check.datetime(), id: json[:id] diff --git a/lib/credit_note/credit_note_log.ex b/lib/credit_note/credit_note_log.ex index 6174255..7eee5b1 100644 --- a/lib/credit_note/credit_note_log.ex +++ b/lib/credit_note/credit_note_log.ex @@ -12,16 +12,16 @@ defmodule StarkInfra.CreditNote.Log do Groups CreditNote.Log related functions """ @doc """ - Every time an CreditNote entity is updated, a corresponding creditnote.Log + Every time an CreditNote entity is updated, a corresponding CreditNote.Log is generated for the entity. This log is never generated by the user, but it can be retrieved to check additional information on the CreditNote. - ## Attributes: - - `:id` [string]: unique id returned when the log is created. ex: "5656565656565656" + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the log is created. ex: "5656565656565656" - `:note` [CreditNote]: CreditNote entity to which the log refers to. - - `:errors` [list of strings]: list of errors linked to this CreditNote event - - `:type` [string]: type of the CreditNote event which triggered the log creation. Options: “canceled”, “created”, “expired”, “failed”, “refunded”, “registered”, “sending”, “sent”, “signed”, “success”. - - `:created` [DateTime, default nil]: creation DateTime for the CreditNote. ex: ~U[2020-3-10 10:30:0:0] + - `:errors` [list of binaries]: list of errors linked to this CreditNote event + - `:type` [binary]: type of the CreditNote event which triggered the log creation. ex: “canceled”, “created”, “expired”, “failed”, “refunded”, “registered”, “sending”, “sent”, “signed”, “success”. + - `:created` [DateTime, default nil]: creation DateTime for the Log. ex: ~U[2020-3-10 10:30:0:0] """ @enforce_keys [ :id, @@ -41,16 +41,16 @@ defmodule StarkInfra.CreditNote.Log do @type t() :: %__MODULE__{} @doc """ - Receive a single CreditNote.Log struct previously created by the Stark Infra API by its id + Receive a single CreditNote.Log object previously created by the Stark Infra API by its id ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" ## Parameters (optional): - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - CreditNote.Log struct with updated attributes + - CreditNote.Log object that corresponds to the given id. """ @spec get( binary, @@ -75,18 +75,18 @@ defmodule StarkInfra.CreditNote.Log do end @doc """ - Receive a stream of CreditNote.Log structs previously created in the Stark Infra API + Receive a stream of CreditNote.Log objects previously created in the Stark Infra API - ## Options: - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil] date filter for structs created only after specified date. ex: ~D[2020, 3, 10] - - `:before` [Date or string, default nil] date filter for structs created only before specified date. ex: ~D[2020, 3, 10] - - `:types` [list of strings, default []]: filter for log event types. Options: “canceled”, “created”, “expired”, “failed”, “refunded”, “registered”, “sending”, “sent”, “signed”, “success”. - - `:note_ids` [list of strings, default []]: list of CreditNote ids to filter logs. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020, 3, 10] + - `:types` [list of binaries, default []]: filter for log event types. ex: “canceled”, “created”, “expired”, “failed”, “refunded”, “registered”, “sending”, “sent”, “signed”, “success”. + - `:note_ids` [list of binaries, default []]: list of CreditNote ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of CreditNote.Log structs with updated attributes + - stream of CreditNote.Log objects with updated attributes """ @spec query( limit: integer, @@ -119,21 +119,21 @@ defmodule StarkInfra.CreditNote.Log do end @doc """ - Receive a list of up to 100 CreditNote.Log structs previously created in the Stark Infra API and the cursor to the next page. + Receive a list of up to 100 CreditNote.Log objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your requests. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. It must be an integer between 1 and 100. ex: 50 - - `:after` [Date or string, default nil] date filter for structs created only after specified date. ex: ~D[2020, 3, 10] - - `:before` [Date or string, default nil] date filter for structs created only before specified date. ex: ~D[2020, 3, 10] - - `:types` [list of strings, default []]: filter for log event types. Options: “canceled”, “created”, “expired”, “failed”, “refunded”, “registered”, “sending”, “sent”, “signed”, “success”. - - `:note_ids` [list of strings, default []]: list of CreditNote ids to filter logs. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020, 3, 10] + - `:types` [list of binaries, default []]: filter for log event types. ex: ["canceled", "created", "expired", "failed", "refunded", "registered", "sending", "sent", "signed", "success"] + - `:note_ids` [list of binaries, default []]: list of CreditNote ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of CreditNote.Log structs with updated attributes - - cursor to retrieve the next page of CreditNote.Log structs + - list of CreditNote.Log objects with updated attributes + - cursor to retrieve the next page of CreditNote.Log objects """ @spec page( cursor: binary, diff --git a/lib/credit_note/invoice/description.ex b/lib/credit_note/invoice/description.ex index a14ef95..c86afcb 100644 --- a/lib/credit_note/invoice/description.ex +++ b/lib/credit_note/invoice/description.ex @@ -9,10 +9,10 @@ defmodule StarkInfra.CreditNote.Invoice.Description do Invoice description information. ## Parameters (required): - - `:key` [string]: Description for the value. ex: "Taxes" + - `:key` [binary]: Description for the value. ex: "Taxes" ## Parameters (optional): - - `:value` [string, nil]: amount related to the described key. ex: "R$100,00" + - `:value` [binary, default nil]: amount related to the described key. ex: "R$100,00" """ @enforce_keys [ :key diff --git a/lib/credit_note/invoice/discount.ex b/lib/credit_note/invoice/discount.ex index 115b800..412f218 100644 --- a/lib/credit_note/invoice/discount.ex +++ b/lib/credit_note/invoice/discount.ex @@ -11,7 +11,7 @@ defmodule StarkInfra.CreditNote.Invoice.Discount do ## Parameters (required): - `:percentage` [float]: percentage of discount applied until specified due date - - `:due` [DateTime, Date or string]: due datetime for the discount + - `:due` [DateTime, Date or binary]: due datetime for the discount """ @enforce_keys [ :percentage, diff --git a/lib/credit_note/invoice/invoice.ex b/lib/credit_note/invoice/invoice.ex index a336539..f9d4268 100644 --- a/lib/credit_note/invoice/invoice.ex +++ b/lib/credit_note/invoice/invoice.ex @@ -8,38 +8,34 @@ defmodule StarkInfra.CreditNote.Invoice do """ @doc """ - When you initialize an Invoice struct, the entity will not be automatically - sent to the Stark Infra API. The 'create' function sends the structs - to the Stark Infra API and returns the list of created structs. - To create scheduled Invoices, which will display the discount, interest, etc. on the final users banking interface, - use dates instead of datetimes on the "due" and "discounts" fields. + Invoice issued after the contract is signed, to be paid by the credit receiver. ## Parameters (required): - - `:amount` [integer]: Invoice value in cents. Minimum = 0 (any value will be accepted). ex: 1234 (= R$ 12.34) - - `:due` [DateTime, Date or string, default now + 2 days]: Invoice due date in UTC ISO format. ex: ~U[2021-03-26 19:32:35.418698Z] for immediate invoices and ~D[2020-10-28] for scheduled invoices + - `:amount` [integer]: Invoice value in cents. Minimum = 1 (any value will be accepted). ex: 1234 (= R$ 12.34) - ## Parameters (optional): - - `:expiration` [integer, default 59 days]: time interval in seconds between due date and expiration date. ex 123456789 - - `:fine` [float, default 0.0]: Invoice fine for overdue payment in %. ex: 2.5 - - `:interest` [float, default 0.0]: Invoice monthly interest for overdue payment in %. ex: 5.2 - - `:tags` [list of strings, default nil]: list of strings for tagging - - `:descriptions` [list of Descriptions or maps, default nil]: list of Descriptions or maps with "key":string and (optional) "value":string pairs + ## Parameters (optional): + - `:due` [DateTime, Date or binary, default now + 2 days]: Invoice due date in UTC ISO format. ex: ~U[2021-03-26 19:32:35.418698Z] for immediate invoices and ~D[2020-10-28] for scheduled invoices + - `:expiration` [integer, default 5097600 (59 days)]: time interval in seconds between due date and expiration date. ex 123456789 + - `:tags` [list of binaries, default nil]: list of binaries for tagging + - `:descriptions` [list of CreditNote.Invoice.Description objects or maps, default nil]: list of Descriptions - ## Attributes (return-only): - - `:id` [string, default nil]: unique id returned when Invoice is created. ex: "5656565656565656" - - `:tax_id` [string]: payer tax ID (CPF or CNPJ) with or without formatting. ex: "01234567890" or "20.018.183/0001-80" - - `:name` [string]: payer name. ex: "Iron Infra S.A." - - `:pdf` [string]: public Invoice PDF URL. ex: "https://invoice.starkbank.com/pdf/d454fa4e524441c1b0c1a729457ed9d8" - - `:link` [string]: public Invoice webpage URL. ex: "https://my-workspace.sandbox.starkbank.com/invoicelink/d454fa4e524441c1b0c1a729457ed9d8" + ## Attributes (return-only): + - `:id` [binary]: unique id returned when Invoice is created. ex: "5656565656565656" + - `:name` [binary]: payer name. ex: "Iron Bank S.A." + - `:tax_id` [binary]: payer tax ID (CPF or CNPJ) with or without formatting. ex: "01234567890" or "20.018.183/0001-80" + - `:pdf` [binary]: public Invoice PDF URL. ex: "https://invoice.starkbank.com/pdf/d454fa4e524441c1b0c1a729457ed9d8" + - `:link` [binary]: public Invoice webpage URL. ex: "https://my-workspace.sandbox.starkbank.com/invoicelink/d454fa4e524441c1b0c1a729457ed9d8" + - `:fine` [float]: Invoice fine for overdue payment in %. ex: 2.5 + - `:interest` [float]: Invoice monthly interest for overdue payment in %. ex: 5.2 - `:nominal_amount` [integer]: Invoice emission value in cents (will change if invoice is updated, but not if it's paid). ex: 400000 - `:fine_amount` [integer]: Invoice fine value calculated over nominal_amount. ex: 20000 - `:interest_amount` [integer]: Invoice interest value calculated over nominal_amount. ex: 10000 - `:discount_amount` [integer]: Invoice discount value calculated over nominal_amount. ex: 3000 - - `:discounts` [list of Discounts or maps, default nil]: list of Discounts or maps with "percentage":float and "due":string pairs - - `:brcode` [string]: BR Code for the Invoice payment. ex: "00020101021226800014br.gov.bcb.pix2558invoice.starkbank.com/f5333103-3279-4db2-8389-5efe335ba93d5204000053039865802BR5913Arya Stark6009Sao Paulo6220051656565656565656566304A9A0" - - `:status` [string]: current Invoice status. ex: "registered" or "paid" + - `:discounts` [list of CreditNote.Invoice.Discount objects or maps, default nil]: list of Discounts or maps with "percentage":float and "due":binary pairs + - `:brcode` [binary]: BR Code for the Invoice payment. ex: "00020101021226800014br.gov.bcb.pix2558invoice.starkbank.com/f5333103-3279-4db2-8389-5efe335ba93d5204000053039865802BR5913Arya Stark6009Sao Paulo6220051656565656565656566304A9A0" + - `:status` [binary]: current Invoice status. ex: "registered" or "paid" - `:fee` [integer]: fee charged by this Invoice. ex: 200 (= R$ 2.00) - - `:transaction_ids` [list of strings]: ledger transaction ids linked to this Invoice (if there are more than one, all but the first are reversals or failed reversal chargebacks). ex: ["19827356981273"] + - `:transaction_ids` [list of binaries]: ledger transaction ids linked to this Invoice (if there are more than one, all but the first are reversals or failed reversal chargebacks). ex: ["19827356981273"] - `:created` [DateTime]: creation DateTime for the CreditNote. ex: ~U[2020-3-10 10:30:0:0] - `:updated` [DateTime]: latest update DateTime for the CreditNote. ex: ~U[2020-3-10 10:30:0:0] """ diff --git a/lib/credit_note/signer.ex b/lib/credit_note/signer.ex deleted file mode 100644 index 3635d43..0000000 --- a/lib/credit_note/signer.ex +++ /dev/null @@ -1,37 +0,0 @@ -defmodule StarkInfra.CreditNote.Signer do - alias __MODULE__, as: Signer - - @moduledoc """ - Groups Signer related functions - """ - - @doc """ - CreditNote signer's information. - - ## Parameters (required): - - `:name` [string]: signer's name. ex: "Tony Stark" - - `:contact` [string]: signer's contact information. ex: "tony@starkindustries.com" - - `:method` [string]: delivery method for the contract. ex: "link" - """ - @enforce_keys [ - :name, - :contact, - :method - ] - defstruct [ - :name, - :contact, - :method - ] - - @type t() :: %__MODULE__{} - - @doc false - def resource_maker(json) do - %Signer{ - name: json[:name], - contact: json[:contact], - method: json[:method] - } - end -end diff --git a/lib/credit_note/transfer.ex b/lib/credit_note/transfer.ex index c838788..e675c1b 100644 --- a/lib/credit_note/transfer.ex +++ b/lib/credit_note/transfer.ex @@ -7,44 +7,56 @@ defmodule StarkInfra.CreditNote.Transfer do """ @doc """ - CreditNote signer's information. + Transfer sent to the credit receiver after the contract is signed. ## Parameters (required): - - `:name` [string]: receiver full name. ex: "Anthony Edward Stark" - - `:tax_id` [string]: receiver tax ID (CPF or CNPJ) with or without formatting. ex: "01234567890" or "20.018.183/0001-80" - - `:bank_code` [string]: code of the receiver Bank institution in Brazil. - - `:branch_code` [string]: receiver Bank account branch. Use '-' in case there is a verifier digit. ex: "1357-9" - - `:account_number` [string]: Receiver Bank account number. Use '-' before the verifier digit. ex: "876543-2" + - `:name` [binary]: receiver full name. ex: "Anthony Edward Stark" + - `:tax_id` [binary]: receiver tax ID (CPF or CNPJ) with or without formatting. ex: "01234567890" or "20.018.183/0001-80" + - `:bank_code` [binary]: code of the receiver Bank institution in Brazil. ex: "20018183" or "341" + - `:branch_code` [binary]: receiver Bank account branch. Use '-' in case there is a verifier digit. ex: "1357-9" + - `:account_number` [binary]: Receiver Bank account number. Use '-' before the verifier digit. ex: "876543-2" - ## Options: - - `:account_type` [string, default "checking"]: Receiver Bank account type. This parameter only has effect on Pix Transfers. ex: "checking", "savings", "salary" or "payment" - - `:scheduled` [Date, DateTime or string, default now]: date or datetime when the transfer will be processed. May be pushed to next business day if necessary. ex: ~U[2020-03-26 19:32:35.418698Z] - - `:tags` [list of strings]: list of strings for reference when searching for transfers. ex: ["employees", "monthly"] + ## Parameters (optional): + - `:account_type` [binary, default "checking"]: Receiver Bank account type. This parameter only has effect on Pix Transfers. ex: "checking", "savings", "salary" or "payment" + - `:tags` [list of binaries]: list of binaries for reference when searching for transfers. ex: ["employees", "monthly"] - Attributes (return-only): - - `:id` [string, default nil]: unique id returned when Transfer is created. ex: "5656565656565656" + Attributes (return-only): + - `:id` [binary]: unique id returned when Transfer is created. ex: "5656565656565656" - `:amount` [integer]: amount in cents to be transferred. ex: 1234 (= R$ 12.34) - - `:status` [string, default nil]: current transfer status. ex: "success" or "failed" + - `:external_id` [binary]: url safe string that must be unique among all your transfers. Duplicated external_ids will cause failures. By default, this parameter will block any transfer that repeats amount and receiver information on the same date. ex: "my-internal-id-123456" + - `:scheduled` [Date, DateTime or binary, default now]: date or datetime when the transfer will be processed. May be pushed to next business day if necessary. ex: ~U[2020-03-26 19:32:35.418698Z] + - `:description` [binary]: optional description to override default description to be shown in the bank statement. ex: "Payment for service #1234" + - `:fee` [integer]: fee charged when the Transfer is processed. ex: 200 (= R$ 2.00) + - `:status` [binary]: current transfer status. ex: "success" or "failed" + - `:transaction_ids` [list of binaries]: ledger Transaction IDs linked to this Transfer (if there are two, the second is the chargeback). ex: ["19827356981273"] + - `:created` [DateTime]: creation DateTime for the CreditNote. ex: ~U[2020-3-10 10:30:0:0] + - `:updated` [DateTime]: latest update DateTime for the CreditNote. ex: ~U[2020-3-10 10:30:0:0] """ @enforce_keys [ + :name, + :tax_id, :bank_code, :branch_code, - :account_number, - :name, - :tax_id + :account_number ] defstruct [ - :account_number, - :account_type, - :amount, + :name, + :tax_id, :bank_code, :branch_code, + :account_number, + :account_type, + :tags, :id, - :name, + :amount, + :external_id, :scheduled, + :description, + :fee, :status, - :tags, - :tax_id + :transaction_ids, + :created, + :updated ] @type t() :: %__MODULE__{} @@ -52,17 +64,23 @@ defmodule StarkInfra.CreditNote.Transfer do @doc false def resource_maker(json) do %Transfer{ - account_number: json[:account_number], - account_type: json[:account_type], - amount: json[:amount], + name: json[:name], + tax_id: json[:tax_id], bank_code: json[:bank_code], branch_code: json[:branch_code], + account_number: json[:account_number], + account_type: json[:account_type], + tags: json[:tags], id: json[:id], - name: json[:name], - scheduled: json[:scheduled] |> Check.datetime(), + amount: json[:amount], + external_id: json[:external_id], + scheduled: json[:scheduled], + description: json[:description], + fee: json[:fee], status: json[:status], - tags: json[:tags], - tax_id: json[:tax_id] + transaction_ids: json[:transaction_ids], + created: json[:created], + updated: json[:updated] } end end diff --git a/lib/credit_preview/credit_note_preview.ex b/lib/credit_preview/credit_note_preview.ex new file mode 100644 index 0000000..c6830b2 --- /dev/null +++ b/lib/credit_preview/credit_note_preview.ex @@ -0,0 +1,89 @@ +defmodule StarkInfra.CreditNotePreview do + alias __MODULE__, as: CreditNotePreview + + @moduledoc """ + Groups CreditNotePreview related functions + """ + + @doc """ + A CreditNotePreview is used to preview a CCB contract between the borrower and lender with a specific table type. + + When you initialize a CreditNotePreview, the entity will not be automatically + created in the Stark Infra API. The 'create' function sends the objects + to the Stark Infra API and returns the created object. + + ## Parameters (required): + - `:type` [binary]: table type that defines the amortization system. ex: "sac", "price", "american", "bullet", "custom" + - `:nominal_amount` [integer]: amount in cents transferred to the credit receiver, before deductions. ex: 11234 (= R$ 112.34) + - `:scheduled` [Date, DateTime or binary]: date of transfer execution. ex: ~D[2020, 3, 10] + - `:tax_id` [binary]: credit receiver's tax ID (CPF or CNPJ). ex: "20.018.183/0001-80" + + ## Parameters (conditionally required): + - `:invoices` [list of CreditNote.Invoice objects]: list of Invoice objects to be created and sent to the credit receiver. ex: [Invoice(), Invoice()] + - `:nominal_interest` [float]: yearly nominal interest rate of the CreditNote, in percentage. ex: 12.5 + - `:initial_due` [Date, DateTime or binary]: date of the first invoice. ex: ~D[2020, 3, 10] + - `:count` [integer]: quantity of invoices for payment. ex: 12 + - `:initial_amount` [integer]: value of the first invoice in cents. ex: 1234 (= R$12.34) + - `:interval` [binary]: interval between invoices. ex: "year", "month" + + ## Parameters (optional): + - `:rebate_amount` [integer, default nil]: credit analysis fee deducted from lent amount. ex: 11234 (= R$ 112.34) + + ## Attributes (return-only): + - `:amount` [integer]: CreditNote value in cents. ex: 1234 (= R$ 12.34) + - `:interest` [float]: yearly effective interest rate of the CreditNote, in percentage. ex: 12.5 + - `:tax_amount` [integer]: tax amount included in the CreditNote. ex: 100 + """ + @enforce_keys [ + :type, + :nominal_amount, + :scheduled, + :tax_id + ] + defstruct [ + :type, + :nominal_amount, + :scheduled, + :tax_id, + :invoices, + :nominal_interest, + :initial_due, + :count, + :initial_amount, + :interval, + :rebate_amount, + :amount, + :interest, + :tax_amount + ] + + @type t() :: %__MODULE__{} + + @doc false + def resource() do + { + "CreditNotePreview", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %CreditNotePreview{ + type: json[:type], + nominal_amount: json[:nominal_amount], + scheduled: json[:scheduled], + tax_id: json[:tax_id], + invoices: json[:invoices], + nominal_interest: json[:nominal_interest], + initial_due: json[:initial_due], + count: json[:count], + initial_amount: json[:initial_amount], + interval: json[:interval], + rebate_amount: json[:rebate_amount], + amount: json[:amount], + interest: json[:interest], + tax_amount: json[:tax_amount], + } + end +end diff --git a/lib/credit_preview/credit_preview.ex b/lib/credit_preview/credit_preview.ex new file mode 100644 index 0000000..475a280 --- /dev/null +++ b/lib/credit_preview/credit_preview.ex @@ -0,0 +1,94 @@ +defmodule StarkInfra.CreditPreview do + alias __MODULE__, as: CreditPreview + alias StarkInfra.Error + alias StarkInfra.Utils.Rest + alias StarkInfra.User.Project + alias StarkInfra.User.Organization + + @moduledoc """ + Groups CreditPreview related functions + """ + + @doc """ + A CreditPreview is used to get information from a credit before taking it. + This resource can be used to preview CreditNotes + + ## Parameters (required): + - `:credit` [CreditNotePreview object or map]: Information preview of the informed credit. + - `:type` [binary]: Credit type. ex: "credit-note" + """ + @enforce_keys [ + :credit, + :type + ] + defstruct [ + :credit, + :type + ] + + @type t() :: %__MODULE__{} + + @doc """ + Send a list of CreditPreview objects for processing in the Stark Infra API + + ## Parameters (required): + - `:previews` [list of CreditPreview objects]: list of CreditPreview objects to be created in the API + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of CreditPreview objects with updated attributes + """ + @spec create( + [CreditPreview.t() | map()], + user: Project.t() | Organization.t() | nil + ) :: + {:ok, [CreditPreview.t()]} | + {:error, [Error.t()]} + def create(previews, options \\ []) do + Rest.post( + resource(), + previews, + options + ) + end + + @doc """ + Same as create(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec create!( + [CreditPreview.t() | map()], + user: Project.t() | Organization.t() | nil + ) :: any + def create!(previews, options \\ []) do + Rest.post!( + resource(), + previews, + options + ) + end + + defp parse_credit!(credit, type) do + case type do + "credit" -> API.from_api_json(credit, &Transfer.resource_maker/1) + _ -> credit + end + end + + @doc false + def resource() do + { + "CreditPreview", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %CreditPreview{ + credit: parse_credit!(json[:credit], json[:type]), + type: json[:type] + } + end +end diff --git a/lib/credit_signer/credit_signer.ex b/lib/credit_signer/credit_signer.ex new file mode 100644 index 0000000..8debb21 --- /dev/null +++ b/lib/credit_signer/credit_signer.ex @@ -0,0 +1,50 @@ +defmodule StarkInfra.CreditSigner do + alias __MODULE__, as: CreditSigner + + @moduledoc """ + Groups CreditSigner related functions + """ + + @doc """ + CreditNote signer's information. + + ## Parameters (required): + - `:name` [binary]: signer's name. ex: "Tony Stark" + - `:contact` [binary]: signer's contact information. ex: "tony@starkindustries.com" + - `:method` [binary]: delivery method for the contract. ex: "link" + + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the CreditSigner is created. ex: "5656565656565656" + """ + @enforce_keys [ + :name, + :contact, + :method + ] + defstruct [ + :name, + :contact, + :method, + :id + ] + + @type t() :: %__MODULE__{} + + @doc false + def resource() do + { + "CreditSigner", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %CreditSigner{ + name: json[:name], + contact: json[:contact], + method: json[:method], + id: json[:id] + } + end +end diff --git a/lib/dynamic_brcode/dynamic_brcode.ex b/lib/dynamic_brcode/dynamic_brcode.ex new file mode 100644 index 0000000..be3fbd1 --- /dev/null +++ b/lib/dynamic_brcode/dynamic_brcode.ex @@ -0,0 +1,462 @@ +defmodule StarkInfra.DynamicBrcode do + alias __MODULE__, as: DynamicBrcode + alias StarkInfra.Error + alias StarkInfra.Utils.Rest + alias StarkInfra.Utils.Parse + alias StarkInfra.Utils.Check + alias StarkInfra.User.Project + alias StarkInfra.User.Organization + + @moduledoc """ + Groups DynamicBrcode related functions + """ + + @doc """ + 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. + + When you initialize a DynamicBrcode, the entity will not be automatically + created in the Stark Infra API. The 'create' function sends the objects + to the Stark Infra API and returns the created object. + + ## Parameters (required): + - `:name` [binary]: receiver's name. ex: "Tony Stark" + - `:city` [binary]: receiver's city name. ex: "Rio de Janeiro" + - `:external_id` [binary]: binary that must be unique among all your DynamicBrcodes. Duplicated external ids will cause failures. ex: "my-internal-id-123456" + + ## Parameters (optional): + - `:type` [binary, default "instant"]: type of the DynamicBrcode. ex: "instant", "due" + - `:tags` [list of binaries, default []]: list of binaries for tagging. ex: ["travel", "food"] + + ## Attributes (return-only): + - `:id` [binary]: id returned on creation, this is the BR Code. ex: "00020126360014br.gov.bcb.pix0114+552840092118152040000530398654040.095802BR5915Jamie Lannister6009Sao Paulo620705038566304FC6C" + - `:uuid` [binary]: unique uuid returned when the DynamicBrcode is created. ex: "4e2eab725ddd495f9c98ffd97440702d" + - `:url` [binary]: url link to the BR Code image. ex: "https://brcode-h.development.starkinfra.com/dynamic-qrcode/901e71f2447c43c886f58366a5432c4b.png" + - `:created` [DateTime]: creation DateTime for the CreditNote. ex: ~U[2020-3-10 10:30:0:0] + - `:updated` [DateTime]: latest update DateTime for the CreditNote. ex: ~U[2020-3-10 10:30:0:0] + """ + @enforce_keys [ + :name, + :city, + :external_id, + ] + defstruct [ + :name, + :city, + :external_id, + :type, + :tags, + :id, + :uuid, + :url, + :created, + :updated + ] + + @type t() :: %__MODULE__{} + + @doc """ + Send a list of DynamicBrcode objects for creation at the Stark Infra API + + ## Parameters (required): + - `:brcodes` [list of DynamicBrcode objects]: list of DynamicBrcode objects to be created in the API. + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of DynamicBrcode objects with updated attributes + """ + @spec create( + [DynamicBrcode.t() | map()], + user: Project.t() | Organization.t() | nil + ) :: + {:ok, [DynamicBrcode.t()]} | + {:error, [Error.t()]} + def create(brcodes, options \\ []) do + Rest.post( + resource(), + brcodes, + options + ) + end + + @doc """ + Same as create(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec create!( + [DynamicBrcode.t() | map()], + user: Project.t() | Organization.t() | nil + ) :: any + def create!(brcodes, options \\ []) do + Rest.post!( + resource(), + brcodes, + options + ) + end + + @doc """ + Receive a single DynamicBrcode object previously created in the Stark Infra API by its uuid + + ## Parameters (required): + - `:uuid` [binary]: object's unique uuid. ex: "901e71f2447c43c886f58366a5432c4b" + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - DynamicBrcode object with updated attributes + """ + @spec get( + binary, + user: Project.t() | Organization.t() | nil + ) :: + {:ok, [DynamicBrcode.t()]} | + {:error, [Error.t()]} + def get(uuid, options \\ []) do + Rest.get_id(resource(), uuid, options) + end + + @doc """ + Same as get(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec get!(binary, user: Project.t() | Organization.t() | nil) :: any + def get!(uuid, options \\ []) do + Rest.get_id!(resource(), uuid, options) + end + + @doc """ + Receive a stream of DynamicBrcode objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020, 3, 10] + - `:external_ids` [list of binaries, default nil]: list of external_ids to filter retrieved objects. ex: ["my_external_id1", "my_external_id2"] + - `:uuids` [list of binaries, default nil]: list of uuids to filter retrieved objects. ex: ["901e71f2447c43c886f58366a5432c4b", "4e2eab725ddd495f9c98ffd97440702d"] + - `:tags` [list of binaries, default []]: list of tags to filter retrieved objects. ex: ["tony", "stark"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - stream of DynamicBrcode objects with updated attributes + """ + @spec query( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + external_ids: [binary], + tags: [binary], + uuids: [binary], + user: Project.t() | Organization.t() | nil + ) :: + ({:cont, {:ok, [DynamicBrcode.t()]}} | + {:error, [Error.t()]} | + {:halt, any} | + {:suspend, any}, + any -> any) + def query(options \\ []) do + Rest.get_list( + resource(), + options + ) + end + + @doc """ + Same as query(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec query!( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + external_ids: [binary], + tags: [binary], + uuids: [binary], + user: Project.t() | Organization.t() | nil + ) :: any + def query!(options \\ []) do + Rest.get_list!( + resource(), + options + ) + end + + @doc """ + Receive a list of up to 100 DynamicBrcode objects previously created in the Stark Infra API and the cursor to the next page. + Use this function instead of query if you want to manually page your requests. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020, 3, 10] + - `:external_ids` [list of binaries, default nil]: list of external_ids to filter retrieved objects. ex: ["my_external_id1", "my_external_id2"] + - `:uuids` [list of binaries, default nil]: list of uuids to filter retrieved objects. ex: ["901e71f2447c43c886f58366a5432c4b", "4e2eab725ddd495f9c98ffd97440702d"] + - `:tags` [list of binaries, default []]: list of tags to filter retrieved objects. ex: ["tony", "stark"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of DynamicBrcode objects with updated attributes + - cursor to retrieve the next page of DynamicBrcode objects + """ + @spec page( + cursor: binary | nil, + limit: integer | nil, + after: Date.t() | binary | nil, + before: Date.t() | binary | nil, + external_ids: [binary] | nil, + tags: [binary] | nil, + uuids: [binary] | nil, + user: Project.t() | Organization.t() | nil + ) :: + {:ok, {binary, [DynamicBrcode.t()]}} | + {:error, [Error.t()]} + def page(options \\ []) do + Rest.get_page( + resource(), + options + ) + end + + @doc """ + Same as page(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec page!( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + external_ids: [binary], + tags: [binary], + uuids: [binary], + user: Project.t() | Organization.t() | nil + ) :: + [DynamicBrcode.t()] + def page!(options \\ []) do + Rest.get_page!( + resource(), + options + ) + end + + @doc """ + Helps you respond to a due DynamicBrcode Read + + When a Due DynamicBrcode is read by your user, a GET request containing the BR Code's + 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. + + ## Parameters (required): + - `:version` [integer]: integer that represents how many times the BR Code was updated. + - `:created` [DateTime or binary] creation datetime in ISO format of the DynamicBrcode. ex: ~U[2020-3-10 10:30:0:0] + - `:due` [DateTime or binary]: requested payment due datetime in ISO format. ex: ~U[2020-3-10 10:30:0:0] + - `:key_id` [binary]: receiver's PixKey id. Can be a tax_id (CPF/CNPJ), a phone number, an email or an alphanumeric sequence (EVP). ex: "+5511989898989" + - `:status` [binary]: BR Code status. ex: "created", "overdue", "paid", "canceled" or "expired" + - `:reconciliation_id` [binary]: id to be used for conciliation of the resulting Pix transaction. This id must have from to 26 to 35 alphanumeric characters ex: "cd65c78aeb6543eaaa0170f68bd741ee" + - `:nominal_amount` [integer]: positive integer that represents the amount in cents of the resulting Pix transaction. ex: 1234 (= R$ 12.34) + - `:sender_name` [binary]: sender's full name. ex: "Anthony Edward Stark" + - `:receiver_name` [binary]: receiver's full name. ex: "Jamie Lannister" + - `:receiver_street_line` [binary]: receiver's main address. ex: "Av. Paulista, 200" + - `:receiver_city` [binary]: receiver's address city name. ex: "Sao Paulo" + - `:receiver_state_code` [binary]: receiver's address state code. ex: "SP" + - `:receiver_zip_code` [binary]: receiver's address zip code. ex: "01234-567" + + ## Parameters (optional): + - `:expiration [integer, default 86400 (1 day)]: time in seconds counted from the creation datetime until the DynamicBrcode expires. After expiration, the BR Code cannot be paid anymore. + - `:sender_tax_id`: [binary, default nil]: sender's CPF (11 digits formatted or unformatted) or CNPJ (14 digits formatted or unformatted). ex: "01.001.001/0001-01" + - `:receiver_tax_id`: [binary, default nil]: receiver's CPF (11 digits formatted or unformatted) or CNPJ (14 digits formatted or unformatted). ex: "012.345.678-90" + - `:fine [float:, default 2.0]: Percentage charged if the sender pays after the due datetime. + - `:interest`: [float, default 1.0]: Interest percentage charged if the sender pays after the due datetime. + - `:discounts`: [list of dictionaries, default nil]: list of dictionaries with "percentage":float and "due":DateTime or binary pairs. + - `:description`: [binary, default nil]: additional information to be shown to the sender at the moment of payment. + + ## Return: + - Dumped JSON binary that must be returned to us + """ + + @spec response_due( + map() + ) :: + {:ok, DynamicBrcode.t()} | + {:error, [Error.t()]} + def response_due(body) do + params = %{ + version: body.version, + created: body.created, + due: body.due, + keyId: body.key_id, + status: body.status, + reconciliationId: body.reconciliation_id, + nominalAmount: body.nominal_amount, + sendeNname: body.sender_name, + senderTaxId: body.sender_tax_id, + receiverName: body.receiver_name, + receiverStreetLine: body.receiver_street_line, + receiverCity: body.receiver_city, + receiverStateCode: body.receiver_state_code, + expiration: body.expiration, + receiverTaxId: body.receiver_tax_id, + fine: body.fine, + interest: body.interest, + discounts: body.discounts, + description: body.description, + } + params + |> Jason.encode! + end + + @doc """ + Helps you respond to an instant DynamicBrcode Read + + When an instant DynamicBrcode is read by your user, a GET request containing the BR Code's 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. + + ## Parameters (required): + - `:version` [integer]: integer that represents how many times the BR Code was updated. + - `:created` [DateTime or binary]: creation datetime of the DynamicBrcode. ex: "2022-05-17" + - `:key_id` [binary]: receiver's PixKey id. Can be a tax_id (CPF/CNPJ), a phone number, an email or an alphanumeric sequence (EVP). ex: "+5511989898989" + - `:status` [binary]: BR Code status. ex: "created", "overdue", "paid", "canceled" or "expired" + - `:reconciliation_id` [binary]: id to be used for conciliation of the resulting Pix transaction. ex: "cd65c78aeb6543eaaa0170f68bd741ee" + - `:amount` [integer]: positive integer that represents the amount in cents of the resulting Pix transaction. ex: 1234 (= R$ 12.34) + + ## Parameters (conditionally-required): + - `:cashier_type` [binary, default nil]: cashier's type. Required if the cash_amount is different from 0. ex: "merchant", "participant" and "other" + - `:cashier_bank_code` [binary, default nil]: cashier's bank code. Required if the cash_amount is different from 0. ex: "20018183" + + ## Parameters (optional): + - `:cash_amount` [integer, default 0]: amount to be withdrawn from the cashier in cents. ex: 1000 (= R$ 10.00) + - `:expiration` [integer, default 86400 (1 day)]: time in seconds counted from the creation datetime until the DynamicBrcode expires. After expiration, the BR Code cannot be paid anymore. Default value: 86400 (1 day) + - `:sender_name` [binary, default nil]: sender's full name. ex: "Anthony Edward Stark" + - `:sender_tax_id` [binary, default nil]: sender's CPF (11 digits formatted or unformatted) or CNPJ (14 digits formatted or unformatted). ex: "01.001.001/0001-01" + - `:amount_type` [binary, default "fixed"]: amount type of the Brcode. If the amount type is "custom" the Brcode's amount can be changed by the sender at the moment of payment. Options: "fixed"or "custom" + - `:description` [binary, default nil]: additional information to be shown to the sender at the moment of payment. + ## Return: + - Dumped JSON string that must be returned to us + """ + @spec response_instant( + map() + ) :: + {:ok, DynamicBrcode.t()} | + {:error, [Error.t()]} + def response_instant(body \\ nil) do + params = %{ + version: body.version, + created: body.created, + keyId: body.key_id, + status: body.status, + reconciliationId: body.reconciliation_id, + amount: body.amount, + cashierType: body.cashier_type, + cashierBankCode: body.cashier_bank_code, + cashAmount: body.cash_amount, + expiration: body.expiration , + senderName: body.sender_name, + senderTaxId: body.sender_tax_id, + amountType: body.amount_type, + description: body.description + } + params + |> Jason.encode! + end + + @doc """ + Verify a DynamicBrcode Read + + When a DynamicBrcode is read by your user, a GET request will be made to your registered URL to + retrieve additional information needed to complete the transaction. + Use this method to verify the authenticity of a GET request received at your registered endpoint. + If the provided digital signature does not check out with the StarkInfra public key, + a StarkInfra.Exception.InvalidSignatureException will be raised. + + ## Parameters (required): + - `:uuid` [binary]: unique uuid of the DynamicBrcode, passed as a path variable in the DynamicBrcode Read request. ex: "4e2eab725ddd495f9c98ffd97440702d" + - `:signature` [binary]: base-64 digital signature received at response header "Digital-Signature" + + ## Options + - `cache_pid` [PID, default nil]: PID of the process that holds the public key cache, returned on previous parses. If not provided, a new cache process will be generated. + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - verified BR Code's uuid. + """ + @spec verify( + content: binary, + signature: binary, + cache_pid: PID, + user: Project.t() | Organization.t() + ):: + {:ok, DynamicBrcode.t()} | + {:error, [error: Error.t()]} + def verify(options) do + %{content: uuid, signature: signature, cache_pid: cache_pid, user: user} = + Enum.into( + options |> Check.enforced_keys([:content, :signature]), + %{cache_pid: nil, user: nil} + ) + Parse.parse_and_verify!( + content: uuid, + signature: signature, + cache_pid: cache_pid, + key: nil, + resource_maker: &resource_maker/1, + user: user + ) + end + + @doc """ + Same as verify(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec verify!( + content: binary, + signature: binary, + cache_pid: PID, + user: Project.t() | Organization.t() + ) :: any + def verify!(options \\ []) do + %{content: uuid, signature: signature, cache_pid: cache_pid, user: user} = + Enum.into( + options |> Check.enforced_keys([:content, :signature]), + %{cache_pid: nil, user: nil} + ) + Parse.parse_and_verify!( + content: uuid, + signature: signature, + cache_pid: cache_pid, + key: nil, + resource_maker: &resource_maker/1, + user: user + ) + end + + @doc false + def resource() do + { + "DynamicBrcode", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %DynamicBrcode{ + name: json[:name], + city: json[:city], + external_id: json[:external_id], + type: json[:type], + tags: json[:tags], + id: json[:id], + uuid: json[:uuid], + url: json[:url], + created: json[:created], + updated: json[:updated] + } + end +end diff --git a/lib/error.ex b/lib/error.ex index 6ce78c0..e90dec8 100644 --- a/lib/error.ex +++ b/lib/error.ex @@ -7,9 +7,9 @@ defmodule StarkInfra.Error do - "unknownException": a request encounters an error that has not been sent by the API, such as connectivity problems. - any other binary: the API has detected a mistake in your request - ## Attributes: - - `:code` [string]: defines de error code. ex: "invalidCredentials" - - `:message` [string]: explains the detected error. ex: "Provided digital signature in the header Access-Signature does not check out." + ## Attributes (return-only): + - `:code` [binary]: defines de error code. ex: "invalidCredentials" + - `:message` [binary]: explains the detected error. ex: "Provided digital signature in the header Access-Signature does not check out." """ defstruct [:code, :message] diff --git a/lib/event/event_attempt.ex b/lib/event/attempt.ex similarity index 61% rename from lib/event/event_attempt.ex rename to lib/event/attempt.ex index f13a549..7e90e7c 100644 --- a/lib/event/event_attempt.ex +++ b/lib/event/attempt.ex @@ -14,12 +14,12 @@ defmodule StarkInfra.Event.Attempt do When an Event delivery fails, an event attempt will be registered. It carries information meant to help you debug event reception issues. - ## Attributes: - - `:id` [string]: unique id that identifies the delivery attempt. ex: "5656565656565656" - - `:code` [string]: delivery error code. ex: badHttpStatus, badConnection, timeout - - `:message` [string]: delivery error full description. ex: "HTTP POST request returned status 404" - - `:event_id` [string]: ID of the Event whose delivery failed. ex: "4848484848484848" - - `:webhook_id` [string]: ID of the Webhook that triggered this event. ex: "5656565656565656" + ## Attributes (return-only): + - `:id` [binary]: unique id that identifies the delivery attempt. ex: "5656565656565656" + - `:code` [binary]: delivery error code. ex: "badHttpStatus", "badConnection", "timeout" + - `:message` [binary]: delivery error full description. ex: "HTTP POST request returned status 404" + - `:event_id` [binary]: ID of the Event whose delivery failed. ex: "4848484848484848" + - `:webhook_id` [binary]: ID of the Webhook that triggered this event. ex: "5656565656565656" - `:created` [DateTime]: datetime representing the moment when the attempt was made. ex: ~U[2020-03-26 19:32:35.418698Z] """ @enforce_keys [:id, :code, :message, :webhook_id, :event_id, :created] @@ -28,16 +28,16 @@ defmodule StarkInfra.Event.Attempt do @type t() :: %__MODULE__{} @doc """ - Receive a single Event.Attempt struct previously created by the Stark Infra API by its id + Receive a single Event.Attempt object previously created by the Stark Infra API by its id ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - Event.Attempt struct with updated attributes + - Event.Attempt object that corresponds to the given id. """ @spec get( binary, @@ -58,18 +58,18 @@ defmodule StarkInfra.Event.Attempt do end @doc """ - Receive a stream of Event.Attempt structs previously created in the Stark Infra API + Receive a stream of Event.Attempt objects previously created in the Stark Infra API - ## Options: - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:event_ids` [list of strings, default nil]: list of Event ids to filter attempts. ex: ["5656565656565656", "4545454545454545"] - - `:webhook_ids` [list of strings, default nil]: list of Webhook ids to filter attempts. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:event_ids` [list of binaries, default nil]: list of Event ids to filter attempts. ex: ["5656565656565656", "4545454545454545"] + - `:webhook_ids` [list of binaries, default nil]: list of Webhook ids to filter attempts. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of Event.Attempt structs with updated attributes + - stream of Event.Attempt objects with updated attributes """ @spec query( limit: integer, @@ -108,20 +108,21 @@ defmodule StarkInfra.Event.Attempt do end @doc """ - Receive a list of up to 100 Attempt structs previously created in the Stark Infra API and the cursor to the next page. + Receive a list of up to 100 Event.Attempt objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your requests. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Max = 100. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:event_ids` [list of strings, default nil]: list of Event ids to filter attempts. ex: ["5656565656565656", "4545454545454545"] - - `:webhook_ids` [list of strings, default nil]: list of Webhook ids to filter attempts. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:event_ids` [list of binaries, default nil]: list of Event ids to filter attempts. ex: ["5656565656565656", "4545454545454545"] + - `:webhook_ids` [list of binaries, default nil]: list of Webhook ids to filter attempts. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of Attempt structs with updated attributes and cursor to retrieve the next page of Attempt structs + - list of Event.Attempt objects with updated attributes + - cursor to retrieve the next page of Event.Attempt objects """ @spec page( cursor: binary, diff --git a/lib/event/event.ex b/lib/event/event.ex index 47bbe18..45d85f9 100644 --- a/lib/event/event.ex +++ b/lib/event/event.ex @@ -28,29 +28,29 @@ defmodule StarkInfra.Event do Events cannot be created, but may be retrieved from the Stark Infra API to list all generated updates on entities. - ## Attributes: - - `:id` [string]: unique id returned when the event is created. ex: "5656565656565656" - - `:log` [Log]: a Log struct from one the subscription services (PixRequest.Log, PixReversal.Log, PixKey.log) + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the Event is created. ex: "5656565656565656" + - `:log` [Log]: a Log object from one the subscription services (PixRequest.Log, PixReversal.Log, PixKey.log) - `:created` [DateTime]: creation datetime for the notification event. ex: ~U[2020-03-26 19:32:35.418698Z] - `:is_delivered` [bool]: true if the event has been successfully delivered to the user url. ex: false - - `:subscription` [string]: service that triggered this event. ex: "transfer", "utility-payment" - - `:workspace_id` [string]: ID of the Workspace that generated this event. Mostly used when multiple Workspaces have Webhooks registered to the same endpoint. ex: "4545454545454545" + - `:subscription` [binary]: service that triggered this event. ex: "pix-request.in", "pix-request.out", "pix-reversal.in", "pix-reversal.out", "pix-key", "pix-claim", "pix-infraction", "pix-chargeback", "issuing-card", "issuing-invoice", "issuing-purchase", "credit-note" + - `:workspace_id` [binary]: ID of the Workspace that generated this event. Mostly used when multiple Workspaces have Webhooks registered to the same endpoint. ex: "4545454545454545" """ defstruct [:id, :log, :created, :is_delivered, :subscription, :workspace_id] @type t() :: %__MODULE__{} @doc """ - Receive a single notification Event struct previously created in the Stark Infra API by passing its id + Receive a single notification Event object previously created in the Stark Infra API by passing its id ## Parameters (required): - - `id` [string]: struct unique id. ex: "5656565656565656" + - `id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - Event struct with updated attributes + - Event object that corresponds to the given id. """ @spec get(binary, user: Project.t() | Organization.t() | nil) :: {:ok, Event.t()} | {:error, [%Error{}]} def get(id, options \\ []) do @@ -66,17 +66,17 @@ defmodule StarkInfra.Event do end @doc """ - Receive a stream of notification Event structs previously created in the Stark Infra API + Receive a stream of notification Event objects previously created in the Stark Infra API - ## Options: - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] - `:is_delivered` [bool, default nil]: filter successfully delivered events. ex: true or false - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of Event structs with updated attributes + - stream of Event objects with updated attributes """ @spec query( limit: integer, @@ -113,19 +113,20 @@ defmodule StarkInfra.Event do end @doc """ - Receive a list of up to 100 Event structs previously created in the Stark Infra API and the cursor to the next page. + Receive a list of up to 100 Event objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your requests. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Max = 100. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] - `:is_delivered` [bool, default nil]: filter successfully delivered events. ex: true or false - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of Event structs with updated attributes and cursor to retrieve the next page of Event structs + - list of Event objects with updated attributes + - cursor to retrieve the next page of Event objects """ @spec page( cursor: binary, @@ -157,16 +158,16 @@ defmodule StarkInfra.Event do end @doc """ - Delete a list of notification Event entities previously created in the Stark Infra API + Delete a notification Event entity previously created in the Stark Infra API ## Parameters (required): - - `id` [string]: Event unique id. ex: "5656565656565656" + - `id` [binary]: Event unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - deleted Event struct + - deleted Event object """ @spec delete(binary, user: Project.t() | Organization.t() | nil) :: {:ok, Event.t()} | {:error, [%Error{}]} def delete(id, options \\ []) do @@ -186,11 +187,11 @@ defmodule StarkInfra.Event do If is_delivered is true, the event will no longer be returned on queries with is_delivered=false. ## Parameters (required): - - `id` [list of strings]: Event unique ids. ex: "5656565656565656" + - `id` [list of binaries]: Event unique ids. ex: "5656565656565656" - `:is_delivered` [bool]: If true and event hasn't been delivered already, event will be set as delivered. ex: true - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - target Event with updated attributes @@ -219,20 +220,20 @@ defmodule StarkInfra.Event do end @doc """ - Create a single Event struct from a content string received from a handler listening at the request url. + Create a single Event object received from Event listening at subscribed user endpoint. If the provided digital signature does not check out with the StarkInfra public key, a - starkinfra.error.InvalidSignatureError will be raised. + Starkinfra.Error.InvalidSignatureError will be raised. ## Parameters (required): - - `:content` [string]: response content from request received at user endpoint (not parsed) - - `:signature` [string]: base-64 digital signature received at response header "Digital-Signature" + - `:content` [binary]: response content from request received at user endpoint (not parsed) + - `:signature` [binary]: base-64 digital signature received at response header "Digital-Signature" - ## Options: + ## Parameters (optional): - `cache_pid` [PID, default nil]: PID of the process that holds the public key cache, returned on previous parses. If not provided, a new cache process will be generated. - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - Parsed Resource object + - Parsed Event object """ @spec parse( content: binary, diff --git a/lib/individual_document/individual_document.ex b/lib/individual_document/individual_document.ex new file mode 100644 index 0000000..cc03374 --- /dev/null +++ b/lib/individual_document/individual_document.ex @@ -0,0 +1,261 @@ +defmodule StarkInfra.IndividualDocument do + alias __MODULE__, as: IndividualDocument + alias StarkInfra.Error + alias StarkInfra.Utils.API + alias StarkInfra.Utils.Rest + alias StarkInfra.Utils.Check + alias StarkInfra.User.Project + alias StarkInfra.User.Organization + + @moduledoc """ + Groups IndividualDocument related functions + """ + + @doc """ + Individual documents are images containing either side of a document or a selfie + to be used in a matching validation. When created, they must be attached to an individual + identity to be used for its validation. + + When you initialize a IndividualDocument, the entity will not be automatically + created in the Stark Infra API. The 'create' function sends the objects + to the Stark Infra API and returns the list of created objects. + + ## Parameters (required): + - `:type` [binary]: type of the IndividualDocument. Options: "drivers-license-front", "drivers-license-back", "identity-front", "identity-back" or "selfie" + - `:content` [binary]: Base64 data url of the picture. ex: data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD... + - `:content_type` [binary]: content MIME type. This parameter is required as input only. ex: "image/png" or "image/jpeg" + - `:identity_id` [integer]: Unique id of IndividualIdentity. ex: "5656565656565656" + + ## Parameters (optional): + - `:tags` [list of binaries, default nil]: list of binaries for reference when searching for IndividualDocuments. ex: [\"employees\", \"monthly\"] + + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the IndividualDocument is created. ex: "5656565656565656" + - `:status` [binary]: current status of the IndividualDocument. Options: "created", "canceled", "processing", "failed", "success" + - `:created` [DateTime]: creation DateTime for the IndividualDocument. ex: ~U[2020-3-10 10:30:0:0] + """ + @enforce_keys [ + :type, + :content, + :content_type, + :identity_id + ] + defstruct [ + :type, + :content, + :content_type, + :identity_id, + :tags, + :id, + :status, + :created + ] + + @type t() :: %__MODULE__{} + + @doc """ + Send a list of IndividualDocument objects for creation in the Stark Infra API + + ## Parameters (required): + - `:identities` [list of IndividualDocument objects]: list of IndividualDocument objects to be created in the API + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of IndividualDocument objects with updated attributes + """ + @spec create( + [IndividualDocument.t() | map()], + user: Project.t() | Organization.t() | nil + ) :: + {:ok, [IndividualDocument.t()]} | + {:error, [Error.t()]} + def create(identities, options \\ []) do + Rest.post( + resource(), + identities, + options + ) + end + + @doc """ + Same as create(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec create!( + [IndividualDocument.t() | map()], + user: Project.t() | Organization.t() | nil + ) :: any + def create!(identities, options \\ []) do + Rest.post!( + resource(), + identities, + options + ) + end + + @doc """ + Receive a single IndividualDocument object previously created in the Stark Infra API by its id + + ## Parameters (required): + - `:id` [binary]: object's unique id. ex: "5656565656565656" + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - IndividualDocument object that corresponds to the given id. + """ + @spec get( + binary, + user: Project.t() | Organization.t() | nil + ) :: + {:ok, [IndividualDocument.t()]} | + {:error, [Error.t()]} + def get(id, options \\ []) do + Rest.get_id(resource(), id, options) + end + + @doc """ + Same as get(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec get!(binary, user: Project.t() | Organization.t() | nil) :: any + def get!(id, options \\ []) do + Rest.get_id!(resource(), id, options) + end + + @doc """ + Receive a stream of IndividualDocument objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020, 3, 10] + - `:status` [binary, default nil]: filter for status of retrieved objects. ex: “canceled”, “created”, “expired”, “failed”, “processing”, “signed”, “success”. + - `:tags` [list of binaries, default []]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:ids` [list of binaries, default []]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - stream of IndividualDocument objects with updated attributes + """ + @spec query( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: binary, + tags: [binary], + ids: [binary], + user: Project.t() | Organization.t() | nil + ) :: + ({:cont, {:ok, [IndividualDocument.t()]}} | + {:error, [Error.t()]} | + {:halt, any} | + {:suspend, any}, + any -> any) + def query(options \\ []) do + Rest.get_list(resource(), options) + end + + @doc """ + Same as query(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec query!( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: binary, + tags: [binary], + ids: [binary], + user: Project.t() | Organization.t() | nil + ) :: + ({:cont, [IndividualDocument.t()]} | + {:error, [Error.t()]} | + {:halt, any} | + {:suspend, any}, + any -> any) + def query!(options \\ []) do + Rest.get_list!(resource(), options) + end + + @doc """ + Receive a list of up to 100 IndividualDocument objects previously created in the Stark Infra API and the cursor to the next page. + Use this function instead of query if you want to manually page your requests. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: Date filter for objects created only after specified date. ex: ~D[2020-3-10] + - `:before` [Date or binary, default nil]: Date filter for objects created only before specified date. ex: ~D(2020-3-10] + - `:status` [binary, default nil]: filter for status of retrieved objects. ex: “canceled”, “created”, “expired”, “failed”, “processing”, “signed”, “success”. + - `:tags` [list of binaries, default []]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:ids` [list of binaries, default []]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of IndividualDocument objects with updated attributes + - cursor to retrieve the next page of IndividualDocument objects + """ + @spec page( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: binary, + tags: [binary], + ids: [binary], + user: Project.t() | Organization.t() | nil + ) :: + {:ok, {binary, [IndividualDocument.t()]}} | + {:error, [Error.t()]} + def page(options \\ []) do + Rest.get_page(resource(), options) + end + + @doc """ + Same as page(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec page!( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: binary, + tags: [binary], + ids: [binary], + user: Project.t() | Organization.t() | nil + ) :: + [IndividualDocument.t()] + def page!(options \\ []) do + Rest.get_page!(resource(), options) + end + + defp parse_payment!(payment, payment_type) do + case payment_type do + "transfer" -> API.from_api_json(payment, &Transfer.resource_maker/1) + _ -> payment + end + end + + @doc false + def resource() do + { + "IndividualDocument", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %IndividualDocument{ + type: json[:type], + content: json[:content], + content_type: json[:content_type], + identity_id: json[:identity_id], + tags: json[:tags], + id: json[:id], + status: json[:status], + created: json[:created], + } + end +end diff --git a/lib/individual_document/individual_document_log.ex b/lib/individual_document/individual_document_log.ex new file mode 100644 index 0000000..be30e2e --- /dev/null +++ b/lib/individual_document/individual_document_log.ex @@ -0,0 +1,187 @@ +defmodule StarkInfra.IndividualDocument.Log do + alias __MODULE__, as: Log + alias StarkInfra.Utils.Rest + alias StarkInfra.Utils.API + alias StarkInfra.Utils.Check + alias StarkInfra.IndividualDocument + alias StarkInfra.User.Project + alias StarkInfra.User.Organization + alias StarkInfra.Error + + @moduledoc """ + Groups IndividualDocument.Log related functions + """ + @doc """ + Every time an IndividualDocument entity is updated, a corresponding IndividualDocument.Log + is generated for the entity. This log is never generated by the user, but + it can be retrieved to check additional information on the IndividualDocument. + + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the log is created. ex: "5656565656565656" + - `:document` [IndividualDocument]: IndividualDocument entity to which the log refers to. + - `:errors` [list of binaries]: list of errors linked to this IndividualDocument event + - `:type` [binary]: type of the IndividualDocument event which triggered the log creation. ex: "created", "canceled", "processing", "failed", "success" + - `:created` [DateTime, default nil]: creation DateTime for the Log. ex: ~U[2020-3-10 10:30:0:0] + """ + @enforce_keys [ + :id, + :document, + :errors, + :type, + :created + ] + defstruct [ + :id, + :document, + :errors, + :type, + :created + ] + + @type t() :: %__MODULE__{} + + @doc """ + Receive a single IndividualDocument.Log object previously created by the Stark Infra API by its id + + ## Parameters (required): + - `:id` [binary]: object unique id. ex: "5656565656565656" + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - IndividualDocument.Log object that corresponds to the given id. + """ + @spec get( + binary, + user: Project.t() | + Organization.t() | nil + ) :: + {:ok, [Log.t()]} | + {:error, [Error.t()]} + def get(id, options \\ []) do + Rest.get_id(resource(), id, options) + end + + @doc """ + Same as get(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec get!( + binary, + user: Project.t() | Organization.t() | nil + ) :: Log.t() + def get!(id, options \\ []) do + Rest.get_id!(resource(), id, options) + end + + @doc """ + Receive a stream of IndividualDocument.Log objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020, 3, 10] + - `:types` [list of binaries, default []]: filter for log event types. ex: ["created", "canceled", "processing", "failed", "success"] + - `:document_ids` [list of binaries, default []]: list of IndividualDocument ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - stream of IndividualDocument.Log objects with updated attributes + """ + @spec query( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + document_ids: [binary], + user: Project.t() | Organization.t() + ) :: + ({:cont, {:ok, [Log.t()]}} | + {:error, [Error.t()]}, + any -> any) + def query(options \\ []) do + Rest.get_list(resource(), options) + end + + @doc """ + Same as query(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec query!( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + document_ids: [binary], + user: Project.t() | Organization.t() + ) :: [Log.t()] + def query!(options \\ []) do + Rest.get_list!(resource(), options) + end + + @doc """ + Receive a list of up to 100 IndividualDocument.Log objects previously created in the Stark Infra API and the cursor to the next page. + Use this function instead of query if you want to manually page your requests. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020, 3, 10] + - `:types` [list of binaries, default []]: filter for log event types. ex: ["created", "canceled", "processing", "failed", "success"] + - `:document_ids` [list of binaries, default []]: list of IndividualDocument ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of IndividualDocument.Log objects with updated attributes + - cursor to retrieve the next page of IndividualDocument.Log objects + """ + @spec page( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + document_ids: [binary], + user: Project.t() | Organization.t() + ) :: + {:ok, {binary, [Invoice.t()]}} | + {:error, [Error.t()]} + def page(options \\ []) do + Rest.get_page(resource(), options) + end + + @doc """ + Same as page(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec page!( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + document_ids: [binary], + user: Project.t() | Organization.t() + ) :: + [Log.t()] + def page!(options \\ []) do + Rest.get_page!(resource(), options) + end + + @doc false + def resource() do + { + "IndividualDocumentLog", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %Log{ + id: json[:id], + document: json[:document] |> API.from_api_json(&IndividualDocument.resource_maker/1), + created: json[:created] |> Check.datetime(), + type: json[:type], + errors: json[:errors] + } + end +end diff --git a/lib/individual_identity/individual_identity.ex b/lib/individual_identity/individual_identity.ex new file mode 100644 index 0000000..0fdae7b --- /dev/null +++ b/lib/individual_identity/individual_identity.ex @@ -0,0 +1,333 @@ +defmodule StarkInfra.IndividualIdentity do + alias __MODULE__, as: IndividualIdentity + alias StarkInfra.Error + alias StarkInfra.Utils.API + alias StarkInfra.Utils.Rest + alias StarkInfra.Utils.Check + alias StarkInfra.User.Project + alias StarkInfra.User.Organization + + @moduledoc """ + Groups IndividualIdentity related functions + """ + + @doc """ + An IndividualDocument represents an individual to be validated. It can have several individual documents attached + to it, which are used to validate the identity of the individual. Once an individual identity is created, individual + documents must be attached to it using the created method of the individual document resource. When all the required + individual documents are attached to an individual identity it can be sent to validation by patching its status to + processing. + + When you initialize a IndividualIdentity, the entity will not be automatically + created in the Stark Infra API. The 'create' function sends the objects + to the Stark Infra API and returns the list of created objects. + + ## Parameters (required): + - `:name` [binary]: individual's full name. ex: "Edward Stark". + - `:tax_id` [binary]: individual's tax ID (CPF). ex: "594.739.480-42" + + ## Parameters (optional): + - `:tags` [list of binaries, default nil]: list of binaries for reference when searching for IndividualIdentitys. ex: [\"employees\", \"monthly\"] + + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the IndividualIdentity is created. ex: "5656565656565656" + - `:status` [binary]: current status of the IndividualIdentity. ex: "created", "canceled", "processing", "failed", "success" + - `:created` [DateTime]: creation DateTime for the IndividualIdentity. ex: ~U[2020-3-10 10:30:0:0] + """ + @enforce_keys [ + :name, + :tax_id + ] + defstruct [ + :name, + :tax_id, + :tags, + :id, + :status, + :created + ] + + @type t() :: %__MODULE__{} + + @doc """ + Send a list of IndividualIdentity objects for creation in the Stark Infra API + + ## Parameters (required): + - `:identities` [list of IndividualIdentity objects]: list of IndividualIdentity objects to be created in the API + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of IndividualIdentity objects with updated attributes + """ + @spec create( + [IndividualIdentity.t() | map()], + user: Project.t() | Organization.t() | nil + ) :: + {:ok, [IndividualIdentity.t()]} | + {:error, [Error.t()]} + def create(identities, options \\ []) do + Rest.post( + resource(), + identities, + options + ) + end + + @doc """ + Same as create(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec create!( + [IndividualIdentity.t() | map()], + user: Project.t() | Organization.t() | nil + ) :: any + def create!(identities, options \\ []) do + Rest.post!( + resource(), + identities, + options + ) + end + + @doc """ + Receive a single IndividualIdentity object previously created in the Stark Infra API by its id + + ## Parameters (required): + - `:id` [binary]: object's unique id. ex: "5656565656565656" + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - IndividualIdentity object that corresponds to the given id. + """ + @spec get( + binary, + user: Project.t() | Organization.t() | nil + ) :: + {:ok, [IndividualIdentity.t()]} | + {:error, [Error.t()]} + def get(id, options \\ []) do + Rest.get_id(resource(), id, options) + end + + @doc """ + Same as get(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec get!(binary, user: Project.t() | Organization.t() | nil) :: any + def get!(id, options \\ []) do + Rest.get_id!(resource(), id, options) + end + + @doc """ + Receive a stream of IndividualIdentity objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020, 3, 10] + - `:status` [binary, default nil]: filter for status of retrieved objects. ex: ["created", "canceled", "processing", "failed", "success"] + - `:tags` [list of binaries, default []]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:ids` [list of binaries, default []]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - stream of IndividualIdentity objects with updated attributes + """ + @spec query( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: binary, + tags: [binary], + ids: [binary], + user: Project.t() | Organization.t() | nil + ) :: + ({:cont, {:ok, [IndividualIdentity.t()]}} | + {:error, [Error.t()]} | + {:halt, any} | + {:suspend, any}, + any -> any) + def query(options \\ []) do + Rest.get_list(resource(), options) + end + + @doc """ + Same as query(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec query!( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: binary, + tags: [binary], + ids: [binary], + user: Project.t() | Organization.t() | nil + ) :: + ({:cont, [IndividualIdentity.t()]} | + {:error, [Error.t()]} | + {:halt, any} | + {:suspend, any}, + any -> any) + def query!(options \\ []) do + Rest.get_list!(resource(), options) + end + + @doc """ + Receive a list of up to 100 IndividualIdentity objects previously created in the Stark Infra API and the cursor to the next page. + Use this function instead of query if you want to manually page your requests. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: Date filter for objects created only after specified date. ex: ~D[2020-3-10] + - `:before` [Date or binary, default nil]: Date filter for objects created only before specified date. ex: ~D(2020-3-10] + - `:status` [binary, default nil]: filter for status of retrieved objects. ex: ["created", "canceled", "processing", "failed", "success"] + - `:tags` [list of binaries, default []]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:ids` [list of binaries, default []]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of IndividualIdentity objects with updated attributes + - cursor to retrieve the next page of IndividualIdentity objects + """ + @spec page( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: binary, + tags: [binary], + ids: [binary], + user: Project.t() | Organization.t() | nil + ) :: + {:ok, {binary, [IndividualIdentity.t()]}} | + {:error, [Error.t()]} + def page(options \\ []) do + Rest.get_page(resource(), options) + end + + @doc """ + Same as page(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec page!( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: binary, + tags: [binary], + ids: [binary], + user: Project.t() | Organization.t() | nil + ) :: + [IndividualIdentity.t()] + def page!(options \\ []) do + Rest.get_page!(resource(), options) + end + + @doc """ + Update an IndividualIdentity by passing id. + + ## Parameters (required): + - `:id` [binary]: IndividualIdentity id. ex: '5656565656565656' + - `:status` [binary]: You may send IndividualDocuments to validation by passing 'processing' in the status + + ## Parameters (Optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - target IndividualIdentity with updated attributes + """ + @spec update( + id: binary, + status: binary, + user: (Organization.t() | Project.t() | nil) + ) :: + {:ok, IndividualIdentity.t()} | + {:error, [Error.t()]} + def update(id, parameters \\ []) do + Rest.patch_id( + resource(), + id, + parameters + ) + end + + @doc """ + Same as update(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec update!( + id: binary, + status: binary, + user: (Organization.t() | Project.t() | nil) + ) :: any + def update!(id, parameters \\ []) do + Rest.patch_id!( + resource(), + id, + parameters + ) + end + + @doc """ + Cancel an IndividualIdentity entity previously created in the Stark Infra API. + + ## Parameters (required): + - `:id` [binary]: IndividualIdentity unique id. ex: "5656565656565656" + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - canceled IndividualIdentity object + """ + @spec cancel( + id: binary, + user: (Organization.t() | Project.t() | nil) + ) :: + {:ok, IndividualIdentity.t()} | + {:error, [Error.t()]} + def cancel(id, options \\ []) do + Rest.delete_id( + resource(), + id, + options + ) + end + + @doc """ + Same as cancel(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec cancel!( + id: binary, + user: (Organization.t() | Project.t() | nil) + ) :: any + def cancel!(id, options \\ []) do + Rest.delete_id!( + resource(), + id, + options + ) + end + + @doc false + def resource() do + { + "IndividualIdentity", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %IndividualIdentity{ + name: json[:name], + tax_id: json[:tax_id], + tags: json[:tags], + id: json[:id], + status: json[:status], + created: json[:created], + } + end +end diff --git a/lib/individual_identity/individual_identity_log.ex b/lib/individual_identity/individual_identity_log.ex new file mode 100644 index 0000000..4da08ff --- /dev/null +++ b/lib/individual_identity/individual_identity_log.ex @@ -0,0 +1,187 @@ +defmodule StarkInfra.IndividualIdentity.Log do + alias __MODULE__, as: Log + alias StarkInfra.Utils.Rest + alias StarkInfra.Utils.API + alias StarkInfra.Utils.Check + alias StarkInfra.IndividualIdentity + alias StarkInfra.User.Project + alias StarkInfra.User.Organization + alias StarkInfra.Error + + @moduledoc """ + Groups IndividualIdentity.Log related functions + """ + @doc """ + Every time an IndividualIdentity entity is updated, a corresponding IndividualIdentity.Log + is generated for the entity. This log is never generated by the user, but + it can be retrieved to check additional information on the IndividualIdentity. + + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the log is created. ex: "5656565656565656" + - `:identity` [IndividualIdentity]: IndividualIdentity entity to which the log refers to. + - `:errors` [list of binaries]: list of errors linked to this IndividualIdentity event + - `:type` [binary]: type of the IndividualIdentity event which triggered the log creation. ex: "created", "canceled", "processing", "failed", "success" + - `:created` [DateTime, default nil]: creation DateTime for the Log. ex: ~U[2020-3-10 10:30:0:0] + """ + @enforce_keys [ + :id, + :identity, + :errors, + :type, + :created + ] + defstruct [ + :id, + :identity, + :errors, + :type, + :created + ] + + @type t() :: %__MODULE__{} + + @doc """ + Receive a single IndividualIdentity.Log object previously created by the Stark Infra API by its id + + ## Parameters (required): + - `:id` [binary]: object unique id. ex: "5656565656565656" + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - IndividualIdentity.Log object that corresponds to the given id. + """ + @spec get( + binary, + user: Project.t() | + Organization.t() | nil + ) :: + {:ok, [Log.t()]} | + {:error, [Error.t()]} + def get(id, options \\ []) do + Rest.get_id(resource(), id, options) + end + + @doc """ + Same as get(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec get!( + binary, + user: Project.t() | Organization.t() | nil + ) :: Log.t() + def get!(id, options \\ []) do + Rest.get_id!(resource(), id, options) + end + + @doc """ + Receive a stream of IndividualIdentity.Log objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020, 3, 10] + - `:types` [list of binaries, default []]: filter for log event types. ex: ["created", "canceled", "processing", "failed", "success"] + - `:identity_ids` [list of binaries, default []]: list of IndividualIdentity ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - stream of IndividualIdentity.Log objects with updated attributes + """ + @spec query( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + identity_ids: [binary], + user: Project.t() | Organization.t() + ) :: + ({:cont, {:ok, [Log.t()]}} | + {:error, [Error.t()]}, + any -> any) + def query(options \\ []) do + Rest.get_list(resource(), options) + end + + @doc """ + Same as query(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec query!( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + identity_ids: [binary], + user: Project.t() | Organization.t() + ) :: [Log.t()] + def query!(options \\ []) do + Rest.get_list!(resource(), options) + end + + @doc """ + Receive a list of up to 100 IndividualIdentity.Log objects previously created in the Stark Infra API and the cursor to the next page. + Use this function instead of query if you want to manually page your requests. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020, 3, 10] + - `:types` [list of binaries, default []]: filter for log event types. ex: ["created", "canceled", "processing", "failed", "success"] + - `:identity_ids` [list of binaries, default []]: list of IndividualIdentity ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of IndividualIdentity.Log objects with updated attributes + - cursor to retrieve the next page of IndividualIdentity.Log objects + """ + @spec page( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + identity_ids: [binary], + user: Project.t() | Organization.t() + ) :: + {:ok, {binary, [Invoice.t()]}} | + {:error, [Error.t()]} + def page(options \\ []) do + Rest.get_page(resource(), options) + end + + @doc """ + Same as page(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec page!( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + identity_ids: [binary], + user: Project.t() | Organization.t() + ) :: + [Log.t()] + def page!(options \\ []) do + Rest.get_page!(resource(), options) + end + + @doc false + def resource() do + { + "IndividualIdentityLog", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %Log{ + id: json[:id], + identity: json[:identity] |> API.from_api_json(&IndividualIdentity.resource_maker/1), + created: json[:created] |> Check.datetime(), + type: json[:type], + errors: json[:errors] + } + end +end diff --git a/lib/issuing_authorization/issuing_authorization.ex b/lib/issuing_authorization/issuing_authorization.ex deleted file mode 100644 index 8c9a991..0000000 --- a/lib/issuing_authorization/issuing_authorization.ex +++ /dev/null @@ -1,221 +0,0 @@ -defmodule StarkInfra.IssuingAuthorization do - alias __MODULE__, as: IssuingAuthorization - alias StarkInfra.Error - alias StarkInfra.Utils.JSON - alias StarkInfra.Utils.Parse - alias StarkInfra.Utils.Check - alias StarkInfra.User.Project - alias StarkInfra.User.Organization - - - @moduledoc """ - Groups IssuingAuthorization related functions - """ - - @doc """ - An IssuingAuthorization presents purchase data to be analysed and answered with an approval or a declination. - - ## Attributes (return-only): - - `:end_to_end_id` [string]: central bank's unique transaction ID. ex: "E79457883202101262140HHX553UPqeq" - - `:amount` [integer]: IssuingPurchase value in cents. Minimum = 0. ex: 1234 (= R$ 12.34) - - `:tax` [integer]: IOF amount taxed for international purchases. ex: 1234 (= R$ 12.34) - - `:card_id` [string]: unique id returned when IssuingCard is created. ex: "5656565656565656" - - `:issuer_amount` [integer]: issuer amount. ex: 1234 (= R$ 12.34) - - `:issuer_currency_code` [string]: issuer currency code. ex: "USD" - - `:merchant_amount` [integer]: merchant amount. ex: 1234 (= R$ 12.34) - - `:merchant_currency_code` [string]: merchant currency code. ex: "USD" - - `:merchant_category_code` [string]: merchant category code. ex: "fastFoodRestaurants" - - `:merchant_country_code` [string]: merchant country code. ex: "USA" - - `:acquirer_id` [string]: acquirer ID. ex: "5656565656565656" - - `:merchant_id` [string]: merchant ID. ex: "5656565656565656" - - `:merchant_name` [string]: merchant name. ex: "Google Cloud Platform" - - `:merchant_fee` [integer]: merchant fee charged. ex: 200 (= R$ 2.00) - - `:wallet_id` [string]: virtual wallet ID. ex: "googlePay" - - `:method_code` [string]: method code. ex: "chip", "token", "server", "manual", "magstripe" or "contactless" - - `:score` [float]: internal score calculated for the authenticity of the purchase. Nil in case of insufficient data. ex: 7.6 - - `:is_partial_allowed` [bool]: true if the the merchant allows partial purchases. ex: False - - `:purpose` [string]: purchase purpose. ex: "purchase" - - `:card_tags` [list of strings]: tags of the IssuingCard responsible for this purchase. ex: ["travel", "food"] - - `:holder_tags` [list of strings]: tags of the IssuingHolder responsible for this purchase. ex: ["technology", "john snow"] - """ - @enforce_keys [ - :id, - :end_to_end_id, - :amount, - :tax, - :card_id, - :issuer_amount, - :issuer_currency_code, - :merchant_amount, - :merchant_currency_code, - :merchant_category_code, - :merchant_country_code, - :acquirer_id, - :merchant_id, - :merchant_name, - :merchant_fee, - :wallet_id, - :method_code, - :score, - :is_partial_allowed, - :purpose, - :card_tags, - :holder_tags - ] - defstruct [ - :id, - :end_to_end_id, - :amount, - :tax, - :card_id, - :issuer_amount, - :issuer_currency_code, - :merchant_amount, - :merchant_currency_code, - :merchant_category_code, - :merchant_country_code, - :acquirer_id, - :merchant_id, - :merchant_name, - :merchant_fee, - :wallet_id, - :method_code, - :score, - :is_partial_allowed, - :purpose, - :card_tags, - :holder_tags - ] - - @type t() :: %__MODULE__{} - - @doc """ - Create a single IssuingAuthorization struct received from IssuingAuthorization at the informed endpoint. - If the provided digital signature does not check out with the StarkInfra public key, a - starkinfra.error.InvalidSignatureError will be raised. - - ## Parameters (required): - - `:content` [string]: response content from request received at user endpoint (not parsed) - - `:signature` [string]: base-64 digital signature received at response header "Digital-Signature" - - ## Options - - `cache_pid` [PID, default nil]: PID of the process that holds the public key cache, returned on previous parses. If not provided, a new cache process will be generated. - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. - - ## Return: - - Parsed IssuingAuthorization struct - """ - @spec parse( - content: binary, - signature: binary, - cache_pid: PID, - user: Project.t() | Organization.t() - ):: - {:ok, IssuingAuthorization.t()} | - {:error, [error: Error.t()]} - def parse(options) do - %{content: content, signature: signature, cache_pid: cache_pid, user: user} = - Enum.into( - options |> Check.enforced_keys([:content, :signature]), - %{cache_pid: nil, user: nil} - ) - Parse.parse_and_verify( - content: content, - signature: signature, - cache_pid: cache_pid, - key: nil, - resource_maker: &resource_maker/1, - user: user - ) - end - - @doc """ - Same as parse(), but it will unwrap the error tuple and raise in case of errors. - """ - @spec parse!( - content: binary, - signature: binary, - cache_pid: PID, - user: Project.t() | Organization.t() - ) :: any - def parse!(options \\ []) do - %{content: content, signature: signature, cache_pid: cache_pid, user: user} = - Enum.into( - options |> Check.enforced_keys([:content, :signature]), - %{cache_pid: nil, user: nil} - ) - Parse.parse_and_verify!( - content: content, - signature: signature, - cache_pid: cache_pid, - key: nil, - resource_maker: &resource_maker/1, - user: user - ) - end - - @doc """ - Helps you respond IssuingAuthorization requests. - - ## Parameters (required): - - `:status` [string]: sub-issuer response to the authorization. ex: "accepted" or "denied" - - ## Options - - `:amount` [integer, default 0]: amount in cents that was authorized. ex: 1234 (= R$ 12.34) - - `:reason` [string, default ""]: denial reason. ex: "other" - - `:tags` [list of strings, default []]: tags to filter retrieved object. ex: ["tony", "stark"] - - ## Return: - - Dumped JSON string that must be returned to us on the IssuingAuthorization request - """ - @spec response!( - status: binary, - amount: integer, - reason: binary, - tags: [binary] - ) :: any - def response!(status, options \\ []) do - options = options ++ [status: status] - JSON.encode!(%{authorization: - Enum.into(options |> Check.enforced_keys([:status]), %{amount: 0, reason: "", tags: []}) - |> Enum.filter(fn {_, v} -> v != nil end) - |> Enum.into(%{}) - }) - end - - @doc false - def resource() do - { - "IssuingAuthorization", - &resource_maker/1 - } - end - - @doc false - def resource_maker(json) do - %IssuingAuthorization{ - id: json[:id], - end_to_end_id: json[:end_to_end_id], - amount: json[:amount], - tax: json[:tax], - card_id: json[:card_id], - issuer_amount: json[:issuer_amount], - issuer_currency_code: json[:issuer_currency_code], - merchant_amount: json[:merchant_amount], - merchant_currency_code: json[:merchant_currency_code], - merchant_category_code: json[:merchant_category_code], - merchant_country_code: json[:merchant_country_code], - acquirer_id: json[:acquirer_id], - merchant_id: json[:merchant_id], - merchant_name: json[:merchant_name], - merchant_fee: json[:merchant_fee], - wallet_id: json[:wallet_id], - method_code: json[:method_code], - score: json[:score], - is_partial_allowed: json[:is_partial_allowed], - purpose: json[:purpose], - card_tags: json[:card_tags], - holder_tags: json[:holder_tags] - } - end -end diff --git a/lib/issuing_balance/issuing_balance.ex b/lib/issuing_balance/issuing_balance.ex index 5c5f813..f00ff15 100644 --- a/lib/issuing_balance/issuing_balance.ex +++ b/lib/issuing_balance/issuing_balance.ex @@ -11,15 +11,15 @@ defmodule StarkInfra.IssuingBalance do """ @doc """ - The IssuingBalance struct displays the current issuing balance of the Workspace, + The IssuingBalance object displays the current issuing balance of the Workspace, which is the result of the sum of all transactions within this Workspace. The balance is never generated by the user, but it can be retrieved to see the available information. ## Attributes (return-only): - - `:id` [string]: unique id returned when IssuingBalance is created. ex: "5656565656565656" + - `:id` [binary]: unique id returned when IssuingBalance is created. ex: "5656565656565656" - `:amount` [integer]: current balance amount of the Workspace in cents. ex: 200 (= R$ 2.00) - - `:currency` [string]: currency of the current Workspace. Expect others to be added eventually. ex: "BRL" + - `:currency` [binary]: currency of the current Workspace. Expect others to be added eventually. ex: "BRL" - `:updated` [DateTime]: latest update DateTime for the IssuingBalance. ex: ~U[2020-3-10 10:30:0:0] """ @enforce_keys [ @@ -38,18 +38,18 @@ defmodule StarkInfra.IssuingBalance do @type t() :: %__MODULE__{} @doc """ - Receive the IssuingBalance struct linked to your Workspace in the Stark Infra API + Receive the IssuingBalance object linked to your Workspace in the Stark Infra API - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - IssuingBalance struct with updated attributes + - IssuingBalance object that corresponds to the given id. """ @spec get( user: Project.t() | Organization.t() | nil ) :: - { :ok, [IssuingBalance.t()] } | + {:ok, [IssuingBalance.t()] } | { :error, [error: Error.t()] } def get(options \\ []) do case Rest.get_list(resource(), options) |> Enum.take(1) do diff --git a/lib/issuing_bin/issuing_bin.ex b/lib/issuing_bin/issuing_bin.ex deleted file mode 100644 index 20866b9..0000000 --- a/lib/issuing_bin/issuing_bin.ex +++ /dev/null @@ -1,133 +0,0 @@ -defmodule StarkInfra.IssuingBin do - alias __MODULE__, as: IssuingBin - alias StarkInfra.Utils.Rest - alias StarkInfra.Utils.Check - alias StarkInfra.User.Project - alias StarkInfra.User.Organization - alias StarkInfra.Error - - @moduledoc """ - Groups IssuingBin related functions - """ - - @doc """ - The IssuingBin object displays information of BINs registered to your Workspace. - They represent a group of cards that begin with the same numbers (BIN) and offer the same product to end customers. - - ## Attributes (return-only): - - `:id` [string]: unique BIN number registered within the card network. ex: "53810200" - - `:network` [string]: card network flag. ex: "mastercard" - - `:settlement` [string]: settlement type. ex: "credit" - - `:category` [string]: purchase category. ex: "prepaid" - - `:client` [string]: client type. ex: "business" - - `:updated` [DateTime]: latest update DateTime for the IssuingBin. ex: ~U[2020-3-10 10:30:0:0] - - `:created` [DateTime]: creation datetime for the IssuingBin. ex: ~U[2020-03-10 10:30:0:0] - """ - @enforce_keys [ - :id, - :network, - :settlement, - :category, - :client, - :updated, - :created - ] - defstruct [ - :id, - :network, - :settlement, - :category, - :client, - :updated, - :created - ] - - @type t() :: %__MODULE__{} - - @doc """ - Receive a stream of IssuingBin structs previously registered in the Stark Infra API - - ## Options: - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. - - ## Return: - - stream of IssuingBin structs with updated attributes - """ - @spec query( - limit: integer, - user: Project.t() | Organization.t() | nil - ) :: - { :ok, [IssuingBin.t()] } | - { :error, [error: Error.t()] } - def query(options \\ []) do - Rest.get_list(resource(), options) - end - - @doc """ - Same as query(), but it will unwrap the error tuple and raise in case of errors. - """ - @spec query!( - limit: integer, - user: Project.t() | Organization.t() | nil - ) :: any - def query!(options \\ []) do - Rest.get_list!(resource(), options) - end - - @doc """ - Receive a list of up to 100 IssuingBin structs previously registered in the Stark Infra API and the cursor to the next page. - - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. - - ## Return: - - list of IssuingBin structs with updated attributes - - cursor to retrieve the next page of IssuingBin structs - """ - @spec page( - cursor: binary, - limit: integer, - user: Project.t() | Organization.t() | nil - ) :: - { :ok, {binary, [IssuingBin.t()]}} | - { :error, [error: Error.t()] } - def page(options \\ []) do - Rest.get_page(resource(), options) - end - - @doc """ - \Same as page(), but it will unwrap the error tuple and raise in case of errors. - """ - @spec page!( - cursor: binary, - limit: integer, - user: Project.t() | Organization.t() | nil - ) :: any - def page!(options \\ []) do - Rest.get_page!(resource(), options) - end - - @doc false - def resource() do - { - "IssuingBin", - &resource_maker/1 - } - end - - @doc false - def resource_maker(json) do - %IssuingBin{ - id: json[:id], - network: json[:network], - settlement: json[:settlement], - category: json[:category], - client: json[:client], - updated: json[:updated] |> Check.datetime(), - created: json[:created] |> Check.datetime() - } - end -end diff --git a/lib/issuing_card/issuing_card.ex b/lib/issuing_card/issuing_card.ex index c0ede8c..4ca3129 100644 --- a/lib/issuing_card/issuing_card.ex +++ b/lib/issuing_card/issuing_card.ex @@ -13,34 +13,34 @@ defmodule StarkInfra.IssuingCard do """ @doc """ - The IssuingCard struct displays the information of the cards created in your Workspace. + The IssuingCard object displays the information of the cards created in your Workspace. Sensitive information will only be returned when the "expand" parameter is used, to avoid security concerns. ## Parameters (required): - - `:holder_name` [string]: card holder name. ex: "Tony Stark" - - `:holder_tax_id` [string]: card holder tax ID. ex: "012.345.678-90" - - `:holder_external_id` [string] card holder unique id, generated by the user to avoid duplicated holders. ex: "my-entity/123" + - `:holder_name` [binary]: card holder name. ex: "Tony Stark" + - `:holder_tax_id` [binary]: card holder tax ID. ex: "012.345.678-90" + - `:holder_external_id` [binary] card holder unique id, generated by the user to avoid duplicated holders. ex: "my-entity/123" ## Parameters (optional): - - `:display_name` [string, default nil]: card displayed name. ex: "ANTHONY STARK" + - `:display_name` [binary, default nil]: card displayed name. ex: "ANTHONY STARK" - `:rules` [list of IssuingRule, default nil]: [EXPANDABLE] list of card spending rules. - - `:bin_id` [string, default nil]: BIN ID to which the card is bound. ex: "53810200" - - `:tags` [list of strings]: list of strings for tagging. ex: ["travel", "food"] - - `:street_line_1` [string, default nil]: card holder main address. ex: "Av. Paulista, 200" - - `:street_line_2` [string, default nil]: card holder address complement. ex: "Apto. 123" - - `:district` [string]: card holder address district / neighbourhood. ex: "Bela Vista" - - `:city` [string, default nil]: card holder address city. ex: "Rio de Janeiro" - - `:state_code` [string, default nil]: card holder address state. ex: "GO" - - `:zip_code` [string]: card holder address zip code. ex: "01311-200" + - `:product_id` [binary, default nil]: card product ID to which the card is bound. ex: "53810200" + - `:tags` [list of binaries]: list of binaries for tagging. ex: ["travel", "food"] + - `:street_line_1` [binary, default nil]: card holder main address. ex: "Av. Paulista, 200" + - `:street_line_2` [binary, default nil]: card holder address complement. ex: "Apto. 123" + - `:district` [binary, default sub-issuer district]: card holder address district / neighbourhood. ex: "Bela Vista" + - `:city` [binary, default sub-issuer city]]: card holder address city. ex: "Rio de Janeiro" + - `:state_code` [binary, default sub-issuer state code]: card holder address state. ex: "GO" + - `:zip_code` [binary, default sub-issuer zip code]: card holder address zip code. ex: "01311-200" ## Attributes (return-only): - - `:id` [string]: unique id returned when IssuingCard is created. ex: "5656565656565656" - - `:holder_id` [string]: card holder unique id. ex: "5656565656565656" - - `:type` [string]: card type. ex: "virtual" - - `:status` [string]: current IssuingCard status. ex: "canceled" or "active" - - `:number` [string]: [EXPANDABLE] masked card number. Expand to unmask the value. ex: "123". - - `:security_code` [string]: [EXPANDABLE] masked card verification value (cvv). Expand to unmask the value. ex: "123". - - `:expiration` [string]: [EXPANDABLE] masked card expiration datetime. Expand to unmask the value. ex: '2020-03-10 10:30:00.000'. + - `:id` [binary]: unique id returned when IssuingCard is created. ex: "5656565656565656" + - `:holder_id` [binary]: card holder unique id. ex: "5656565656565656" + - `:type` [binary]: card type. ex: "virtual" + - `:status` [binary]: current IssuingCard status. Options: "active", "blocked", "canceled", "expired" + - `:number` [binary]: [EXPANDABLE] masked card number. Expand to unmask the value. ex: "123". + - `:security_code` [binary]: [EXPANDABLE] masked card verification value (cvv). Expand to unmask the value. ex: "123". + - `:expiration` [binary]: [EXPANDABLE] masked card expiration datetime. Expand to unmask the value. ex: ~U[2020-3-10 10:30:0:0] - `:updated` [DateTime]: latest update DateTime for the IssuingCard. ex: ~U[2020-3-10 10:30:0:0] - `:created` [DateTime]: creation datetime for the IssuingCard. ex: ~U[2020-03-10 10:30:0:0] """ @@ -56,7 +56,7 @@ defmodule StarkInfra.IssuingCard do :holder_external_id, :display_name, :rules, - :bin_id, + :product_id, :tags, :street_line_1, :street_line_2, @@ -78,17 +78,17 @@ defmodule StarkInfra.IssuingCard do @type t() :: %__MODULE__{} @doc """ - Send a list of IssuingCard structs for creation in the Stark Infra API. + Send a list of IssuingCard objects for creation in the Stark Infra API. ## Parameters (required): - - `:cards` [list of IssuingCard structs]: list of IssuingCard structs to be created in the API + - `:cards` [list of IssuingCard objects]: list of IssuingCard objects to be created in the API - ## Options: - - `:expand` [list of strings, default []]: fields to expand information. ex: ["rules", "security_code", "number", "expiration"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:expand` [list of binaries, default []]: fields to expand information. ex: ["rules", "security_code", "number", "expiration"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of IssuingCard structs with updated attributes + - list of IssuingCard objects with updated attributes """ @spec create( [IssuingCard.t() | map], @@ -122,32 +122,32 @@ defmodule StarkInfra.IssuingCard do end @doc """ - Receive a stream of IssuingCards structs previously created in the Stark Infra API. - - ## Options: - - `:status` [string, default nil]: filter for status of retrieved structs. ex: "paid" or "registered" - - `:types` [list of strings, default nil]: card type. ex: ["virtual"] - - `:holder_ids` [list of strings]: card holder IDs. ex: ["5656565656565656", "4545454545454545"] - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:tags` [list of strings, default nil]: tags to filter retrieved structs. ex: ["tony", "stark"] - - `:ids` [list of strings, default nil]: list of ids to filter retrieved structs. ex: ["5656565656565656", "4545454545454545"] - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:expand` [list of strings, default []]: fields to expand information. ex: ["rules", "security_code", "number", "expiration"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + Receive a stream of IssuingCard objects previously created in the Stark Infra API. + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. ex: ["active", "blocked", "canceled", "expired"] + - `:types` [list of binaries, default nil]: card type. ex: ["virtual"] + - `:holder_ids` [list of binaries, default nil]: card holder IDs. ex: ["5656565656565656", "4545454545454545"] + - `:tags` [list of binaries, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:expand` [list of binaries, default nil]: fields to expand information. ex: ["rules", "security_code", "number", "expiration"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of IssuingCards structs with updated attributes + - stream of IssuingCard objects with updated attributes """ @spec query( - status: binary, - types: [binary], - holder_ids: [binary], + limit: integer, after: Date.t() | binary, before: Date.t() | binary, + status: [binary], + types: [binary], + holder_ids: [binary], tags: [binary], ids: [binary], - limit: integer, expand: [binary], user: (Organization.t() | Project.t() | nil) ) :: @@ -164,14 +164,14 @@ defmodule StarkInfra.IssuingCard do Same as query(), but it will unwrap the error tuple and raise in case of errors. """ @spec query!( - status: binary, - types: [binary], - holder_ids: [binary], + limit: integer, after: Date.t() | binary, before: Date.t() | binary, + status: [binary], + types: [binary], + holder_ids: [binary], tags: [binary], ids: [binary], - limit: integer, expand: [binary], user: (Organization.t() | Project.t() | nil) ) :: any @@ -183,35 +183,35 @@ defmodule StarkInfra.IssuingCard do end @doc """ - Receive a list of IssuingCards structs previously created in the Stark Infra API and the cursor to the next page. - - ## Options: - - `:status` [string, default nil]: filter for status of retrieved structs. ex: "paid" or "registered" - - `:types` [list of strings, default nil]: card type. ex: ["virtual"] - - `:holder_ids` [list of strings, default nil]: card holder IDs. ex: ["5656565656565656", "4545454545454545"] - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:tags` [list of strings, default nil]: tags to filter retrieved structs. ex: ["tony", "stark"] - - `:ids` [list of strings, default nil]: list of ids to filter retrieved structs. ex: ["5656565656565656", "4545454545454545"] - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:expand` [list of strings, default []]: fields to expand information. ex: ["rules", "security_code", "number", "expiration"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + Receive a list of IssuingCard previously created in the Stark Infra API and the cursor to the next page. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. ex: ["active", "blocked", "canceled", "expired"] + - `:types` [list of binaries, default nil]: card type. ex: ["virtual"] + - `:holder_ids` [list of binaries]: card holder IDs. ex: ["5656565656565656", "4545454545454545"] + - `:tags` [list of binaries, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:expand` [list of binaries, default []]: fields to expand information. ex: ["rules", "security_code", "number", "expiration"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of IssuingCards structs with updated attributes - - cursor to retrieve the next page of IssuingCards structs + - list of IssuingCard objects with updated attributes + - cursor to retrieve the next page of IssuingCard objects """ @spec page( - status: binary, - types: [binary], - holder_ids: [binary], + cursor: binary, + limit: integer, after: Date.t() | binary, before: Date.t() | binary, + status: [binary], + types: [binary], + holder_ids: [binary], tags: [binary], ids: [binary], - limit: integer, - cursor: binary, expand: [binary], user: (Organization.t() | Project.t() | nil) ) :: @@ -228,15 +228,15 @@ defmodule StarkInfra.IssuingCard do Same as page(), but it will unwrap the error tuple and raise in case of errors. """ @spec page!( - status: binary, - types: [binary], - holder_ids: [binary], + cursor: binary, + limit: integer, after: Date.t() | binary, before: Date.t() | binary, + status: [binary], + types: [binary], + holder_ids: [binary], tags: [binary], ids: [binary], - limit: integer, - cursor: binary, expand: [binary], user: (Organization.t() | Project.t() | nil) ) :: any @@ -248,17 +248,17 @@ defmodule StarkInfra.IssuingCard do end @doc """ - Receive a single IssuingCards struct previously created in the Stark Infra API by its id. + Receive a single IssuingCard objects previously created in the Stark Infra API by its id. ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:expand` [list of strings, default nil]: fields to expand information. ex: ["rules"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:expand` [list of binaries, default nil]: fields to expand information. ex: ["rules", "security_code", "number", "expiration"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - IssuingCards struct with updated attributes + - IssuingCard objects that corresponds to the given id. """ @spec get( id: binary, @@ -295,14 +295,15 @@ defmodule StarkInfra.IssuingCard do Update an IssuingCard by passing id. ## Parameters (required): - - `:id` [string]: IssuingCard id. ex: '5656565656565656' + - `:id` [binary]: IssuingCard id. ex: '5656565656565656' ## Parameters (Optional): - - `:status` [string]: You may block the IssuingCard by passing 'blocked' in the status - - `:display_name` [string, default nil]: card displayed name - - `:rules` [list of dictionaries, default nil]: list of dictionaries with "amount": int, "currencyCode": string, "id": string, "interval": string, "name": string pairs. - - `:tags` [list of strings, default nil]: list of strings for tagging - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + - `:status` [binary, default nil]: You may block the IssuingCard by passing 'blocked' or activate by passing 'active' in the status + - `:pin` [binary, default nil]: You may unlock your physical card by passing its PIN. This is also the PIN you use to authorize a purhcase. + - `:display_name` [binary, default nil]: card displayed name. ex: "ANTHONY EDWARD" + - `:rules` [list of dictionaries, default nil]: list of dictionaries with "amount": int, "currencyCode": binary, "id": binary, "interval": binary, "name": binary pairs. + - `:tags` [list of binaries, default nil]: list of binaries for tagging + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - target IssuingCard with updated attributes @@ -311,6 +312,7 @@ defmodule StarkInfra.IssuingCard do id: binary, status: binary, display_name: binary, + pin: binary, rules: [IssuingRule.t()], tags: [binary], user: (Organization.t() | Project.t() | nil) @@ -332,6 +334,7 @@ defmodule StarkInfra.IssuingCard do id: binary, status: binary, display_name: binary, + pin: binary, rules: [IssuingRule.t()], tags: [binary], user: (Organization.t() | Project.t() | nil) @@ -348,13 +351,13 @@ defmodule StarkInfra.IssuingCard do Cancel an IssuingCard entity previously created in the Stark Infra API. ## Parameters (required): - - `:id` [string]: IssuingCard unique id. ex: "5656565656565656" + - `:id` [binary]: IssuingCard unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - canceled IssuingCard struct + - canceled IssuingCard object """ @spec cancel( id: binary, @@ -400,7 +403,7 @@ defmodule StarkInfra.IssuingCard do holder_tax_id: json[:holder_tax_id], holder_external_id: json[:holder_external_id], display_name: json[:display_name], - bin_id: json[:bin_id], + product_id: json[:product_id], tags: json[:tags], street_line_1: json[:street_line_1], street_line_2: json[:street_line_2], diff --git a/lib/issuing_card/issuing_card_log.ex b/lib/issuing_card/issuing_card_log.ex index 373f74e..1ff5c8b 100644 --- a/lib/issuing_card/issuing_card_log.ex +++ b/lib/issuing_card/issuing_card_log.ex @@ -16,10 +16,10 @@ defmodule StarkInfra.IssuingCard.Log do user, but it can be retrieved to check additional information on the IssuingCard. - ## Attributes: - - `:id` [string]: unique id returned when the log is created. ex: "5656565656565656" + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the log is created. ex: "5656565656565656" - `:card` [IssuingCard]: IssuingCard entity to which the log refers to. - - `:type` [string]: type of the IssuingCard event which triggered the log creation. ex: "blocked", "canceled", "created", "expired", "unblocked", "updated" + - `:type` [binary]: type of the IssuingCard event which triggered the log creation. ex: "blocked", "canceled", "created", "expired", "unblocked", "updated" - `:created` [DateTime]: creation datetime for the log. ex: ~U[2020-03-10 10:30:0:0] """ @enforce_keys [ @@ -38,22 +38,22 @@ defmodule StarkInfra.IssuingCard.Log do @type t() :: %__MODULE__{} @doc """ - Receive a single IssuingCard.Log struct previously created by the Stark Infra API by its id. + Receive a single IssuingCard.Log object previously created by the Stark Infra API by its id. ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - IssuingCard.Log struct with updated attributes + - IssuingCard.Log object that corresponds to the given id. """ @spec get( id: binary, user: Project.t() | Organization.t() | nil ) :: - { :ok, Log.t() } | + {:ok, Log.t() } | { :error, [Error.t()] } def get(id, options \\ []) do Rest.get_id( @@ -79,18 +79,18 @@ defmodule StarkInfra.IssuingCard.Log do end @doc """ - Receive a stream of IssuingCard.Log structs previously created in the Stark Infra API - - ## Options: - - `:ids` [list of strings, default nil]: list of ids to filter retrieved structs. ex: ["5656565656565656", "4545454545454545"] - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:types` [list of strings, default nil]: filter for log event types. ex: ["blocked", "canceled", "created", "expired", "unblocked", "updated"] - - `:card_ids` [list of strings, default nil]: list of IssuingCard ids to filter logs. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + Receive a stream of IssuingCard.Log objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:types` [list of binaries, default nil]: filter for log event types. ex: ["blocked", "canceled", "created", "expired", "unblocked", "updated"] + - `:card_ids` [list of binaries, default nil]: list of IssuingCard ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of IssuingCard.Log structs with updated attributes + - stream of IssuingCard.Log objects with updated attributes """ @spec query( ids: [binary], @@ -101,7 +101,7 @@ defmodule StarkInfra.IssuingCard.Log do card_ids: [binary], user: Project.t() | Organization.t() | nil ) :: - { :ok, {binary, [Log.t()]} } | + {:ok, {binary, [Log.t()]} } | { :error, [Error.t()] } def query(options \\ []) do Rest.get_list( @@ -130,34 +130,34 @@ defmodule StarkInfra.IssuingCard.Log do end @doc """ - Receive a list of up to 100 IssuingCard.Log structs previously created in the Stark Infra API and the cursor to the next page. + Receive a list of up to 100 IssuingCard.Log objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your requests. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:ids` [list of strings, default nil]: list of ids to filter retrieved structs. ex: ["5656565656565656", "4545454545454545"] - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. It must be an integer between 1 and 100. ex: 50 - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:types` [list of strings, default nil]: filter for log event types. ex: ["blocked", "canceled", "created", "expired", "unblocked", "updated"] - - `:card_ids` [list of strings, default nil]: list of IssuingCard ids to filter logs. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:types` [list of binaries, default nil]: filter for log event types. ex: ["blocked", "canceled", "created", "expired", "unblocked", "updated"] + - `:card_ids` [list of binaries, default nil]: list of IssuingCard ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of IssuingCard.Log structs with updated attributes - - cursor to retrieve the next page of IssuingCard.Log structs + - list of IssuingCard.Log objects with updated attributes + - cursor to retrieve the next page of IssuingCard.Log objects """ @spec page( cursor: binary, - ids: [binary], limit: integer, after: Date.t() | binary, before: Date.t() | binary, types: [binary], card_ids: [binary], + ids: [binary], user: Project.t() | Organization.t() | nil ) :: - { :ok, {binary, [Log.t()]} } | + {:ok, {binary, [Log.t()]} } | { :error, [Error.t()] } def page(options \\ []) do Rest.get_page( @@ -171,12 +171,12 @@ defmodule StarkInfra.IssuingCard.Log do """ @spec page!( cursor: binary, - ids: [binary], limit: integer, after: Date.t() | binary, before: Date.t() | binary, types: [binary], card_ids: [binary], + ids: [binary], user: Project.t() | Organization.t() | nil ) :: any def page!(options \\ []) do diff --git a/lib/issuing_design/issuing_design.ex b/lib/issuing_design/issuing_design.ex new file mode 100644 index 0000000..d19250e --- /dev/null +++ b/lib/issuing_design/issuing_design.ex @@ -0,0 +1,232 @@ +defmodule StarkInfra.IssuingDesign do + alias __MODULE__, as: IssuingDesign + alias StarkInfra.IssuingRule + alias StarkInfra.Utils.Rest + alias StarkInfra.Utils.API + alias StarkInfra.Utils.Check + alias StarkInfra.User.Project + alias StarkInfra.User.Organization + alias StarkInfra.Error + + @moduledoc """ + Groups IssuingDesign related functions + """ + + @doc """ + The IssuingDesign object displays information on the card and card package designs available to your Workspace. + + ## Attributes (return-only): + - `:id` [binary]: unique id returned when IssuingDesign is created. ex: "5656565656565656" + - `:name` [binary]: card or package design name. ex: "stark-plastic-dark-001" + - `:embosser_ids` [list of binaries]: list of embosser unique ids. ex: ["5136459887542272", "5136459887542273"] + - `:type` [binary]: card or package design type. Options: "card", "envelope" + - `:updated` [DateTime]: latest update DateTime for the IssuingDesign. ex: ~U[2020-3-10 10:30:0:0] + - `:created` [DateTime]: creation datetime for the IssuingDesign. ex: ~U[2020-03-10 10:30:0:0] + """ + + @enforce_keys [ + :id, + :name, + :embosser_ids, + :type, + :updated, + :created + ] + defstruct [ + :id, + :name, + :embosser_ids, + :type, + :updated, + :created + ] + + @type t() :: %__MODULE__{} + + @doc """ + Receive a stream of IssuingDesign objects previously created in the Stark Infra API. + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - stream of IssuingDesign objects with updated attributes + """ + @spec query( + limit: integer, + ids: [binary], + user: (Organization.t() | Project.t() | nil) + ) :: + {:ok, [IssuingDesign.t()]} | + {:error, [Error.t()]} + def query(options \\ []) do + Rest.get_list( + resource(), + options + ) + end + + @doc """ + Same as query(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec query!( + limit: integer, + ids: [binary], + user: (Organization.t() | Project.t() | nil) + ) :: any + def query!(options \\ []) do + Rest.get_list!( + resource(), + options + ) + end + + @doc """ + Receive a list of IssuingDesign previously created in the Stark Infra API and the cursor to the next page. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of IssuingDesign objects with updated attributes + - cursor to retrieve the next page of IssuingDesign objects + """ + @spec page( + cursor: binary, + limit: integer, + ids: [binary], + user: (Organization.t() | Project.t() | nil) + ) :: + {:ok, {binary, [IssuingDesign.t()]}} | + {:error, [Error.t()]} + def page(options \\ []) do + Rest.get_page( + resource(), + options + ) + end + + @doc """ + Same as page(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec page!( + cursor: binary, + limit: integer, + ids: [binary], + user: (Organization.t() | Project.t() | nil) + ) :: any + def page!(options \\ []) do + Rest.get_page!( + resource(), + options + ) + end + + @doc """ + Receive a single IssuingDesign objects previously created in the Stark Infra API by its id. + + ## Parameters (required): + - `:id` [binary]: object unique id. ex: "5656565656565656" + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - IssuingDesign objects that corresponds to the given id. + """ + @spec get( + id: binary, + user: (Organization.t() | Project.t() | nil) + ) :: + {:ok, IssuingDesign.t()} | + {:error, [Error.t()]} + def get(id, options \\ []) do + Rest.get_id( + resource(), + id, + options + ) + end + + @doc """ + Same as get(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec get!( + id: binary, + user: (Organization.t() | Project.t() | nil) + ) :: any + def get!(id, options \\ []) do + Rest.get_id!( + resource(), + id, + options + ) + end + + @doc """ + Receive a single IssuingDesign pdf file generated in the Stark Infra API by its id. + + ## Parameters (required): + - `id` [string]: object unique id. ex: "5656565656565656" + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkBank.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - IssuingDesign pdf file content + """ + @spec pdf( + id: binary, + user: Project.t() | Organization.t() | nil + ) :: + {:ok, binary} | + {:error, [%Error{}]} + def pdf(id, options \\ []) do + Rest.get_content( + resource(), + id, + "pdf", + options |> Keyword.delete(:user), options[:user] + ) + end + + @doc """ + Same as pdf(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec pdf!( + id: binary, + user: Project.t() | Organization.t() | nil + ) :: binary + def pdf!(id, options \\ []) do + Rest.get_content!( + resource(), + id, + "pdf", + options |> Keyword.delete(:user), options[:user]) + end + + @doc false + def resource() do + { + "IssuingDesign", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %IssuingDesign{ + id: json[:id], + name: json[:name], + embosser_ids: json[:embosser_ids], + type: json[:type], + created: json[:created] |> Check.datetime(), + updated: json[:updated] |> Check.datetime() + } + end +end diff --git a/lib/issuing_embossing_kit/issuing_embossing_kit.ex b/lib/issuing_embossing_kit/issuing_embossing_kit.ex new file mode 100644 index 0000000..3fba54e --- /dev/null +++ b/lib/issuing_embossing_kit/issuing_embossing_kit.ex @@ -0,0 +1,209 @@ +defmodule StarkInfra.IssuingEmbossingKit do + alias __MODULE__, as: IssuingEmbossingKit + alias StarkInfra.Utils.Rest + alias StarkInfra.Utils.API + alias StarkInfra.Utils.Check + alias StarkInfra.User.Project + alias StarkInfra.User.Organization + alias StarkInfra.Error + + @moduledoc """ + Groups IssuingEmbossingKit related functions + """ + + @doc """ + The IssuingEmbossingKit object displays information on the embossing kits available to your Workspace. + + ## Attributes (return-only): + - `:id` [binary]: unique id returned when IssuingEmbossingKit is created. ex: "5656565656565656" + - `:name` [binary]: embossing kit name. ex: "stark-plastic-dark-001" + - `:designs` [list of IssuingDesign objects]: status of the IssuingDesign objects. + - `:updated` [DateTime]: latest update datetime for the IssuingEmbossingKit. + - `:created` [DateTime]: creation datetime for the IssuingEmbossingKit. + """ + + @enforce_keys [ + :id, + :name, + :designs, + :updated, + :created + ] + defstruct [ + :id, + :name, + :designs, + :updated, + :created + ] + + @type t() :: %__MODULE__{} + + @doc """ + Receive a stream of IssuingEmbossingKit objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. ex: ["created", "processing", "success", "failed"] + - `:design_ids` [list of binaries, default nil]: list of design_ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - stream of IssuingEmbossingKit objects with updated attributes + """ + @spec query( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: binary, + design_ids: [binary], + ids: [binary], + user: (Organization.t() | Project.t() | nil) + ) :: + {:ok, [IssuingEmbossingKit.t()]} | + {:error, [Error.t()]} + def query(options \\ []) do + Rest.get_list( + resource(), + options + ) + end + + @doc """ + Same as query(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec query!( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: binary, + design_ids: [binary], + ids: [binary], + user: (Organization.t() | Project.t() | nil) + ) :: any + def query!(options \\ []) do + Rest.get_list!( + resource(), + options + ) + end + + @doc """ + Receive a list of IssuingEmbossingKit previously created in the Stark Infra API and the cursor to the next page. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. ex: ["created", "processing", "success", "failed"] + - `:design_ids` [list of binaries, default nil]: list of design_ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of IssuingEmbossingKit objects with updated attributes + - cursor to retrieve the next page of IssuingEmbossingKit objects + """ + @spec page( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: binary, + design_ids: [binary], + ids: [binary], + user: (Organization.t() | Project.t() | nil) + ) :: + {:ok, {binary, [IssuingEmbossingKit.t()]}} | + {:error, [Error.t()]} + def page(options \\ []) do + Rest.get_page( + resource(), + options + ) + end + + @doc """ + Same as page(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec page!( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: binary, + design_ids: [binary], + ids: [binary], + user: (Organization.t() | Project.t() | nil) + ) :: any + def page!(options \\ []) do + Rest.get_page!( + resource(), + options + ) + end + + @doc """ + Receive a single IssuingEmbossingKit objects previously created in the Stark Infra API by its id. + + ## Parameters (required): + - `:id` [binary]: object unique id. ex: "5656565656565656" + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - IssuingEmbossingKit objects that corresponds to the given id. + """ + @spec get( + id: binary, + user: (Organization.t() | Project.t() | nil) + ) :: + {:ok, IssuingEmbossingKit.t()} | + {:error, [Error.t()]} + def get(id, options \\ []) do + Rest.get_id( + resource(), + id, + options + ) + end + + @doc """ + Same as get(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec get!( + id: binary, + user: (Organization.t() | Project.t() | nil) + ) :: any + def get!(id, options \\ []) do + Rest.get_id!( + resource(), + id, + options + ) + end + + @doc false + def resource() do + { + "IssuingEmbossingKit", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %IssuingEmbossingKit{ + id: json[:id], + name: json[:name], + designs: json[:designs] |> Enum.map(fn design -> API.from_api_json(design, &IssuingDesign.resource_maker/1) end), + updated: json[:updated], + created: json[:created] + } + end +end diff --git a/lib/issuing_embossing_request/issuing_embossing_request.ex b/lib/issuing_embossing_request/issuing_embossing_request.ex new file mode 100644 index 0000000..aeec386 --- /dev/null +++ b/lib/issuing_embossing_request/issuing_embossing_request.ex @@ -0,0 +1,319 @@ +defmodule StarkInfra.IssuingEmbossingRequest do + alias __MODULE__, as: IssuingEmbossingRequest + alias StarkInfra.IssuingRule + alias StarkInfra.Utils.Rest + alias StarkInfra.Utils.API + alias StarkInfra.Utils.Check + alias StarkInfra.User.Project + alias StarkInfra.User.Organization + alias StarkInfra.Error + + @moduledoc """ + Groups IssuingEmbossingRequest related functions + """ + + @doc """ + The IssuingEmbossingRequest object displays the information of embossing requests in your Workspace. + + ## Parameters (required): + - `:card_id` [binary]: id of the IssuingCard to be embossed. ex "5656565656565656" + - `:kit_id` [binary]: card embossing kit id. ex "5656565656565656" + - `:display_name_1` [binary]: card displayed name. ex: "ANTHONY STARK" + - `:shipping_city` [binary]: shipping city. ex: "NEW YORK" + - `:shipping_country_code` [binary]: shipping country code. ex: "US" + - `:shipping_district` [binary]: shipping district. ex: "NY" + - `:shipping_state_code` [binary]: shipping state code. ex: "NY" + - `:shipping_street_line_1` [binary]: shipping main address. ex: "AVENUE OF THE AMERICAS" + - `:shipping_street_line_2` [binary]: shipping address complement. ex: "Apt. 6" + - `:shipping_service` [binary]: shipping service. ex: "loggi" + - `:shipping_tracking_number` [binary]: shipping tracking number. ex: "5656565656565656" + - `:shipping_zip_code` [binary]: shipping zip code. ex: "12345-678" + + ## Parameters (optional): + - `:embosser_id` [binary, default nil]: id of the card embosser. ex: "5656565656565656" + - `:display_name_2` [binary, default nil]: card displayed name. ex: "IT Services" + - `:display_name_3` [binary, default nil]: card displayed name. ex: "StarkBank S.A." + - `:shipping_phone` [binary, default nil]: shipping phone. ex: "+5511999999999" + - `:tags` [list of binaries, default nil]: list of binaries for tagging. ex: ["card", "corporate"] + + ## Attributes (return-only): + - `:id` [binary]: unique id returned when IssuingEmbossingRequest is created. ex: "5656565656565656" + - `:fee` [integer]: fee charged when IssuingEmbossingRequest is created. ex: 1000 + - `:status` [binary]: status of the IssuingEmbossingRequest. ex: "created", "processing", "success", "failed" + - `:updated` [DateTime]: latest update datetime for the IssuingEmbossingRequest. + - `:created` [DateTime]: creation datetime for the IssuingEmbossingRequest. + """ + + @enforce_keys [ + :card_id, + :kit_id, + :display_name_1, + :shipping_city, + :shipping_country_code, + :shipping_district, + :shipping_state_code, + :shipping_street_line_1, + :shipping_street_line_2, + :shipping_service, + :shipping_tracking_number, + :shipping_zip_code + ] + defstruct [ + :card_id, + :kit_id, + :display_name_1, + :shipping_city, + :shipping_country_code, + :shipping_district, + :shipping_state_code, + :shipping_street_line_1, + :shipping_street_line_2, + :shipping_service, + :shipping_tracking_number, + :shipping_zip_code, + :embosser_id, + :display_name_2, + :display_name_3, + :shipping_phone, + :tags, + :id, + :fee, + :status, + :updated, + :created + ] + + @type t() :: %__MODULE__{} + + @doc """ + Send a list of IssuingEmbossingRequest objects for creation in the Stark Infra API. + + ## Parameters (required): + - `:requests` [list of IssuingEmbossingRequest objects]: list of IssuingEmbossingRequest objects to be created in the API + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of IssuingEmbossingRequest objects with updated attributes + """ + @spec create( + [IssuingEmbossingRequest.t() | map], + user: Organization.t() | Project.t() | nil + ) :: + {:ok, [IssuingEmbossingRequest.t()]} | + {:error, [Error.t()]} + def create(requests, options \\ []) do + Rest.post( + resource(), + requests, + options + ) + end + + @doc """ + Same as create(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec create!( + [IssuingEmbossingRequest.t() | map], + user: Organization.t() | Project.t() | nil + ) :: any + def create!(requests, options \\ []) do + Rest.post!( + resource(), + requests, + options + ) + end + + @doc """ + Receive a stream of IssuingEmbossingRequest objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. ex: ["created", "processing", "success", "failed"] + - `:card_ids` [list of binaries, default nil]: list of card_ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:tags` [list of binaries, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - stream of IssuingEmbossingRequest objects with updated attributes + """ + @spec query( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: binary, + card_ids: [binary], + tags: [binary], + ids: [binary], + user: (Organization.t() | Project.t() | nil) + ) :: + {:ok, [IssuingEmbossingRequest.t()]} | + {:error, [Error.t()]} + def query(options \\ []) do + Rest.get_list( + resource(), + options + ) + end + + @doc """ + Same as query(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec query!( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: binary, + card_ids: [binary], + tags: [binary], + ids: [binary], + user: (Organization.t() | Project.t() | nil) + ) :: any + def query!(options \\ []) do + Rest.get_list!( + resource(), + options + ) + end + + @doc """ + Receive a list of IssuingEmbossingRequest previously created in the Stark Infra API and the cursor to the next page. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. ex: ["created", "processing", "success", "failed"] + - `:card_ids` [list of binaries, default nil]: list of card_ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:tags` [list of binaries, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of IssuingEmbossingRequest objects with updated attributes + - cursor to retrieve the next page of IssuingEmbossingRequest objects + """ + @spec page( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: binary, + card_ids: [binary], + ids: [binary], + tags: [binary], + user: (Organization.t() | Project.t() | nil) + ) :: + {:ok, {binary, [IssuingEmbossingRequest.t()]}} | + {:error, [Error.t()]} + def page(options \\ []) do + Rest.get_page( + resource(), + options + ) + end + + @doc """ + Same as page(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec page!( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: binary, + card_ids: [binary], + ids: [binary], + tags: [binary], + user: (Organization.t() | Project.t() | nil) + ) :: any + def page!(options \\ []) do + Rest.get_page!( + resource(), + options + ) + end + + @doc """ + Receive a single IssuingEmbossingRequest objects previously created in the Stark Infra API by its id. + + ## Parameters (required): + - `:id` [binary]: object unique id. ex: "5656565656565656" + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - IssuingEmbossingRequest objects that corresponds to the given id. + """ + @spec get( + id: binary, + user: (Organization.t() | Project.t() | nil) + ) :: + {:ok, IssuingEmbossingRequest.t()} | + {:error, [Error.t()]} + def get(id, options \\ []) do + Rest.get_id( + resource(), + id, + options + ) + end + + @doc """ + Same as get(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec get!( + id: binary, + user: (Organization.t() | Project.t() | nil) + ) :: any + def get!(id, options \\ []) do + Rest.get_id!( + resource(), + id, + options + ) + end + + @doc false + def resource() do + { + "IssuingEmbossingRequest", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %IssuingEmbossingRequest{ + card_id: json[:card_id], + kit_id: json[:kit_id], + display_name_1: json[:display_name_1], + shipping_city: json[:shipping_city], + shipping_country_code: json[:shipping_country_code], + shipping_district: json[:shipping_district], + shipping_state_code: json[:shipping_state_code], + shipping_street_line_1: json[:shipping_street_line_1], + shipping_street_line_2: json[:shipping_street_line_2], + shipping_service: json[:shipping_service], + shipping_tracking_number: json[:shipping_tracking_number], + shipping_zip_code: json[:shipping_zip_code], + embosser_id: json[:embosser_id], + display_name_2: json[:display_name_2], + display_name_3: json[:display_name_3], + shipping_phone: json[:shipping_phone], + tags: json[:tags], + id: json[:id], + fee: json[:fee], + status: json[:status], + updated: json[:updated], + created: json[:created] + } + end +end diff --git a/lib/issuing_embossing_request/issuing_embossing_request_log.ex b/lib/issuing_embossing_request/issuing_embossing_request_log.ex new file mode 100644 index 0000000..df0d25d --- /dev/null +++ b/lib/issuing_embossing_request/issuing_embossing_request_log.ex @@ -0,0 +1,210 @@ +defmodule StarkInfra.IssuingEmbossingRequest.Log do + alias __MODULE__, as: Log + alias StarkInfra.Utils.Rest + alias StarkInfra.Utils.Check + alias StarkInfra.User.Project + alias StarkInfra.User.Organization + alias StarkInfra.Error + + @moduledoc """ + Groups IssuingEmbossingRequest.Log related functions + """ + + @doc """ + Every time an IssuingEmbossingRequest entity is updated, a corresponding IssuingEmbossingRequest.Log + is generated for the entity. This log is never generated by the + user, but it can be retrieved to check additional information + on the IssuingEmbossingRequest. + + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the log is created. ex: "5656565656565656" + - `:request` [IssuingEmbossingRequest]: IssuingEmbossingRequest entity to which the log refers to. + - `:errors` [list of binaries]: list of errors linked to this IssuingEmbossingRequest event. + - `:type` [binary]: type of the IssuingEmbossingRequest event which triggered the log creation. ex: "created", "sending", "sent", "processing", "success", "failed" + - `:created` [DateTime]: creation datetime for the log. ex: ~U[2020-03-10 10:30:0:0] + """ + @enforce_keys [ + :id, + :request, + :errors, + :type, + :created + ] + defstruct [ + :id, + :request, + :errors, + :type, + :created + ] + + @type t() :: %__MODULE__{} + + @doc """ + Receive a single IssuingEmbossingRequest.Log object previously created by the Stark Infra API by its id. + + ## Parameters (required): + - `:id` [binary]: object unique id. ex: "5656565656565656" + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - IssuingEmbossingRequest.Log object that corresponds to the given id. + """ + @spec get( + id: binary, + user: Project.t() | Organization.t() | nil + ) :: + {:ok, Log.t() } | + { :error, [Error.t()] } + def get(id, options \\ []) do + Rest.get_id( + resource(), + id, + options + ) + end + + @doc """ + Same as get(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec get!( + id: binary, + user: Project.t() | Organization.t() | nil + ) :: any + def get!(id, options \\ []) do + Rest.get_id!( + resource(), + id, + options + ) + end + + @doc """ + Receive a stream of IssuingEmbossingRequest.Log objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:types` [list of binaries, default nil]: filter for log event types. ex: ["created", "sending", "sent", "processing", "success", "failed"] + - `:request_ids` [list of binaries, default nil]: list of IssuingEmbossingRequest ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Return: + - stream of IssuingEmbossingRequest.Log objects with updated attributes + """ + @spec query( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + request_ids: [binary], + ids: [binary], + user: Project.t() | Organization.t() | nil + ) :: + {:ok, {binary, [Log.t()]} } | + { :error, [Error.t()] } + def query(options \\ []) do + Rest.get_list( + resource(), + options + ) + end + + @doc """ + Same as query(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec query!( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + request_ids: [binary], + ids: [binary], + user: Project.t() | Organization.t() | nil + ) :: any + def query!(options \\ []) do + Rest.get_list!( + resource(), + options + ) + end + + @doc """ + Receive a list of up to 100 IssuingEmbossingRequest.Log objects previously created in the Stark Infra API and the cursor to the next page. + Use this function instead of query if you want to manually page your requests. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:types` [list of binaries, default nil]: filter for log event types. ex: ["created", "sending", "sent", "processing", "success", "failed"] + - `:request_ids` [list of binaries, default nil]: list of IssuingEmbossingRequest ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of IssuingEmbossingRequest.Log objects with updated attributes + - cursor to retrieve the next page of IssuingEmbossingRequest.Log objects + """ + @spec page( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + request_ids: [binary], + ids: [binary], + user: Project.t() | Organization.t() | nil + ) :: + {:ok, {binary, [Log.t()]} } | + { :error, [Error.t()] } + def page(options \\ []) do + Rest.get_page( + resource(), + options + ) + end + + @doc """ + Same as page(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec page!( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + request_ids: [binary], + ids: [binary], + user: Project.t() | Organization.t() | nil + ) :: any + def page!(options \\ []) do + Rest.get_page!( + resource(), + options + ) + end + + @doc false + def resource() do + { + "IssuingEmbossingRequestLog", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %Log{ + id: json[:id], + request: json[:request], + errors: json[:errors], + type: json[:type], + created: json[:created] |> Check.datetime(), + } + end +end diff --git a/lib/issuing_holder/issuing_holder.ex b/lib/issuing_holder/issuing_holder.ex index 027a3f2..5a3da02 100644 --- a/lib/issuing_holder/issuing_holder.ex +++ b/lib/issuing_holder/issuing_holder.ex @@ -16,13 +16,13 @@ defmodule StarkInfra.IssuingHolder do The IssuingHolder describes a card holder that may group several cards. ## Parameters (required): - - `:name` [binary]: card holder's name. - - `:tax_id` [binary]: card holder's tax ID - - `:external_id` [binary] card holder's external ID + - `:name` [binary]: card holder's name. ex: "Tony Stark" + - `:tax_id` [binary]: card holder's tax ID. ex: "012.345.678-90" + - `:external_id` [binary] card holder unique id, generated by the user to avoid duplicated holders. ex: "my-entity/123" ## Parameters (optional): - - `:rules` [list of IssuingRule structs, default []]: [EXPANDABLE] list of holder spending rules - - `:tags` [list of binarys, default []]: list of binarys for tagging. ex: ["travel", "food"] + - `:rules` [list of IssuingRule objects, default []]: [EXPANDABLE] list of holder spending rules + - `:tags` [list of binaries, default []]: list of binaries for tagging. ex: ["travel", "food"] ## Attributes (return-only): - `:id` [binary]: unique id returned when IssuingHolder is created. ex: "5656565656565656" @@ -50,22 +50,24 @@ defmodule StarkInfra.IssuingHolder do @type t() :: %__MODULE__{} @doc """ - Send a list of IssuingHolder structs for creation in the Stark Infra API. + Send a list of IssuingHolder objects for creation in the Stark Infra API. ## Parameters (required): - - `:holders` [list of IssuingHolder structs]: list of IssuingHolder structs to be created in the API + - `:holders` [list of IssuingHolder objects]: list of IssuingHolder objects to be created in the API - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:expand` [list of strings, default []]: fields to expand information. ex: ["rules"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of IssuingHolder structs with updated attributes + - list of IssuingHolder objects with updated attributes """ @spec create( holders: [IssuingHolder.t()], + expand: [binary] | nil, user: Project.t() | Organization.t() | nil ) :: - { :ok, [IssuingHolder.t()] } | + {:ok, [IssuingHolder.t()] } | { :error, [error: Error.t()] } def create(holders, options \\ []) do Rest.post(resource(), holders, options) @@ -83,24 +85,24 @@ defmodule StarkInfra.IssuingHolder do end @doc """ - Receive a single IssuingHolder struct previously created in the Stark Infra API by its id. + Receive a single IssuingHolder object previously created in the Stark Infra API by its id. ## Parameters (required): - - `:id` [binary]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:expand` [list of binarys, default nil]: fields to expand information. ex: ["rules"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:expand` [list of binaries, default nil]: fields to expand information. ex: ["rules"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - IssuingHolder struct with updated attributes + - IssuingHolder object that corresponds to the given id. """ @spec get( id: binary, expand: [binary] | nil, user: Project.t() | Organization.t() | nil ) :: - { :ok, [IssuingHolder.t()] } | + {:ok, [IssuingHolder.t()] } | { :error, [error: Error.t()] } def get(id, options \\ []) do Rest.get_id(resource(), id, options) @@ -119,20 +121,20 @@ defmodule StarkInfra.IssuingHolder do end @doc """ - Receive a stream of IssuingHolder structs previously created in the Stark Infra API - - ## Options: - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:status` [binary, default nil]: filter for status of retrieved structs. ex: "paid" or "registered" - - `:tags` [list of binarys, default nil]: tags to filter retrieved structs. ex: ["tony", "stark"] - - `:ids` [list of binarys, default nil]: list of ids to filter retrieved structs. ex: ["5656565656565656", "4545454545454545"] - - `:expand` [list of binarys, default nil]: fields to expand information. ex: ["rules"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + Receive a stream of IssuingHolder objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:status` [binary, default nil]: filter for status of retrieved objects. ex: ["active", "blocked", "canceled"] + - `:tags` [list of binaries, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:expand` [list of binaries, default nil]: fields to expand information. ex: ["rules"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of IssuingHolder structs with updated attributes + - stream of IssuingHolder objects with updated attributes """ @spec query( limit: integer | nil, @@ -140,8 +142,8 @@ defmodule StarkInfra.IssuingHolder do before: Date.t() | binary | nil, status: binary | nil, tags: [binary] | nil, - ids: [binary] | nil, expand: [binary] | nil, + ids: [binary] | nil, user: Project.t() | Organization.t() | nil ) :: { :cont, [IssuingHolder.t()] } | @@ -159,8 +161,8 @@ defmodule StarkInfra.IssuingHolder do before: Date.t() | binary | nil, status: binary | nil, tags: [binary] | nil, - ids: [binary] | nil, expand: [binary] | nil, + ids: [binary] | nil, user: Project.t() | Organization.t() | nil ) :: any def query!(options \\ []) do @@ -168,32 +170,32 @@ defmodule StarkInfra.IssuingHolder do end @doc """ - Receive a list of IssuingHolder structs previously created in the Stark Infra API and the cursor to the next page. - - ## Options: - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:status` [string, default nil]: filter for status of retrieved structs. ex: "paid" or "registered" - - `:tags` [list of strings, default nil]: tags to filter retrieved structs. ex: ["tony", "stark"] - - `:ids` [list of strings, default nil]: list of ids to filter retrieved structs. ex: ["5656565656565656", "4545454545454545"] - - `:expand` [string, default nil]: fields to expand information. ex: "rules, securityCode, number, expiration" - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + Receive a list of IssuingHolder objects previously created in the Stark Infra API and the cursor to the next page. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:status` [binary, default nil]: filter for status of retrieved objects. ex: ["active", "blocked", "canceled"] + - `:tags` [list of binaries, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:expand` [list of binaries, default nil]: fields to expand information. ex: ["rules"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of IssuingHolder structs with updated attributes - - cursor to retrieve the next page of IssuingHolder structs + - list of IssuingHolder objects with updated attributes + - cursor to retrieve the next page of IssuingHolder objects """ @spec page( + cursor: binary | nil, limit: integer | nil, after: Date.t() | binary | nil, before: Date.t() | binary | nil, status: binary | nil, tags: [binary] | nil, - ids: [binary] | nil, expand: [binary] | nil, - cursor: binary | nil, + ids: [binary] | nil, user: Project.t() | Organization.t() | nil ) :: { :cont, {binary, [IssuingHolder.t()] }} | @@ -206,6 +208,7 @@ defmodule StarkInfra.IssuingHolder do Same as page(), but it will unwrap the error tuple and raise in case of errors. """ @spec page!( + cursor: binary | nil, limit: integer | nil, after: Date.t() | binary | nil, before: Date.t() | binary | nil, @@ -213,7 +216,6 @@ defmodule StarkInfra.IssuingHolder do tags: [binary] | nil, ids: [binary] | nil, expand: [binary] | nil, - cursor: binary | nil, user: Project.t() | Organization.t() | nil ) :: any def page!(options \\ []) do @@ -224,14 +226,14 @@ defmodule StarkInfra.IssuingHolder do Update an IssuingHolder by passing id, if it hasn't been paid yet. ## Parameters (required): - - `:id` [string]: IssuingHolder id. ex: '5656565656565656' + - `:id` [binary]: IssuingHolder id. ex: '5656565656565656' ## Parameters (optional): - - `:status` [string, default nil]: You may block the IssuingHolder by passing 'blocked' in the status. - - `:name` [string, default nil]: card holder name. - - `:tags` [list of strings, default nil]: list of strings for tagging. - - `:rules` [list of dictionaries, default nil]: list of dictionaries with "amount": int, "currencyCode": string, "id": string, "interval": string, "name": string pairs - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + - `:status` [binary, default nil]: You may block the IssuingHolder by passing 'blocked' in the status. + - `:name` [binary, default nil]: card holder name. ex: "Tony Stark" + - `:tags` [list of binaries, default nil]: list of binaries for tagging. ex: ["tony", "stark"] + - `:rules` [list of dictionaries, default nil]: list of dictionaries with "amount": int, "currencyCode": binary, "id": binary, "interval": binary, "name": binary pairs + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - target IssuingHolder with updated attributes @@ -244,7 +246,7 @@ defmodule StarkInfra.IssuingHolder do rules: [IssuingRule.t()] | nil, user: Project.t() | Organization.t() | nil ) :: - { :ok, IssuingHolder.t() } | + {:ok, IssuingHolder.t() } | { :error, [error: Error.t()] } def update(id, parameters \\ []) do Rest.patch_id(resource(), id, parameters) @@ -269,19 +271,19 @@ defmodule StarkInfra.IssuingHolder do Cancel an IssuingHolder entity previously created in the Stark Infra API. ## Parameters (required): - - `:id` [string]: IssuingHolder unique id. ex: "5656565656565656" + - `:id` [binary]: IssuingHolder unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - canceled IssuingHolder struct + - canceled IssuingHolder object """ @spec cancel( id: binary, user: Project.t() | Organization.t() | nil ) :: - { :ok, IssuingHolder.t() } | + {:ok, IssuingHolder.t() } | { :error, [error: Error.t()] } def cancel(id, options \\ []) do Rest.delete_id(resource(), id, options) @@ -310,14 +312,14 @@ defmodule StarkInfra.IssuingHolder do def resource_maker(json) do %IssuingHolder{ id: json[:id], - status: json[:status], - updated: json[:updated] |> Check.datetime(), - created: json[:created] |> Check.datetime(), name: json[:name], tax_id: json[:tax_id], external_id: json[:external_id], rules: json[:rules] |> Enum.map(fn rule -> API.from_api_json(rule, &IssuingRule.resource_maker/1) end), - tags: json[:tags] + tags: json[:tags], + status: json[:status], + created: json[:created] |> Check.datetime(), + updated: json[:updated] |> Check.datetime() } end end diff --git a/lib/issuing_holder/issuing_holder_log.ex b/lib/issuing_holder/issuing_holder_log.ex index aa75cf7..56b0833 100644 --- a/lib/issuing_holder/issuing_holder_log.ex +++ b/lib/issuing_holder/issuing_holder_log.ex @@ -13,13 +13,12 @@ defmodule StarkInfra.IssuingHolder.Log do @doc """ Every time an IssuingHolder entity is updated, a corresponding IssuingHolder.Log is generated for the entity. This log is never generated by the - user, but it can be retrieved to check additional information - on the IssuingHolder. + user, but it can be retrieved to check additional information on the IssuingHolder. - ## Attributes: - - `:id` [string]: unique id returned when the log is created. ex: "5656565656565656" + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the log is created. ex: "5656565656565656" - `:holder` [IssuingHolder]: IssuingHolder entity to which the log refers to. - - `:type` [string]: type of the IssuingHolder event which triggered the log creation. ex: "blocked", "canceled", "created", "unblocked", "updated" + - `:type` [binary]: type of the IssuingHolder event which triggered the log creation. ex: "blocked", "canceled", "created", "unblocked", "updated" - `:created` [DateTime]: creation datetime for the log. ex: ~U[2020-03-10 10:30:0:0] """ @enforce_keys [ @@ -38,22 +37,22 @@ defmodule StarkInfra.IssuingHolder.Log do @type t() :: %__MODULE__{} @doc """ - Receive a single IssuingHolder.Log struct previously created by the Stark Infra API by its id. + Receive a single IssuingHolder.Log object previously created by the Stark Infra API by its id. ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - IssuingHolder.Log struct with updated attributes + - IssuingHolder.Log object that corresponds to the given id. """ @spec get( id: binary, user: Project.t() | Organization.t() | nil ) :: - { :ok, Log.t() } | + {:ok, Log.t() } | { :error, [Error.t()] } def get(id, options \\ []) do Rest.get_id( @@ -79,30 +78,30 @@ defmodule StarkInfra.IssuingHolder.Log do end @doc """ - Receive a stream of IssuingHolder.Log structs previously created in the Stark Infra API + Receive a stream of IssuingHolder.Log objects previously created in the Stark Infra API - ## Options: - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:ids` [list of strings, default nil]: list of ids to filter retrieved structs. ex: ["5656565656565656", "4545454545454545"] - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:types` [list of strings, default nil]: filter for log event types. ex: ["created", "blocked"] - - `:holder_ids` [list of strings, default nil]: list of IssuingHolder ids to filter logs. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:types` [list of binaries, default nil]: filter for log event types. ex: ["created", "blocked"] + - `:holder_ids` [list of binaries, default nil]: list of IssuingHolder ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of IssuingHolder.Log structs with updated attributes + - stream of IssuingHolder.Log objects with updated attributes """ @spec query( - ids: [binary], limit: integer, after: Date.t() | binary, before: Date.t() | binary, types: [binary], holder_ids: [binary], + ids: [binary], user: Project.t() | Organization.t() | nil ) :: - { :ok, {binary, [Log.t()]} } | + {:ok, {binary, [Log.t()]} } | { :error, [Error.t()] } def query(options \\ []) do Rest.get_list( @@ -115,12 +114,12 @@ defmodule StarkInfra.IssuingHolder.Log do Same as query(), but it will unwrap the error tuple and raise in case of errors. """ @spec query!( - ids: [binary], limit: integer, after: Date.t() | binary, before: Date.t() | binary, types: [binary], holder_ids: [binary], + ids: [binary], user: Project.t() | Organization.t() | nil ) :: any def query!(options \\ []) do @@ -131,34 +130,34 @@ defmodule StarkInfra.IssuingHolder.Log do end @doc """ - Receive a list of up to 100 IssuingHolder.Log structs previously created in the Stark Infra API and the cursor to the next page. + Receive a list of up to 100 IssuingHolder.Log objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your requests. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:ids` [list of strings, default nil]: list of ids to filter retrieved structs. ex: ["5656565656565656", "4545454545454545"] - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. It must be an integer between 1 and 100. ex: 50 - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:types` [list of strings, default nil]: filter for log event types. ex: ["created", "blocked"] - - `:holder_ids` [list of strings, default nil]: list of IssuingHolder ids to filter logs. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:types` [list of binaries, default nil]: filter for log event types. ex: ["created", "blocked"] + - `:holder_ids` [list of binaries, default nil]: list of IssuingHolder ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of IssuingHolder.Log structs with updated attributes - - cursor to retrieve the next page of IssuingHolder.Log structs + - list of IssuingHolder.Log objects with updated attributes + - cursor to retrieve the next page of IssuingHolder.Log objects """ @spec page( cursor: binary, - ids: [binary], limit: integer, after: Date.t() | binary, before: Date.t() | binary, types: [binary], holder_ids: [binary], + ids: [binary], user: Project.t() | Organization.t() | nil ) :: - { :ok, {binary, [Log.t()]} } | + {:ok, {binary, [Log.t()]} } | { :error, [Error.t()] } def page(options \\ []) do Rest.get_page( @@ -172,12 +171,12 @@ defmodule StarkInfra.IssuingHolder.Log do """ @spec page!( cursor: binary, - ids: [binary], limit: integer, after: Date.t() | binary, before: Date.t() | binary, types: [binary], holder_ids: [binary], + ids: [binary], user: Project.t() | Organization.t() | nil ) :: any def page!(options \\ []) do diff --git a/lib/issuing_invoice/issuing_invoice.ex b/lib/issuing_invoice/issuing_invoice.ex index dedc1b2..a316da2 100644 --- a/lib/issuing_invoice/issuing_invoice.ex +++ b/lib/issuing_invoice/issuing_invoice.ex @@ -7,24 +7,27 @@ defmodule StarkInfra.IssuingInvoice do alias StarkInfra.Error @moduledoc """ - # IssuingInvoice struct + # IssuingInvoice object """ @doc """ - The IssuingInvoice structs created in your Workspace load your Issuing balance when paid. + The IssuingInvoice objects created in your Workspace load your Issuing balance when paid. ## Parameters (required): - `:amount` [integer]: IssuingInvoice value in cents. ex: 1234 (= R$ 12.34) ## Parameters (optional): - - `:tax_id` [string, default sub-issuer tax ID]: payer tax ID (CPF or CNPJ) with or without formatting. ex: "01234567890" or "20.018.183/0001-80" - - `:name` [string, default sub-issuer name]: payer name. ex: "Iron Bank S.A." - - `:tags` [list of strings, default []]: list of strings for tagging. ex: ["travel", "food"] + - `:tax_id` [binary, default sub-issuer tax ID]: payer tax ID (CPF or CNPJ) with or without formatting. ex: "01234567890" or "20.018.183/0001-80" + - `:name` [binary, default sub-issuer name]: payer name. ex: "Iron Bank S.A." + - `:tags` [list of binaries, default []]: list of binaries for tagging. ex: ["travel", "food"] ## Attributes (return-only): - - `:id` [string]: unique id returned when IssuingInvoice is created. ex: "5656565656565656" - - `:status` [string]: current IssuingInvoice status. ex: "created", "expired", "overdue", "paid" - - `:issuing_transaction_id` [string]: ledger transaction ids linked to this IssuingInvoice. ex: "issuing-invoice/5656565656565656" + - `:id` [binary]: unique id returned when IssuingInvoice is created. ex: "5656565656565656" + - `:brcode` [binary]: BR Code for the Invoice payment. ex: "00020101021226930014br.gov.bcb.pix2571brcode-h.development.starkinfra.com/v2/d7f6546e194d4c64a153e8f79f1c41ac5204000053039865802BR5925Stark Bank S.A. - Institu6009Sao Paulo62070503***63042109" + - `:due` [Date, DateTime or binary]: Invoice due and expiration date in UTC ISO format. ex: "2020-10-28T17:59:26.249976+00:00" + - `:link` [binary]: public Invoice webpage URL. ex: "https://starkbank-card-issuer.development.starkbank.com/invoicelink/d7f6546e194d4c64a153e8f79f1c41ac" + - `:status` [binary]: current IssuingInvoice status. Options: "created", "expired", "overdue", "paid" + - `:issuing_transaction_id` [binary]: ledger transaction ids linked to this IssuingInvoice. ex: "issuing-invoice/5656565656565656" - `:updated` [DateTime]: latest update DateTime for the IssuingInvoice. ex: ~U[2020-3-10 10:30:0:0] - `:created` [DateTime]: creation datetime for the IssuingInvoice. ex: ~U[2020-03-10 10:30:0:0] """ @@ -37,6 +40,9 @@ defmodule StarkInfra.IssuingInvoice do :name, :tags, :id, + :brcode, + :due, + :link, :status, :issuing_transaction_id, :updated, @@ -46,16 +52,16 @@ defmodule StarkInfra.IssuingInvoice do @type t() :: %__MODULE__{} @doc """ - Send a list of IssuingInvoice structs for creation in the Stark Infra API + Send a list of IssuingInvoice objects for creation in the Stark Infra API ## Parameters (required): - - `:invoice` [IssuingInvoice struct]: IssuingInvoice struct to be created in the API. + - `:invoice` [IssuingInvoice object]: IssuingInvoice object to be created in the API. - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - IssuingInvoice struct with updated attributes + - IssuingInvoice object with updated attributes """ @spec create( invoice: IssuingInvoice.t(), @@ -87,16 +93,16 @@ defmodule StarkInfra.IssuingInvoice do end @doc """ - Receive a single IssuingInvoice struct previously created in the Stark Infra API by its id + Receive a single IssuingInvoice object previously created in the Stark Infra API by its id ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - IssuingInvoice struct with updated attributes + - IssuingInvoice object that corresponds to the given id. """ @spec get( id: binary, @@ -128,18 +134,18 @@ defmodule StarkInfra.IssuingInvoice do end @doc """ - Receive a stream of IssuingInvoices structs previously created in the Stark Infra API + Receive a stream of IssuingInvoice objects previously created in the Stark Infra API - ## Options: - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:status` [list of strings, default nil]: filter for status of retrieved structs. ex: ["created", "expired", "overdue", "paid"] - - `:tags` [list of strings, default nil]: tags to filter retrieved structs. ex: ["tony", "stark"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. ex: ["created", "expired", "overdue", "paid"] + - `:tags` [list of binaries, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of IssuingInvoices structs with updated attributes + - stream of IssuingInvoice objects with updated attributes """ @spec query( limit: integer | nil, @@ -177,20 +183,21 @@ defmodule StarkInfra.IssuingInvoice do end @doc """ - Receive a list of IssuingInvoices structs previously created in the Stark Infra API and the cursor to the next page. + Receive a list of up to 100 IssuingInvoice objects previously created in the Stark Infra API and the cursor to the next page. + Use this function instead of query if you want to manually page your requests. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:status` [list of strings, default nil]: filter for status of retrieved structs. ex: ["created", "expired", "overdue", "paid"] - - `:tags` [list of strings, default nil]: tags to filter retrieved structs. ex: ["tony", "stark"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. ex: ["created", "expired", "overdue", "paid"] + - `:tags` [list of binaries, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of IssuingInvoices structs with updated attributes - - cursor to retrieve the next page of IssuingInvoices structs + - list of IssuingInvoice objects with updated attributes + - cursor to retrieve the next page of IssuingInvoice objects """ @spec page( cursor: binary | nil, @@ -245,6 +252,9 @@ defmodule StarkInfra.IssuingInvoice do name: json[:name], tags: json[:tags], id: json[:id], + brcode: json[:brcode], + due: json[:due], + link: json[:link], status: json[:status], issuing_transaction_id: json[:issuing_transaction_id], updated: json[:updated] |> Check.datetime(), diff --git a/lib/issuing_invoice/issuing_invoice_log.ex b/lib/issuing_invoice/issuing_invoice_log.ex index ac146a5..eacae24 100644 --- a/lib/issuing_invoice/issuing_invoice_log.ex +++ b/lib/issuing_invoice/issuing_invoice_log.ex @@ -16,10 +16,10 @@ defmodule StarkInfra.IssuingInvoice.Log do user, but it can be retrieved to check additional information on the IssuingInvoice. - ## Attributes: - - `:id` [string]: unique id returned when the log is created. ex: "5656565656565656" + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the log is created. ex: "5656565656565656" - `:invoice` [IssuingInvoice]: IssuingInvoice entity to which the log refers to. - - `:type` [string]: type of the IssuingInvoice event which triggered the log creation. ex: "created", "credited", "expired", "overdue", "paid". + - `:type` [binary]: type of the IssuingInvoice event which triggered the log creation. Options: "created", "credited", "expired", "overdue", "paid". - `:created` [DateTime]: creation datetime for the log. ex: ~U[2020-03-10 10:30:0:0] """ @enforce_keys [ @@ -38,22 +38,22 @@ defmodule StarkInfra.IssuingInvoice.Log do @type t() :: %__MODULE__{} @doc """ - Receive a single IssuingInvoice.Log struct previously created by the Stark Infra API by its id. + Receive a single IssuingInvoice.Log object previously created by the Stark Infra API by its id. ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - IssuingInvoice.Log struct with updated attributes + - IssuingInvoice.Log object that corresponds to the given id. """ @spec get( id: binary, user: Project.t() | Organization.t() | nil ) :: - { :ok, Log.t() } | + {:ok, Log.t() } | { :error, [Error.t()] } def get(id, options \\ []) do Rest.get_id( @@ -79,29 +79,28 @@ defmodule StarkInfra.IssuingInvoice.Log do end @doc """ - Receive a stream of IssuingInvoice.Log structs previously created in the Stark Infra API + Receive a stream of IssuingInvoice.Log objects previously created in the Stark Infra API - ## Options: - - `:ids` [list of strings, default nil]: list of IssuingInvoice ids to filter logs. ex: ["5656565656565656", "4545454545454545"] - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:types` [list of strings, default nil]: filter for log event types. ex: ["created", "credited", "expired", "overdue", "paid"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:types` [list of binaries, default nil]: filter for log event types. ex: ["created", "credited", "expired", "overdue", "paid"] + - `:ids` [list of binaries, default nil]: list of IssuingInvoice ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of IssuingInvoice.Log structs with updated attributes + - stream of IssuingInvoice.Log objects with updated attributes """ @spec query( - ids: [binary], limit: integer, after: Date.t() | binary, before: Date.t() | binary, types: [binary], - invoice_ids: [binary], + ids: [binary], user: Project.t() | Organization.t() | nil ) :: - { :ok, {binary, [Log.t()]} } | + {:ok, {binary, [Log.t()]} } | { :error, [Error.t()] } def query(options \\ []) do Rest.get_list( @@ -111,15 +110,14 @@ defmodule StarkInfra.IssuingInvoice.Log do end @doc """ - Same as query(), but it will unwrap the error tuple and raise in case of errors. + Same as query(), but it will unwrap the error tuple and raise in case of errors. """ @spec query!( - ids: [binary], limit: integer, after: Date.t() | binary, before: Date.t() | binary, types: [binary], - invoice_ids: [binary], + ids: [binary], user: Project.t() | Organization.t() | nil ) :: any def query!(options \\ []) do @@ -130,33 +128,32 @@ defmodule StarkInfra.IssuingInvoice.Log do end @doc """ - Receive a list of up to 100 IssuingInvoice.Log structs previously created in the Stark Infra API and the cursor to the next page. + Receive a list of up to 100 IssuingInvoice.Log objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your requests. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:ids` [list of strings, default nil]: list of IssuingInvoice ids to filter logs. ex: ["5656565656565656", "4545454545454545"] - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. It must be an integer between 1 and 100. ex: 50 - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:types` [list of strings, default nil]: filter for log event types. ex: ["created", "credited", "expired", "overdue", "paid"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:types` [list of binaries, default nil]: filter for log event types. ex: ["created", "credited", "expired", "overdue", "paid"] + - `:ids` [list of binaries, default nil]: list of IssuingInvoice ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of IssuingInvoice.Log structs with updated attributes - - cursor to retrieve the next page of IssuingInvoice.Log structs + - list of IssuingInvoice.Log objects with updated attributes + - cursor to retrieve the next page of IssuingInvoice.Log objects """ @spec page( cursor: binary, - ids: [binary], limit: integer, after: Date.t() | binary, before: Date.t() | binary, types: [binary], - invoice_ids: [binary], + ids: [binary], user: Project.t() | Organization.t() | nil ) :: - { :ok, {binary, [Log.t()]} } | + {:ok, {binary, [Log.t()]} } | { :error, [Error.t()] } def page(options \\ []) do Rest.get_page( @@ -170,12 +167,11 @@ defmodule StarkInfra.IssuingInvoice.Log do """ @spec page!( cursor: binary, - ids: [binary], limit: integer, after: Date.t() | binary, before: Date.t() | binary, types: [binary], - invoice_ids: [binary], + ids: [binary], user: Project.t() | Organization.t() | nil ) :: any def page!(options \\ []) do @@ -197,8 +193,8 @@ defmodule StarkInfra.IssuingInvoice.Log do def resource_maker(json) do %Log{ id: json[:id], - type: json[:type], invoice: json[:invoice], + type: json[:type], created: json[:created] |> Check.datetime(), } end diff --git a/lib/issuing_product/issuing_product.ex b/lib/issuing_product/issuing_product.ex new file mode 100644 index 0000000..3ff64f5 --- /dev/null +++ b/lib/issuing_product/issuing_product.ex @@ -0,0 +1,130 @@ +defmodule StarkInfra.IssuingProduct do + alias __MODULE__, as: IssuingProduct + alias StarkInfra.Utils.Rest + alias StarkInfra.Utils.Check + alias StarkInfra.User.Project + alias StarkInfra.User.Organization + alias StarkInfra.Error + + @moduledoc """ + Groups IssuingProduct related functions + """ + + @doc """ + The IssuingProduct object displays information of available card products registered to your Workspace. + They represent a group of cards that begin with the same numbers (id) and offer the same product to end customers. + + ## Attributes (return-only): + - `:id` [binary]: unique card product number (BIN) registered within the card network. ex: "53810200" + - `:network` [binary]: card network flag. ex: "mastercard" + - `:funding_type` [binary]: type of funding used for payment. ex: "credit", "debit" + - `:holder_type` [binary]: holder type. ex: "business", "individual" + - `:code` [binary]: internal code from card flag informing the product. ex: "MRW", "MCO", "MWB", "MCS" + - `:created` [DateTime]: creation datetime for the IssuingProduct. ex: ~U[2020-03-10 10:30:0:0] + """ + @enforce_keys [ + :id, + :network, + :funding_type, + :holder_type, + :code, + :created + ] + defstruct [ + :id, + :network, + :funding_type, + :holder_type, + :code, + :created + ] + + @type t() :: %__MODULE__{} + + @doc """ + Receive a stream of IssuingProduct objects previously registered in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - stream of IssuingProduct objects with updated attributes + """ + @spec query( + limit: integer, + user: Project.t() | Organization.t() | nil + ) :: + {:ok, [IssuingProduct.t()] } | + { :error, [error: Error.t()] } + def query(options \\ []) do + Rest.get_list(resource(), options) + end + + @doc """ + Same as query(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec query!( + limit: integer, + user: Project.t() | Organization.t() | nil + ) :: any + def query!(options \\ []) do + Rest.get_list!(resource(), options) + end + + @doc """ + Receive a list of up to 100 IssuingProduct objects previously created in the Stark Infra API and the cursor to the next page. + Use this function instead of query if you want to manually page your requests. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of IssuingProduct objects with updated attributes + - cursor to retrieve the next page of IssuingProduct objects + """ + @spec page( + cursor: binary, + limit: integer, + user: Project.t() | Organization.t() | nil + ) :: + {:ok, {binary, [IssuingProduct.t()]}} | + { :error, [error: Error.t()] } + def page(options \\ []) do + Rest.get_page(resource(), options) + end + + @doc """ + Same as page(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec page!( + cursor: binary, + limit: integer, + user: Project.t() | Organization.t() | nil + ) :: any + def page!(options \\ []) do + Rest.get_page!(resource(), options) + end + + @doc false + def resource() do + { + "IssuingProduct", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %IssuingProduct{ + id: json[:id], + network: json[:network], + funding_type: json[:funding_type], + holder_type: json[:holder_type], + code: json[:code], + created: json[:created] |> Check.datetime() + } + end +end diff --git a/lib/issuing_purchase/issuing_purchase.ex b/lib/issuing_purchase/issuing_purchase.ex index 2600dbc..56c130d 100644 --- a/lib/issuing_purchase/issuing_purchase.ex +++ b/lib/issuing_purchase/issuing_purchase.ex @@ -7,46 +7,58 @@ defmodule StarkInfra.IssuingPurchase do alias StarkInfra.Error @moduledoc """ - # IssuingPurchase struct + # IssuingPurchase object """ @doc """ - Displays the IssuingPurchase structs created in your Workspace. + Displays the IssuingPurchase objects created in your Workspace. ## Attributes (return-only): - - `:id` [string]: unique id returned when IssuingPurchase is created. ex: "5656565656565656" - - `:holder_name` [string]: card holder name. ex: "Tony Stark" - - `:card_id` [string]: unique id returned when IssuingCard is created. ex: "5656565656565656" - - `:card_ending` [string]: last 4 digits of the card number. ex: "1234" + - `:id` [binary]: unique id returned when IssuingPurchase is created. ex: "5656565656565656" + - `:holder_name` [binary]: card holder name. ex: "Tony Stark" + - `:product_id` [binary]: unique card product number (BIN) registered within the card network. ex: "53810200" + - `:card_id` [binary]: unique id returned when IssuingCard is created. ex: "5656565656565656" + - `:card_ending` [binary]: last 4 digits of the card number. ex: "1234" + - `:purpose` [binary]: purchase purpose. ex: "purchase" - `:amount` [integer]: IssuingPurchase value in cents. Minimum = 0. ex: 1234 (= R$ 12.34) - `:tax` [integer]: IOF amount taxed for international purchases. ex: 1234 (= R$ 12.34) - `:issuer_amount` [integer]: issuer amount. ex: 1234 (= R$ 12.34) - - `:issuer_currency_code` [string]: issuer currency code. ex: "USD" - - `:issuer_currency_symbol` [string]: issuer currency symbol. ex: "$" + - `:issuer_currency_code` [binary]: issuer currency code. ex: "USD" + - `:issuer_currency_symbol` [binary]: issuer currency symbol. ex: "$" - `:merchant_amount` [integer]: merchant amount. ex: 1234 (= R$ 12.34) - - `:merchant_currency_code` [string]: merchant currency code. ex: "USD" - - `:merchant_currency_symbol` [string]: merchant currency symbol. ex: "$" - - `:merchant_category_code` [string]: merchant category code. ex: "fastFoodRestaurants" - - `:merchant_country_code` [string]: merchant country code. ex: "USA" - - `:acquirer_id` [string]: acquirer ID. ex: "5656565656565656" - - `:merchant_id` [string]: merchant ID. ex: "5656565656565656" - - `:merchant_name` [string]: merchant name. ex: "Google Cloud Platform" + - `:merchant_currency_code` [binary]: merchant currency code. ex: "USD" + - `:merchant_currency_symbol` [binary]: merchant currency symbol. ex: "$" + - `:merchant_category_code` [binary]: merchant category code. ex: "fastFoodRestaurants" + - `:merchant_country_code` [binary]: merchant country code. ex: "USA" + - `:acquirer_id` [binary]: acquirer ID. ex: "5656565656565656" + - `:merchant_id` [binary]: merchant ID. ex: "5656565656565656" + - `:merchant_name` [binary]: merchant name. ex: "Google Cloud Platform" - `:merchant_fee` [integer]: fee charged by the merchant to cover specific costs, such as ATM withdrawal logistics, etc. ex: 200 (= R$ 2.00) - - `:wallet_id` [string]: virtual wallet ID. ex: "5656565656565656" - - `:method_code` [string]: method code. ex: "chip", "token", "server", "manual", "magstripe" or "contactless" + - `:wallet_id` [binary]: virtual wallet ID. ex: "5656565656565656" + - `:method_code` [binary]: method code. ex: "chip", "token", "server", "manual", "magstripe" or "contactless" - `:score` [float]: internal score calculated for the authenticity of the purchase. nil in case of insufficient data. ex: 7.6 - - `:issuing_transaction_ids` [string]: ledger transaction ids linked to this Purchase - - `:end_to_end_id` [string]: central bank's unique transaction ID. ex: "E79457883202101262140HHX553UPqeq" - - `:status` [string]: current IssuingCard status. ex: "approved", "canceled", "denied", "confirmed", "voided" - - `:tags` [string]: list of strings for tagging returned by the sub-issuer during the authorization. ex: ["travel", "food"] - - `:updated` [DateTime]: latest update DateTime for the IssuingPurchase. ex: ~U[2020-3-10 10:30:0:0] + - `:end_to_end_id` [binary]: Unique id used to identify the transaction through all of its life cycle, even before the purchase is denied or accepted and gets its usual id. ex: "679cd385-642b-49d0-96b7-89491e1249a5" + - `:tags` [list of binaries]: list of binaries for tagging returned by the sub-issuer during the authorization. ex: ["travel", "food"] + - `:zip_code` [binary]: zip code of the merchant location. ex: "02101234" + + ## Attributes (IssuingPurchase only): + - `:issuing_transaction_ids` [binary]: ledger transaction ids linked to this Purchase + - `:status` [binary]: current IssuingCard status. ex: "approved", "canceled", "denied", "confirmed", "voided" + - `:updated` [DateTime]: latest update datetime for the IssuingPurchase. ex: ~U[2020-03-10 10:30:0:0] - `:created` [DateTime]: creation datetime for the IssuingPurchase. ex: ~U[2020-03-10 10:30:0:0] + + ## Attributes (authorization request only): + - `:is_partial_allowed` [bool]: true if the merchant allows partial purchases. ex: False + - `:card_tags` [list of binaries]: tags of the IssuingCard responsible for this purchase. ex: ["travel", "food"] + - `:holder_tags` [list of binaries]: tags of the IssuingHolder responsible for this purchase. ex: ["technology", "john snow"] """ @enforce_keys [ :id, :holder_name, + :product_id, :card_id, :card_ending, + :purpose, :amount, :tax, :issuer_amount, @@ -64,19 +76,25 @@ defmodule StarkInfra.IssuingPurchase do :wallet_id, :method_code, :score, - :issuing_transaction_ids, :end_to_end_id, - :status, :tags, + :zip_code, + :issuing_transaction_ids, + :status, :updated, - :created + :created, + :is_partial_allowed, + :card_tags, + :holder_tags, ] defstruct [ :id, :holder_name, + :product_id, :card_id, :card_ending, + :purpose, :amount, :tax, :issuer_amount, @@ -94,27 +112,31 @@ defmodule StarkInfra.IssuingPurchase do :wallet_id, :method_code, :score, - :issuing_transaction_ids, :end_to_end_id, - :status, :tags, + :zip_code, + :issuing_transaction_ids, + :status, :updated, - :created + :created, + :is_partial_allowed, + :card_tags, + :holder_tags, ] @type t() :: %__MODULE__{} @doc """ - Receive a single IssuingPurchase struct previously created in the Stark Infra API by its id + Receive a single IssuingPurchase object previously created in the Stark Infra API by its id ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - IssuingPurchase struct with updated attributes + - IssuingPurchase object that corresponds to the given id. """ @spec get( id: binary, @@ -146,24 +168,23 @@ defmodule StarkInfra.IssuingPurchase do end @doc """ - Receive a stream of IssuingPurchases structs previously created in the Stark Infra API - - ## Options: - - `:ids` [list of strings, default [], default nil]: purchase IDs - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:end_to_end_ids` [list of strings, default []]: central bank's unique transaction ID. ex: "E79457883202101262140HHX553UPqeq" - - `:holder_ids` [list of strings, default []]: card holder IDs. ex: ["5656565656565656", "4545454545454545"] - - `:card_ids` [list of strings, default []]: card IDs. ex: ["5656565656565656", "4545454545454545"] - - `:status` [list of strings, default nil]: filter for status of retrieved structs. ex: ["approved", "canceled", "denied", "confirmed", "voided"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + Receive a stream of IssuingPurchase objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:end_to_end_ids` [list of binaries, default []]: central bank's unique transaction ID. ex: "E79457883202101262140HHX553UPqeq" + - `:holder_ids` [list of binaries, default []]: card holder IDs. ex: ["5656565656565656", "4545454545454545"] + - `:card_ids` [list of binaries, default []]: card IDs. ex: ["5656565656565656", "4545454545454545"] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. ex: ["approved", "canceled", "denied", "confirmed", "voided"] + - `:ids` [list of binaries, default []]: purchase IDs + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of IssuingPurchase structs with updated attributes + - stream of IssuingPurchase objects with updated attributes """ @spec query( - ids: [binary], limit: integer, after: Date.t() | binary, before: Date.t() | binary, @@ -171,6 +192,7 @@ defmodule StarkInfra.IssuingPurchase do holder_ids: [binary], card_ids: [binary], status: [binary], + ids: [binary], user: Organization.t() | Project.t() | nil ) :: {:ok, {binary, [IssuingPurchase.t()]}} | @@ -186,7 +208,6 @@ defmodule StarkInfra.IssuingPurchase do Same as query(), but it will unwrap the error tuple and raise in case of errors. """ @spec page!( - ids: [binary], limit: integer, after: Date.t() | binary, before: Date.t() | binary, @@ -194,6 +215,7 @@ defmodule StarkInfra.IssuingPurchase do holder_ids: [binary], card_ids: [binary], status: [binary], + ids: [binary], user: Organization.t() | Project.t() | nil ) :: any def query!(options \\ []) do @@ -204,27 +226,27 @@ defmodule StarkInfra.IssuingPurchase do end @doc """ - Receive a list of IssuingPurchase structs previously created in the Stark Infra API and the cursor to the next page. - - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:ids` [list of strings, default [], default nil]: purchase IDs - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:end_to_end_ids` [list of strings, default []]: central bank's unique transaction ID. ex: "E79457883202101262140HHX553UPqeq" - - `:holder_ids` [list of strings, default []]: card holder IDs. ex: ["5656565656565656", "4545454545454545"] - - `:card_ids` [list of strings, default []]: card IDs. ex: ["5656565656565656", "4545454545454545"] - - `:status` [list of strings, default nil]: filter for status of retrieved structs. ex: ["approved", "canceled", "denied", "confirmed", "voided"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + Receive a list of up to 100 IssuingPurchase objects previously created in the Stark Infra API and the cursor to the next page. + Use this function instead of query if you want to manually page your requests. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:end_to_end_ids` [list of binaries, default []]: central bank's unique transaction ID. ex: "E79457883202101262140HHX553UPqeq" + - `:holder_ids` [list of binaries, default []]: card holder IDs. ex: ["5656565656565656", "4545454545454545"] + - `:card_ids` [list of binaries, default []]: card IDs. ex: ["5656565656565656", "4545454545454545"] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. ex: ["approved", "canceled", "denied", "confirmed", "voided"] + - `:ids` [list of binaries, default []]: purchase IDs + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of IssuingPurchase structs with updated attributes - - cursor to retrieve the next page of IssuingPurchase structs + - list of IssuingPurchase objects with updated attributes + - cursor to retrieve the next page of IssuingPurchase objects """ @spec page( cursor: binary, - ids: [binary], limit: integer, after: Date.t() | binary, before: Date.t() | binary, @@ -232,6 +254,7 @@ defmodule StarkInfra.IssuingPurchase do holder_ids: [binary], card_ids: [binary], status: [binary], + ids: [binary], user: Organization.t() | Project.t() | nil ) :: {:ok, {binary, [IssuingPurchase.t()]}} | @@ -248,7 +271,6 @@ defmodule StarkInfra.IssuingPurchase do """ @spec page!( cursor: binary, - ids: [binary], limit: integer, after: Date.t() | binary, before: Date.t() | binary, @@ -256,6 +278,7 @@ defmodule StarkInfra.IssuingPurchase do holder_ids: [binary], card_ids: [binary], status: [binary], + ids: [binary], user: Organization.t() | Project.t() | nil ) :: any def page!(options \\ []) do @@ -265,6 +288,103 @@ defmodule StarkInfra.IssuingPurchase do ) end + @doc """ + Create a single verified IssuingPurchase authorization request from a content string + Use this method to parse and verify the authenticity of the authorization request received at the informed endpoint. + Authorization requests are posted to your registered endpoint whenever IssuingPurchases are received. + They present IssuingPurchase data that must be analyzed and answered with approval or declination. + If the provided digital signature does not check out with the StarkInfra public key, a stark.exception.InvalidSignatureException will be raised. + If the authorization request is not answered within 2 seconds or is not answered with an HTTP status code 200 the IssuingPurchase will go through the pre-configured stand-in validation. + + ## Parameters (required): + - `:content` [binary]: response content from request received at user endpoint (not parsed) + - `:signature` [binary]: base-64 digital signature received at response header "Digital-Signature" + + ## Parameters (optional): + - `cache_pid` [PID, default nil]: PID of the process that holds the public key cache, returned on previous parses. If not provided, a new cache process will be generated. + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - Parsed IssuingPurchase object + """ + @spec parse( + content: binary, + signature: binary, + cache_pid: PID, + user: Project.t() | Organization.t() + ):: + {:ok, IssuingPurchase.t()} | + {:error, [error: Error.t()]} + def parse(options) do + %{content: content, signature: signature, cache_pid: cache_pid, user: user} = + Enum.into( + options |> Check.enforced_keys([:content, :signature]), + %{cache_pid: nil, user: nil} + ) + Parse.parse_and_verify( + content: content, + signature: signature, + cache_pid: cache_pid, + key: nil, + resource_maker: &resource_maker/1, + user: user + ) + end + + @spec parse!( + content: binary, + signature: binary, + cache_pid: PID, + user: Project.t() | Organization.t() + ) :: any + def parse!(options \\ []) do + %{content: content, signature: signature, cache_pid: cache_pid, user: user} = + Enum.into( + options |> Check.enforced_keys([:content, :signature]), + %{cache_pid: nil, user: nil} + ) + Parse.parse_and_verify!( + content: content, + signature: signature, + cache_pid: cache_pid, + key: nil, + resource_maker: &resource_maker/1, + user: user + ) + end + + @doc """ + Helps you respond to a PixReversal authorization + + ## Parameters (required): + - `:status` [binary]: sub-issuer response to the authorization. ex: "approved" or "denied" + + ## Parameters (conditionally-required): + - `:reason` [binary, default nil]: denial reason. Options: "other", "blocked", "lostCard", "stolenCard", "invalidPin", "invalidCard", "cardExpired", "issuerError", "concurrency", "standInDenial", "subIssuerError", "invalidPurpose", "invalidZipCode", "invalidWalletId", "inconsistentCard", "settlementFailed", "cardRuleMismatch", "invalidExpiration", "prepaidInstallment", "holderRuleMismatch", "insufficientBalance", "tooManyTransactions", "invalidSecurityCode", "invalidPaymentMethod", "confirmationDeadline", "withdrawalAmountLimit", "insufficientCardLimit", "insufficientHolderLimit" + + ## Parameters (optional): + - `:amount` [binary, default nil]: amount in cents that was authorized. ex: 1234 (= R$ 12.34) + - `:tags` [list of binaries, default nil]: tags to filter retrieved object. ex: ["tony", "stark"] + + ## Return: + - Dumped JSON binary that must be returned to us + """ + + @spec response( + map(), + user: Project.t() | Organization.t() | nil + ) :: + {:ok, PixReversal.t()} | + {:error, [Error.t()]} + def response(status, reason, amount, tags) do + body = %{status: status, reason: reason, amount: amount, tags: tags} + params = %{authorization: body} + params + |> Jason.encode! + end + + @spec resource :: + {<<_::120>>, (nil | maybe_improper_list | map -> StarkInfra.IssuingPurchase.t())} @doc false def resource() do { @@ -278,9 +398,11 @@ defmodule StarkInfra.IssuingPurchase do %IssuingPurchase{ id: json[:id], holder_name: json[:holder_name], + product_id: json[:product_id], card_id: json[:card_id], card_ending: json[:card_ending], amount: json[:amount], + purpose: json[:purpose], tax: json[:tax], issuer_amount: json[:issuer_amount], issuer_currency_code: json[:issuer_currency_code], @@ -297,12 +419,16 @@ defmodule StarkInfra.IssuingPurchase do wallet_id: json[:wallet_id], method_code: json[:method_code], score: json[:score], - issuing_transaction_ids: json[:issuing_transaction_ids], end_to_end_id: json[:end_to_end_id], - status: json[:status], tags: json[:tags], + zip_code: json[:zip_code], + issuing_transaction_ids: json[:issuing_transaction_ids], + status: json[:status], updated: json[:updated] |> Check.datetime(), - created: json[:created] |> Check.datetime() + created: json[:created] |> Check.datetime(), + is_partial_allowed: json[:is_partial_allowed], + card_tags: json[:card_tags], + holder_tags: json[:holder_tags], } end end diff --git a/lib/issuing_purchase/issuing_purchase_log.ex b/lib/issuing_purchase/issuing_purchase_log.ex index 64b1db1..0de2967 100644 --- a/lib/issuing_purchase/issuing_purchase_log.ex +++ b/lib/issuing_purchase/issuing_purchase_log.ex @@ -7,7 +7,7 @@ defmodule StarkInfra.IssuingPurchase.Log do alias StarkInfra.Error @moduledoc """ - # IssuingPurchase.Log struct + # IssuingPurchase.Log object """ @doc """ @@ -16,12 +16,12 @@ defmodule StarkInfra.IssuingPurchase.Log do user, but it can be retrieved to check additional information on the IssuingPurchase. - ## Attributes: - - `:id` [string]: unique id returned when the log is created. ex: "5656565656565656" + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the log is created. ex: "5656565656565656" - `:purchase` [IssuingPurchase]: IssuingPurchase entity to which the log refers to. - - `:issuing_transaction_id` [string]: transaction ID related to the IssuingCard. - - `:errors` [list of strings]: list of errors linked to this IssuingPurchase event - - `:type` [string]: type of the IssuingPurchase event which triggered the log creation. ex: "approved", "canceled", "confirmed", "denied", "reversed", "voided". + - `:issuing_transaction_id` [binary]: transaction ID related to the IssuingCard. + - `:errors` [list of binaries]: list of errors linked to this IssuingPurchase event + - `:type` [binary]: type of the IssuingPurchase event which triggered the log creation. Options: "approved", "canceled", "confirmed", "denied", "reversed", "voided". - `:created` [DateTime]: creation datetime for the log. ex: ~U[2020-03-10 10:30:0:0] """ @enforce_keys [ @@ -44,22 +44,22 @@ defmodule StarkInfra.IssuingPurchase.Log do @type t() :: %__MODULE__{} @doc """ - Receive a single IssuingPurchase.Log struct previously created by the Stark Infra API by its id + Receive a single IssuingPurchase.Log object previously created by the Stark Infra API by its id ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - IssuingPurchase.Log struct with updated attributes + - IssuingPurchase.Log object that corresponds to the given id. """ @spec get( id: binary, user: Project.t() | Organization.t() | nil ) :: - { :ok, Log.t() } | + {:ok, Log.t() } | { :error, [Error.t()] } def get(id, options \\ []) do Rest.get_id( @@ -85,19 +85,19 @@ defmodule StarkInfra.IssuingPurchase.Log do end @doc """ - Receive a stream of IssuingPurchase.Log structs previously created in the Stark Infra API + Receive a stream of IssuingPurchase.Log objects previously created in the Stark Infra API - ## Options: - - `:ids` [list of strings, default nil]: list of IssuingPurchase ids to filter logs. ex: ["5656565656565656", "4545454545454545"] - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:types` [list of strings, default nil]: filter for log event types. ex: ["approved", "canceled", "confirmed", "denied", "reversed", "voided"] - - `:purchase_ids` [list of strings, default nil]: list of Purchase ids to filter logs. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:types` [list of binaries, default nil]: filter for log event types. ex: ["approved", "canceled", "confirmed", "denied", "reversed", "voided"] + - `:purchase_ids` [list of binaries, default nil]: list of Purchase ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: list of IssuingPurchase ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of IssuingPurchase.Log structs with updated attributes + - stream of IssuingPurchase.Log objects with updated attributes """ @spec query( ids: [binary], @@ -108,7 +108,7 @@ defmodule StarkInfra.IssuingPurchase.Log do purchase_ids: [binary], user: Project.t() | Organization.t() | nil ) :: - { :ok, {binary, [Log.t()]} } | + {:ok, {binary, [Log.t()]} } | { :error, [Error.t()] } def query(options \\ []) do Rest.get_list( @@ -121,12 +121,12 @@ defmodule StarkInfra.IssuingPurchase.Log do Same as query(), but it will unwrap the error tuple and raise in case of errors. """ @spec query!( - ids: [binary], limit: integer, after: Date.t() | binary, before: Date.t() | binary, types: [binary], purchase_ids: [binary], + ids: [binary], user: Project.t() | Organization.t() | nil ) :: any def query!(options \\ []) do @@ -137,33 +137,33 @@ defmodule StarkInfra.IssuingPurchase.Log do end @doc """ - Receive a list of up to 100 IssuingPurchase.Log structs previously created in the Stark Infra API and the cursor to the next page. + Receive a list of up to 100 IssuingPurchase.Log objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your requests. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:ids` [list of strings, default nil]: list of IssuingPurchase ids to filter logs. ex: ["5656565656565656", "4545454545454545"] - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:types` [list of strings, default nil]: filter for log event types. ex: ["approved", "canceled", "confirmed", "denied", "reversed", "voided"] - - `:purchase_ids` [list of strings, default nil]: list of Purchase ids to filter logs. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:types` [list of binaries, default nil]: filter for log event types. ex: ["approved", "canceled", "confirmed", "denied", "reversed", "voided"] + - `:purchase_ids` [list of binaries, default nil]: list of Purchase ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: list of IssuingPurchase ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of IssuingPurchase.Log structs with updated attributes - - cursor to retrieve the next page of IssuingPurchase.Log structs + - list of IssuingPurchase.Log objects with updated attributes + - cursor to retrieve the next page of IssuingPurchase.Log objects """ @spec page( cursor: binary, - ids: [binary], limit: integer, after: Date.t() | binary, before: Date.t() | binary, types: [binary], purchase_ids: [binary], + ids: [binary], user: Project.t() | Organization.t() | nil - ) :: { :ok, {binary, [Log.t()]} } | { :error, [Error.t()] } + ) :: {:ok, {binary, [Log.t()]} } | { :error, [Error.t()] } def page(options \\ []) do Rest.get_page( resource(), @@ -203,10 +203,10 @@ defmodule StarkInfra.IssuingPurchase.Log do def resource_maker(json) do %Log{ id: json[:id], - type: json[:type], - errors: json[:errors], purchase: json[:purchase], issuing_transaction_id: json[:issuing_transaction_id], + errors: json[:errors], + type: json[:type], created: json[:created] |> Check.datetime(), } end diff --git a/lib/issuing_restock/issuing_restock.ex b/lib/issuing_restock/issuing_restock.ex new file mode 100644 index 0000000..0843f00 --- /dev/null +++ b/lib/issuing_restock/issuing_restock.ex @@ -0,0 +1,226 @@ +defmodule StarkInfra.IssuingRestock do + alias __MODULE__, as: IssuingRestock + alias StarkInfra.Utils.Rest + alias StarkInfra.Utils.Check + alias StarkInfra.User.Project + alias StarkInfra.User.Organization + alias StarkInfra.Error + + @moduledoc """ + # IssuingRestock object + """ + + @doc """ + The IssuingRestock object displays the information of the restock orders created in your Workspace. + This resource place a restock order for a specific IssuingStock object. + + ## Parameters (required): + - `:count` [binary]: number of restocks to be restocked. ex: 100 + - `:stock_id` [binary]: IssuingStock unique id ex: "5136459887542272" + + ## Parameters (optional): + - `:tags` [list of binaries]: list of strings for tagging. ex: ["card", "corporate"] + + ## Attributes (return-only): + - `:id` [binary]: unique id returned when IssuingRestock is created. ex: "5656565656565656" + - `:status` [binary]: current IssuingCard status. ex: "approved", "canceled", "denied", "confirmed", "voided" + - `:updated` [DateTime]: latest update datetime for the IssuingRestock. ex: ~U[2020-03-10 10:30:0:0] + - `:created` [DateTime]: creation datetime for the IssuingRestock. ex: ~U[2020-03-10 10:30:0:0] + """ + @enforce_keys [ + :count, + :stock_id, + :tags, + ] + + defstruct [ + :count, + :stock_id, + :tags, + :id, + :status, + :updated, + :created + ] + + @type t() :: %__MODULE__{} + + @doc """ + Receive a single IssuingRestock object previously created in the Stark Infra API by its id + + ## Parameters (required): + - `:id` [binary]: object unique id. ex: "5656565656565656" + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - IssuingRestock object that corresponds to the given id. + """ + @spec get( + id: binary, + user: Organization.t() | Project.t() | nil + ) :: + {:ok, IssuingRestock.t()} | + {:error, [Error.t()]} + def get(id, options \\ []) do + Rest.get_id( + resource(), + id, + options + ) + end + + @doc """ + Same as get(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec get!( + id: binary, + user: Organization.t() | Project.t() | nil + ) :: any + def get!(id, options \\ []) do + Rest.get_id!( + resource(), + id, + options + ) + end + + @doc """ + Receive a stream of IssuingRestock objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:status` [list of binaries, default []]: filter for status of retrieved objects. ex: ["created", "processing", "confirmed"] + - `:stock_ids` [list of binaries, default []]: list of stock_ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:tags` [list of binaries, default []]: tags to filter retrieved objects. ex: ["card", "corporate"] + - `:ids` [list of binaries, default []]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - stream of IssuingRestock objects with updated attributes + """ + @spec query( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: [binary], + stock_ids: [binary], + tags: [binary], + ids: [binary], + user: Organization.t() | Project.t() | nil + ) :: + {:ok, {binary, [IssuingRestock.t()]}} | + {:error, [Error.t()]} + def query(options \\ []) do + Rest.get_list( + resource(), + options + ) + end + + @doc """ + Same as query(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec page!( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: [binary], + stock_ids: [binary], + tags: [binary], + ids: [binary], + user: Organization.t() | Project.t() | nil + ) :: any + def query!(options \\ []) do + Rest.get_list!( + resource(), + options + ) + end + + @doc """ + Receive a list of up to 100 IssuingRestock objects previously created in the Stark Infra API and the cursor to the next page. + Use this function instead of query if you want to manually page your requests. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:status` [list of binaries, default []]: filter for status of retrieved objects. ex: ["created", "processing", "confirmed"] + - `:stock_ids` [list of binaries, default []]: list of stock_ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:tags` [list of binaries, default []]: tags to filter retrieved objects. ex: ["card", "corporate"] + - `:ids` [list of binaries, default []]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of IssuingRestock objects with updated attributes + - cursor to retrieve the next page of IssuingRestock objects + """ + @spec page( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: [binary], + stock_ids: [binary], + tags: [binary], + ids: [binary], + user: Organization.t() | Project.t() | nil + ) :: + {:ok, {binary, [IssuingRestock.t()]}} | + {:error, [Error.t()]} + def page(options \\ []) do + Rest.get_page( + resource(), + options + ) + end + + @doc """ + Same as page(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec page!( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: [binary], + stock_ids: [binary], + tags: [binary], + ids: [binary], + user: Organization.t() | Project.t() | nil + ) :: any + def page!(options \\ []) do + Rest.get_page!( + resource(), + options + ) + end + + @spec resource :: + {<<_::120>>, (nil | maybe_improper_list | map -> StarkInfra.IssuingRestock.t())} + @doc false + def resource() do + { + "IssuingRestock", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %IssuingRestock{ + count: json[:count], + stock_id: json[:stock_id], + tags: json[:tags], + id: json[:id], + status: json[:status], + created: json[:created], + updated: json[:updated] + } + end +end diff --git a/lib/issuing_restock/issuing_restock_log.ex b/lib/issuing_restock/issuing_restock_log.ex new file mode 100644 index 0000000..6538105 --- /dev/null +++ b/lib/issuing_restock/issuing_restock_log.ex @@ -0,0 +1,205 @@ +defmodule StarkInfra.IssuingRestock.Log do + alias __MODULE__, as: Log + alias StarkInfra.Utils.Rest + alias StarkInfra.Utils.Check + alias StarkInfra.User.Project + alias StarkInfra.User.Organization + alias StarkInfra.Error + + @moduledoc """ + # IssuingRestock.Log object + """ + + @doc """ + Every time an IssuingRestock entity is updated, a corresponding IssuingRestock.Log + is generated for the entity. This log is never generated by the + user, but it can be retrieved to check additional information + on the IssuingRestock. + + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the log is created. ex: "5656565656565656" + - `:restock` [IssuingRestock]: IssuingRestock entity to which the log refers to. + - `:type` [binary]: type of the IssuingRestock event which triggered the log creation. ex: "created", "processing", "confirmed" + - `:created` [DateTime]: creation datetime for the log. ex: ~U[2020-03-10 10:30:0:0] + """ + @enforce_keys [ + :id, + :restock, + :type, + :created + ] + defstruct [ + :id, + :restock, + :type, + :created + ] + + @type t() :: %__MODULE__{} + + @doc """ + Receive a single IssuingRestock.Log object previously created by the Stark Infra API by its id + + ## Parameters (required): + - `:id` [binary]: object unique id. ex: "5656565656565656" + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - IssuingRestock.Log object that corresponds to the given id. + """ + @spec get( + id: binary, + user: Project.t() | Organization.t() | nil + ) :: + {:ok, Log.t() } | + { :error, [Error.t()] } + def get(id, options \\ []) do + Rest.get_id( + resource(), + id, + options + ) + end + + @doc """ + Same as get(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec get!( + id: binary, + user: Project.t() | Organization.t() | nil + ) :: any + def get!(id, options \\ []) do + Rest.get_id!( + resource(), + id, + options + ) + end + + @doc """ + Receive a stream of IssuingRestock.Log objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:types` [list of binaries, default nil]: filter for log event types. ex: ["created", "processing", "confirmed"] + - `:restock_ids` [list of binaries, default nil]: list of restock ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: list of IssuingRestock ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - stream of IssuingRestock.Log objects with updated attributes + """ + @spec query( + ids: [binary], + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + restock_ids: [binary], + user: Project.t() | Organization.t() | nil + ) :: + {:ok, {binary, [Log.t()]} } | + { :error, [Error.t()] } + def query(options \\ []) do + Rest.get_list( + resource(), + options + ) + end + + @doc """ + Same as query(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec query!( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + restock_ids: [binary], + ids: [binary], + user: Project.t() | Organization.t() | nil + ) :: any + def query!(options \\ []) do + Rest.get_list!( + resource(), + options + ) + end + + @doc """ + Receive a list of up to 100 IssuingRestock.Log objects previously created in the Stark Infra API and the cursor to the next page. + Use this function instead of query if you want to manually page your requests. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:types` [list of binaries, default nil]: filter for log event types. ex: ["created", "processing", "confirmed"] + - `:restock_ids` [list of binaries, default nil]: list of restock ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: list of IssuingRestock ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of IssuingRestock.Log objects with updated attributes + - cursor to retrieve the next page of IssuingRestock.Log objects + """ + @spec page( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + restock_ids: [binary], + ids: [binary], + user: Project.t() | Organization.t() | nil + ) :: {:ok, {binary, [Log.t()]} } | { :error, [Error.t()] } + def page(options \\ []) do + Rest.get_page( + resource(), + options + ) + end + + @doc """ + Same as page(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec page!( + cursor: binary, + ids: [binary], + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + restock_ids: [binary], + user: Project.t() | Organization.t() | nil + ) :: any + def page!(options \\ []) do + Rest.get_page!( + resource(), + options + ) + end + + @doc false + def resource() do + { + "IssuingRestockLog", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %Log{ + id: json[:id], + restock: json[:restock], + type: json[:type], + created: json[:created] |> Check.datetime(), + } + end +end diff --git a/lib/issuing_rule/issuing_rule.ex b/lib/issuing_rule/issuing_rule.ex index d83da5b..f7e3658 100644 --- a/lib/issuing_rule/issuing_rule.ex +++ b/lib/issuing_rule/issuing_rule.ex @@ -1,37 +1,36 @@ defmodule StarkInfra.IssuingRule do + alias StarkInfra.CardMethod + alias StarkInfra.MerchantCountry + alias StarkInfra.MerchantCategory alias __MODULE__, as: IssuingRule @moduledoc """ - # IssuingRule struct + # IssuingRule object """ @doc """ - The IssuingRule struct displays the spending rules of IssuingCards and IssuingHolders created in your Workspace. + The IssuingRule object displays the spending rules of IssuingCards and IssuingHolders created in your Workspace. ## Parameters (required): - - `:name` [string]: rule name. ex: "Travel" or "Food" + - `:name` [binary]: rule name. ex: "Travel" or "Food" - `:amount` [integer]: maximum amount that can be spent in the informed interval. ex: 200000 (= R$ 2000.00) - - `:interval` [string]: interval after which the rule amount counter will be reset to 0. ex: "instant", "day", "week", "month", "year" or "lifetime" - ## Parameters (optional): - - `:currency_code` [string, default "BRL"]: code of the currency that the rule amount refers to. ex: "BRL" or "USD" - - `:categories` [list of strings, default []]: merchant categories accepted by the rule. ex: ["eatingPlacesRestaurants", "travelAgenciesTourOperators"] - - `:countries` [list of strings, default []]: countries accepted by the rule. ex: ["BRA", "USA"] - - `:methods` [list of strings, default []]: card purchase methods accepted by the rule. ex: ["chip", "token", "server", "manual", "magstripe", "contactless"] + ## Parameters (optional): + - `:interval` [binary, default nil]: interval after which the rule amount counter will be reset to 0. ex: "instant", "day", "week", "month", "year" or "lifetime" + - `:currency_code` [binary, default "BRL"]: code of the currency that the rule amount refers to. ex: "BRL" or "USD" + - `:categories` [list of MerchantCategories, default []]: merchant categories accepted by the rule. ex: [%{ code: "fastFoodRestaurants"}] + - `:countries` [list of MerchantCountries, default []]: countries accepted by the rule. ex: [%{ code: "BRA"}] + - `:methods` [list of CardMethods, default []]: card purchase methods accepted by the rule. ex: [%{ code: "magstripe"}] - ## Attributes (expanded return-only): + ## Attributes (expanded return-only): + - `:id` [binary]: unique id returned when Rule is created, used to update a specific IssuingRule. ex: "5656565656565656" - `:counter_amount` [integer]: current rule spent amount. ex: 1000 - - `:currency_symbol` [string]: currency symbol. ex: "R$" - - `:currency_name` [string]: currency name. ex: "Brazilian Real" - - ## Attributes (return-only): - - `:id` [string]: unique id returned when Rule is created. ex: "5656565656565656" + - `:currency_symbol` [binary]: currency symbol. ex: "R$" + - `:currency_name` [binary]: currency name. ex: "Brazilian Real" """ @enforce_keys [ - :amount, - :currency_code, - :interval, - :name + :name, + :amount ] defstruct [ :amount, @@ -65,13 +64,12 @@ defmodule StarkInfra.IssuingRule do id: json[:id], interval: json[:interval], name: json[:name], - categories: json[:categories], - countries: json[:countries], - methods: json[:methods], + categories: json[:categories] |> Enum.map(fn category -> API.from_api_json(category, &MerchantCategory.resource_maker/1) end), + countries: json[:countries] |> Enum.map(fn country -> API.from_api_json(country, &MerchantCountry.resource_maker/1) end), + methods: json[:methods] |> Enum.map(fn method -> API.from_api_json(method, &CardMethod.resource_maker/1) end), counter_amount: json[:counter_amount], currency_symbol: json[:currency_symbol], currency_name: json[:currency_name] } end - end diff --git a/lib/issuing_stock/issuing_stock.ex b/lib/issuing_stock/issuing_stock.ex new file mode 100644 index 0000000..2877f7d --- /dev/null +++ b/lib/issuing_stock/issuing_stock.ex @@ -0,0 +1,225 @@ +defmodule StarkInfra.IssuingStock do + alias __MODULE__, as: IssuingStock + alias StarkInfra.Utils.Rest + alias StarkInfra.Utils.Check + alias StarkInfra.User.Project + alias StarkInfra.User.Organization + alias StarkInfra.Error + + @moduledoc """ + # IssuingStock object + """ + + @doc """ + The IssuingStock object displays the information of the restock orders created in your Workspace. + This resource place a restock order for a specific IssuingStock object. + + ## Attributes (return-only): + - `:id` [binary]: unique id returned when IssuingStock is created. ex: "5656565656565656" + - `:balance` [integer]: [EXPANDABLE] current stock balance. ex: 1000 + - `:design_id` [binary]: IssuingDesign unique id. ex: "5656565656565656" + - `:embosser_id` [binary]: Embosser unique id. ex: "5656565656565656" + - `:updated` [DateTime]: latest update datetime for the IssuingStock. ex: ~U[2020-03-10 10:30:0:0] + - `:created` [DateTime]: creation datetime for the IssuingStock. ex: ~U[2020-03-10 10:30:0:0] + """ + @enforce_keys [ + :id, + :balance, + :design_id, + :embosser_id, + :created, + :updated, + ] + + defstruct [ + :id, + :balance, + :design_id, + :embosser_id, + :created, + :updated, + ] + + @type t() :: %__MODULE__{} + + @doc """ + Receive a single IssuingStock objects previously created in the Stark Infra API by its id. + + ## Parameters (required): + - `:id` [binary]: object unique id. ex: "5656565656565656" + + ## Parameters (optional): + - `:expand` [list of binaries, default nil]: fields to expand information. ex: ["balance"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - IssuingStock objects that corresponds to the given id. + """ + @spec get( + id: binary, + expand: [binary] | nil, + user: (Organization.t() | Project.t() | nil) + ) :: + {:ok, IssuingStock.t()} | + {:error, [Error.t()]} + def get(id, options \\ []) do + Rest.get_id( + resource(), + id, + options + ) + end + + @doc """ + Same as get(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec get!( + id: binary, + expand: [binary] | nil, + user: (Organization.t() | Project.t() | nil) + ) :: any + def get!(id, options \\ []) do + Rest.get_id!( + resource(), + id, + options + ) + end + + @doc """ + Receive a stream of IssuingStock objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:design_ids` [list of binaries, default []]: list of stock_ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:embosser_id` [list of binaries, default []]: filter for status of retrieved objects. ex: ["created", "processing", "confirmed"] + - `:ids` [list of binaries, default []]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:expand` [list of binaries, default nil]: fields to expand information. ex: ["balance"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - stream of IssuingStock objects with updated attributes + """ + @spec query( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + design_ids: [binary], + embosser_ids: [binary], + ids: [binary], + expand: [binary], + user: Organization.t() | Project.t() | nil + ) :: + {:ok, {binary, [IssuingStock.t()]}} | + {:error, [Error.t()]} + def query(options \\ []) do + Rest.get_list( + resource(), + options + ) + end + + @doc """ + Same as query(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec page!( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + design_ids: [binary], + embosser_ids: [binary], + ids: [binary], + expand: [binary], + user: Organization.t() | Project.t() | nil + ) :: any + def query!(options \\ []) do + Rest.get_list!( + resource(), + options + ) + end + + @doc """ + Receive a list of up to 100 IssuingStock objects previously created in the Stark Infra API and the cursor to the next page. + Use this function instead of query if you want to manually page your requests. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:design_ids` [list of binaries, default []]: list of stock_ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:embosser_id` [list of binaries, default []]: filter for status of retrieved objects. ex: ["created", "processing", "confirmed"] + - `:ids` [list of binaries, default []]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:expand` [list of binaries, default nil]: fields to expand information. ex: ["balance"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of IssuingStock objects with updated attributes + - cursor to retrieve the next page of IssuingStock objects + """ + @spec page( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + design_ids: [binary], + embosser_ids: [binary], + ids: [binary], + expand: [binary], + user: Organization.t() | Project.t() | nil + ) :: + {:ok, {binary, [IssuingStock.t()]}} | + {:error, [Error.t()]} + def page(options \\ []) do + Rest.get_page( + resource(), + options + ) + end + + @doc """ + Same as page(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec page!( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + status: [binary], + stock_ids: [binary], + tags: [binary], + ids: [binary], + user: Organization.t() | Project.t() | nil + ) :: any + def page!(options \\ []) do + Rest.get_page!( + resource(), + options + ) + end + + @spec resource :: + {<<_::120>>, (nil | maybe_improper_list | map -> StarkInfra.IssuingStock.t())} + @doc false + def resource() do + { + "IssuingStock", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %IssuingStock{ + id: json[:id], + balance: json[:balance], + design_id: json[:design_id], + embosser_id: json[:embosser_id], + created: json[:created], + updated: json[:updated] + } + end +end diff --git a/lib/issuing_stock/issuing_stock_log.ex b/lib/issuing_stock/issuing_stock_log.ex new file mode 100644 index 0000000..81661cb --- /dev/null +++ b/lib/issuing_stock/issuing_stock_log.ex @@ -0,0 +1,209 @@ +defmodule StarkInfra.IssuingStock.Log do + alias __MODULE__, as: Log + alias StarkInfra.Utils.Rest + alias StarkInfra.Utils.Check + alias StarkInfra.User.Project + alias StarkInfra.User.Organization + alias StarkInfra.Error + + @moduledoc """ + # IssuingStock.Log object + """ + + @doc """ + Every time an IssuingStock entity is updated, a corresponding IssuingStock.Log + is generated for the entity. This log is never generated by the + user, but it can be retrieved to check additional information + on the IssuingStock. + + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the log is created. ex: "5656565656565656" + - `:stock` [IssuingStock]: IssuingStock entity to which the log refers to. + - `:type` [IssuingStock]: type of the IssuingStock event which triggered the log creation. ex: "created", "spent", "restocked", "lost" + - `:count` [binary]: shift in stock balance. ex: 10 + - `:created` [DateTime]: creation datetime for the log. ex: ~U[2020-03-10 10:30:0:0] + """ + @enforce_keys [ + :id, + :stock, + :type, + :count, + :created + ] + defstruct [ + :id, + :stock, + :type, + :count, + :created + ] + + @type t() :: %__MODULE__{} + + @doc """ + Receive a single IssuingStock.Log object previously created by the Stark Infra API by its id + + ## Parameters (required): + - `:id` [binary]: object unique id. ex: "5656565656565656" + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - IssuingStock.Log object that corresponds to the given id. + """ + @spec get( + id: binary, + user: Project.t() | Organization.t() | nil + ) :: + {:ok, Log.t() } | + { :error, [Error.t()] } + def get(id, options \\ []) do + Rest.get_id( + resource(), + id, + options + ) + end + + @doc """ + Same as get(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec get!( + id: binary, + user: Project.t() | Organization.t() | nil + ) :: any + def get!(id, options \\ []) do + Rest.get_id!( + resource(), + id, + options + ) + end + + @doc """ + Receive a stream of IssuingStock.Log objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:types` [list of binaries, default nil]: filter for log event types. ex: ["created", "spent", "restocked", "lost"] + - `:stock_ids` [list of binaries, default nil]: list of IssuingStock ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: list of IssuingStock ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - stream of IssuingStock.Log objects with updated attributes + """ + @spec query( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + stock_ids: [binary], + ids: [binary], + user: Project.t() | Organization.t() | nil + ) :: + {:ok, {binary, [Log.t()]} } | + { :error, [Error.t()] } + def query(options \\ []) do + Rest.get_list( + resource(), + options + ) + end + + @doc """ + Same as query(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec query!( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + stock_ids: [binary], + ids: [binary], + user: Project.t() | Organization.t() | nil + ) :: any + def query!(options \\ []) do + Rest.get_list!( + resource(), + options + ) + end + + @doc """ + Receive a list of up to 100 IssuingStock.Log objects previously created in the Stark Infra API and the cursor to the next page. + Use this function instead of query if you want to manually page your requests. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:types` [list of binaries, default nil]: filter for log event types. ex: ["created", "spent", "restocked", "lost"] + - `:stock_ids` [list of binaries, default nil]: list of IssuingStock ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: list of IssuingStock ids to filter logs. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of IssuingStock.Log objects with updated attributes + - cursor to retrieve the next page of IssuingStock.Log objects + """ + @spec page( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + stock_ids: [binary], + ids: [binary], + user: Project.t() | Organization.t() | nil + ) :: {:ok, {binary, [Log.t()]} } | { :error, [Error.t()] } + def page(options \\ []) do + Rest.get_page( + resource(), + options + ) + end + + @doc """ + Same as page(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec page!( + cursor: binary, + ids: [binary], + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + types: [binary], + stock_ids: [binary], + user: Project.t() | Organization.t() | nil + ) :: any + def page!(options \\ []) do + Rest.get_page!( + resource(), + options + ) + end + + @doc false + def resource() do + { + "IssuingStockLog", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %Log{ + id: json[:id], + stock: json[:stock], + type: json[:type], + count: json[:count], + created: json[:created] |> Check.datetime(), + } + end +end diff --git a/lib/issuing_transaction/issuing_transaction.ex b/lib/issuing_transaction/issuing_transaction.ex index 491e8e5..1d1e0bc 100644 --- a/lib/issuing_transaction/issuing_transaction.ex +++ b/lib/issuing_transaction/issuing_transaction.ex @@ -7,53 +7,53 @@ defmodule StarkInfra.IssuingTransaction do alias StarkInfra.Error @moduledoc """ - # IssuingTransaction struct + # IssuingTransaction object """ @doc """ - The IssuingTransaction structs created in your Workspace to represent each balance shift. + The IssuingTransaction objects created in your Workspace to represent each balance shift. ## Attributes (return-only): - - `:id` [string]: unique id returned when IssuingTransaction is created. ex: "5656565656565656" + - `:id` [binary]: unique id returned when IssuingTransaction is created. ex: "5656565656565656" - `:amount` [integer]: IssuingTransaction value in cents. ex: 1234 (= R$ 12.34) - `:balance` [integer]: balance amount of the Workspace at the instant of the Transaction in cents. ex: 200 (= R$ 2.00) - - `:description` [string]: IssuingTransaction description. ex: "Buying food" - - `:source` [string]: source of the transaction. ex: "issuing-purchase/5656565656565656" - - `:tags` [string]: list of strings inherited from the source resource. ex: ["tony", "stark"] + - `:description` [binary]: IssuingTransaction description. ex: "Buying food" + - `:source` [binary]: source of the transaction. ex: "issuing-purchase/5656565656565656" + - `:tags` [list of binaries]: list of binaries inherited from the source resource. ex: ["tony", "stark"] - `:created` [DateTime]: creation datetime for the IssuingTransaction. ex: ~U[2020-03-10 10:30:0:0] """ @enforce_keys [ + :id, :amount, - :description, :balance, + :description, :source, :tags, - :id, :created ] defstruct [ + :id, :amount, - :description, :balance, + :description, :source, :tags, - :id, :created ] @type t() :: %__MODULE__{} @doc """ - Receive a single IssuingTransaction struct previously created in the Stark Infra API by its id + Receive a single IssuingTransaction object previously created in the Stark Infra API by its id - ## Options: - - `:id` [string]: struct unique id. ex: "5656565656565656" + ## Parameters (optional): + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - IssuingTransaction struct with updated attributes + - IssuingTransaction object that corresponds to the given id. """ @spec get( id: binary, @@ -85,29 +85,29 @@ defmodule StarkInfra.IssuingTransaction do end @doc """ - Receive a stream of IssuingTransaction structs previously created in the Stark Infra API - - ## Options: - - `:tags` [list of strings, default nil]: tags to filter retrieved structs. ex: ["tony", "stark"] - - `:external_ids` [list of strings, default []]: external IDs. ex: ["5656565656565656", "4545454545454545"] - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:status` [string, default nil]: filter for status of retrieved structs. ex: "approved", "canceled", "denied", "confirmed" or "voided" - - `:ids` [list of strings, default [], default nil]: purchase IDs - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + Receive a stream of IssuingTransaction objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:tags` [list of binaries, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:external_ids` [list of binaries, default []]: external IDs. ex: ["5656565656565656", "4545454545454545"] + - `:status` [binary, default nil]: filter for status of retrieved objects. ex: "approved", "canceled", "denied", "confirmed" or "voided" + - `:ids` [list of binaries, default [], default nil]: purchase IDs + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of IssuingTransaction structs with updated attributes + - stream of IssuingTransaction objects with updated attributes """ @spec query( - tags: [binary] | nil, - external_ids: [binary] | nil, + limit: integer | nil, after: Date.t() | binary | nil, before: Date.t() | binary | nil, + tags: [binary] | nil, + external_ids: [binary] | nil, status: binary | nil, ids: [binary] | nil, - limit: integer | nil, user: Organization.t() | Project.t() | nil ) :: {:ok, {binary, [IssuingTransaction.t()]}} | @@ -123,13 +123,13 @@ defmodule StarkInfra.IssuingTransaction do Same as query(), but it will unwrap the error tuple and raise in case of errors. """ @spec query!( - tags: [binary] | nil, - external_ids: [binary] | nil, + limit: integer | nil, after: Date.t() | binary | nil, before: Date.t() | binary | nil, + tags: [binary] | nil, + external_ids: [binary] | nil, status: binary | nil, ids: [binary] | nil, - limit: integer | nil, user: Organization.t() | Project.t() | nil ) :: any def query!(options \\ []) do @@ -140,32 +140,32 @@ defmodule StarkInfra.IssuingTransaction do end @doc """ - Receive a list of IssuingTransaction structs previously created in the Stark Infra API and the cursor to the next page. - - ## Options: - - `:tags` [list of strings, default nil]: tags to filter retrieved structs. ex: ["tony", "stark"] - - `:external_ids` [list of strings, default []]: external IDs. ex: ["5656565656565656", "4545454545454545"] - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:status` [string, default nil]: filter for status of retrieved structs. ex: "approved", "canceled", "denied", "confirmed" or "voided" - - `:ids` [list of strings, default [], default nil]: purchase IDs - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + Receive a list of IssuingTransaction objects previously created in the Stark Infra API and the cursor to the next page. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:tags` [list of binaries, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:external_ids` [list of binaries, default []]: external IDs. ex: ["5656565656565656", "4545454545454545"] + - `:status` [binary, default nil]: filter for status of retrieved objects. ex: "approved", "canceled", "denied", "confirmed" or "voided" + - `:ids` [list of binaries, default [], default nil]: purchase IDs + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of IssuingTransaction structs with updated attributes - - cursor to retrieve the next page of IssuingPurchase structs + - list of IssuingTransaction objects with updated attributes + - cursor to retrieve the next page of IssuingPurchase objects """ @spec page( - tags: [binary] | nil, - external_ids: [binary] | nil, + cursor: binary | nil, + limit: integer | nil, after: Date.t() | binary | nil, before: Date.t() | binary | nil, + tags: [binary] | nil, + external_ids: [binary] | nil, status: binary | nil, ids: [binary] | nil, - limit: integer | nil, - cursor: binary | nil, user: Organization.t() | Project.t() | nil ) :: {:ok, {binary, [IssuingTransaction.t()]}} | @@ -181,14 +181,14 @@ defmodule StarkInfra.IssuingTransaction do Same as page(), but it will unwrap the error tuple and raise in case of errors. """ @spec page!( - tags: [binary] | nil, - external_ids: [binary] | nil, + cursor: binary | nil, + limit: integer | nil, after: Date.t() | binary | nil, before: Date.t() | binary | nil, + tags: [binary] | nil, + external_ids: [binary] | nil, status: binary | nil, ids: [binary] | nil, - limit: integer | nil, - cursor: binary | nil, user: Organization.t() | Project.t() | nil ) :: any def page!(options \\ []) do @@ -210,11 +210,11 @@ defmodule StarkInfra.IssuingTransaction do def resource_maker(json) do %IssuingTransaction{ id: json[:id], - tags: json[:tags], amount: json[:amount], - source: json[:source], balance: json[:balance], description: json[:description], + source: json[:source], + tags: json[:tags], created: json[:created] |> Check.datetime() } end diff --git a/lib/issuing_withdrawal/issuing_withdrawal.ex b/lib/issuing_withdrawal/issuing_withdrawal.ex index 256a807..0acdb96 100644 --- a/lib/issuing_withdrawal/issuing_withdrawal.ex +++ b/lib/issuing_withdrawal/issuing_withdrawal.ex @@ -7,24 +7,24 @@ defmodule StarkInfra.IssuingWithdrawal do alias StarkInfra.User.Organization @moduledoc """ - # IssuingWithdrawal struct + # IssuingWithdrawal object """ @doc """ - The IssuingWithdrawal structs created in your Workspace return cash from your Issuing balance to your Banking balance. + The IssuingWithdrawal objects created in your Workspace return cash from your Issuing balance to your Banking balance. ## Parameters (required): - `:amount` [integer]: IssuingWithdrawal value in cents. Minimum = 0 (any value will be accepted). ex: 1234 (= R$ 12.34) - - `:external_id` [string] IssuingWithdrawal external ID. ex: "12345" - - `:description` [string]: IssuingWithdrawal description. ex: "sending money back" + - `:external_id` [binary] IssuingWithdrawal external ID. ex: "12345" + - `:description` [binary]: IssuingWithdrawal description. ex: "sending money back" ## Parameters (optional): - - `:tags` [list of strings, default []]: list of strings for tagging. ex: ["tony", "stark"] + - `:tags` [list of binaries, default []]: list of binaries for tagging. ex: ["tony", "stark"] ## Attributes (return-only): - - `:id` [string]: unique id returned when IssuingWithdrawal is created. ex: "5656565656565656" - - `:transaction_id` [string]: Stark Infra ledger transaction ids linked to this IssuingWithdrawal - - `:issuing_transaction_id` [string]: issuing ledger transaction ids linked to this IssuingWithdrawal + - `:id` [binary]: unique id returned when IssuingWithdrawal is created. ex: "5656565656565656" + - `:transaction_id` [binary]: Stark Infra ledger transaction ids linked to this IssuingWithdrawal + - `:issuing_transaction_id` [binary]: issuing ledger transaction ids linked to this IssuingWithdrawal - `:updated` [DateTime]: latest update DateTime for the IssuingWithdrawal. ex: ~U[2020-3-10 10:30:0:0] - `:created` [DateTime]: creation datetime for the IssuingWithdrawal. ex: ~U[2020-03-10 10:30:0:0] """ @@ -48,16 +48,16 @@ defmodule StarkInfra.IssuingWithdrawal do @type t() :: %__MODULE__{} @doc """ - Send a list of IssuingWithdrawal structs for creation in the Stark Infra API + Send a list of IssuingWithdrawal objects for creation in the Stark Infra API ## Parameters (required): - - `:withdrawal` [IssuingWithdrawal struct]: IssuingWithdrawal struct to be created in the API. + - `:withdrawal` [IssuingWithdrawal object]: IssuingWithdrawal object to be created in the API. - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - IssuingWithdrawal struct with updated attributes + - IssuingWithdrawal object with updated attributes """ @spec create( withdrawal: IssuingWithdrawal.t(), @@ -89,16 +89,16 @@ defmodule StarkInfra.IssuingWithdrawal do end @doc """ - Receive a single IssuingWithdrawal struct previously created in the Stark Infra API by its id + Receive a single IssuingWithdrawal object previously created in the Stark Infra API by its id ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - IssuingWithdrawal struct with updated attributes + - IssuingWithdrawal object that corresponds to the given id. """ @spec get( id: binary, @@ -130,25 +130,25 @@ defmodule StarkInfra.IssuingWithdrawal do end @doc """ - Receive a stream of IssuingWithdrawal structs previously created in the Stark Infra API + Receive a stream of IssuingWithdrawal objects previously created in the Stark Infra API - ## Options: - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:external_ids` [list of strings, default []]: external IDs. ex: ["5656565656565656", "4545454545454545"] - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:tags` [list of strings, default nil]: tags to filter retrieved structs. ex: ["tony", "stark"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:tags` [list of binaries, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:external_ids` [list of binaries, default []]: external IDs. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of IssuingWithdrawals structs with updated attributes + - stream of IssuingWithdrawal objects with updated attributes """ @spec query( limit: integer, - external_ids: [binary] | [], after: Date.t() | binary, before: Date.t() | binary, tags: [binary], + external_ids: [binary] | [], user: (Organization.t() | Project.t()) | nil ) :: {:ok, [IssuingWithdrawal.t()]} | @@ -165,10 +165,10 @@ defmodule StarkInfra.IssuingWithdrawal do """ @spec query!( limit: integer, - external_ids: [binary] | [], after: Date.t() | binary, before: Date.t() | binary, tags: [binary], + external_ids: [binary] | [], user: (Organization.t() | Project.t()) | nil ) :: any def query!(options \\ []) do @@ -179,25 +179,28 @@ defmodule StarkInfra.IssuingWithdrawal do end @doc """ - Receive a list of IssuingWithdrawal structs previously created in the Stark Infra API and the cursor to the next page. + Receive a list of up to 100 IssuingWithdrawal objects previously created in the Stark Infra API and the cursor to the next page. + Use this function instead of query if you want to manually page your requests. - ## Options: - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:external_ids` [list of strings, default []]: external IDs. ex: ["5656565656565656", "4545454545454545"] - - `:after` [Date or string, default nil]: date filter for structs created only after specified date. ex: ~D[2020-03-25] - - `:before` [Date or string, default nil]: date filter for structs created only before specified date. ex: ~D[2020-03-25] - - `:tags` [list of strings, default nil]: tags to filter retrieved structs. ex: ["tony", "stark"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020-03-25] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020-03-25] + - `:external_ids` [list of binaries, default []]: external IDs. ex: ["5656565656565656", "4545454545454545"] + - `:tags` [list of binaries, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of IssuingWithdrawal structs with updated attributes - - cursor to retrieve the next page of IssuingWithdrawal structs + - list of IssuingWithdrawal objects with updated attributes + - cursor to retrieve the next page of IssuingWithdrawal objects """ @spec page( + cursor: binary(), limit: integer, - external_ids: [binary] | [], after: Date.t() | binary, before: Date.t() | binary, + external_ids: [binary] | [], tags: [binary], user: (Organization.t() | Project.t()) | nil ) :: @@ -214,10 +217,11 @@ defmodule StarkInfra.IssuingWithdrawal do Same as page(), but it will unwrap the error tuple and raise in case of errors. """ @spec page!( + cursor: binary(), limit: integer, - external_ids: [binary] | [], after: Date.t() | binary, before: Date.t() | binary, + external_ids: [binary] | [], tags: [binary], user: (Organization.t() | Project.t()) | nil ) :: any diff --git a/lib/key.ex b/lib/key.ex index 44a0703..aed488c 100644 --- a/lib/key.ex +++ b/lib/key.ex @@ -10,7 +10,7 @@ defmodule StarkInfra.Key do Generates a secp256k1 ECDSA private/public key pair to be used in the API authentications ## Parameters (optional): - - `path` [string, default nil]: path to save the keys .pem files. No files will be saved if this parameter isn't provided. + - `path` [binary, default nil]: path to save the keys .pem files. No files will be saved if this parameter isn't provided. """ @spec create(any) :: {binary, binary} def create(path \\ nil) do diff --git a/lib/merchant_category/merchant_category.ex b/lib/merchant_category/merchant_category.ex new file mode 100644 index 0000000..f154328 --- /dev/null +++ b/lib/merchant_category/merchant_category.ex @@ -0,0 +1,93 @@ +defmodule StarkInfra.MerchantCategory do + alias __MODULE__, as: MerchantCategory + alias StarkInfra.Error + alias StarkInfra.Utils.Rest + alias StarkInfra.User.Project + alias StarkInfra.User.Organization + + @moduledoc """ + Groups MerchantCategory related functions + """ + + @doc """ + MerchantCategory's codes and types are used to define categories filters in IssuingRules. + A MerchantCategory filter must define exactly one parameter between code and type. + A type, such as "food", "services", etc., defines an entire group of merchant codes, + whereas a code only specifies a specific MCC. + + ## Parameters (conditionally required): + - `:code` [binary, default nil]: category's code. ex: "veterinaryServices", "fastFoodRestaurants" + - `:type` [binary, default nil]: category's type. ex: "pets", "food" + + ## Attributes (return-only): + - `:name` [binary]: category's name. ex: "Veterinary services", "Fast food restaurants" + - `:number` [binary]: category's number. ex: "742", "5814" + """ + @enforce_keys [ + :code, + :type + ] + defstruct [ + :code, + :type, + :name, + :number + ] + + @type t() :: %__MODULE__{} + + @doc """ + Receive a stream of MerchantCategory objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:search` [binary, default nil]: keyword to search for code, type, name or number + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - stream of MerchantCategory objects with updated attributes + """ + @spec query( + search: binary, + user: (Organization.t() | Project.t()) | nil + ) :: + {:ok, [MerchantCategory.t()]} | + {:error, [Error.t()]} + def query(options \\ []) do + Rest.get_list( + resource(), + options + ) + end + + @doc """ + Same as query(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec query!( + search: binary, + user: (Organization.t() | Project.t()) | nil + ) :: any + def query!(options \\ []) do + Rest.get_list!( + resource(), + options + ) + end + + @doc false + def resource() do + { + "MerchantCategory", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %MerchantCategory{ + code: json[:code], + type: json[:type], + name: json[:name], + number: json[:number] + } + end +end diff --git a/lib/merchant_country/merchant_country.ex b/lib/merchant_country/merchant_country.ex new file mode 100644 index 0000000..0b043fc --- /dev/null +++ b/lib/merchant_country/merchant_country.ex @@ -0,0 +1,89 @@ +defmodule StarkInfra.MerchantCountry do + alias __MODULE__, as: MerchantCountry + alias StarkInfra.Error + alias StarkInfra.Utils.Rest + alias StarkInfra.User.Project + alias StarkInfra.User.Organization + + @moduledoc """ + Groups MerchantCountry related functions + """ + + @doc """ + MerchantCountry's codes are used to define country filters in IssuingRules. + + ## Parameters (required): + - `:code` [binary]: country's code. ex: "BRA" + + ## Attributes (return-only): + - `:name` [binary]: country's name. ex: "Brazil" + - `:number` [binary]: country's number. ex: "076" + - `:short_code` [binary]: country's short code. ex: "BR" + """ + @enforce_keys [ + :code + ] + defstruct [ + :code, + :name, + :number, + :short_code, + ] + + @type t() :: %__MODULE__{} + + @doc """ + Receive a stream of MerchantCountry objects available in the Stark Infra API + + ## Parameters (optional): + - `:search` [binary, default nil]: keyword to search for code, name, number or short_code + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - stream of MerchantCountry objects with updated attributes + """ + @spec query( + search: binary, + user: (Organization.t() | Project.t()) | nil + ) :: + {:ok, [MerchantCountry.t()]} | + {:error, [Error.t()]} + def query(options \\ []) do + Rest.get_list( + resource(), + options + ) + end + + @doc """ + Same as query(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec query!( + search: binary, + user: (Organization.t() | Project.t()) | nil + ) :: any + def query!(options \\ []) do + Rest.get_list!( + resource(), + options + ) + end + + @doc false + def resource() do + { + "MerchantCountry", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %MerchantCountry{ + code: json[:code], + name: json[:name], + number: json[:number], + short_code: json[:short_code], + } + end +end diff --git a/lib/pix_balance/pix_balance.ex b/lib/pix_balance/pix_balance.ex index 6dd023a..ed54afa 100644 --- a/lib/pix_balance/pix_balance.ex +++ b/lib/pix_balance/pix_balance.ex @@ -11,15 +11,15 @@ defmodule StarkInfra.PixBalance do """ @doc """ - The PixBalance struct displays the current balance of the Workspace, which + The PixBalance object displays the current balance of the Workspace, which is the result of the sum of all transactions within this Workspace. The balance is never generated by the user, but it can be retrieved to see the available information. ## Attributes (return-only): - - `:id` [string]: unique id returned when Balance is created. ex: "5656565656565656" + - `:id` [binary]: unique id returned when Balance is created. ex: "5656565656565656" - `:amount` [integer]: current balance amount of the Workspace in cents. ex: 200 (= R$ 2.00) - - `:currency` [string]: currency of the current Workspace. Expect others to be added eventually. ex: "BRL" + - `:currency` [binary]: currency of the current Workspace. Expect others to be added eventually. ex: "BRL" - `:updated` [DateTime]: latest update DateTime for the PixBalance. ex: ~U[2020-3-10 10:30:0:0] """ defstruct [:id, :amount, :currency, :updated] @@ -27,13 +27,13 @@ defmodule StarkInfra.PixBalance do @type t() :: %__MODULE__{} @doc """ - Receive the PixBalance struct linked to your Workspace in the Stark Infra API + Receive the PixBalance object linked to your Workspace in the Stark Infra API - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of PixBalance struct with updated attributes + - list of PixBalance object that corresponds to the given id. """ @spec get( user: Project.t() | Organization.t() | nil diff --git a/lib/pix_chargeback/pix_chargeback.ex b/lib/pix_chargeback/pix_chargeback.ex index ce57942..aff7705 100644 --- a/lib/pix_chargeback/pix_chargeback.ex +++ b/lib/pix_chargeback/pix_chargeback.ex @@ -14,28 +14,30 @@ defmodule StarkInfra.PixChargeback do A Pix chargeback can be created when fraud is detected on a transaction or a system malfunction results in an erroneous transaction. It notifies another participant of your request to reverse the payment they have received. + When you initialize a PixChargeback, the entity will not be automatically created in the Stark Infra API. The 'create' function sends the objects - to the Stark Infra API and returns the created struct. + to the Stark Infra API and returns the created object. ## Parameters (required): - `:amount` [integer]: amount in cents to be reversed. ex: 11234 (= R$ 112.34) - - `:reference_id` [string]: end_to_end_id or return_id of the transaction to be reversed. ex: "E20018183202201201450u34sDGd19lz" - - `:reason` [string]: reason why the reversal was requested. Options: "fraud", "flaw", "reversalChargeback" + - `:reference_id` [binary]: end_to_end_id or return_id of the transaction to be reversed. ex: "E20018183202201201450u34sDGd19lz" + - `:reason` [binary]: reason why the reversal was requested. Options: "fraud", "flaw", "reversalChargeback" ## Parameters (optional): - - `:description` [string, default nil]: description for the PixChargeback. + - `:description` [binary, default nil]: description for the PixChargeback. + - `:tags` [list of binaries, default []]: list of binaries for tagging. ex: ["travel", "food"] ## Attributes (return-only): - - `:id` [string]: unique id returned when the PixChargeback is created. ex: "5656565656565656" - - `:analysis` [string]: analysis that led to the result. - - `:bacen_id` [string]: central bank's unique UUID that identifies the PixChargeback. - - `:sender_bank_code` [string]: bank_code of the Pix participant that created the PixChargeback. ex: "20018183" - - `:receiver_bank_code` [string]: bank_code of the Pix participant that received the PixChargeback. ex: "20018183" - - `:rejection_reason` [string]: reason for the rejection of the Pix chargeback. Options: "noBalance", "accountClosed", "unableToReverse" - - `:reversal_reference_id` [string]: return id of the reversal transaction. ex: "D20018183202202030109X3OoBHG74wo". - - `:result` [string]: result after the analysis of the PixChargeback by the receiving party. Options: "rejected", "accepted", "partiallyAccepted" - - `:status` [string]: current PixChargeback status. Options: "created", "failed", "delivered", "closed", "canceled". + - `:id` [binary]: unique id returned when the PixChargeback is created. ex: "5656565656565656" + - `:analysis` [binary]: analysis that led to the result. + - `:sender_bank_code` [binary]: bank_code of the Pix participant that created the PixChargeback. ex: "20018183" + - `:receiver_bank_code` [binary]: bank_code of the Pix participant that received the PixChargeback. ex: "20018183" + - `:rejection_reason` [binary]: reason for the rejection of the Pix chargeback. ex: "noBalance", "accountClosed", "unableToReverse" + - `:reversal_reference_id` [binary]: return id of the reversal transaction. ex: "D20018183202202030109X3OoBHG74wo". + - `:result` [binary]: result after the analysis of the PixChargeback by the receiving party. ex: "rejected", "accepted", "partiallyAccepted" + - `:flow` [binary]: direction of the Pix Chargeback. ex: "in" for received chargebacks, "out" for chargebacks you requested + - `:status` [binary]: current PixChargeback status. ex: "created", "failed", "delivered", "closed", "canceled". - `:created` [DateTime]: creation datetime for the PixChargeback. ex: ~U[2020-3-10 10:30:0:0] - `:updated` [DateTime]: latest update datetime for the PixChargeback. ex: ~U[2020-3-10 10:30:0:0] """ @@ -49,14 +51,15 @@ defmodule StarkInfra.PixChargeback do :reference_id, :reason, :description, + :tags, :id, :analysis, - :bacen_id, :sender_bank_code, :receiver_bank_code, :rejection_reason, :reversal_reference_id, :result, + :flow, :status, :created, :updated @@ -68,13 +71,13 @@ defmodule StarkInfra.PixChargeback do Create a PixChargeback in the Stark Infra API ## Parameters (required): - - `:chargebacks` [list of PixChargeback]: list of PixChargeback structs to be created in the API. + - `:chargebacks` [list of PixChargeback objects]: list of PixChargeback objects to be created in the API. - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of PixChargeback structs with updated attributes + - list of PixChargeback objects with updated attributes """ @spec create( chargebacks: [PixChargeback.t() | map()], @@ -106,16 +109,16 @@ defmodule StarkInfra.PixChargeback do end @doc """ - Retrieve the PixChargeback struct linked to your Workspace in the Stark Infra API using its id. + Retrieve the PixChargeback object linked to your Workspace in the Stark Infra API using its id. ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656". + - `:id` [binary]: object unique id. ex: "5656565656565656". - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - PixChargeback struct that corresponds to the given id. + - PixChargeback object that corresponds to the given id. """ @spec get( id: binary, @@ -147,18 +150,20 @@ defmodule StarkInfra.PixChargeback do end @doc """ - Receive a stream of PixChargebacks structs previously created in the Stark Infra API + Receive a stream of PixChargeback objects previously created in the Stark Infra API - ## Options: - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after a specified date. ex: ~D[2020-03-10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020-03-10] - - `:status` [list of strings, default nil]: filter for status of retrieved objects. ex: ["created", "failed", "delivered", "closed", "canceled"] - - `:ids` [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created after a specified date. ex: ~D[2020-03-10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020-03-10] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. ex: ["created", "failed", "delivered", "closed", "canceled"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:flow` [binary, default nil]: direction of the Pix Chargeback. ex: "in" for received chargebacks, "out" for chargebacks you requested + - `:tags` [list of binaries, default nil]: filter for tags of retrieved objects. ex: ["travel", "food"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of PixChargeback structs with updated attributes + - stream of PixChargeback objects with updated attributes """ @spec query( limit: integer, @@ -166,6 +171,8 @@ defmodule StarkInfra.PixChargeback do before: Date.t() | binary, status: [binary], ids: [binary], + flow: binary, + tags: [binary], user: Organization.t() | Project.t() | nil ) :: {:ok, [PixChargeback.t()]} | @@ -186,6 +193,8 @@ defmodule StarkInfra.PixChargeback do before: Date.t() | binary, status: [binary], ids: [binary], + flow: binary, + tags: [binary], user: Organization.t() | Project.t() | nil ) :: any def query!(options \\ []) do @@ -196,19 +205,22 @@ defmodule StarkInfra.PixChargeback do end @doc """ - Receive a stream of PixChargebacks structs previously created in the Stark Infra API + Receive a list of up to 100 PixChargeback objects previously created in the Stark Infra API and the cursor to the next page. + Use this function instead of query if you want to manually page your requests. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call. - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Max = 100. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after a specified date. ex: ~D[2020-03-10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020-03-10] - - `:status` [list of strings, default nil]: filter for status of retrieved objects. ex: ["created", "failed", "delivered", "closed", "canceled"] - - `:ids` [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call. + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created after a specified date. ex: ~D[2020-03-10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020-03-10] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. ex: ["created", "failed", "delivered", "closed", "canceled"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:flow` [binary, default nil]: direction of the Pix Chargeback. ex: "in" for received chargebacks, "out" for chargebacks you requested + - `:tags` [list of binaries, default nil]: filter for tags of retrieved objects. ex: ["travel", "food"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of PixChargeback structs with updated attributes + - list of PixChargeback objects with updated attributes - cursor to retrieve the next page of PixChargeback objects """ @spec page( @@ -218,6 +230,8 @@ defmodule StarkInfra.PixChargeback do before: Date.t() | binary, status: [binary], ids: [binary], + flow: binary, + tags: [binary], user: Organization.t() | Project.t() | nil ) :: {:ok, {binary, [PixChargeback.t()]}} | @@ -239,6 +253,8 @@ defmodule StarkInfra.PixChargeback do before: Date.t() | binary, status: [binary], ids: [binary], + flow: binary, + tags: [binary], user: Organization.t() | Project.t() | nil ) :: any def page!(options \\ []) do @@ -252,22 +268,22 @@ defmodule StarkInfra.PixChargeback do Respond to a received PixChargeback. ## Parameters (required): - - `:id` [string]: PixChargeback id. ex: '5656565656565656' - - `:result` [string]: result after the analysis of the PixChargeback. Options: "rejected", "accepted", "partiallyAccepted". + - `:id` [binary]: PixChargeback id. ex: '5656565656565656' + - `:result` [binary]: result after the analysis of the PixChargeback. ex: "rejected", "accepted", "partiallyAccepted". ## Parameters (conditionally required): - - `rejection_reason` [string, default nil]: if the PixChargeback is rejected a reason is required. Options: "noBalance", "accountClosed", "unableToReverse", - - `reversal_reference_id` [string, default nil]: return_id of the reversal transaction. ex: "D20018183202201201450u34sDGd19lz" + - `:rejection_reason` [binary, default nil]: if the PixChargeback is rejected a reason is required. ex: "noBalance", "accountClosed", "unableToReverse", + - `:reversal_reference_id` [binary, default nil]: return_id of the reversal transaction. ex: "D20018183202201201450u34sDGd19lz" ## Parameters (optional): - - `analysis` [string, default nil]: description of the analysis that led to the result. - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + - `:analysis` [binary, default nil]: description of the analysis that led to the result. + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - PixChargeback with updated attributes + - PixChargeback object with updated attributes """ @spec update( - binary, + id: binary, result: binary, rejection_reason: binary, reversal_reference_id: binary, @@ -289,7 +305,7 @@ defmodule StarkInfra.PixChargeback do Same as update(), but it will unwrap the error tuple and raise in case of errors. """ @spec update!( - binary, + id: binary, result: binary, rejection_reason: binary, reversal_reference_id: binary, @@ -309,13 +325,13 @@ defmodule StarkInfra.PixChargeback do Cancel a PixChargeback entity previously created in the Stark Infra API ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - canceled PixChargeback struct + - canceled PixChargeback object """ @spec cancel( id: binary, @@ -357,18 +373,19 @@ defmodule StarkInfra.PixChargeback do @doc false def resource_maker(json) do %PixChargeback{ + id: json[:id], amount: json[:amount], reference_id: json[:reference_id], reason: json[:reason], description: json[:description], + tags: json[:tags], analysis: json[:analysis], - bacen_id: json[:bacen_id], sender_bank_code: json[:sender_bank_code], receiver_bank_code: json[:receiver_bank_code], rejection_reason: json[:rejection_reason], reversal_reference_id: json[:reversal_reference_id], - id: json[:id], result: json[:result], + flow: json[:flow], status: json[:status], created: json[:created] |> Check.datetime(), updated: json[:updated] |> Check.datetime(), diff --git a/lib/pix_chargeback/pix_chargeback_log.ex b/lib/pix_chargeback/pix_chargeback_log.ex index 1f11752..ea2fbb8 100644 --- a/lib/pix_chargeback/pix_chargeback_log.ex +++ b/lib/pix_chargeback/pix_chargeback_log.ex @@ -15,11 +15,11 @@ defmodule StarkInfra.PixChargeback.Log do Every time a PixChargeback entity is modified, a corresponding PixChargeback.Log is generated for the entity. This log is never generated by the user. - ## Attributes: - - `:id` [string]: unique id returned when the log is created. ex: "5656565656565656" - - `:type` [string]: type of the PixChargeback event which triggered the log creation. ex: "created", "failed", "delivering", "delivered", "closed", "canceled" - - `:errors` [list of strings]: list of errors linked to this PixChargeback event + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the log is created. ex: "5656565656565656" - `:chargeback` [PixChargeback]: PixChargeback entity to which the log refers to. + - `:type` [binary]: type of the PixChargeback event which triggered the log creation. ex: "created", "failed", "delivering", "delivered", "closed", "canceled" + - `:errors` [list of binaries]: list of errors linked to this PixChargeback event - `:created` [DateTime]: creation datetime for the log. ex: ~U[2020-3-10 10:30:0:0] """ @enforce_keys [ @@ -40,16 +40,16 @@ defmodule StarkInfra.PixChargeback.Log do @type t() :: %__MODULE__{} @doc """ - Receive a single PixChargeback.Log struct previously created by the Stark Infra API by its id + Receive a single PixChargeback.Log object previously created by the Stark Infra API by its id ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - PixChargeback.Log struct with updated attributes + - PixChargeback.Log object that corresponds to the given id. """ @spec get( id: binary, @@ -73,27 +73,27 @@ defmodule StarkInfra.PixChargeback.Log do end @doc """ - Receive a stream of PixChargeback.Log structs previously created in the Stark Infra API + Receive a stream of PixChargeback.Log objects previously created in the Stark Infra API - ## Options: - - `:ids` [list of strings, default nil]: Log ids to filter PixChargeback Logs. ex: ["5656565656565656"] - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after specified date. ex: ~D[2020-03-10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020-03-10] - - `:types` [list of strings, default nil]: filter retrieved structs by types. ex: ["created", "failed", "delivering", "delivered", "closed", "canceled"] - - `:chargeback_ids` [list of strings, default nil]: list of PixChargeback IDs to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created after specified date. ex: ~D[2020-03-10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020-03-10] + - `:types` [list of binaries, default nil]: filter retrieved objects by types. ex: ["created", "failed", "delivering", "delivered", "closed", "canceled"] + - `:chargeback_ids` [list of binaries, default nil]: list of PixChargeback IDs to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: Log ids to filter PixChargeback Logs. ex: ["5656565656565656"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of PixChargeback.Log structs with updated attributes + - stream of PixChargeback.Log objects with updated attributes """ @spec query( - ids: [binary] | nil, limit: integer | nil, after: Date.t() | binary | nil, before: Date.t() | binary | nil, types: [binary] | nil, chargeback_ids: [binary] | nil, + ids: [binary] | nil, user: Project.t() | Organization.t() | nil ) :: {:ok, [Log.t()]} | @@ -106,12 +106,12 @@ defmodule StarkInfra.PixChargeback.Log do Same as query(), but it will unwrap the error tuple and raise in case of errors. """ @spec query!( - ids: [binary] | nil, limit: integer | nil, after: Date.t() | binary | nil, before: Date.t() | binary | nil, types: [binary] | nil, chargeback_ids: [binary] | nil, + ids: [binary] | nil, user: Project.t() | Organization.t() | nil ) :: any def query!(options \\ []) do @@ -119,31 +119,31 @@ defmodule StarkInfra.PixChargeback.Log do end @doc """ - Receive a list of up to 100 PixChargeback.Log structs previously created in the Stark Infra API and the cursor to the next page. + Receive a list of up to 100 PixChargeback.Log objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your chargebacks. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:ids` [list of strings, default nil]: Log ids to filter PixChargeback Logs. ex: ["5656565656565656"] - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Max = 100. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after a specified date. ex: ~D[2020-03-10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020-03-10] - - `:types` [list of strings, default nil]: filter retrieved structs by types. ex: ["created", "failed", "delivering", "delivered", "closed", "canceled"] - - `:chargeback_ids` [list of strings, default nil]: list of PixChargeback IDs to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created after a specified date. ex: ~D[2020-03-10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020-03-10] + - `:types` [list of binaries, default nil]: filter retrieved objects by types. ex: ["created", "failed", "delivering", "delivered", "closed", "canceled"] + - `:chargeback_ids` [list of binaries, default nil]: list of PixChargeback IDs to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: Log ids to filter PixChargeback Logs. ex: ["5656565656565656"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of PixChargeback.Log structs with updated attributes + - list of PixChargeback.Log objects with updated attributes - cursor to retrieve the next page of PixChargeback.Log objects """ @spec page( cursor: binary | nil, - ids: [binary] | nil, limit: integer | nil, after: Date.t() | binary | nil, before: Date.t() | binary | nil, types: [binary] | nil, chargeback_ids: [binary] | nil, + ids: [binary] | nil, user: Project.t() | Organization.t() | nil ) :: {:ok, [Log.t()], binary} | @@ -181,9 +181,9 @@ defmodule StarkInfra.PixChargeback.Log do def resource_maker(json) do %Log{ id: json[:id], + chargeback: json[:chargeback] |> API.from_api_json(&PixChargeback.resource_maker/1), type: json[:type], errors: json[:errors], - chargeback: json[:chargeback] |> API.from_api_json(&PixChargeback.resource_maker/1), created: json[:created] |> Check.datetime(), } end diff --git a/lib/pix_claim/pix_claim.ex b/lib/pix_claim/pix_claim.ex index 61adc2f..9b976ae 100644 --- a/lib/pix_claim/pix_claim.ex +++ b/lib/pix_claim/pix_claim.ex @@ -12,27 +12,31 @@ defmodule StarkInfra.PixClaim do @doc """ PixClaims intend to transfer a PixKey from one account to another. + When you initialize a PixClaim, the entity will not be automatically - created in the Stark Infra API. The 'create' function sends the structs - to the Stark Infra API and returns the created struct. + created in the Stark Infra API. The 'create' function sends the objects + to the Stark Infra API and returns the created object. ## Parameters (required): - - `:account_created` [Date, DateTime or string]: opening Date or DateTime for the account claiming the PixKey. ex: "2022-01-01". - - `:account_number` [string]: number of the account claiming the PixKey. ex: "76543". - - `:account_type` [string]: type of the account claiming the PixKey. Options: "checking", "savings", "salary" or "payment". - - `:branch_code` [string]: branch code of the account claiming the PixKey. ex: 1234". - - `:name` [string]: holder's name of the account claiming the PixKey. ex: "Jamie Lannister". - - `:tax_id` [string]: holder's taxId of the account claiming the PixKey (CPF/CNPJ). ex: "012.345.678-90". - - `:key_id` [string]: id of the registered Pix Key to be claimed. Allowed keyTypes are CPF, CNPJ, phone number or email. ex: "+5511989898989". + - `:account_created` [Date, DateTime or binary]: opening Date or DateTime for the account claiming the PixKey. ex: "2022-01-01". + - `:account_number` [binary]: number of the account claiming the PixKey. ex: "76543". + - `:account_type` [binary]: type of the account claiming the PixKey. ex: "checking", "savings", "salary" or "payment". + - `:branch_code` [binary]: branch code of the account claiming the PixKey. ex: 1234". + - `:name` [binary]: holder's name of the account claiming the PixKey. ex: "Jamie Lannister". + - `:tax_id` [binary]: holder's taxId of the account claiming the PixKey (CPF/CNPJ). ex: "012.345.678-90". + - `:key_id` [binary]: id of the registered Pix Key to be claimed. Allowed keyTypes are CPF, CNPJ, phone number or email. ex: "+5511989898989". + + ## Parameters (optional): + - `:tags` [list of binaries, default []]: list of binaries for tagging. ex: ["travel", "food"] ## Attributes (return-only): - - `:id` [string]: unique id returned when the PixClaim is created. ex: "5656565656565656" - - `:status` [string]: current PixClaim status. Options: "created", "failed", "delivered", "confirmed", "success", "canceled" - - `:type` [string]: type of Pix Claim. Options: "ownership", "portability". - - `:key_type` [string]: keyType of the claimed PixKey. Options: "CPF", "CNPJ", "phone" or "email" - - `:agent` [string]: Options: "claimer" if you requested the PixClaim or "claimed" if you received a PixClaim request. - - `:bank_code` [string]: bank_code of the account linked to the PixKey being claimed. ex: "20018183". - - `:claimed_bank_code` [string]: bank_code of the account donating the PixKey. ex: "20018183". + - `:id` [binary]: unique id returned when the PixClaim is created. ex: "5656565656565656" + - `:status` [binary]: current PixClaim status. ex: "created", "failed", "delivered", "confirmed", "success", "canceled" + - `:type` [binary]: type of Pix Claim. ex: "ownership", "portability". + - `:key_type` [binary]: keyType of the claimed PixKey. ex: "CPF", "CNPJ", "phone" or "email" + - `:flow` [binary]: direction of the Pix Claim. ex: "in" if you received the PixClaim or "out" if you created the PixClaim. + - `:claimer_bank_code` [binary]: bank_code of the Pix participant that created the PixClaim. ex: "20018183" + - `:claimed_bank_code` [binary]: bank_code of the account donating the PixKey. ex: "20018183". - `:created` [DateTime]: creation DateTime for the PixClaim. ex: ~U[2020-3-10 10:30:0:0] - `:updated` [DateTime]: update DateTime for the PixClaim. ex: ~U[2020-3-10 10:30:0:0] """ @@ -57,8 +61,8 @@ defmodule StarkInfra.PixClaim do :status, :type, :key_type, - :agent, - :bank_code, + :flow, + :claimer_bank_code, :claimed_bank_code, :created, :updated @@ -71,13 +75,13 @@ defmodule StarkInfra.PixClaim do hosted at other Pix participants in the Stark Infra API. ## Parameters (required): - - `:claim` [PixClaim struct]: PixClaim struct to be created in the API. + - `:claim` [PixClaim object]: PixClaim object to be created in the API. - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - PixClaim struct with updated attributes. + - PixClaim object with updated attributes. """ @spec create( PixClaim.t() | map(), @@ -106,16 +110,16 @@ defmodule StarkInfra.PixClaim do end @doc """ - Retrieve a PixClaim struct linked to your Workspace in the Stark Infra API by its id. + Retrieve a PixClaim object linked to your Workspace in the Stark Infra API by its id. ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - PixClaim struct that corresponds to the given id. + - PixClaim object that corresponds to the given id. """ @spec get( id: binary, @@ -147,22 +151,23 @@ defmodule StarkInfra.PixClaim do end @doc """ - Receive a stream of PixClaims structs previously created in the Stark Infra API - - ## Options: - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after a specified date. ex: ~D[2020-03-10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020-03-10] - - `:status` [list of strings, default nil]: filter for status of retrieved structs. Options: "created", "failed", "delivered", "confirmed", "success", "canceled". - - `:ids` [list of strings, default nil]: list of ids to filter retrieved structs. ex: ["5656565656565656", "4545454545454545"] - - `:type` [strings, default nil]: filter for the type of retrieved PixClaims. Options: "ownership" or "portability". - - `:agent` [string, default nil]: filter for the agent of retrieved PixClaims. Options: "claimer" or "claimed". - - `:key_type` [string, default nil]: filter for the PixKey type of retrieved PixClaims. Options: "cpf", "cnpj", "phone", "email", "evp". - - `:key_id` [string, default nil]: filter PixClaims linked to a specific PixKey id. Example: "+5511989898989". - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + Receive a stream of PixClaim objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created after a specified date. ex: ~D[2020-03-10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020-03-10] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. ex: "created", "failed", "delivered", "confirmed", "success", "canceled". + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:type` [binaries, default nil]: filter for the type of retrieved PixClaims. ex: "ownership" or "portability". + - `:key_type` [binary, default nil]: filter for the PixKey type of retrieved PixClaims. ex: "cpf", "cnpj", "phone", "email" and "evp" + - `:key_id` [binary, default nil]: filter PixClaims linked to a specific PixKey id. ex: "+5511989898989" + - `:flow` [binary, default nil]: direction of the Pix Claim. ex: "in" if you received the PixClaim or "out" if you created the PixClaim. + - `:tags` [list of binaries, default nil]: list of binaries to filter retrieved objects. ex: ["travel", "food"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of PixClaim structs with updated attributes + - stream of PixClaim objects with updated attributes """ @spec query( limit: integer, @@ -171,9 +176,10 @@ defmodule StarkInfra.PixClaim do status: binary, ids: [binary], type: binary, - agent: binary, key_type: binary, key_id: binary, + flow: binary, + tags: [binary], user: Project.t() | Organization.t() | nil ) :: {:ok, [PixClaim.t()]} | {:error, [error: Error.t()]} @@ -194,9 +200,10 @@ defmodule StarkInfra.PixClaim do status: binary, ids: [binary], type: binary, - agent: binary, key_type: binary, key_id: binary, + flow: binary, + tags: [binary], user: Project.t() | Organization.t() | nil ) :: any def query!(options \\ []) do @@ -207,25 +214,26 @@ defmodule StarkInfra.PixClaim do end @doc """ - Receive a list of up to 100 PixClaims structs previously created in the Stark Infra API and the cursor to the next page. + Receive a list of up to 100 PixClaim objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your requests. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call. - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Max = 100. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after a specified date. ex: ~D[2020, 3, 10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020, 3, 10] - - `:status` [list of strings, default nil]: filter for status of retrieved structs. Options: "created", "failed", "delivered", "confirmed", "success", "canceled" - - `:ids` [list of strings, default nil]: list of ids to filter retrieved structs. ex: ["5656565656565656", "4545454545454545"] - - `:type` [strings, default nil]: filter for the type of retrieved PixClaims. Options: "ownership" or "portability". - - `:agent` [string, default nil]: filter for the agent of retrieved PixClaims. Options: "claimer" or "claimed". - - `:key_type` [string, default nil]: filter for the PixKey type of retrieved PixClaims. Options: "cpf", "cnpj", "phone", "email", "evp". - - `:key_id` [string, default nil]: filter PixClaims linked to a specific PixKey id. Example: "+5511989898989". - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call. + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created after a specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020, 3, 10] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. ex: "created", "failed", "delivered", "confirmed", "success", "canceled" + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:type` [binaries, default nil]: filter for the type of retrieved PixClaims. ex: "ownership" or "portability". + - `:key_type` [binary, default nil]: filter for the PixKey type of retrieved PixClaims. ex: "cpf", "cnpj", "phone", "email", "evp". + - `:key_id` [binary, default nil]: filter PixClaims linked to a specific PixKey id. Example: "+5511989898989". + - `:flow` [binary, default nil]: direction of the Pix Claim. ex: "in" if you received the PixClaim or "out" if you created the PixClaim. + - `:tags` [list of binaries, default nil]: list of binaries to filter retrieved objects. ex: ["travel", "food"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - cursor to retrieve the next page of PixClaim structs - - stream of PixClaim structs with updated attributes + - list of PixClaim objects with updated attributes + - cursor to retrieve the next page of PixClaim objects """ @spec page( cursor: binary, @@ -235,9 +243,10 @@ defmodule StarkInfra.PixClaim do status: binary, ids: [binary], type: binary, - agent: binary, key_type: binary, key_id: binary, + flow: binary, + tags: [binary], user: Project.t() | Organization.t() | nil ) :: {:ok, {binary, [PixClaim.t()]}} | @@ -260,9 +269,10 @@ defmodule StarkInfra.PixClaim do status: binary, ids: [binary], type: binary, - agent: binary, key_type: binary, key_id: binary, + flow: binary, + tags: [binary], user: Project.t() | Organization.t() | nil ) :: any def page!(options \\ []) do @@ -276,18 +286,18 @@ defmodule StarkInfra.PixClaim do Update a PixClaim parameters by passing id. ## Parameters (required): - - `:id` [string]: PixClaim id. ex: '5656565656565656' - - `:status` [string]: patched status for Pix Claim. Options: "confirmed" and "canceled" + - `:id` [binary]: PixClaim id. ex: '5656565656565656' + - `:status` [binary]: patched status for Pix Claim. ex: "confirmed" and "canceled" ## Parameters (optional): - - `:reason` [string, default: "userRequested"]: reason why the PixClaim is being patched. Options: "fraud", "userRequested". - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + - `:reason` [binary, default: "userRequested"]: reason why the PixClaim is being patched. ex: "fraud", "userRequested", "accountClosure" + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - PixClaim with updated attributes """ @spec update( - binary, + id: binary, status: binary, reason: binary, user: Project.t() | Organization.t() | nil @@ -304,10 +314,10 @@ defmodule StarkInfra.PixClaim do end @doc """ - Same as update, but it will unwrap the error tuple and raise in case of error. + Same as update(), but it will unwrap the error tuple and raise in case of error. """ @spec update!( - binary, + id: binary, status: binary, reason: binary, user: Project.t() | Organization.t() | nil @@ -343,8 +353,8 @@ defmodule StarkInfra.PixClaim do status: json[:status], type: json[:type], key_type: json[:key_type], - agent: json[:agent], - bank_code: json[:bank_code], + flow: json[:flow], + claimer_bank_code: json[:claimer_bank_code], claimed_bank_code: json[:claimed_bank_code], created: json[:created] |> Check.datetime(), updated: json[:updated] |> Check.datetime() diff --git a/lib/pix_claim/pix_claim_log.ex b/lib/pix_claim/pix_claim_log.ex index d49c3de..babd3b4 100644 --- a/lib/pix_claim/pix_claim_log.ex +++ b/lib/pix_claim/pix_claim_log.ex @@ -16,21 +16,19 @@ defmodule StarkInfra.PixClaim.Log do Every time a PixClaim entity is modified, a corresponding PixClaim.Log is generated for the entity. This log is never generated by the user. - ## Attributes: - - `:id` [string]: unique id returned when the log is created. ex: "5656565656565656" - - `:created` [DateTime]: creation datetime for the log. ex: ~U[2020-3-10 10:30:0:0] - - `:type` [string]: type of the PixClaim event which triggered the log creation. Options: “created”, “failed”, “delivering”, “delivered”, “confirming”, “confirmed”, “success”, “canceling” and “canceled”. - - `:errors` [list of strings]: list of errors linked to this PixClaim event - - `:agent` [string]: agent that modified the PixClaim resulting in the Log. Options: "claimer", "claimed". - - `:reason` [string]: reason why the PixClaim was modified, resulting in the Log. Options: "fraud", "userRequested", "accountClosure", "defaultOperation", "reconciliation". + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the log is created. ex: "5656565656565656" - `:claim` [PixClaim]: PixClaim entity to which the log refers to. + - `:type` [binary]: type of the PixClaim event which triggered the log creation. ex: “created”, “failed”, “delivering”, “delivered”, “confirming”, “confirmed”, “success”, “canceling” and “canceled”. + - `:errors` [list of binaries]: list of errors linked to this PixClaim event + - `:reason` [binary]: reason why the PixClaim was modified, resulting in the Log. ex: "fraud", "userRequested", "accountClosure", "defaultOperation", "reconciliation". + - `:created` [DateTime]: creation datetime for the log. ex: ~U[2020-3-10 10:30:0:0] """ @enforce_keys [ :id, :created, :type, :errors, - :agent, :reason, :claim ] @@ -39,7 +37,6 @@ defmodule StarkInfra.PixClaim.Log do :created, :type, :errors, - :agent, :reason, :claim ] @@ -47,22 +44,22 @@ defmodule StarkInfra.PixClaim.Log do @type t() :: %__MODULE__{} @doc """ - Receive a single PixClaim.Log struct previously created by the Stark Infra API by its id + Receive a single PixClaim.Log object previously created by the Stark Infra API by its id ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - PixClaim.Log struct with updated attributes + - PixClaim.Log object that corresponds to the given id. """ @spec get( id: binary, user: Project.t() | Organization.t() | nil ) :: - { :ok, Log.t()} | + {:ok, Log.t()} | {:error, [Error.t()]} def get(id, options \\ []) do Rest.get_id(resource(), id, options) @@ -80,27 +77,27 @@ defmodule StarkInfra.PixClaim.Log do end @doc """ - Receive a stream of PixClaim.Log structs previously created in the Stark Infra API + Receive a stream of PixClaim.Log objects previously created in the Stark Infra API - ## Options: - - `:ids` [list of strings, default nil]: Log ids to filter PixClaim Logs. ex: ["5656565656565656"] - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after specified date. ex: ~D[2020, 3, 10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020, 3, 10] - - `:types` [list of strings, default nil]: filter retrieved structs by types. Options: “created”, “failed”, “delivering”, “delivered”, “confirming”, “confirmed”, “success”, “canceling” and “canceled” - - `:claim_ids` [list of strings, default nil]: list of PixClaim ids to filter retrieved structs. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created after specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020, 3, 10] + - `:types` [list of binaries, default nil]: filter retrieved objects by types. ex: “created”, “failed”, “delivering”, “delivered”, “confirming”, “confirmed”, “success”, “canceling” and “canceled” + - `:claim_ids` [list of binaries, default nil]: list of PixClaim ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: Log ids to filter PixClaim Logs. ex: ["5656565656565656"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of PixClaim.Log structs with updated attributes + - stream of PixClaim.Log objects with updated attributes """ @spec query( - ids: [binary] | nil, limit: integer | nil, after: Date.t() | binary | nil, before: Date.t() | binary | nil, types: [binary] | nil, claim_ids: [binary] | nil, + ids: [binary] | nil, user: Project.t() | Organization.t() | nil ) :: {:ok, [Log.t()] } | @@ -113,12 +110,12 @@ defmodule StarkInfra.PixClaim.Log do Same as query(), but it will unwrap the error tuple and raise in case of errors. """ @spec query!( - ids: [binary] | nil, limit: integer | nil, after: Date.t() | binary | nil, before: Date.t() | binary | nil, types: [binary] | nil, claim_ids: [binary] | nil, + ids: [binary] | nil, user: Project.t() | Organization.t() | nil ) :: [Log.t()] def query!(options \\ []) do @@ -126,31 +123,31 @@ defmodule StarkInfra.PixClaim.Log do end @doc """ - Receive a list of up to 100 PixClaim.Log structs previously created in the Stark Infra API and the cursor to the next page. + Receive a list of up to 100 PixClaim.Log objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your claims. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:ids` [list of strings, default nil]: Log ids to filter PixClaim Logs. ex: ["5656565656565656"] - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Max = 100. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after a specified date. ex: ~D[2020, 3, 10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020, 3, 10] - - `:types` [list of strings, default nil]: filter retrieved structs by types. Options: “created”, “failed”, “delivering”, “delivered”, “confirming”, “confirmed”, “success”, “canceling” and “canceled” - - `:claim_ids` [list of strings, default nil]: list of PixClaim IDs to filter retrieved structs. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created after a specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020, 3, 10] + - `:types` [list of binaries, default nil]: filter retrieved objects by types. ex: “created”, “failed”, “delivering”, “delivered”, “confirming”, “confirmed”, “success”, “canceling” and “canceled” + - `:claim_ids` [list of binaries, default nil]: list of PixClaim IDs to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: Log ids to filter PixClaim Logs. ex: ["5656565656565656"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of PixClaim.Log structs with updated attributes - - cursor to retrieve the next page of PixClaim.Log structs + - list of PixClaim.Log objects with updated attributes + - cursor to retrieve the next page of PixClaim.Log objects """ @spec page( cursor: binary | nil, - ids: [binary] | nil, limit: integer | nil, after: Date.t() | binary | nil, before: Date.t() | binary | nil, types: [binary] | nil, claim_ids: [binary] | nil, + ids: [binary] | nil, user: Project.t() | Organization.t() | nil ) :: {:ok, {binary, [Log.t()]}} | @@ -164,12 +161,12 @@ defmodule StarkInfra.PixClaim.Log do """ @spec page!( cursor: binary | nil, - ids: [binary] | nil, limit: integer | nil, after: Date.t() | binary | nil, before: Date.t() | binary | nil, types: [binary] | nil, claim_ids: [binary] | nil, + ids: [binary] | nil, user: Project.t() | Organization.t() | nil ) :: {binary, [Log.t()]} @@ -189,12 +186,11 @@ defmodule StarkInfra.PixClaim.Log do def resource_maker(json) do %Log{ id: json[:id], - created: json[:created] |> Check.datetime(), + claim: json[:claim] |> API.from_api_json(&PixClaim.resource_maker/1), type: json[:type], errors: json[:errors], - agent: json[:agent], reason: json[:reason], - claim: json[:claim] |> API.from_api_json(&PixClaim.resource_maker/1) + created: json[:created] |> Check.datetime(), } end end diff --git a/lib/pix_director/pix_director.ex b/lib/pix_director/pix_director.ex index 0a6b8ca..2d9be20 100644 --- a/lib/pix_director/pix_director.ex +++ b/lib/pix_director/pix_director.ex @@ -10,21 +10,23 @@ defmodule StarkInfra.PixDirector do """ @doc """ - The PixDomain struct displays the domain name and the QR Code domain certificate of Pix participants. - All certificates must be registered with the Central Bank. + Mandatory data that must be registered within the Central Bank for emergency contact purposes. + + When you initialize a PixDirector, the entity will not be automatically + created in the Stark Infra API. The 'create' function sends the objects + to the Stark Infra API and returns the list of created objects. # Parameters (required): - - `:name` [string]: name of the PixDirector. ex: "Edward Stark". - - `:tax_id` [string]: tax ID (CPF/CNPJ) of the PixDirector. ex: "03.300.300/0001-00" - - `:phone` [string]: phone of the PixDirector. ex: "+551198989898" - - `:email` [string]: email of the PixDirector. ex: "ned.stark@starkbank.com" - - `:password` [string]: password of the PixDirector. ex: "12345678" - - `:team_email` [string]: team email. ex: "aria.stark@starkbank.com" - - `:team_phones` [list of strings]: list of phones of the team. ex: ["+5511988889999", "+5511988889998"] + - `:name` [binary]: name of the PixDirector. ex: "Edward Stark". + - `:tax_id` [binary]: tax ID (CPF/CNPJ) of the PixDirector. ex: "03.300.300/0001-00" + - `:phone` [binary]: phone of the PixDirector. ex: "+551198989898" + - `:email` [binary]: email of the PixDirector. ex: "ned.stark@starkbank.com" + - `:password` [binary]: password of the PixDirector. ex: "12345678" + - `:team_email` [binary]: team email. ex: "aria.stark@starkbank.com" + - `:team_phones` [list of binaries]: list of phones of the team. ex: ["+5511988889999", "+5511988889998"] ## Attributes (return-only): - - `:id` [string]: unique id returned when the PixDirector is created. ex: "5656565656565656" - - `:status` [string]: current PixDirector status. ex: "success" + - `:status` [binary]: current PixDirector status. ex: "success" """ @enforce_keys [ :name, @@ -43,23 +45,22 @@ defmodule StarkInfra.PixDirector do :password, :team_email, :team_phones, - :id, :status ] @type t() :: %__MODULE__{} @doc """ - Send a PixDirector struct for creation in the Stark Infra API + Send a PixDirector object for creation in the Stark Infra API ## Parameters (required): - - `:director` [PixDirector struct]: PixDirector struct to be created in the API + - `:director` [PixDirector object]: PixDirector object to be created in the API - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - PixDirector struct with updated attributes + - PixDirector object with updated attributes """ @spec create( PixDirector.t() | map(), @@ -101,7 +102,6 @@ defmodule StarkInfra.PixDirector do @doc false def resource_maker(json) do %PixDirector{ - id: json[:id], name: json[:name], tax_id: json[:tax_id], phone: json[:phone], diff --git a/lib/pix_domain/pix_domain_certificate.ex b/lib/pix_domain/certificate.ex similarity index 76% rename from lib/pix_domain/pix_domain_certificate.ex rename to lib/pix_domain/certificate.ex index 05366d5..d189102 100644 --- a/lib/pix_domain/pix_domain_certificate.ex +++ b/lib/pix_domain/certificate.ex @@ -6,10 +6,10 @@ defmodule StarkInfra.PixDomain.Certificate do """ @doc """ - The Certificate struct displays the certificate information from a specific domain. + The Certificate object displays the certificate information from a specific domain. ## Attributes (return-only): - - content [string]: certificate of the Pix participant in PEM format. + - content [binary]: certificate of the Pix participant in PEM format. """ defstruct [ :content diff --git a/lib/pix_domain/pix_domain.ex b/lib/pix_domain/pix_domain.ex index 86d7f4f..e5a0af3 100644 --- a/lib/pix_domain/pix_domain.ex +++ b/lib/pix_domain/pix_domain.ex @@ -12,12 +12,12 @@ defmodule StarkInfra.PixDomain do """ @doc """ - The PixDomain struct displays the QR Code domain certificate information of Pix participants. + The PixDomain object displays the domain name and the QR Code domain certificate of Pix participants. All certificates must be registered with the Central Bank. ## Attributes (return-only): - certificates [list of PixDomain.Certificate]: certificate information of the Pix participant. - - name [string]: current active domain (URL) of the Pix participant. + - name [binary]: current active domain (URL) of the Pix participant. """ @enforce_keys [ :certificates, @@ -31,13 +31,13 @@ defmodule StarkInfra.PixDomain do @type t() :: %__MODULE__{} @doc """ - Receive a stream of PixDomain objects. + Receive a stream of PixDomain objects of Pix participants able to issue BR Codes - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of PixDomain structs with updated attributes + - stream of PixDomain objects with updated attributes """ @spec query( user: Organization.t() | Project.t() | nil diff --git a/lib/pix_infraction/pix_infraction.ex b/lib/pix_infraction/pix_infraction.ex index 5a0bfa1..c9bafe0 100644 --- a/lib/pix_infraction/pix_infraction.ex +++ b/lib/pix_infraction/pix_infraction.ex @@ -13,27 +13,28 @@ defmodule StarkInfra.PixInfraction do @doc """ PixInfraction are used to report transactions that are suspected of fraud, to request a refund or to reverse a refund. + When you initialize a PixInfraction, the entity will not be automatically created in the Stark Infra API. The 'create' function sends the objects - to the Stark Infra API and returns the created struct. + to the Stark Infra API and returns the created object. ## Parameters (required): - - `:reference_id` [string]: end_to_end_id or return_id of the transaction being reported. ex: "E20018183202201201450u34sDGd19lz" - - `:type` [string]: type of infraction report. Options: "fraud", "reversal", "reversalChargeback" + - `:reference_id` [binary]: end_to_end_id or return_id of the transaction being reported. ex: "E20018183202201201450u34sDGd19lz" + - `:type` [binary]: type of infraction report. Options: "fraud", "reversal", "reversalChargeback" ## Parameters (optional): - - `:description` [string, default nil]: description for any details that can help with the infraction investigation. + - `:description` [binary, default nil]: description for any details that can help with the infraction investigation. + - `:tags` [list of binaries, default []]: list of binaries for tagging. ex: ["travel", "food"] ## Attributes (return-only): - - id [string]: unique id returned when the PixInfraction is created. ex: "5656565656565656" - - credited_bank_code [string]: bank_code of the credited Pix participant in the reported transaction. ex: "20018183" - - debited_bank_code [string]: bank_code of the debited Pix participant in the reported transaction. ex: "20018183" - - agent [string]: Options: "reporter" if you created the PixInfraction, "reported" if you received the PixInfraction. - - analysis [string]: analysis that led to the result. - - bacen_id [string]: central bank's unique UUID that identifies the infraction report. - - reported_by [string]: agent that reported the PixInfraction. Options: "debited", "credited". - - result [string]: result after the analysis of the PixInfraction by the receiving party. Options: "agreed", "disagreed" - - status [string]: current PixInfraction status. Options: "created", "failed", "delivered", "closed", "canceled". + - id [binary]: unique id returned when the PixInfraction is created. ex: "5656565656565656" + - credited_bank_code [binary]: bank_code of the credited Pix participant in the reported transaction. ex: "20018183" + - debited_bank_code [binary]: bank_code of the debited Pix participant in the reported transaction. ex: "20018183" + - flow [binary]: direction of the PixInfraction flow. ex: "out" if you created the PixInfraction, "in" if you received the PixInfraction. + - analysis [binary]: analysis that led to the result. + - reported_by [binary]: agent that reported the PixInfraction. Options: "debited", "credited". + - result [binary]: result after the analysis of the PixInfraction by the receiving party. Options: "agreed", "disagreed" + - status [binary]: current PixInfraction status. Options: "created", "failed", "delivered", "closed", "canceled". - created [DateTime]: creation datetime for the PixInfraction. ex: ~U[2020-3-10 10:30:0:0] - updated [DateTime]: latest update datetime for the PixInfraction. ex: ~U[2020-3-10 10:30:0:0] """ @@ -45,12 +46,12 @@ defmodule StarkInfra.PixInfraction do :reference_id, :type, :description, + :tags, :id, :credited_bank_code, :debited_bank_code, - :agent, + :flow, :analysis, - :bacen_id, :reported_by, :result, :status, @@ -61,16 +62,16 @@ defmodule StarkInfra.PixInfraction do @type t() :: %__MODULE__{} @doc """ - Create PixInfractions in the Stark Infra API + Create PixInfraction objects in the Stark Infra API ## Parameters (required): - - `:infractions` [list of PixInfraction]: list of PixInfraction structs to be created in the API. + - `:infractions` [list of PixInfraction]: list of PixInfraction objects to be created in the API. - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of PixInfraction structs with updated attributes + - list of PixInfraction objects with updated attributes """ @spec create( [PixInfraction.t() | map], @@ -102,16 +103,16 @@ defmodule StarkInfra.PixInfraction do end @doc """ - Retrieve the PixInfraction struct linked to your Workspace in the Stark Infra API using its id. + Retrieve the PixInfraction object linked to your Workspace in the Stark Infra API using its id. ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656". + - `:id` [binary]: object unique id. ex: "5656565656565656". - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - PixInfraction struct that corresponds to the given id. + - PixInfraction object that corresponds to the given id. """ @spec get( id: binary, @@ -143,19 +144,21 @@ defmodule StarkInfra.PixInfraction do end @doc """ - Receive a stream of PixInfractions structs previously created in the Stark Infra API + Receive a stream of PixInfraction objects previously created in the Stark Infra API - ## Options: - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after a specified date. ex: ~D[2020-03-10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020-03-10] - - `:status` [list of strings, default nil]: filter for status of retrieved objects. ex: ["created", "failed", "delivered", "closed", "canceled"] - - `:ids` [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] - - `:type` [list of strings, default nil]: filter for the type of retrieved PixInfractions. Options: "fraud", "reversal", "reversalChargeback" - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created after a specified date. ex: ~D[2020-03-10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020-03-10] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. Options: ["created", "failed", "delivered", "closed", "canceled"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:type` [list of binaries, default nil]: filter for the type of retrieved PixInfractions. Options: "fraud", "reversal", "reversalChargeback" + - `:flow` [binary, default nil]: direction of the PixInfraction flow. Options: "out" if you created the PixInfraction, "in" if you received the PixInfraction. + - `:tags` [list of binaries, default nil]: list of binaries for tagging. ex: ["travel", "food"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of PixInfraction structs with updated attributes + - stream of PixInfraction objects with updated attributes """ @spec query( limit: integer | nil, @@ -164,6 +167,8 @@ defmodule StarkInfra.PixInfraction do status: [binary] | nil, ids: [binary] | nil, type: [binary] | nil, + flow: binary | nil, + tags: [binary] | nil, user: Organization.t() | Project.t() | nil ) :: ({:cont, {:ok, [PixInfraction.t() | map]}} | @@ -188,6 +193,8 @@ defmodule StarkInfra.PixInfraction do status: [binary] | nil, ids: [binary] | nil, type: [binary] | nil, + flow: binary | nil, + tags: [binary] | nil, user: Organization.t() | Project.t() | nil ) :: any def query!(options \\ []) do @@ -198,21 +205,24 @@ defmodule StarkInfra.PixInfraction do end @doc """ - Receive a list of up to 100 PixInfractions structs previously created in the Stark Infra API and the cursor to the next page. + Receive a list of up to 100 PixInfraction objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your requests. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call. - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Max = 100. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after a specified date. ex: ~D[2020-03-10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020-03-10] - - `:status` [list of strings, default nil]: filter for status of retrieved objects. ex: ["created", "failed", "delivered", "closed", "canceled"] - - `:ids` [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] - - `:type` [list of strings, default nil]: filter for the type of retrieved PixInfractions. Options: "fraud", "reversal", "reversalChargeback" - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call. + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created after a specified date. ex: ~D[2020-03-10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020-03-10] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. Options: ["created", "failed", "delivered", "closed", "canceled"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:type` [list of binaries, default nil]: filter for the type of retrieved PixInfractions. Options: "fraud", "reversal", "reversalChargeback" + - `:flow` [binary, default nill]: direction of the PixInfraction flow. Options: "out" if you created the PixInfraction, "in" if you received the PixInfraction. + - `:tags` [list of binaries, default nill]: list of strings for tagging. ex: ["travel", "food"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of PixInfraction structs with updated attributes and cursor to retrieve the next page of PixInfraction objects + - list of PixInfraction objects with updated attributes + - cursor to retrieve the next page of PixInfraction objects """ @spec page( cursor: binary | nil, @@ -222,6 +232,8 @@ defmodule StarkInfra.PixInfraction do status: [binary] | nil, ids: [binary] | nil, type: [binary] | nil, + flow: binary | nil, + tags: [binary] | nil, user: Organization.t() | Project.t() | nil ) :: {:ok, {binary, [PixInfraction.t() | map]}} | @@ -244,6 +256,8 @@ defmodule StarkInfra.PixInfraction do status: [binary] | nil, ids: [binary] | nil, type: [binary] | nil, + flow: binary | nil, + tags: [binary] | nil, user: Organization.t() | Project.t() | nil ) :: any def page!(options \\ []) do @@ -254,21 +268,21 @@ defmodule StarkInfra.PixInfraction do end @doc """ - Respond to a received PixInfraction. + Update a PixInfraction by passing id. ## Parameters (required): - - `:id` [string]: PixInfraction id. ex: '5656565656565656' - - `:result` [string]: result after the analysis of the PixInfraction. Options: "agreed", "disagreed" + - `:id` [binary]: object unique id. ex: '5656565656565656' + - `:result` [binary]: result after the analysis of the PixInfraction. Options: "agreed", "disagreed" ## Parameters (optional): - - `:analysis` [string, default nil]: analysis that led to the result. - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + - `:analysis` [binary, default nil]: analysis that led to the result. + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - PixInfraction with updated attributes """ @spec update( - binary, + id: binary, result: binary, analysis: binary | nil, user: Organization.t() | Project.t() | nil @@ -288,7 +302,7 @@ defmodule StarkInfra.PixInfraction do Same as update(), but it will unwrap the error tuple and raise in case of errors. """ @spec update!( - binary, + id: binary, result: binary, analysis: binary | nil, user: Organization.t() | Project.t() | nil @@ -306,13 +320,13 @@ defmodule StarkInfra.PixInfraction do Cancel a PixInfraction entity previously created in the Stark Infra API ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - canceled PixInfraction struct + - canceled PixInfraction object """ @spec cancel( id: binary, @@ -357,12 +371,12 @@ defmodule StarkInfra.PixInfraction do reference_id: json[:reference_id], type: json[:type], description: json[:description], + tags: json[:tags], id: json[:id], credited_bank_code: json[:credited_bank_code], debited_bank_code: json[:debited_bank_code], - agent: json[:agent], + flow: json[:flow], analysis: json[:analysis], - bacen_id: json[:bacen_id], reported_by: json[:reported_by], result: json[:result], status: json[:status], diff --git a/lib/pix_infraction/pix_infraction_log.ex b/lib/pix_infraction/pix_infraction_log.ex index 0c898b1..563384e 100644 --- a/lib/pix_infraction/pix_infraction_log.ex +++ b/lib/pix_infraction/pix_infraction_log.ex @@ -16,41 +16,41 @@ defmodule StarkInfra.PixInfraction.Log do Every time a PixInfraction entity is modified, a corresponding PixInfraction.Log is generated for the entity. This log is never generated by the user. - ## Attributes: - - `:id` [string]: unique id returned when the log is created. ex: "5656565656565656" + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the log is created. ex: "5656565656565656" + - `:infraction` [PixInfraction object]: PixInfraction entity to which the log refers to. + - `:type` [binary]: type of the PixInfraction event which triggered the log creation. Options: "created", "failed", "delivering", "delivered", "closed", "canceled" + - `:errors` [list of binaries]: list of errors linked to this PixInfraction event - `:created `[DateTime]: creation datetime for the log. ex: ~U[2020-3-10 10:30:0:0] - - `:type` [string]: type of the PixInfraction event which triggered the log creation. ex: "created", "failed", "delivering", "delivered", "closed", "canceled" - - `:errors` [list of strings]: list of errors linked to this PixInfraction event - - `:infraction` [PixInfraction]: PixInfraction entity to which the log refers to. """ @enforce_keys [ :id, - :created, + :infraction, :type, :errors, - :infraction + :created, ] defstruct [ :id, - :created, + :infraction, :type, :errors, - :infraction + :created, ] @type t() :: %__MODULE__{} @doc """ - Receive a single PixInfraction.Log struct previously created by the Stark Infra API by its id + Receive a single PixInfraction.Log object previously created by the Stark Infra API by its id ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - PixInfraction.Log struct with updated attributes + - PixInfraction.Log object that corresponds to the given id. """ @spec get( id: binary, @@ -74,19 +74,19 @@ defmodule StarkInfra.PixInfraction.Log do end @doc """ - Receive a stream of PixInfraction.Log structs previously created in the Stark Infra API + Receive a stream of PixInfraction.Log objects previously created in the Stark Infra API - ## Options: - - `:ids` [list of strings, default nil]: Log ids to filter PixInfraction Logs. ex: ["5656565656565656"] - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after specified date. ex: ~D[2020-03-10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020-03-10] - - `:types` [list of strings, default nil]: filter retrieved structs by types. ex: ["created", "failed", "delivering", "delivered", "closed", "canceled"] - - `:infraction_ids` [list of strings, default nil]: list of PixInfraction IDs to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created after specified date. ex: ~D[2020-03-10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020-03-10] + - `:types` [list of binaries, default nil]: filter retrieved objects by types. ex: ["created", "failed", "delivering", "delivered", "closed", "canceled"] + - `:infraction_ids` [list of binaries, default nil]: list of PixInfraction IDs to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: Log ids to filter PixInfraction Logs. ex: ["5656565656565656"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of PixInfraction.Log structs with updated attributes + - stream of PixInfraction.Log objects with updated attributes """ @spec query( ids: [binary] | nil, @@ -120,20 +120,21 @@ defmodule StarkInfra.PixInfraction.Log do end @doc """ - Receive a list of up to 100 PixInfraction.Log structs previously created in the Stark Infra API and the cursor to the next page. + Receive a list of up to 100 PixInfraction.Log objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your infractions. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:ids` [list of strings, default nil]: Log ids to filter PixInfraction Logs. ex: ["5656565656565656"] - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Max = 100. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after a specified date. ex: ~D[2020-03-10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020-03-10] - - `:types` [list of strings, default nil]: filter retrieved structs by types. ex: ["created", "failed", "delivering", "delivered", "closed", "canceled"] - - `:infraction_ids` [list of strings, default nil]: list of PixInfraction ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. - ## Return: - - list of PixInfraction.Log structs with updated attributes + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created after a specified date. ex: ~D[2020-03-10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020-03-10] + - `:types` [list of binaries, default nil]: filter retrieved objects by types. ex: ["created", "failed", "delivering", "delivered", "closed", "canceled"] + - `:infraction_ids` [list of binaries, default nil]: list of PixInfraction ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: Log ids to filter PixInfraction Logs. ex: ["5656565656565656"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of PixInfraction.Log objects with updated attributes - cursor to retrieve the next page of PixInfraction.Log objects """ @spec page( @@ -181,10 +182,10 @@ defmodule StarkInfra.PixInfraction.Log do def resource_maker(json) do %Log{ id: json[:id], - created: json[:created] |> Check.datetime(), + infraction: json[:infraction] |> API.from_api_json(&PixInfraction.resource_maker/1), type: json[:type], errors: json[:errors], - infraction: json[:infraction] |> API.from_api_json(&PixInfraction.resource_maker/1) + created: json[:created] |> Check.datetime(), } end end diff --git a/lib/pix_key/pix_key.ex b/lib/pix_key/pix_key.ex index 7a5a1ee..8487af0 100644 --- a/lib/pix_key/pix_key.ex +++ b/lib/pix_key/pix_key.ex @@ -13,29 +13,30 @@ defmodule StarkInfra.PixKey do @doc """ PixKeys link bank account information to key ids. Key ids are a convenient way to search and pass bank account information. + When you initialize a Pix Key, the entity will not be automatically - created in the Stark Infra API. The 'create' function sends the structs - to the Stark Infra API and returns the created struct. + created in the Stark Infra API. The 'create' function sends the objects + to the Stark Infra API and returns the created object. ## Parameters (required): - - `:account_created` [Date, DateTime or string]: opening Date or DateTime for the linked account. ex: "2022-01-01". - - `:account_number` [string]: number of the linked account. ex: "76543". - - `:account_type` [string]: type of the linked account. Options: "checking", "savings", "salary" or "payment". - - `:branch_code` [string]: branch code of the linked account. ex: 1234. - - `:name` [string]: holder's name of the linked account. ex: "Jamie Lannister". - - `:tax_id` [string]: holder's taxId (CPF/CNPJ) of the linked account. ex: "012.345.678-90". + - `:account_created` [Date, DateTime or binary]: opening Date or DateTime for the linked account. ex: "2022-01-01". + - `:account_number` [binary]: number of the linked account. ex: "76543". + - `:account_type` [binary]: type of the linked account. ex: "checking", "savings", "salary" or "payment". + - `:branch_code` [binary]: branch code of the linked account. ex: 1234. + - `:name` [binary]: holder's name of the linked account. ex: "Jamie Lannister". + - `:tax_id` [binary]: holder's taxId (CPF/CNPJ) of the linked account. ex: "012.345.678-90". ## Parameters (optional): - - `:id` [string, default nil]: id of the registered PixKey. Allowed types are: CPF, CNPJ, phone number or email. If this parameter is not passed, an EVP will be created. ex: "+5511989898989"; - - `:tags` [list of strings, default nil]: list of strings for reference when searching for PixKeys. ex: ["employees", "monthly"] + - `:id` [binary, default nil]: id of the registered PixKey. Allowed types are: CPF, CNPJ, phone number or email. If this parameter is not passed, an EVP will be created. ex: "+5511989898989"; + - `:tags` [list of binaries, default nil]: list of binaries for reference when searching for PixKeys. ex: ["employees", "monthly"] ## Attributes (return-only): - `:owned` [DateTime]: datetime when the key was owned by the holder. ex: ~U[2020-3-10 10:30:0:0] - - `:owner_type` [string]: type of the owner of the PixKey. Options: "business" or "individual". - - `:status` [string]: current PixKey status. Options: "created", "registered", "canceled", "failed" - - `:bank_code` [string]: bank_code of the account linked to the Pix Key. ex: "20018183". - - `:bank_name` [string]: name of the bank that holds the account linked to the PixKey. ex: "StarkBank" - - `:type` [string]: type of the PixKey. Options: "cpf", "cnpj", "phone", "email" and "evp", + - `:owner_type` [binary]: type of the owner of the PixKey. ex: "business" or "individual". + - `:status` [binary]: current PixKey status. ex: "created", "registered", "canceled", "failed" + - `:bank_code` [binary]: bank_code of the account linked to the Pix Key. ex: "20018183". + - `:bank_name` [binary]: name of the bank that holds the account linked to the PixKey. ex: "StarkBank" + - `:type` [binary]: type of the PixKey. ex: "cpf", "cnpj", "phone", "email" and "evp", - `:created` [DateTime]: creation datetime for the PixKey. ex: ~U[2020-03-10 10:30:0:0] """ @enforce_keys [ @@ -69,14 +70,14 @@ defmodule StarkInfra.PixKey do @doc """ Create a PixKey linked to a specific account in the Stark Infra API - ## Options: - - `:key` [PixKey struct]: PixKey struct to be created in the API. + ## Parameters (optional): + - `:key` [PixKey object]: PixKey object to be created in the API. - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - PixKey struct with updated attributes. + - PixKey object with updated attributes. """ @spec create( PixKey.t() | map(), @@ -108,21 +109,21 @@ defmodule StarkInfra.PixKey do end @doc """ - Retrieve the PixKey struct linked to your Workspace in the Stark Infra API by its id. + Retrieve the PixKey object linked to your Workspace in the Stark Infra API by its id. ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656". - - `:payer_id` [string]: tax id (CPF/CNPJ) of the individual or business requesting the PixKey information. This id is used by the Central Bank to limit request rates. ex: "20.018.183/0001-80". + - `:id` [binary]: object unique id. ex: "5656565656565656". + - `:payer_id` [binary]: tax id (CPF/CNPJ) of the individual or business requesting the PixKey information. This id is used by the Central Bank to limit request rates. ex: "20.018.183/0001-80". - ## Options: - - `:end_to_end_id` [string, default nil]: central bank's unique transaction id. If the request results in the creation of a PixRequest, the same endToEndId should be used. If this parameter is not passed, one endToEndId will be automatically created. Example: "E00002649202201172211u34srod19le" - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:end_to_end_id` [binary, default nil]: central bank's unique transaction id. If the request results in the creation of a PixRequest, the same endToEndId should be used. If this parameter is not passed, one endToEndId will be automatically created. Example: "E00002649202201172211u34srod19le" + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - PixKey struct that corresponds to the given id. + - PixKey object that corresponds to the given id. """ @spec get( - binary, + id: binary, payer_id: binary, end_to_end_id: binary | nil, user: Project.t() | Organization.t() | nil @@ -138,7 +139,7 @@ defmodule StarkInfra.PixKey do Same as get(), but it will unwrap the error tuple and raise in case of errors. """ @spec get!( - binary, + id: binary, payer_id: binary, end_to_end_id: binary | nil, user: Project.t() | Organization.t() | nil @@ -149,20 +150,20 @@ defmodule StarkInfra.PixKey do end @doc """ - Receive a stream of PixKeys structs previously created in the Stark Infra API - - ## Options: - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after a specified date. ex: ~D[2020, 3, 10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020, 3, 10] - - `:status` [list of strings, default nil]: filter for status of retrieved structs. Options: "created", "registered", "canceled", "failed". - - `:tags` [list of strings, default nil]: tags to filter retrieved structs. ex: ["tony", "stark"] - - `:ids` [list of strings, default nil]: list of ids to filter retrieved structs. ex: ["5656565656565656", "4545454545454545"] - - `:type` [list of strings, default nil]: filter for the type of retrieved PixKeys. Options: "cpf", "cnpj", "phone", "email", "evp". - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + Receive a stream of PixKey objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created after a specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020, 3, 10] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. ex: "created", "registered", "canceled", "failed". + - `:tags` [list of binaries, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:type` [list of binaries, default nil]: filter for the type of retrieved PixKeys. ex: "cpf", "cnpj", "phone", "email", "evp". + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of PixKey structs with updated attributes + - stream of PixKey objects with updated attributes """ @spec query( limit: integer, @@ -197,22 +198,23 @@ defmodule StarkInfra.PixKey do end @doc """ - Receive a stream of PixKeys structs previously created in the Stark Infra API - - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call. - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Max = 100. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after a specified date. ex: ~D[2020, 3, 10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020, 3, 10] - - `:status` [list of strings, default nil]: filter for status of retrieved structs. Options: "created", "failed", "delivered", "confirmed", "success", "canceled" - - `:tags` [list of strings, default nil]: tags to filter retrieved structs. ex: ["tony", "stark"] - - `:ids` [list of strings, default nil]: list of ids to filter retrieved structs. ex: ["5656565656565656", "4545454545454545"] - - `:type` [list of strings, default nil]: filter for the type of retrieved PixKeys. Options: "cpf", "cnpj", "phone", "email", "evp". - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + Receive a list of up to 100 PixKey objects previously created in the Stark Infra API and the cursor to the next page. + Use this function instead of query if you want to manually page your requests. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call. + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created after a specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020, 3, 10] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. ex: "created", "failed", "delivered", "confirmed", "success", "canceled" + - `:tags` [list of binaries, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:type` [list of binaries, default nil]: filter for the type of retrieved PixKeys. ex: "cpf", "cnpj", "phone", "email", "evp". + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - cursor to retrieve the next page of PixKey structs - - stream of PixKey structs with updated attributes + - list of PixKey objects with updated attributes + - cursor to retrieve the next page of PixKey objects """ @spec page( cursor: binary, @@ -251,21 +253,22 @@ defmodule StarkInfra.PixKey do Update a PixKey parameters by passing id. ## Parameters (required): - - `:id` [string]: PixKey id. ex: '5656565656565656' - - `:reason` [string]: reason why the PixKey is being patched. Options: "branchTransfer", "reconciliation" or "userRequested". + - `:id` [binary]: PixKey id. ex: '5656565656565656' + - `:reason` [binary]: reason why the PixKey is being patched. ex: "branchTransfer", "reconciliation" or "userRequested". ## Parameters (optional): - - `:account_created` [Date, DateTime or string, default nil]: opening Date or DateTime for the account to be linked. ex: "2022-01-01. - - `:account_number` [string, default nil]: number of the account to be linked. ex: "76543". - - `:account_type` [string, default nil]: type of the account to be linked. Options: "checking", "savings", "salary" or "payment". - - `:branch_code` [string, default nil]: branch code of the account to be linked. ex: 1234". - - `:name` [string, default nil]: holder's name of the account to be linked. ex: "Jamie Lannister". + - `:account_created` [Date, DateTime or binary, default nil]: opening Date or DateTime for the account to be linked. ex: "2022-01-01. + - `:account_number` [binary, default nil]: number of the account to be linked. ex: "76543". + - `:account_type` [binary, default nil]: type of the account to be linked. ex: "checking", "savings", "salary" or "payment". + - `:branch_code` [binary, default nil]: branch code of the account to be linked. ex: 1234". + - `:name` [binary, default nil]: holder's name of the account to be linked. ex: "Jamie Lannister". + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - PixKey with updated attributes """ @spec update( - binary, + id: binary, reason: binary, account_created: Date.t(), account_number: binary, @@ -289,7 +292,7 @@ defmodule StarkInfra.PixKey do Same as update(), but it will unwrap the error tuple and raise in case of errors. """ @spec update!( - binary, + id: binary, reason: binary, account_created: Date.t(), account_number: binary, @@ -308,16 +311,16 @@ defmodule StarkInfra.PixKey do end @doc """ - Delete a pixKey entity previously created in the Stark Infra API + Cancel a PixKey entity previously created in the Stark Infra API ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - canceled pixKey struct + - canceled PixKey object """ @spec cancel( id: binary, diff --git a/lib/pix_key/pix_key_log.ex b/lib/pix_key/pix_key_log.ex index b08b816..83180fb 100644 --- a/lib/pix_key/pix_key_log.ex +++ b/lib/pix_key/pix_key_log.ex @@ -16,41 +16,41 @@ defmodule StarkInfra.PixKey.Log do Every time a PixKey entity is modified, a corresponding PixKey.Log is generated for the entity. This log is never generated by the user. - ## Attributes: - - `:id` [string]: unique id returned when the log is created. ex: "5656565656565656" + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the log is created. ex: "5656565656565656" + - `:key` [PixKey object]: PixKey entity to which the log refers to. + - `:type` [binary]: type of the PixKey event which triggered the log creation. Options: "created", "registered", "updated", "failed", "canceling" and "canceled". + - `:errors` [list of binaries]: list of errors linked to this PixKey event - `:created` [DateTime]: creation datetime for the log. ex: ~U[2020-3-10 10:30:0:0] - - `:type` [string]: type of the PixKey event which triggered the log creation. ex: "created", "registered", "updated", "failed", "canceling" and "canceled". - - `:errors` [list of strings]: list of errors linked to this PixKey event - - `:key` [PixKey]: PixKey entity to which the log refers to. """ @enforce_keys [ :id, - :created, :type, :errors, - :key + :key, + :created, ] defstruct [ :id, - :created, :type, :errors, - :key + :key, + :created, ] @type t() :: %__MODULE__{} @doc """ - Receive a single PixKey.Log struct previously created by the Stark Infra API by its id + Receive a single PixKey.Log object previously created by the Stark Infra API by its id ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - PixKey.Log struct with updated attributes + - PixKey.Log object that corresponds to the given id. """ @spec get( id: binary, @@ -74,19 +74,19 @@ defmodule StarkInfra.PixKey.Log do end @doc """ - Receive a stream of PixKey.Log structs previously created in the Stark Infra API + Receive a stream of PixKey.Log objects previously created in the Stark Infra API - ## Options: - - `:ids` [list of strings, default nil]: Log ids to filter PixKey Logs. ex: ["5656565656565656"] - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after specified date. ex: ~D[2020, 3, 10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020, 3, 10] - - `:types` [list of strings, default nil]: filter retrieved structs by types. ex: ["created"] or ["failed"] - - `:key_ids` [list of strings, default nil]: list of PixKey IDs to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created after specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020, 3, 10] + - `:types` [list of binaries, default nil]: filter retrieved objects by types. ex: ["created", "registered", "updated", "failed", "canceling", "canceled"] + - `:key_ids` [list of binaries, default nil]: list of PixKey IDs to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: Log ids to filter PixKey Logs. ex: ["5656565656565656"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of PixKey.Log structs with updated attributes + - stream of PixKey.Log objects with updated attributes """ @spec query( ids: [binary] | nil, @@ -107,12 +107,12 @@ defmodule StarkInfra.PixKey.Log do Same as query(), but it will unwrap the error tuple and raise in case of errors. """ @spec query!( - ids: [binary] | nil, limit: integer | nil, after: Date.t() | binary | nil, before: Date.t() | binary | nil, types: [binary] | nil, key_ids: [binary] | nil, + ids: [binary] | nil, user: Project.t() | Organization.t() | nil ) :: {binary, [Log.t()]} def query!(options \\ []) do @@ -120,31 +120,31 @@ defmodule StarkInfra.PixKey.Log do end @doc """ - Receive a list of up to 100 PixKey.Log structs previously created in the Stark Infra API and the cursor to the next page. + Receive a list of up to 100 PixKey.Log objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your keys. - ## Options: + ## Parameters (optional): - `:cursor` [binary, default nil]: cursor returned on the previous page function call - - `:ids` [list of strings, default nil]: Log ids to filter PixKey Logs. ex: ["5656565656565656"] - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Max = 100. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after a specified date. ex: ~D[2020, 3, 10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020, 3, 10] - - `:types` [list of strings, default nil]: filter retrieved structs by types. ex: ["created"] or ["failed"] - - `:key_ids` [list of strings, default nil]: list of PixKey IDs to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created after a specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020, 3, 10] + - `:types` [list of binaries, default nil]: filter retrieved objects by types. ex: ["created", "registered", "updated", "failed", "canceling", "canceled"] + - `:key_ids` [list of binaries, default nil]: list of PixKey IDs to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:ids` [list of binaries, default nil]: Log ids to filter PixKey Logs. ex: ["5656565656565656"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of PixKey.Log structs with updated attributes + - list of PixKey.Log objects with updated attributes - cursor to retrieve the next page of PixKey.Log objects """ @spec page( cursor: binary | nil, - ids: [binary] | nil, limit: integer | nil, after: Date.t() | binary | nil, before: Date.t() | binary | nil, types: [binary] | nil, key_ids: [binary] | nil, + ids: [binary] | nil, user: Project.t() | Organization.t() | nil ) :: {:ok, {binary, [Log.t()]}} | @@ -158,12 +158,12 @@ defmodule StarkInfra.PixKey.Log do """ @spec page!( cursor: binary | nil, - ids: [binary] | nil, limit: integer | nil, after: Date.t() | binary | nil, before: Date.t() | binary | nil, types: [binary] | nil, key_ids: [binary] | nil, + ids: [binary] | nil, user: Project.t() | Organization.t() | nil ) :: {binary, [Log.t()]} def page!(options \\ []) do @@ -181,10 +181,10 @@ defmodule StarkInfra.PixKey.Log do def resource_maker(json) do %Log{ id: json[:id], - type: json[:type], - created: json[:created] |> Check.datetime(), key: json[:key] |> API.from_api_json(&PixKey.resource_maker/1), + type: json[:type], errors: json[:errors], + created: json[:created] |> Check.datetime(), } end end diff --git a/lib/pix_request/pix_request.ex b/lib/pix_request/pix_request.ex index a313bd1..2faa15b 100644 --- a/lib/pix_request/pix_request.ex +++ b/lib/pix_request/pix_request.ex @@ -14,43 +14,46 @@ defmodule StarkInfra.PixRequest do @doc """ PixRequests are used to receive or send instant payments to accounts hosted in any Pix participant. + When you initialize a PixRequest, the entity will not be automatically - created in the Stark Infra API. The 'create' function sends the structs - to the Stark Infra API and returns the list of created structs. + created in the Stark Infra API. The 'create' function sends the objects + to the Stark Infra API and returns the list of created objects. ## Parameters (required): - `:amount` [integer]: amount in cents to be transferred. ex: 11234 (= R$ 112.34) - - `:external_id` [string]: string that must be unique among all your PixRequests. Duplicated external IDs will cause failures. By default, this parameter will block any PixRequests that repeats amount and receiver information on the same date. ex: "my-internal-id-123456" - - `:sender_name` [string]: sender's full name. ex: "Edward Stark" - - `:sender_tax_id` [string]: sender's tax ID (CPF or CNPJ) with or without formatting. ex: "01234567890" or "20.018.183/0001-80" - - `:sender_branch_code` [string]: sender's bank account branch code. Use '-' in case there is a verifier digit. ex: "1357-9" - - `:sender_account_number` [string]: sender's bank account number. Use '-' before the verifier digit. ex: "876543-2" - - `:sender_account_type` [string, default "checking"]: sender's bank account type. ex: "checking", "savings", "salary" or "payment" - - `:receiver_name` [string]: receiver's full name. ex: "Edward Stark" - - `:receiver_tax_id` [string]: receiver's tax ID (CPF or CNPJ) with or without formatting. ex: "01234567890" or "20.018.183/0001-80" - - `:receiver_bank_code` [string]: receiver's bank institution code in Brazil. ex: "20018183" - - `:receiver_account_number` [string]: receiver's bank account number. Use '-' before the verifier digit. ex: "876543-2" - - `:receiver_branch_code` [string]: receiver's bank account branch code. Use '-' in case there is a verifier digit. ex: "1357-9" - - `:receiver_account_type` [string]: receiver's bank account type. ex: "checking", "savings", "salary" or "payment" - - `:end_to_end_id` [string]: central bank's unique transaction ID. ex: "E79457883202101262140HHX553UPqeq" + - `:external_id` [binary]: binary that must be unique among all your PixRequests. Duplicated external IDs will cause failures. By default, this parameter will block any PixRequests that repeats amount and receiver information on the same date. ex: "my-internal-id-123456" + - `:sender_name` [binary]: sender's full name. ex: "Edward Stark" + - `:sender_tax_id` [binary]: sender's tax ID (CPF or CNPJ) with or without formatting. ex: "01234567890" or "20.018.183/0001-80" + - `:sender_branch_code` [binary]: sender's bank account branch code. Use '-' in case there is a verifier digit. ex: "1357-9" + - `:sender_account_number` [binary]: sender's bank account number. Use '-' before the verifier digit. ex: "876543-2" + - `:sender_account_type` [binary]: sender's bank account type. ex: "checking", "savings", "salary" or "payment" + - `:receiver_name` [binary]: receiver's full name. ex: "Edward Stark" + - `:receiver_tax_id` [binary]: receiver's tax ID (CPF or CNPJ) with or without formatting. ex: "01234567890" or "20.018.183/0001-80" + - `:receiver_bank_code` [binary]: receiver's bank institution code in Brazil. ex: "20018183" + - `:receiver_account_number` [binary]: receiver's bank account number. Use '-' before the verifier digit. ex: "876543-2" + - `:receiver_branch_code` [binary]: receiver's bank account branch code. Use '-' in case there is a verifier digit. ex: "1357-9" + - `:receiver_account_type` [binary]: receiver's bank account type. ex: "checking", "savings", "salary" or "payment" + - `:end_to_end_id` [binary]: central bank's unique transaction ID. ex: "E79457883202101262140HHX553UPqeq" + + ## Parameters (conditionally-required): + - `:cashier_type` [binary]: Cashier's type. Required if the cash_amount is different from 0. ex: "merchant", "participant" and "other" + - `:cashier_bank_code` [binary]: Cashier's bank code. Required if the cash_amount is different from 0. ex: "20018183" ## Parameters (optional): - - `:receiver_key_id` [string, default nil]: receiver's dict key. ex: "20.018.183/0001-80" - - `:description` [string, default nil]: optional description to override default description to be shown in the bank statement. ex: "Payment for service #1234" - - `:reconciliation_id` [string, default nil]: Reconciliation ID linked to this payment. ex: "b77f5236-7ab9-4487-9f95-66ee6eaf1781" - - `:initiator_tax_id` [string, default nil]: Payment initiator's tax id (CPF/CNPJ). ex: "01234567890" or "20.018.183/0001-80" - `:cash_amount` [integer, default nil]: Amount to be withdrawal from the cashier in cents. ex: 1000 (= R$ 10.00) - - `:cashier_bank_code` [string, default nil]: Cashier's bank code. ex: "00000000" - - `:cashier_type` [string, default nil]: Cashier's type. ex: [merchant, other, participant] - - `:tags` [list of strings, default nil]: list of strings for reference when searching for PixRequests. ex: ["employees", "monthly"] - - `:method` [string, default nil]: execution method for thr creation of the PIX. ex: "manual", "payerQrcode", "dynamicQrcode". + - `:receiver_key_id` [binary, default nil]: receiver's dict key. ex: "20.018.183/0001-80" + - `:description` [binary, default nil]: optional description to override default description to be shown in the bank statement. ex: "Payment for service #1234" + - `:reconciliation_id` [binary, default nil]: Reconciliation ID linked to this payment. ex: "b77f5236-7ab9-4487-9f95-66ee6eaf1781" + - `:initiator_tax_id` [binary, default nil]: Payment initiator's tax id (CPF/CNPJ). ex: "01234567890" or "20.018.183/0001-80" + - `:tags` [list of binaries, default nil]: list of binaries for reference when searching for PixRequests. ex: ["employees", "monthly"] + - `:method` [binary, default nil]: execution method for thr creation of the PIX. ex: "manual", "payerQrcode", "dynamicQrcode". ## Attributes (return-only): - - `:id` [string]: unique id returned when the PixRequest is created. ex: "5656565656565656" + - `:id` [binary]: unique id returned when the PixRequest is created. ex: "5656565656565656" - `:fee` [integer]: fee charged when PixRequest is paid. ex: 200 (= R$ 2.00) - - `:status` [string]: current PixRequest status. Options: “created”, “processing”, “success”, “failed” - - `:flow` [string]: direction of money flow. ex: "in" or "out" - - `:sender_bank_code` [string]: sender's bank institution code in Brazil. ex: "20018183" + - `:status` [binary]: current PixRequest status. ex: “created”, “processing”, “success”, “failed” + - `:flow` [binary]: direction of money flow. ex: "in" or "out" + - `:sender_bank_code` [binary]: sender's bank institution code in Brazil. ex: "20018183" - `:created` [DateTime]: creation datetime for the PixRequest. ex: ~U[2020-03-10 10:30:0:0] - `:updated` [DateTime]: latest update datetime for the PixRequest. ex: ~U[2020-03-10 10:30:0:0] """ @@ -107,16 +110,16 @@ defmodule StarkInfra.PixRequest do @type t() :: %__MODULE__{} @doc """ - Send a list of PixRequest structs for creation in the Stark Infra API + Send a list of PixRequest objects for creation in the Stark Infra API ## Parameters (required): - - `:requests` [list of PixRequest structs]: list of PixRequest structs to be created in the API + - `:requests` [list of PixRequest objects]: list of PixRequest objects to be created in the API - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of PixRequest structs with updated attributes + - list of PixRequest objects with updated attributes """ @spec create( [PixRequest.t() | map()], @@ -148,16 +151,16 @@ defmodule StarkInfra.PixRequest do end @doc """ - Receive a single PixRequest struct previously created in the Stark Infra API by its id + Receive a single PixRequest object previously created in the Stark Infra API by its id ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - PixRequest struct with updated attributes + - PixRequest object that corresponds to the given id. """ @spec get( id: binary, @@ -189,21 +192,21 @@ defmodule StarkInfra.PixRequest do end @doc """ - Receive a stream of PixRequest structs previously created in the Stark Infra API - - ## Options: - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after a specified date. ex: ~D[2020, 3, 10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020, 3, 10] - - `:status` [list of strings, default nil]: filter for status of retrieved structs. Options: “created”, “processing”, “success”, “failed” - - `:tags` [list of strings, default nil]: tags to filter retrieved structs. ex: ["tony", "stark"] - - `:ids` [list of strings, default nil]: list of ids to filter retrieved structs. ex: ["5656565656565656", "4545454545454545"] - - `:end_to_end_ids` [list of strings, default nil]: central bank's unique transaction IDs. ex: ["E79457883202101262140HHX553UPqeq", "E79457883202101262140HHX553UPxzx"] - - `:external_ids` [list of strings, default nil]: url safe strings that must be unique among all your PixRequests. Duplicated external IDs will cause failures. By default, this parameter will block any PixRequests that repeats amount and receiver information on the same date. ex: ["my-internal-id-123456", "my-internal-id-654321"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + Receive a stream of PixRequest objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created after a specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020, 3, 10] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. ex: “created”, “processing”, “success”, “failed” + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:end_to_end_ids` [list of binaries, default nil]: central bank's unique transaction IDs. ex: ["E79457883202101262140HHX553UPqeq", "E79457883202101262140HHX553UPxzx"] + - `:external_ids` [list of binaries, default nil]: url safe binaries that must be unique among all your PixRequests. Duplicated external IDs will cause failures. By default, this parameter will block any PixRequests that repeats amount and receiver information on the same date. ex: ["my-internal-id-123456", "my-internal-id-654321"] + - `:tags` [list of binaries, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of PixRequest structs with updated attributes + - stream of PixRequest objects with updated attributes """ @spec query( limit: integer, @@ -247,24 +250,24 @@ defmodule StarkInfra.PixRequest do end @doc """ - Receive a list of up to 100 PixRequest structs previously created in the Stark Infra API and the cursor to the next page. + Receive a list of up to 100 PixRequest objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your requests. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Max = 100. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after a specified date. ex: ~D[2020, 3, 10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020, 3, 10] - - `:status` [list of strings, default nil]: filter for status of retrieved structs. Options: “created”, “processing”, “success”, “failed” - - `:tags` [list of strings, default nil]: tags to filter retrieved structs. ex: ["tony", "stark"] - - `:ids` [list of strings, default nil]: list of ids to filter retrieved structs. ex: ["5656565656565656", "4545454545454545"] - - `:end_to_end_ids` [list of strings, default nil]: central bank's unique transaction IDs. ex: ["E79457883202101262140HHX553UPqeq", "E79457883202101262140HHX553UPxzx"] - - `:external_ids` [list of strings, default nil]: url safe strings that must be unique among all your PixRequests. Duplicated external IDs will cause failures. By default, this parameter will block any PixRequests that repeats amount and receiver information on the same date. ex: ["my-internal-id-123456", "my-internal-id-654321"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created after a specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020, 3, 10] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. ex: “created”, “processing”, “success”, “failed” + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:end_to_end_ids` [list of binaries, default nil]: central bank's unique transaction IDs. ex: ["E79457883202101262140HHX553UPqeq", "E79457883202101262140HHX553UPxzx"] + - `:external_ids` [list of binaries, default nil]: url safe binaries that must be unique among all your PixRequests. Duplicated external IDs will cause failures. By default, this parameter will block any PixRequests that repeats amount and receiver information on the same date. ex: ["my-internal-id-123456", "my-internal-id-654321"] + - `:tags` [list of binaries, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of PixRequest structs with updated attributes - - cursor to retrieve the next page of PixRequest structs + - list of PixRequest objects with updated attributes + - cursor to retrieve the next page of PixRequest objects """ @spec page( cursor: binary, @@ -310,17 +313,17 @@ defmodule StarkInfra.PixRequest do end @doc """ - Create a single PixRequest struct from a content string received from a handler listening at the request url. + Create a single PixRequest object from a content binary received from a handler listening at the request url. If the provided digital signature does not check out with the StarkInfra public key, a starkinfra.error.InvalidSignatureError will be raised. ## Parameters (required): - - `:content` [string]: response content from request received at user endpoint (not parsed) - - `:signature` [string]: base-64 digital signature received at response header "Digital-Signature" + - `:content` [binary]: response content from request received at user endpoint (not parsed) + - `:signature` [binary]: base-64 digital signature received at response header "Digital-Signature" - ## Options: - - `cache_pid` [PID, default nil]: PID of the process that holds the public key cache, returned on previous parses. If not provided, a new cache process will be generated. - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cache_pid` [PID, default nil]: PID of the process that holds the public key cache, returned on previous parses. If not provided, a new cache process will be generated. + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - Parsed PixRequest object @@ -374,6 +377,33 @@ defmodule StarkInfra.PixRequest do ) end + @doc """ + + Helps you respond to a PixRequest authorizatio + + ## Parameters (required): + - `:status` [binary]: response to the authorization. ex: "approved" or "denied + + ## Parameters (conditionally required): + - `:reason` [binary, default nil]: denial reason. Required if the status is "denied". Options: "invalidAccountNumber", "blockedAccount", "accountClosed", "invalidAccountType", "invalidTransactionType", "taxIdMismatch", "invalidTaxId", "orderRejected", "reversalTimeExpired", "settlementFailed" + + ## Return: + - Dumped JSON binary that must be returned to us + """ + + @spec response( + map(), + user: Project.t() | Organization.t() | nil + ) :: + {:ok, PixRequest.t()} | + {:error, [Error.t()]} + def response(status, reason) do + body = %{status: status, reason: reason} + params = %{authorization: body} + params + |> Jason.encode! + end + @doc false def resource() do { diff --git a/lib/pix_request/pix_request_log.ex b/lib/pix_request/pix_request_log.ex index bb3538c..208225a 100644 --- a/lib/pix_request/pix_request_log.ex +++ b/lib/pix_request/pix_request_log.ex @@ -16,41 +16,41 @@ defmodule StarkInfra.PixRequest.Log do Every time a PixRequest entity is modified, a corresponding PixRequest.Log is generated for the entity. This log is never generated by the user. - ## Attributes: - - `:id` [string]: unique id returned when the log is created. ex: "5656565656565656" + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the log is created. ex: "5656565656565656" + - `:request` [PixRequest object]: PixRequest entity to which the log refers to. + - `:type` [binary]: type of the PixRequest event which triggered the log creation. ex: “sent”, “denied”, “failed”, “created”, “success”, “approved”, “credited”, “refunded”, “processing”. + - `:errors` [list of binaries]: list of errors linked to this PixRequest event - `:created` [DateTime]: creation datetime for the log. ex: ~U[2020-3-10 10:30:0:0] - - `:type` [string]: type of the PixRequest event which triggered the log creation. Options: “sent”, “denied”, “failed”, “created”, “success”, “approved”, “credited”, “refunded”, “processing”. - - `:errors` [list of strings]: list of errors linked to this PixRequest event - - `:request` [PixRequest]: PixRequest entity to which the log refers to. """ @enforce_keys [ :id, - :created, + :request, :type, :errors, - :request + :created, ] defstruct [ :id, - :created, + :request, :type, :errors, - :request + :created, ] @type t() :: %__MODULE__{} @doc """ - Receive a single PixRequest.Log struct previously created by the Stark Infra API by its id + Receive a single PixRequest.Log object previously created by the Stark Infra API by its id ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - PixRequest.Log struct with updated attributes + - PixRequest.Log object that corresponds to the given id. """ @spec get( id: binary, @@ -74,19 +74,19 @@ defmodule StarkInfra.PixRequest.Log do end @doc """ - Receive a stream of PixRequest.Log structs previously created in the Stark Infra API + Receive a stream of PixRequest.Log objects previously created in the Stark Infra API - ## Options: - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after a specified date. ex: ~D[2020, 3, 10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020, 3, 10] - - `:types` [list of strings, default nil]: filter retrieved structs by types. Options: "sent", "denied", "failed", "created", "success", "approved", "credited", "refunded", "processing". - - `:request_ids` [list of strings, default nil]: list of PixRequest ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] - - `:reconciliation_id` [string]: PixRequest reconciliation id to filter retrieved objects. ex: "b77f5236-7ab9-4487-9f95-66ee6eaf1781" - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created after a specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020, 3, 10] + - `:types` [list of binaries, default nil]: filter retrieved objects by types. Options: "sent", "denied", "failed", "created", "success", "approved", "credited", "refunded", "processing". + - `:request_ids` [list of binaries, default nil]: list of PixRequest ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:reconciliation_id` [binary]: PixRequest reconciliation id to filter retrieved objects. ex: "b77f5236-7ab9-4487-9f95-66ee6eaf1781" + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of PixRequest.Log structs with updated attributes + - stream of PixRequest.Log objects with updated attributes """ @spec query( limit: integer, @@ -120,21 +120,21 @@ defmodule StarkInfra.PixRequest.Log do end @doc """ - Receive a list of up to 100 PixRequest.Log structs previously created in the Stark Infra API and the cursor to the next page. + Receive a list of up to 100 PixRequest.Log objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your requests. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Max = 100. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after a specified date. ex: ~D[2020, 3, 10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020, 3, 10] - - `:types` [list of strings, default nil]: filter retrieved structs by types. Options: “sent”, “denied”, “failed”, “created”, “success”, “approved”, “credited”, “refunded”, “processing”. - - `:request_ids` [list of strings, default nil]: list of PixRequest IDs to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] - - `:reconciliation_id` [string]: PixRequest reconciliation id to filter retrieved objects. ex: "b77f5236-7ab9-4487-9f95-66ee6eaf1781" - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created after a specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020, 3, 10] + - `:types` [list of binaries, default nil]: filter retrieved objects by types. Options: “sent”, “denied”, “failed”, “created”, “success”, “approved”, “credited”, “refunded”, “processing”. + - `:request_ids` [list of binaries, default nil]: list of PixRequest IDs to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:reconciliation_id` [binary]: PixRequest reconciliation id to filter retrieved objects. ex: "b77f5236-7ab9-4487-9f95-66ee6eaf1781" + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of PixRequest.Log structs with updated attributes + - list of PixRequest.Log objects with updated attributes - cursor to retrieve the next page of PixRequest.Log objects """ @spec page( @@ -182,10 +182,10 @@ defmodule StarkInfra.PixRequest.Log do def resource_maker(json) do %Log{ id: json[:id], - created: json[:created] |> Check.datetime(), + request: json[:request] |> API.from_api_json(&PixRequest.resource_maker/1), type: json[:type], errors: json[:errors], - request: json[:request] |> API.from_api_json(&PixRequest.resource_maker/1), + created: json[:created] |> Check.datetime(), } end end diff --git a/lib/pix_reversal/pix_reversal.ex b/lib/pix_reversal/pix_reversal.ex index 65255b9..61587aa 100644 --- a/lib/pix_reversal/pix_reversal.ex +++ b/lib/pix_reversal/pix_reversal.ex @@ -13,26 +13,26 @@ defmodule StarkInfra.PixReversal do @doc """ PixReversals are instant payments used to revert PixReversals. You can only revert inbound PixReversals. + When you initialize a PixReversal, the entity will not be automatically created in the Stark Infra API. The 'create' function sends the objects to the Stark Infra API and returns the list of created objects. ## Parameters (required): - `:amount` [integer]: amount in cents to be reversed from the PixReversal. ex: 1234 (= R$ 12.34) - - `:external_id` [string]: string that must be unique among all your PixReversals. Duplicated external IDs will cause failures. By default, this parameter will block any PixReversal that repeats amount and receiver information on the same date. ex: "my-internal-id-123456" - - `:end_to_end_id` [string]: central bank's unique transaction ID. ex: "E79457883202101262140HHX553UPqeq" - - `:reason` [string]: reason why the PixReversal is being reversed. Options are "bankError", "fraud", "chashierError", "customerRequest" + - `:external_id` [binary]: binary that must be unique among all your PixReversals. Duplicated external IDs will cause failures. By default, this parameter will block any PixReversal that repeats amount and receiver information on the same date. ex: "my-internal-id-123456" + - `:end_to_end_id` [binary]: central bank's unique transaction ID. ex: "E79457883202101262140HHX553UPqeq" + - `:reason` [binary]: reason why the PixReversal is being reversed. Options are "bankError", "fraud", "cashierError", "customerRequest" ## Parameters (optional): - - `:tags` [list of strings, default nil]: list of strings for reference when searching for PixReversals. ex: ["employees", "monthly"] + - `:tags` [list of binaries, default nil]: list of binaries for reference when searching for PixReversals. ex: ["employees", "monthly"] ## Attributes (return-only): - - `:id` [string]: unique id returned when the PixReversal is created. ex: "5656565656565656". - - `:return_id` [string]: central bank's unique reversal transaction ID. ex: "D20018183202202030109X3OoBHG74wo". - - `:bank_code` [string]: code of the bank institution in Brazil. ex: "20018183" - - `:fee` [string]: fee charged by this PixReversal. ex: 200 (= R$ 2.00) - - `:status` [string]: current PixReversal status. ex: "registered" or "paid" - - `:flow` [string]: direction of money flow. ex: "in" or "out" + - `:id` [binary]: unique id returned when the PixReversal is created. ex: "5656565656565656". + - `:return_id` [binary]: central bank's unique reversal transaction ID. ex: "D20018183202202030109X3OoBHG74wo". + - `:fee` [binary]: fee charged by this PixReversal. ex: 200 (= R$ 2.00) + - `:status` [binary]: current PixReversal status. ex: "created", "processing", "success", "failed" + - `:flow` [binary]: direction of money flow. ex: "in" or "out" - `:created` [DateTime]: creation datetime for the PixReversal. ex: ~U[2020-03-10 10:30:0:0] - `:updated` [DateTime]: latest update datetime for the PixReversal. ex: ~U[2020-03-10 10:30:0:0] """ @@ -49,7 +49,6 @@ defmodule StarkInfra.PixReversal do :reason, :id, :return_id, - :bank_code, :fee, :status, :flow, @@ -61,16 +60,16 @@ defmodule StarkInfra.PixReversal do @type t() :: %__MODULE__{} @doc """ - Send a list of PixReversal structs for creation in the Stark Infra API + Send a list of PixReversal objects for creation in the Stark Infra API ## Parameters (required): - - `:reversals` [list of PixReversal objects]: list of PixReversal structs to be created in the API + - `:reversals` [list of PixReversal objects]: list of PixReversal objects to be created in the API - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of PixReversal structs with updated attributes + - list of PixReversal objects with updated attributes """ @spec create( [PixReversal.t() | map()], @@ -78,10 +77,10 @@ defmodule StarkInfra.PixReversal do ) :: {:ok, [PixReversal.t()]} | {:error, [error: Error.t()]} - def create(keys, options \\ []) do + def create(reversals, options \\ []) do Rest.post( resource(), - keys, + reversals, options ) end @@ -95,25 +94,25 @@ defmodule StarkInfra.PixReversal do ) :: {:ok, [PixReversal.t()]} | {:error, [error: Error.t()]} - def create!(keys, options \\ []) do + def create!(reversals, options \\ []) do Rest.post!( resource(), - keys, + reversals, options ) end @doc """ - Receive a single PixReversal struct previously created in the Stark Infra API by its id + Receive a single PixReversal object previously created in the Stark Infra API by its id ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - PixReversal struct with updated attributes + - PixReversal object that corresponds to the given id. """ @spec get( id: binary, @@ -147,21 +146,21 @@ defmodule StarkInfra.PixReversal do end @doc """ - Receive a stream of PixReversal structs previously created in the Stark Infra API - - ## Options: - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after a specified date. ex: ~D[2020, 3, 10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020, 3, 10] - - `:status` [list of strings, default nil]: filter for status of retrieved objects. Options: “created”, “processing”, “success”, “failed” - - `:tags` [list of strings, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] - - `:ids` [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] - - `:return_ids` [list of strings, default nil]: central bank's unique reversal transaction IDs. ex: ["D20018183202202030109X3OoBHG74wo", "D20018183202202030109X3OoBHG72rd"]. - - `:external_ids` [list of strings, default nil]: url safe strings that must be unique among all your PixReversals. Duplicated external IDs will cause failures. By default, this parameter will block any PixReversal that repeats amount and receiver information on the same date. ex: ["my-internal-id-123456", "my-internal-id-654321"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + Receive a stream of PixReversal objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created after a specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020, 3, 10] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. ex: “created”, “processing”, “success”, “failed” + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:return_ids` [list of binaries, default nil]: central bank's unique reversal transaction IDs. ex: ["D20018183202202030109X3OoBHG74wo", "D20018183202202030109X3OoBHG72rd"]. + - `:external_ids` [list of binaries, default nil]: url safe binaries that must be unique among all your PixReversals. Duplicated external IDs will cause failures. By default, this parameter will block any PixReversal that repeats amount and receiver information on the same date. ex: ["my-internal-id-123456", "my-internal-id-654321"] + - `:tags` [list of binaries, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of PixReversal structs with updated attributes + - stream of PixReversal objects with updated attributes """ @spec query( limit: integer, @@ -207,23 +206,23 @@ defmodule StarkInfra.PixReversal do end @doc """ - Receive a list of up to 100 PixReversal structs previously created in the Stark Infra API and the cursor to the next page. + Receive a list of up to 100 PixReversal objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your reversals. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Max = 100. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after a specified date. ex: ~D[2020, 3, 10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020, 3, 10] - - `:status` [list of strings, default nil]: filter for status of retrieved objects. Options: “created”, “processing”, “success”, “failed” - - `:tags` [list of strings, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] - - `:ids` [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] - - `:return_ids` [list of strings, default nil]: central bank's unique reversal transaction ID. ex: ["D20018183202202030109X3OoBHG74wo", "D20018183202202030109X3OoBHG72rd"]. - - `:external_ids` [list of strings, default nil]: url safe string that must be unique among all your PixReversals. Duplicated external IDs will cause failures. By default, this parameter will block any PixReversal that repeats amount and receiver information on the same date. ex: ["my-internal-id-123456", "my-internal-id-654321"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created after a specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020, 3, 10] + - `:status` [list of binaries, default nil]: filter for status of retrieved objects. ex: “created”, “processing”, “success”, “failed” + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:return_ids` [list of binaries, default nil]: central bank's unique reversal transaction ID. ex: ["D20018183202202030109X3OoBHG74wo", "D20018183202202030109X3OoBHG72rd"]. + - `:external_ids` [list of binaries, default nil]: url safe binary that must be unique among all your PixReversals. Duplicated external IDs will cause failures. By default, this parameter will block any PixReversal that repeats amount and receiver information on the same date. ex: ["my-internal-id-123456", "my-internal-id-654321"] + - `:tags` [list of binaries, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of PixReversal structs with updated attributes + - list of PixReversal objects with updated attributes - cursor to retrieve the next page of PixReversal objects """ @spec page( @@ -272,17 +271,17 @@ defmodule StarkInfra.PixReversal do end @doc """ - Create a single PixReversal struct from a content string received from a handler listening at the request url. + Create a single PixReversal object from a content binary received from a handler listening at the request url. If the provided digital signature does not check out with the StarkInfra public key, a starkinfra.error.InvalidSignatureError will be raised. ## Parameters (required): - - `:content` [string]: response content from request received at user endpoint (not parsed) - - `:signature` [string]: base-64 digital signature received at response header "Digital-Signature" + - `:content` [binary]: response content from request received at user endpoint (not parsed) + - `:signature` [binary]: base-64 digital signature received at response header "Digital-Signature" - ## Options: + ## Parameters (optional): - `cache_pid` [PID, default nil]: PID of the process that holds the public key cache, returned on previous parses. If not provided, a new cache process will be generated. - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - Parsed PixReversal object @@ -334,6 +333,33 @@ defmodule StarkInfra.PixReversal do resource_maker: &resource_maker/1, user: user ) + + end + + @doc """ + Helps you respond to a PixReversal authorization + + ## Parameters (required): + - `:status` [binary]: response to the authorization. ex: "approved" or "denied" + + ## Parameters (conditionally-required): + - `:reason` [binary, default nil]: denial reason. Required if the status is "denied". Options: "invalidAccountNumber", "blockedAccount", "accountClosed", "invalidAccountType", "invalidTransactionType", "taxIdMismatch", "invalidTaxId", "orderRejected", "reversalTimeExpired", "settlementFailed" + + ## Return: + - Dumped JSON binary that must be returned to us + """ + + @spec response( + map(), + user: Project.t() | Organization.t() | nil + ) :: + {:ok, PixReversal.t()} | + {:error, [Error.t()]} + def response(status, reason) do + body = %{status: status, reason: reason} + params = %{authorization: body} + params + |> Jason.encode! end @doc false @@ -347,19 +373,18 @@ defmodule StarkInfra.PixReversal do @doc false def resource_maker(json) do %PixReversal{ + id: json[:id], amount: json[:amount], external_id: json[:external_id], end_to_end_id: json[:end_to_end_id], reason: json[:reason], - id: json[:id], tags: json[:tags], return_id: json[:return_id], - bank_code: json[:bank_code], fee: json[:fee], status: json[:status], flow: json[:flow], - created: json[:created] |> Check.datetime(), - updated: json[:updated] |> Check.datetime() + created: json[:created] |> Check.datetime(), + updated: json[:updated] |> Check.datetime() } end end diff --git a/lib/pix_reversal/pix_reversal_log.ex b/lib/pix_reversal/pix_reversal_log.ex index f19a22c..ead1bdc 100644 --- a/lib/pix_reversal/pix_reversal_log.ex +++ b/lib/pix_reversal/pix_reversal_log.ex @@ -16,42 +16,42 @@ defmodule StarkInfra.PixReversal.Log do Every time a PixReversal entity is modified, a corresponding PixReversal.Log is generated for the entity. This log is never generated by the user. - ## Attributes: - - `:id` [string]: unique id returned when the log is created. ex: "5656565656565656" + ## Attributes (return-only): + - `:id` [binary]: unique id returned when the log is created. ex: "5656565656565656" + - `:reversal` [PixReversal object]: PixReversal entity to which the log refers to. + - `:type` [binary]: type of the PixReversal event which triggered the log creation. ex: "sent", "denied", "failed", "created", "success", "approved", "credited", "refunded", "processing" + - `:errors` [list of binaries]: list of errors linked to this PixReversal event - `:created` [DateTime]: creation datetime for the log. ex: ~U[2020-3-10 10:30:0:0] - - `:type` [string]: type of the PixReversal event which triggered the log creation. ex: "registered" or "paid" - - `:errors` [string]: list of errors linked to this PixReversal event - - `:reversal` [PixReversal struct]: PixReversal entity to which the log refers to. """ @enforce_keys [ :id, - :created, + :reversal, :type, :errors, - :reversal + :created, ] defstruct [ :id, - :created, + :reversal, :type, :errors, - :reversal + :created, ] @type t() :: %__MODULE__{} @doc """ - Receive a single PixReversal.Log struct previously created by the Stark Infra API by its id + Receive a single PixReversal.Log object previously created by the Stark Infra API by its id ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - PixReversal.Log struct with updated attributes + - PixReversal.Log object that corresponds to the given id. """ @spec get( binary, @@ -75,18 +75,18 @@ defmodule StarkInfra.PixReversal.Log do end @doc """ - Receive a stream of PixReversal.Log structs previously created in the Stark Infra API + Receive a stream of PixReversal.Log objects previously created in the Stark Infra API - ## Options: - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after specified date. ex: ~D[2020, 3, 10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020, 3, 10] - - `:types` [string], default nil]: filter retrieved structs by types. Options: "sent", "denied", "failed", "created", "success", "approved", "credited", "refunded", "processing". - - `:reversal_ids` [string], default nil]: list of PixReversal IDs to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created after specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020, 3, 10] + - `:types` [list of binaries], default nil]: filter retrieved objects by types. Options: "sent", "denied", "failed", "created", "success", "approved", "credited", "refunded", "processing". + - `:reversal_ids` [list of binaries], default nil]: list of PixReversal IDs to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of PixReversal.Log structs with updated attributes + - stream of PixReversal.Log objects with updated attributes """ @spec query( limit: integer, @@ -118,20 +118,20 @@ defmodule StarkInfra.PixReversal.Log do end @doc """ - Receive a list of up to 100 PixReversal.Log structs previously created in the Stark Infra API and the cursor to the next page. + Receive a list of up to 100 PixReversal.Log objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your reversals. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Max = 100. ex: 35 - - `:after` [Date or string, default nil]: date filter for structs created after a specified date. ex: ~D[2020, 3, 10] - - `:before` [Date or string, default nil]: date filter for structs created before a specified date. ex: ~D[2020, 3, 10] - - `:types` [string], default nil]: filter retrieved structs by types. Options: “sent”, “denied”, “failed”, “created”, “success”, “approved”, “credited”, “refunded”, “processing”. - - `:reversal_ids` [string], default nil]: list of PixReversal IDs to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created after a specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created before a specified date. ex: ~D[2020, 3, 10] + - `:types` [list of binaries], default nil]: filter retrieved objects by types. Options: “sent”, “denied”, “failed”, “created”, “success”, “approved”, “credited”, “refunded”, “processing”. + - `:reversal_ids` [list of binaries], default nil]: list of PixReversal IDs to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of PixReversal.Log structs with updated attributes + - list of PixReversal.Log objects with updated attributes - cursor to retrieve the next page of PixRequest.Log objects """ @spec page( @@ -177,10 +177,10 @@ defmodule StarkInfra.PixReversal.Log do def resource_maker(json) do %Log{ id: json[:id], - created: json[:created] |> Check.datetime(), + reversal: json[:reversal] |> API.from_api_json(&PixReversal.resource_maker/1), type: json[:type], errors: json[:errors], - reversal: json[:reversal] |> API.from_api_json(&PixReversal.resource_maker/1) + created: json[:created] |> Check.datetime(), } end end diff --git a/lib/pix_statement/pix_statement.ex b/lib/pix_statement/pix_statement.ex index bf47675..2a57873 100644 --- a/lib/pix_statement/pix_statement.ex +++ b/lib/pix_statement/pix_statement.ex @@ -11,22 +11,23 @@ defmodule StarkInfra.PixStatement do """ @doc """ - The PixStatement struct stores information about all the transactions that - happened on a specific day at your settlment account according to the Central Bank. + The PixStatement object stores information about all the transactions that + happened on a specific day at your settlement account according to the Central Bank. It must be created by the user before it can be accessed. This feature is only available for direct participants. + When you initialize a PixStatement, the entity will not be automatically - created in the Stark Infra API. The 'create' function sends the structs - to the Stark Infra API and returns the created struct. + created in the Stark Infra API. The 'create' function sends the objects + to the Stark Infra API and returns the created object. ## Parameters (required): - `:after` [Date]: transactions that happened at this date are stored in the PixStatement, must be the same as before. ex: ~D[2020, 3, 10] - `:before` [Date]: transactions that happened at this date are stored in the PixStatement, must be the same as after. ex: ~D[2020, 3, 10] - - `:type` [string]: types of entities to include in statement. Options: ["interchange", "interchangeTotal", "transaction"] + - `:type` [binary]: types of entities to include in statement. ex: ["interchange", "interchangeTotal", "transaction"] ## Attributes (return-only): - - `:id` [string]: unique id returned when the PixStatement is created. ex: "5656565656565656" - - `:status` [string]: current PixStatement status. ex: ["success", "failed"] + - `:id` [binary]: unique id returned when the PixStatement is created. ex: "5656565656565656" + - `:status` [binary]: current PixStatement status. ex: ["success", "failed"] - `:transaction_count` [integer]: number of transactions that happened during the day that the PixStatement was requested. ex: 11 - `:created` [DateTime]: creation datetime for the PixStatement. ex: ~U[2020-03-10 10:30:0:0] - `:updated` [DateTime]: latest update datetime for the PixStatement. ex: ~U[2020-03-10 10:30:0:0] @@ -52,14 +53,14 @@ defmodule StarkInfra.PixStatement do @doc """ Create a PixStatement linked to your Workspace in the Stark Infra API - ## Options: - - `:statement` [PixStatement struct]: PixStatement struct to be created in the API. + ## Parameters (optional): + - `:statement` [PixStatement object]: PixStatement object to be created in the API. - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - PixStatement struct with updated attributes. + - PixStatement object with updated attributes. """ @spec create( PixStatement.t() | map(), @@ -93,16 +94,16 @@ defmodule StarkInfra.PixStatement do end @doc """ - Retrieve the PixStatement struct linked to your Workspace in the Stark Infra API by its id. + Retrieve the PixStatement object linked to your Workspace in the Stark Infra API by its id. ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - PixStatement struct that corresponds to the given id. + - PixStatement object that corresponds to the given id. """ @spec get( id: binary, @@ -128,15 +129,15 @@ defmodule StarkInfra.PixStatement do end @doc """ - Receive a stream of PixStatements structs previously created in the Stark Infra API + Receive a stream of PixStatement objects previously created in the Stark Infra API - ## Options: - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:ids` [list of strings, default nil]: list of ids to filter retrieved structs. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of PixStatement structs with updated attributes + - stream of PixStatement objects with updated attributes """ @spec query( limit: integer, @@ -164,17 +165,18 @@ defmodule StarkInfra.PixStatement do end @doc """ - Receive a list of up to 100 PixStatements structs previously created in the Stark Infra API + Receive a list of up to 100 PixStatement objects previously created in the Stark Infra API + Use this function instead of query if you want to manually page your statements. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Max = 100. ex: 35 - - `:ids` [list of strings, default nil]: list of ids to filter retrieved structs. ex: ["5656565656565656", "4545454545454545"] - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:ids` [list of binaries, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of PixStatement structs with updated attributes - - cursor to retrieve the next page of PixStatement structs + - list of PixStatement objects with updated attributes + - cursor to retrieve the next page of PixStatement objects """ @spec page( cursor: binary, @@ -204,13 +206,13 @@ defmodule StarkInfra.PixStatement do end @doc """ - Retrieve a specific PixStatement by its ID in a .csv file. + Retrieve a specific PixStatement by its id in a .csv file. ## Parameters (required): - - `:id` [string]: struct unique id. ex: "5656565656565656" + - `:id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - .zip file containing a PixStatement in .csv format diff --git a/lib/starkinfra.ex b/lib/starkinfra.ex index c3d867d..3f49b44 100644 --- a/lib/starkinfra.ex +++ b/lib/starkinfra.ex @@ -9,7 +9,7 @@ defmodule StarkInfra do alias StarkInfra.Utils.Check @doc """ - The Project struct is an authentication entity for the SDK that is permanently + The Project object is an authentication entity for the SDK that is permanently linked to a specific Workspace. All requests to the Stark Infra API must be authenticated via an SDK user, which must have been previously created at the Stark Infra website @@ -18,9 +18,9 @@ defmodule StarkInfra do each request or may be defined as the default user at the start (See README). ## Parameters (required): - - `:environment` [string]: environment where the project is being used. ex: "sandbox" or "production" - - `:id` [string]: unique id required to identify project. ex: "5656565656565656" - - `:private_key` [string]: PEM string of the private key linked to the project. ex: "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----" + - `:environment` [binary]: environment where the project is being used. ex: "sandbox" or "production" + - `:id` [binary]: unique id required to identify project. ex: "5656565656565656" + - `:private_key` [binary]: PEM binary of the private key linked to the project. ex: "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----" """ @spec project( environment: :production | :sandbox, @@ -38,7 +38,7 @@ defmodule StarkInfra do end @doc """ - The Organization struct is an authentication entity for the SDK that + The Organization object is an authentication entity for the SDK that represents your entire Organization, being able to access any Workspace underneath it and even create new Workspaces. Only a legal representative of your organization can register or change the Organization credentials. @@ -48,18 +48,18 @@ defmodule StarkInfra do before you can use it in this SDK. Organizations may be passed as the user parameter on each request or may be defined as the default user at the start (See README). If you are accessing a specific Workspace using Organization credentials, you should - specify the workspace ID when building the Organization struct or by request, using + specify the workspace ID when building the Organization object or by request, using the Organization.replace(organization, workspace_id) method, which creates a copy of the organization - struct with the altered workspace ID. If you are listing or creating new Workspaces, the + object with the altered workspace ID. If you are listing or creating new Workspaces, the workspace_id should be nil. ## Parameters (required): - - `:environment` [string]: environment where the organization is being used. ex: "sandbox" or "production" - - `:id` [string]: unique id required to identify organization. ex: "5656565656565656" - - `:private_key` [EllipticCurve.Organization()]: PEM string of the private key linked to the organization. ex: "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----" + - `:environment` [binary]: environment where the organization is being used. ex: "sandbox" or "production" + - `:id` [binary]: unique id required to identify organization. ex: "5656565656565656" + - `:private_key` [EllipticCurve.Organization()]: PEM binary of the private key linked to the organization. ex: "-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----" ## Parameters (optional): - - `:workspace_id` [string]: unique id of the accessed Workspace, if any. ex: nil or "4848484848484848" + - `:workspace_id` [binary]: unique id of the accessed Workspace, if any. ex: nil or "4848484848484848" """ @spec organization( environment: :production | :sandbox, diff --git a/lib/static_brcode/static_brcode.ex b/lib/static_brcode/static_brcode.ex new file mode 100644 index 0000000..203e5d8 --- /dev/null +++ b/lib/static_brcode/static_brcode.ex @@ -0,0 +1,269 @@ +defmodule StarkInfra.StaticBrcode do + alias __MODULE__, as: StaticBrcode + alias StarkInfra.Error + alias StarkInfra.Utils.Rest + alias StarkInfra.User.Project + alias StarkInfra.User.Organization + + @moduledoc """ + Groups StaticBrcode related functions + """ + + @doc """ + A StaticBrcode stores account information in the form of a PixKey and can be used to create + Pix transactions easily. + + When you initialize a StaticBrcode, the entity will not be automatically + created in the Stark Infra API. The 'create' function sends the objects + to the Stark Infra API and returns the created object. + + ## Parameters (required): + - `:name` [binary]: receiver's name. ex: "Tony Stark" + - `:key_id` [binary]: receiver's Pix key id. ex: "+5541999999999" + - `:city` [binary]: receiver's city name. ex: "Rio de Janeiro" + + ## Parameters (optional): + - `:amount` [integer, default 0]: positive integer that represents the amount in cents of the resulting Pix transaction. ex: 1234 (= R$ 12.34) + - `:reconciliation_id` [binary, default nil]: id to be used for conciliation of the resulting Pix transaction. This id must have up to 25 alphanumeric digits ex: "ah27s53agj6493hjds6836v49" + - `:tags` [list of binaries, default []]: list of binaries for tagging. ex: ["travel", "food"] + + ## Attributes (return-only): + - `:id` [binary]: id returned on creation, this is the BR Code. ex: "00020126360014br.gov.bcb.pix0114+552840092118152040000530398654040.095802BR5915Jamie Lannister6009Sao Paulo620705038566304FC6C" + - `:uuid` [binary]: unique uuid returned when a StaticBrcode is created. ex: "97756273400d42ce9086404fe10ea0d6" + - `:url` [binary]: url link to the BR Code image. ex: "https://brcode-h.development.starkinfra.com/static-qrcode/97756273400d42ce9086404fe10ea0d6.png" + - `:created` [DateTime]: creation DateTime for the StaticBrcode. ex: ~U[2020-3-10 10:30:0:0] + - `:updated` [DateTime]: latest update DateTime for the StaticBrcode. ex: ~U[2020-3-10 10:30:0:0] + """ + @enforce_keys [ + :name, + :key_id, + :city, + ] + defstruct [ + :name, + :key_id, + :city, + :amount, + :reconciliation_id, + :tags, + :id, + :uuid, + :url, + :created, + :updated + ] + + @type t() :: %__MODULE__{} + + @doc """ + Send a list of StaticBrcode objects for creation at the Stark Infra API + + ## Parameters (required): + - `:brcodes` [list of StaticBrcode objects]: list of StaticBrcode objects to be created in the API. + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of StaticBrcode objects with updated attributes + """ + @spec create( + [StaticBrcode.t() | map()], + user: Project.t() | Organization.t() | nil + ) :: + {:ok, [StaticBrcode.t()]} | + {:error, [Error.t()]} + def create(brcodes, options \\ []) do + Rest.post( + resource(), + brcodes, + options + ) + end + + @doc """ + Same as create(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec create!( + [StaticBrcode.t() | map()], + user: Project.t() | Organization.t() | nil + ) :: + {:ok, [StaticBrcode.t()]} | + {:error, [error: Error.t()]} + def create!(brcodes, options \\ []) do + Rest.post!( + resource(), + brcodes, + options + ) + end + + @doc """ + Same as create(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec create( + [StaticBrcode.t() | map()], + user: Project.t() | Organization.t() | nil + ) :: any + def create!(brcodes, options \\ []) do + Rest.post!( + resource(), + brcodes, + options + ) + end + + @doc """ + Receive a single StaticBrcode object previously created in the Stark Infra API by its uuid + + ## Parameters (required): + - `:uuid` [binary]: object's unique uuid. ex: "901e71f2447c43c886f58366a5432c4b" + + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - StaticBrcode object that corresponds to the given uuid. + """ + @spec get( + binary, + user: Project.t() | Organization.t() | nil + ) :: + {:ok, [StaticBrcode.t()]} | + {:error, [Error.t()]} + def get(uuid, options \\ []) do + Rest.get_id(resource(), uuid, options) + end + + @doc """ + Same as get(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec get!(binary, user: Project.t() | Organization.t() | nil) :: any + def get!(uuid, options \\ []) do + Rest.get_id!(resource(), uuid, options) + end + + @doc """ + Receive a stream of StaticBrcode objects previously created in the Stark Infra API + + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020, 3, 10] + - `:uuids` [list of binaries, default nil]: list of uuids to filter retrieved objects. ex: ["901e71f2447c43c886f58366a5432c4b", "4e2eab725ddd495f9c98ffd97440702d"] + - `:tags` [list of binaries, default nil]: list of tags to filter retrieved objects. ex: ["tony", "stark"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - stream of StaticBrcode objects with updated attributes + """ + @spec query( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + uuids: [binary], + tags: [binary], + user: Project.t() | Organization.t() | nil + ) :: + ({:cont, {:ok, [StaticBrcode.t()]}} | + {:error, [Error.t()]} | + {:halt, any} | + {:suspend, any}, + any -> any) + def query(options \\ []) do + Rest.get_list(resource(), options) + end + + @doc """ + Same as query(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec query!( + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + uuids: [binary], + tags: [binary], + user: Project.t() | Organization.t() | nil + ) :: + ({:cont, [StaticBrcode.t()]} | + {:error, [Error.t()]} | + {:halt, any} | + {:suspend, any}, + any -> any) + def query!(options \\ []) do + Rest.get_list!(resource(), options) + end + + @doc """ + Receive a list of StaticBrcode objects previously created in the Stark Infra API and the cursor to the next page. + + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:after` [Date or binary, default nil]: date filter for objects created only after specified date. ex: ~D[2020, 3, 10] + - `:before` [Date or binary, default nil]: date filter for objects created only before specified date. ex: ~D[2020, 3, 10] + - `:uuids` [list of binaries, default nil]: list of uuids to filter retrieved objects. ex: ["901e71f2447c43c886f58366a5432c4b", "4e2eab725ddd495f9c98ffd97440702d"] + - `:tags` [list of binaries, default []]: list of tags to filter retrieved objects. ex: ["tony", "stark"] + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + + ## Return: + - list of StaticBrcode objects with updated attributes + - cursor to retrieve the next page of StaticBrcode objects + """ + @spec page( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + uuids: [binary], + tags: [binary], + user: Project.t() | Organization.t() | nil + ) :: + {:ok, {binary, [StaticBrcode.t()]}} | + {:error, [Error.t()]} + def page(options \\ []) do + Rest.get_page(resource(), options) + end + + @doc """ + Same as page(), but it will unwrap the error tuple and raise in case of errors. + """ + @spec page!( + cursor: binary, + limit: integer, + after: Date.t() | binary, + before: Date.t() | binary, + uuids: [binary], + tags: [binary], + user: Project.t() | Organization.t() | nil + ) :: + [StaticBrcode.t()] + def page!(options \\ []) do + Rest.get_page!(resource(), options) + end + + @doc false + def resource() do + { + "StaticBrcode", + &resource_maker/1 + } + end + + @doc false + def resource_maker(json) do + %StaticBrcode{ + name: json[:name], + key_id: json[:key_id], + city: json[:city], + amount: json[:amount], + reconciliation_id: json[:reconciliation_id], + tags: json[:tags], + id: json[:id], + uuid: json[:uuid], + url: json[:url], + created: json[:created], + updated: json[:updated] + } + end +end diff --git a/lib/utils/api.ex b/lib/utils/api.ex index 6f42363..7358849 100644 --- a/lib/utils/api.ex +++ b/lib/utils/api.ex @@ -3,8 +3,8 @@ defmodule StarkInfra.Utils.API do alias StarkInfra.Utils.Case - def api_json(%{__struct__: _} = struct) do - struct + def api_json(%{__struct__: _} = object) do + object |> Map.from_struct() |> api_json() end @@ -14,8 +14,8 @@ defmodule StarkInfra.Utils.API do |> cast_json_to_api_format() end - def cast_json_to_api_format(struct) when is_struct(struct) do - struct + def cast_json_to_api_format(object) when is_struct(object) do + object |> Map.from_struct() |> cast_json_to_api_format() end @@ -57,8 +57,8 @@ defmodule StarkInfra.Utils.API do |> String.replace("Z", "+00:00") end - defp coerce_types(%{__struct__: _} = struct) do - api_json(struct) + defp coerce_types(%{__struct__: _} = object) do + api_json(object) end defp coerce_types(map) when is_map(map) do diff --git a/lib/utils/case.ex b/lib/utils/case.ex index db59b48..22bfd64 100644 --- a/lib/utils/case.ex +++ b/lib/utils/case.ex @@ -1,14 +1,14 @@ defmodule StarkInfra.Utils.Case do @moduledoc false - def camel_to_kebab(string) do - string + def camel_to_kebab(binary) do + binary |> camel_to_snake() |> String.replace("_", "-") end - def camel_to_snake(string) do - string + def camel_to_snake(binary) do + binary |> String.graphemes() |> camel_to_snake_graphemes() |> strip_underscore() @@ -36,12 +36,12 @@ defmodule StarkInfra.Utils.Case do rest end - defp strip_underscore(string) do - string + defp strip_underscore(binary) do + binary end - def snake_to_camel(string) do - string + def snake_to_camel(binary) do + binary |> String.graphemes() |> snake_to_camel_graphemes() |> Enum.join() diff --git a/lib/utils/checks.ex b/lib/utils/checks.ex index 230d3d9..45de223 100644 --- a/lib/utils/checks.ex +++ b/lib/utils/checks.ex @@ -61,7 +61,7 @@ defmodule StarkInfra.Utils.Check do :secp256k1 = parsed_key.curve.name parsed_key rescue - _e -> raise "private_key must be valid secp256k1 ECDSA string in pem format" + _e -> raise "private_key must be valid secp256k1 ECDSA binary in pem format" else parsed_key -> parsed_key end diff --git a/lib/utils/parse.ex b/lib/utils/parse.ex index e6f6521..f93c429 100644 --- a/lib/utils/parse.ex +++ b/lib/utils/parse.ex @@ -12,20 +12,20 @@ defmodule StarkInfra.Utils.Parse do @moduledoc false @doc """ - Create a single Event struct received from event listening at subscribed user endpoint. + Create a single Event object received from event listening at subscribed user endpoint. If the provided digital signature does not check out with the StarkInfra public key, an "invalidSignature" error will be returned. ## Parameters (required): - - `content` [string]: response content from request received at user endpoint (not parsed) - - `signature` [string]: base-64 digital signature received at response header "Digital-Signature" + - `:content` [binary]: response content from request received at user endpoint (not parsed) + - `:signature` [binary]: base-64 digital signature received at response header "Digital-Signature" - ## Options: - - `cache_pid` [PID, default nil]: PID of the process that holds the public key cache, returned on previous parses. If not provided, a new cache process will be generated. - - `user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cache_pid` [PID, default nil]: PID of the process that holds the public key cache, returned on previous parses. If not provided, a new cache process will be generated. + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - Event struct with updated attributes + - Event object with updated attributes - Cache PID that holds the Stark Infra public key in order to avoid unnecessary requests to the API on future parses """ @spec parse_and_verify( @@ -63,6 +63,23 @@ defmodule StarkInfra.Utils.Parse do end end + @spec verify( + content: binary, + signature: binary, + cache_pid: PID, + resource_maker: any, + user: Project.t() | Organization.t() + ) :: + {:ok, {Event.t(), binary}} | {:error, [Error.t()]} + def verify(parameters \\ []) do + parameters = + Enum.into( + parameters |> Check.enforced_keys([:content, :signature]), + %{cache_pid: nil, user: nil} + ) + Parse.verify_signature(parameters.user, parameters.content, parameters.signature, parameters.cache_pid, parameters.resource_maker, parameters.key, 0) + end + defp parse(user, content, signature, cache_pid, resource_maker, key, counter) when is_nil(cache_pid) do {:ok, new_cache_pid} = Agent.start_link(fn -> %{} end) parse(user, content, signature, new_cache_pid, resource_maker, key, counter) @@ -94,7 +111,7 @@ defmodule StarkInfra.Utils.Parse do ) end - defp verify_signature(_user, _content, _signature_base_64, _cache_pid, counter) + def verify_signature(_user, _content, _signature_base_64, _cache_pid, counter) when counter > 1 do { :error, @@ -107,7 +124,7 @@ defmodule StarkInfra.Utils.Parse do } end - defp verify_signature(user, content, signature_base_64, cache_pid, counter) + def verify_signature(user, content, signature_base_64, cache_pid, counter) when is_binary(signature_base_64) and counter <= 1 do try do signature_base_64 |> Signature.fromBase64!() @@ -132,7 +149,7 @@ defmodule StarkInfra.Utils.Parse do end end - defp verify_signature(user, content, signature, cache_pid, _counter) do + def verify_signature(user, content, signature, cache_pid, _counter) do case get_StarkInfra_public_key(user, cache_pid) do {:ok, public_key} -> { diff --git a/lib/webhook/webhook.ex b/lib/webhook/webhook.ex index caef63f..5bd75e3 100644 --- a/lib/webhook/webhook.ex +++ b/lib/webhook/webhook.ex @@ -12,14 +12,14 @@ defmodule StarkInfra.Webhook do @doc """ A Webhook is used to subscribe to notification events on a user-selected endpoint. - Currently available services for subscription are contract, credit-note, signer, issuing-card, issuing-invoice, issuing-purchase, pix-request.in, pix-request.out, pix-reversal.in, pix-reversal.out, pix-claim, pix-key, pix-chargeback, pix-infraction. + Currently available services for subscription are credit-note, issuing-card, issuing-invoice, issuing-purchase, pix-request.in, pix-request.out, pix-reversal.in, pix-reversal.out, pix-claim, pix-key, pix-chargeback, pix-infraction. ## Parameters (required): - - `:url` [string]: Url that will be notified when an event occurs. - - `:subscriptions` [list of strings]: list of any non-empty combination of the available services. ex: ["contract", "credit-note", "signer", "issuing-card", "issuing-invoice", "issuing-purchase", "pix-request.in", "pix-request.out", "pix-reversal.in", "pix-reversal.out", "pix-claim", "pix-key", "pix-chargeback", "pix-infraction"] + - `:url` [binary]: URL that will be notified when an event occurs. + - `:subscriptions` [list of binaries]: list of any non-empty combination of the available services. ex: ["contract", "credit-note", "signer", "issuing-card", "issuing-invoice", "issuing-purchase", "pix-request.in", "pix-request.out", "pix-reversal.in", "pix-reversal.out", "pix-claim", "pix-key", "pix-chargeback", "pix-infraction"] - ## Attributes: - - `:id` [string, default nil]: unique id returned when the webhook is created. ex: "5656565656565656" + ## Attributes (return-only): + - `:id` [binary, default nil]: unique id returned when the Webhook is created. ex: "5656565656565656" """ @enforce_keys [ :url, @@ -34,22 +34,22 @@ defmodule StarkInfra.Webhook do @type t() :: %__MODULE__{} @doc """ - Send a single Webhook subscription for creation in the Stark Infra API + Send a single Webhook for creation in the Stark Infra API ## Parameters (required): - - `:url` [string]: url to which notification events will be sent to. ex: "https://webhook.site/60e9c18e-4b5c-4369-bda1-ab5fcd8e1b29" - - `:subscriptions` [list of strings]: list of any non-empty combination of the available services. ex: ["contract", "credit-note", "signer", "issuing-card", "issuing-invoice", "issuing-purchase", "pix-request.in", "pix-request.out", "pix-reversal.in", "pix-reversal.out", "pix-claim", "pix-key", "pix-chargeback", "pix-infraction"] + - `:url` [binary]: URL to which notification events will be sent to. ex: "https://webhook.site/60e9c18e-4b5c-4369-bda1-ab5fcd8e1b29" + - `:subscriptions` [list of binaries]: list of any non-empty combination of the available services. ex: ["contract", "credit-note", "signer", "issuing-card", "issuing-invoice", "issuing-purchase", "pix-request.in", "pix-request.out", "pix-reversal.in", "pix-reversal.out", "pix-claim", "pix-key", "pix-chargeback", "pix-infraction"] - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - Webhook struct with updated attributes + - Webhook object with updated attributes """ @spec create( - user: Project.t() | Organization.t() | nil, url: binary, - subscriptions: [binary] + subscriptions: [binary], + user: Project.t() | Organization.t() | nil, ) :: {:ok, Webhook.t()} | {:error, [Error.t()]} @@ -86,16 +86,16 @@ defmodule StarkInfra.Webhook do end @doc """ - Receive a single Webhook subscription struct previously created in the Stark Infra API by passing its id + Receive a single Webhook object previously created in the Stark Infra API by passing its id ## Parameters (required): - - `id` [string]: struct unique id. ex: "5656565656565656" + - `id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - Webhook struct with updated attributes + - Webhook object with that corresponds to the given id. """ @spec get( binary, @@ -116,14 +116,14 @@ defmodule StarkInfra.Webhook do end @doc """ - Receive a stream of Webhook subcription structs previously created in the Stark Infra API + Receive a stream of Webhook objects previously created in the Stark Infra API - ## Options: - - `:limit` [integer, default nil]: maximum number of structs to be retrieved. Unlimited if nil. ex: 35 - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:limit` [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35 + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - stream of Webhook structs with updated attributes + - stream of Webhook objects with updated attributes """ @spec query( limit: integer, @@ -161,13 +161,13 @@ defmodule StarkInfra.Webhook do Receive a list of up to 100 Webhook objects previously created in the Stark Infra API and the cursor to the next page. Use this function instead of query if you want to manually page your requests. - ## Options: - - `:cursor` [string, default nil]: cursor returned on the previous page function call - - `:limit` [integer, default 100]: maximum number of structs to be retrieved. Max = 100. ex: 35 - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:cursor` [binary, default nil]: cursor returned on the previous page function call + - `:limit` [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 50 + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - list of Webhook structs with updated attributes + - list of Webhook objects with updated attributes - cursor to retrieve the next page of Webhook objects """ @spec page( @@ -194,16 +194,16 @@ defmodule StarkInfra.Webhook do end @doc """ - Delete a Webhook subscription entity previously created in the Stark Infra API + Delete a Webhook entity previously created in the Stark Infra API ## Parameters (required): - - `id` [string]: Webhook unique id. ex: "5656565656565656" + - `id` [binary]: object unique id. ex: "5656565656565656" - ## Options: - - `:user` [Organization/Project, default nil]: Organization or Project struct returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. + ## Parameters (optional): + - `:user` [Organization/Project, default nil]: Organization or Project object returned from StarkInfra.project(). Only necessary if default project or organization has not been set in configs. ## Return: - - deleted Webhook struct + - deleted Webhook object """ @spec delete( binary, diff --git a/test/brcode_preview_test.exs b/test/brcode_preview_test.exs new file mode 100644 index 0000000..7c055c4 --- /dev/null +++ b/test/brcode_preview_test.exs @@ -0,0 +1,28 @@ +defmodule StarkInfraTest.BrcodePreview do + use ExUnit.Case + + @tag :brcode_preview + test "create brcode preview" do + + {:ok, preview} = StarkInfra.BrcodePreview.create([brcodes_examples()]) + preview = preview + |> Enum.take(1) + |> hd + + assert !is_nil(preview.id) + end + + defp get_brcode() do + brcodes = StarkInfra.StaticBrcode.query!(limit: 1) + brcode = brcodes |> Enum.take(1) |> hd + + assert !is_nil(brcode.id) + IO.puts(brcode.id) + end + + defp brcodes_examples() do + %StarkInfra.BrcodePreview{ + id: get_brcode() + } + end +end diff --git a/test/card_method_test.exs b/test/card_method_test.exs new file mode 100644 index 0000000..8359fc9 --- /dev/null +++ b/test/card_method_test.exs @@ -0,0 +1,21 @@ +defmodule StarkInfraTest.CardMethod do + use ExUnit.Case + + @tag :card_method + test "query card method test" do + {:ok, methods} = StarkInfra.CardMethod.query(search: "token") + |> Enum.take(1) + |> hd + + assert !is_nil(methods.code) + end + + @tag :card_method + test "query! card method test" do + methods = StarkInfra.CardMethod.query!(search: "token") + |> Enum.take(1) + |> hd + + assert !is_nil(methods.code) + end +end diff --git a/test/credit_holmes_log_test.exs b/test/credit_holmes_log_test.exs new file mode 100644 index 0000000..449a0df --- /dev/null +++ b/test/credit_holmes_log_test.exs @@ -0,0 +1,60 @@ +defmodule StarkInfraTest.CreditHolmes.Log do + use ExUnit.Case + + @tag :credit_holmes_log + test "get credit holmes log" do + log = + StarkInfra.CreditHolmes.Log.query!(limit: 1) + |> Enum.take(1) + |> hd() + + {:ok, _log} = StarkInfra.CreditHolmes.Log.get(log.id) + end + + @tag :credit_holmes_log + test "get! credit holmes log" do + log = + StarkInfra.CreditHolmes.Log.query!(limit: 1) + |> Enum.take(1) + |> hd() + + _log = StarkInfra.CreditHolmes.Log.get!(log.id) + end + + @tag :credit_holmes_log + test "query credit holmes log" do + StarkInfra.CreditHolmes.Log.query(limit: 101) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :credit_holmes_log + test "query! credit holmes log" do + StarkInfra.CreditHolmes.Log.query!(limit: 101) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :credit_holmes_log + test "query! credit holmes log with filters" do + holmes = StarkInfra.CreditHolmes.query!(status: "created") + |> Enum.take(1) + |> hd() + + StarkInfra.CreditHolmes.Log.query!(limit: 1, holmes_ids: [holmes.id], types: "created") + |> Enum.take(5) + |> (fn list -> assert length(list) == 1 end).() + end + + @tag :credit_holmes_log + test "page credit holmes log" do + {:ok, ids} = StarkInfraTest.Utils.Page.get(&StarkInfra.CreditHolmes.Log.page/1, 2, limit: 5) + assert length(ids) <= 10 + end + + @tag :credit_holmes_log + test "page! credit holmes log" do + ids = StarkInfraTest.Utils.Page.get!(&StarkInfra.CreditHolmes.Log.page!/1, 2, limit: 5) + assert length(ids) <= 10 + end +end diff --git a/test/credit_holmes_test.exs b/test/credit_holmes_test.exs new file mode 100644 index 0000000..d3af7fb --- /dev/null +++ b/test/credit_holmes_test.exs @@ -0,0 +1,92 @@ +defmodule StarkInfraTest.CreditHolmes do + use ExUnit.Case + + @tag :credit_holmes + test "create credit holmes" do + {:ok, credit_holmess} = StarkInfra.CreditHolmes.create([example_credit_holmes()]) + credit_holmes = credit_holmess |> hd + assert !is_nil(credit_holmes.id) + end + + @tag :credit_holmes + test "create! credit holmes" do + credit_holmes = StarkInfra.CreditHolmes.create!([example_credit_holmes()]) |> hd + assert !is_nil(credit_holmes.id) + end + + @tag :credit_holmes + test "get credit holmes" do + credit_holmes = + StarkInfra.CreditHolmes.query!(limit: 1) + |> Enum.take(1) + |> hd() + + {:ok, holmes} = StarkInfra.CreditHolmes.get(credit_holmes.id) + + assert !is_nil(holmes.id) + end + + @tag :credit_holmes + test "get! credit holmes" do + credit_holmes = + StarkInfra.CreditHolmes.query!(limit: 1) + |> Enum.take(1) + |> hd() + holmes = StarkInfra.CreditHolmes.get!(credit_holmes.id) + + assert !is_nil(holmes.id) + end + + @tag :credit_holmes + test "query credit holmes" do + StarkInfra.CreditHolmes.query!(limit: 101, before: DateTime.utc_now()) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :credit_holmes + test "query! credit holmes" do + StarkInfra.CreditHolmes.query!(limit: 101, before: DateTime.utc_now()) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :credit_holmes + test "page credit holmes" do + {:ok, ids} = StarkInfraTest.Utils.Page.get(&StarkInfra.CreditHolmes.page/1, 2, limit: 5) + assert length(ids) <= 10 + end + + @tag :credit_holmes + test "page! credit holmes" do + ids = StarkInfraTest.Utils.Page.get!(&StarkInfra.CreditHolmes.page!/1, 2, limit: 5) + assert length(ids) <= 10 + end + + @tag :credit_holmes + test "create and cancel credit holmes" do + credit_holmes = StarkInfra.CreditHolmes.create!([example_credit_holmes()]) |> hd + + assert !is_nil(credit_holmes) + + {:ok, holmes} = StarkInfra.CreditHolmes.cancel(credit_holmes.id) + assert !is_nil(holmes.id) + end + + @tag :credit_holmes + test "create and cancel! credit holmes" do + credit_holmes = StarkInfra.CreditHolmes.create!([example_credit_holmes()]) |> hd + + assert !is_nil(credit_holmes) + + holmes = StarkInfra.CreditHolmes.cancel!(credit_holmes.id) + assert !is_nil(holmes.id) + end + + def example_credit_holmes() do + %StarkInfra.CreditHolmes{ + tax_id: "123.456.789-00", + competence: "2022-08" + } + end +end diff --git a/test/credit_note_test.exs b/test/credit_note_test.exs index 88b12d9..1a90860 100644 --- a/test/credit_note_test.exs +++ b/test/credit_note_test.exs @@ -96,19 +96,15 @@ defmodule StarkInfraTest.CreditNote do name: "Jamie Lannister", tax_id: "012.345.678-90", nominal_amount: 100000, - scheduled: "2022-05-30", + scheduled: "2023-04-28", invoices: [ %StarkInfra.CreditNote.Invoice{ due: "2023-06-25", - amount: 60000, - fine: 10, - interest: 2 + amount: 60000 }, %StarkInfra.CreditNote.Invoice{ due: "2023-06-25", amount: 59000, - fine: 10, - interest: 1, descriptions: [ %StarkInfra.CreditNote.Invoice.Description{ key: "key", diff --git a/test/credit_preview_test.exs b/test/credit_preview_test.exs new file mode 100644 index 0000000..17ee1e9 --- /dev/null +++ b/test/credit_preview_test.exs @@ -0,0 +1,111 @@ +defmodule StarkInfraTest.CreditPreview do + use ExUnit.Case + + @tag :credit_preview + test "create credit previews" do + {:ok, previews} = StarkInfra.CreditPreview.create(credit_notes()) + + previews = previews |> Enum.take(1) |> hd + end + + @tag :credit_preview + test "create! credit previews" do + previews = StarkInfra.CreditPreview.create!(credit_notes()) + + previews = previews |> Enum.take(1) |> hd + end + + @tag :credit_preview + test "create credit previews in hash" do + {:ok, previews} = StarkInfra.CreditPreview.create([credit_notes_hash()]) + + previews = previews |> Enum.take(1) |> hd + end + + @tag :credit_preview + test "create! credit previews in hash" do + previews = StarkInfra.CreditPreview.create!([credit_notes_hash()]) + + previews = previews |> Enum.take(1) |> hd + end + + defp credit_notes() do + [ + %StarkInfra.CreditPreview{ + type: "credit-note", + credit: %StarkInfra.CreditNotePreview{ + tax_id: "012.345.678-90", + type: "sac", + nominal_amount: 100000, + rebate_amount: 1000, + nominal_interest: 2.5, + scheduled: "2023-04-28", + initial_due: "2023-12-28", + initial_amount: 9999, + interval: "month" + } + }, + %StarkInfra.CreditPreview{ + type: "credit-note", + credit: %StarkInfra.CreditNotePreview{ + tax_id: "012.345.678-90", + type: "bullet", + nominal_amount: 100000, + rebate_amount: 1000, + nominal_interest: 2.5, + scheduled: "2023-04-28", + initial_due: "2023-12-28", + } + }, + %StarkInfra.CreditPreview{ + type: "credit-note", + credit: %StarkInfra.CreditNotePreview{ + tax_id: "012.345.678-90", + type: "price", + nominal_amount: 100000, + rebate_amount: 1000, + nominal_interest: 2.5, + scheduled: "2023-04-28", + initial_due: "2023-12-28", + initial_amount: 9999, + interval: "month" + } + }, + %StarkInfra.CreditPreview{ + type: "credit-note", + credit: %StarkInfra.CreditNotePreview{ + tax_id: "012.345.678-90", + type: "american", + nominal_amount: 100000, + rebate_amount: 1000, + nominal_interest: 2.5, + scheduled: "2023-04-28", + initial_due: "2023-12-28", + count: 12, + interval: "year" + } + } + ] + end + + defp notes_hash() do + %{ + tax_id: "012.345.678-90", + type: "sac", + nominal_amount: 100000, + rebate_amount: 1000, + nominal_interest: 3.0, + scheduled: "2023-04-28", + initial_due: "2023-12-28", + initial_amount: 9999, + interval: "year" + } + end + + defp credit_notes_hash() do + %StarkInfra.CreditPreview{ + type: "credit-note", + credit: notes_hash() + } + end +end diff --git a/test/dynamic_brcode_test.exs b/test/dynamic_brcode_test.exs new file mode 100644 index 0000000..a32471b --- /dev/null +++ b/test/dynamic_brcode_test.exs @@ -0,0 +1,182 @@ +defmodule StarkInfraTest.DynamicBrcode do + use ExUnit.Case + + @tag :dynamic_brcode + test "get dynamic brcode" do + + brcodes = StarkInfra.DynamicBrcode.query!(limit: 1) + |> Enum.take(1) + |> hd + + {:ok, brcode} = StarkInfra.DynamicBrcode.get(brcodes.id) + + assert !is_nil(brcode.id) + end + + @tag :dynamic_brcode + test "get! dynamic brcode" do + brcodes = StarkInfra.DynamicBrcode.query!(limit: 1) + |> Enum.take(1) + |> hd + + brcode = StarkInfra.DynamicBrcode.get!(brcodes.id) + + assert !is_nil(brcode.id) + end + + @tag :dynamic_brcode + test "query dynamic brcode" do + {:ok, brcodes} = StarkInfra.DynamicBrcode.query(before: Date.utc_today |> Date.add(-1)) + |> Enum.take(1) + |> hd + + assert !is_nil(brcodes.id) + end + + @tag :dynamic_brcode + test "query! dynamic brcode" do + brcodes = StarkInfra.DynamicBrcode.query!(before: Date.utc_today |> Date.add(-1)) + |> Enum.take(1) + |> hd + + assert !is_nil(brcodes.id) + end + + @tag :dynamic_brcode + test "page dynamic brcode test" do + {:ok, {_cursor, brcodes}} = StarkInfra.DynamicBrcode.page(limit: 2) + brcode = brcodes |> Enum.take(1) |> hd + + assert !is_nil(brcode.id) + end + + @tag :dynamic_brcode + test "page! dynamic brcode test" do + {_cursor, brcodes} = StarkInfra.DynamicBrcode.page!(limit: 2) + brcode = brcodes |> Enum.take(1) |> hd + + assert !is_nil(brcode.id) + end + + @tag :dynamic_brcode + test "create dynamic brcode test" do + {:ok, brcode} = StarkInfra.DynamicBrcode.create( + [example_dynamic_brcode()] + ) + brcode = brcode |> Enum.take(1) |> hd + + assert !is_nil(brcode.id) + end + + @tag :dynamic_brcode + test "create! dynamic brcode test" do + brcode = StarkInfra.DynamicBrcode.create!( + [example_dynamic_brcode()] + ) + brcode = brcode |> Enum.take(1) |> hd + + assert !is_nil(brcode.id) + end + + @tag :dynamic_brcode + test "response due dynamic brcode test" do + response = StarkInfra.DynamicBrcode.response_due( + example_dynamic_brcode_due() + ) + + |> IO.inspect() + + assert !is_nil(response) + end + + @tag :dynamic_brcode + test "response instant dynamic brcode test" do + response = StarkInfra.DynamicBrcode.response_instant( + example_dynamic_brcode_instant() + ) + + |> IO.inspect() + + assert !is_nil(response) + end + + @tag :dynamic_brcode + test "verify right dynamic brcode test" do + uuid = "21f174ab942843eb90837a5c3135dfd6" + right_signature = "MEYCIQC+Ks0M54DPLEbHIi0JrMiWbBFMRETe/U2vy3gTiid3rAIhANMmOaxT03nx2bsdo+vg6EMhWGzdphh90uBH9PY2gJdd" + verified_response = StarkInfra.DynamicBrcode.verify!(content: uuid, signature: right_signature) + verified_response = verified_response |> Enum.take(1) |> hd + + assert !is_nil(verified_response) + end + + @tag :dynamic_brcode + test "verify wrong dynamic brcode test" do + uuid = "21f174ab942843eb90837a5c3135dfd6" + wrong_signature = "MEUCIQDOpo1j+V40DNZK2URL2786UQK/8mDXon9ayEd8U0/l7AIgYXtIZJBTs8zCRR3vmted6Ehz/qfw1GRut/eYyvf1yOk=" + verified_response = StarkInfra.DynamicBrcode.verify!(content: uuid, signature: wrong_signature) + verified_response = verified_response |> Enum.take(1) |> hd + + assert !is_nil(verified_response) + end + + def example_dynamic_brcode do + StarkInfra.DynamicBrcode.query!(limit: 10) + |> Enum.take(1) + |> hd + |> build_example + end + + def build_example(brcode) do + %StarkInfra.DynamicBrcode{ + name: "Jamie Lannister", + city: "Rio de Janeiro", + external_id: StarkInfraTest.Utils.Random.random_string(32), + type: brcode.type + } + end + + def example_dynamic_brcode_instant() do + %{ + version: 1, + created: "2022-08-27T14:08:38.806507+00:00", + key_id: "+5511989898989", + status: "paid", + reconciliation_id: "b77f5236-7ab9-4487-9f95-66ee6eaf1781", + amount: 10000, + cashier_type: "merchant", + cashier_bank_code: "20018183", + cash_amount: 20018183, + expiration: 86400, + sender_name: "Anthony Edward Stark", + sender_tax_id: "01.001.001/0001-01", + amount_type: "fixed", + description: "Test Instant Response", + } + end + + def example_dynamic_brcode_due() do + %{ + version: 1, + created: "2022-08-27T14:08:38.806507+00:00", + due: "2022-09-27T14:08:38.806507+00:00", + expiration: 999, + key_id: "+5511989898989", + status: "paid", + reconciliation_id: "b77f5236-7ab9-4487-9f95-66ee6eaf1781", + nominal_amount: 100, + sender_name: "Anthony Edward Stark", + sender_tax_id: "012.345.678-90", + receiver_name: "Jamie Lannister", + receiver_street_line: "Av. Paulista, 200", + receiver_city: "Sao Paulo", + receiver_state_code: "SP", + receiver_zip_code: "01234-567", + receiver_tax_id: "20.018.183/0001-8", + fine: 2, + interest: 1, + discounts: "", + description: "Test Elixir" + } + end +end diff --git a/test/individual_document_log_test.exs b/test/individual_document_log_test.exs new file mode 100644 index 0000000..7c6fa03 --- /dev/null +++ b/test/individual_document_log_test.exs @@ -0,0 +1,60 @@ +defmodule StarkInfraTest.IndividualDocument.Log do + use ExUnit.Case + + @tag :individual_document_log + test "get individual document log" do + log = + StarkInfra.IndividualDocument.Log.query!(limit: 1) + |> Enum.take(1) + |> hd() + + {:ok, _log} = StarkInfra.IndividualDocument.Log.get(log.id) + end + + @tag :individual_document_log + test "get! individual document log" do + log = + StarkInfra.IndividualDocument.Log.query!(limit: 1) + |> Enum.take(1) + |> hd() + + _log = StarkInfra.IndividualDocument.Log.get!(log.id) + end + + @tag :individual_document_log + test "query individual document log" do + StarkInfra.IndividualDocument.Log.query(limit: 101) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :individual_document_log + test "query! individual document log" do + StarkInfra.IndividualDocument.Log.query!(limit: 101) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :individual_document_log + test "query! individual document log with filters" do + documents = StarkInfra.IndividualDocument.query!(status: "created") + |> Enum.take(1) + |> hd() + + StarkInfra.IndividualDocument.Log.query!(limit: 1, documents_ids: [documents.id], types: "created") + |> Enum.take(5) + |> (fn list -> assert length(list) == 1 end).() + end + + @tag :individual_document_log + test "page individual document log" do + {:ok, ids} = StarkInfraTest.Utils.Page.get(&StarkInfra.IndividualDocument.Log.page/1, 2, limit: 5) + assert length(ids) <= 10 + end + + @tag :individual_document_log + test "page! individual document log" do + ids = StarkInfraTest.Utils.Page.get!(&StarkInfra.IndividualDocument.Log.page!/1, 2, limit: 5) + assert length(ids) <= 10 + end +end diff --git a/test/individual_document_test.exs b/test/individual_document_test.exs new file mode 100644 index 0000000..58d675e --- /dev/null +++ b/test/individual_document_test.exs @@ -0,0 +1,94 @@ +defmodule StarkInfraTest.IndividualDocument do + use ExUnit.Case + + @tag :individual_document + test "create individual document" do + {:ok, individual_documents} = StarkInfra.IndividualDocument.create([example_individual_document()]) + individual_document = individual_documents |> hd + assert !is_nil(individual_document.id) + end + + @tag :individual_document + test "create! individual document" do + individual_document = StarkInfra.IndividualDocument.create!([example_individual_document()]) |> hd + assert !is_nil(individual_document.id) + end + + @tag :individual_document + test "get individual document" do + individual_document = + StarkInfra.IndividualDocument.query!(limit: 1) + |> Enum.take(1) + |> hd() + + {:ok, note} = StarkInfra.IndividualDocument.get(individual_document.id) + + assert !is_nil(note.id) + end + + @tag :individual_document + test "get! individual document" do + individual_document = + StarkInfra.IndividualDocument.query!(limit: 1) + |> Enum.take(1) + |> hd() + note = StarkInfra.IndividualDocument.get!(individual_document.id) + + assert !is_nil(note.id) + end + + @tag :individual_document + test "query individual document" do + StarkInfra.IndividualDocument.query!(limit: 101, before: DateTime.utc_now()) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :individual_document + test "query! individual document" do + StarkInfra.IndividualDocument.query!(limit: 101, before: DateTime.utc_now()) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :individual_document + test "page individual document" do + {:ok, ids} = StarkInfraTest.Utils.Page.get(&StarkInfra.IndividualDocument.page/1, 2, limit: 5) + assert length(ids) <= 10 + end + + @tag :individual_document + test "page! individual document" do + ids = StarkInfraTest.Utils.Page.get!(&StarkInfra.IndividualDocument.page!/1, 2, limit: 5) + assert length(ids) <= 10 + end + + @tag :individual_document + test "create and cancel individual document" do + individual_document = StarkInfra.IndividualDocument.create!([example_individual_document()]) |> hd + + assert !is_nil(individual_document) + + {:ok, note} = StarkInfra.IndividualDocument.cancel(individual_document.id) + assert !is_nil(note.id) + end + + @tag :individual_document + test "create and cancel! individual document" do + individual_document = StarkInfra.IndividualDocument.create!([example_individual_document()]) |> hd + + assert !is_nil(individual_document) + + note = StarkInfra.IndividualDocument.cancel!(individual_document.id) + assert !is_nil(note.id) + end + + def example_individual_document() do + %StarkInfra.IndividualDocument{ + type: "identity-front", + content: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD...", + identity_id: "5155165527080960", + tags: ["breaking", "bad"] + } + end +end diff --git a/test/individual_identity_log_test.exs b/test/individual_identity_log_test.exs new file mode 100644 index 0000000..224ded1 --- /dev/null +++ b/test/individual_identity_log_test.exs @@ -0,0 +1,60 @@ +defmodule StarkInfraTest.IndividualIdentity.Log do + use ExUnit.Case + + @tag :individual_identity_log + test "get individual identity log" do + log = + StarkInfra.IndividualIdentity.Log.query!(limit: 1) + |> Enum.take(1) + |> hd() + + {:ok, _log} = StarkInfra.IndividualIdentity.Log.get(log.id) + end + + @tag :individual_identity_log + test "get! individual identity log" do + log = + StarkInfra.IndividualIdentity.Log.query!(limit: 1) + |> Enum.take(1) + |> hd() + + _log = StarkInfra.IndividualIdentity.Log.get!(log.id) + end + + @tag :individual_identity_log + test "query individual identity log" do + StarkInfra.IndividualIdentity.Log.query(limit: 101) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :individual_identity_log + test "query! individual identity log" do + StarkInfra.IndividualIdentity.Log.query!(limit: 101) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :individual_identity_log + test "query! individual identity log with filters" do + documents = StarkInfra.IndividualIdentity.query!(status: "created") + |> Enum.take(1) + |> hd() + + StarkInfra.IndividualIdentity.Log.query!(limit: 1, documents_ids: [documents.id], types: "created") + |> Enum.take(5) + |> (fn list -> assert length(list) == 1 end).() + end + + @tag :individual_identity_log + test "page individual identity log" do + {:ok, ids} = StarkInfraTest.Utils.Page.get(&StarkInfra.IndividualIdentity.Log.page/1, 2, limit: 5) + assert length(ids) <= 10 + end + + @tag :individual_identity_log + test "page! individual identity log" do + ids = StarkInfraTest.Utils.Page.get!(&StarkInfra.IndividualIdentity.Log.page!/1, 2, limit: 5) + assert length(ids) <= 10 + end +end diff --git a/test/individual_identity_test.exs b/test/individual_identity_test.exs new file mode 100644 index 0000000..eb93dc5 --- /dev/null +++ b/test/individual_identity_test.exs @@ -0,0 +1,93 @@ +defmodule StarkInfraTest.IndividualIdentity do + use ExUnit.Case + + @tag :individual_identity + test "create individual document" do + {:ok, individual_identities} = StarkInfra.IndividualIdentity.create([example_individual_identity()]) + individual_identity = individual_identities |> hd + assert !is_nil(individual_identity.id) + end + + @tag :individual_identity + test "create! individual document" do + individual_identity = StarkInfra.IndividualIdentity.create!([example_individual_identity()]) |> hd + assert !is_nil(individual_identity.id) + end + + @tag :individual_identity + test "get individual document" do + individual_identity = + StarkInfra.IndividualIdentity.query!(limit: 1) + |> Enum.take(1) + |> hd() + + {:ok, identity} = StarkInfra.IndividualIdentity.get(individual_identity.id) + + assert !is_nil(identity.id) + end + + @tag :individual_identity + test "get! individual document" do + individual_identity = + StarkInfra.IndividualIdentity.query!(limit: 1) + |> Enum.take(1) + |> hd() + identity = StarkInfra.IndividualIdentity.get!(individual_identity.id) + + assert !is_nil(identity.id) + end + + @tag :individual_identity + test "query individual document" do + StarkInfra.IndividualIdentity.query!(limit: 101, before: DateTime.utc_now()) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :individual_identity + test "query! individual document" do + StarkInfra.IndividualIdentity.query!(limit: 101, before: DateTime.utc_now()) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :individual_identity + test "page individual document" do + {:ok, ids} = StarkInfraTest.Utils.Page.get(&StarkInfra.IndividualIdentity.page/1, 2, limit: 5) + assert length(ids) <= 10 + end + + @tag :individual_identity + test "page! individual document" do + ids = StarkInfraTest.Utils.Page.get!(&StarkInfra.IndividualIdentity.page!/1, 2, limit: 5) + assert length(ids) <= 10 + end + + @tag :individual_identity + test "create and cancel individual document" do + individual_identity = StarkInfra.IndividualIdentity.create!([example_individual_identity()]) |> hd + + assert !is_nil(individual_identity) + + {:ok, identity} = StarkInfra.IndividualIdentity.cancel(individual_identity.id) + assert !is_nil(identity.id) + end + + @tag :individual_identity + test "create and cancel! individual document" do + individual_identity = StarkInfra.IndividualIdentity.create!([example_individual_identity()]) |> hd + + assert !is_nil(individual_identity) + + identity = StarkInfra.IndividualIdentity.cancel!(individual_identity.id) + assert !is_nil(identity.id) + end + + def example_individual_identity() do + %StarkInfra.IndividualIdentity{ + name: "Walter White", + tax_id: "012.345.678-90", + tags: ["breaking", "bad"] + } + end +end diff --git a/test/issuing_authorization_test.exs b/test/issuing_authorization_test.exs deleted file mode 100644 index e37ef55..0000000 --- a/test/issuing_authorization_test.exs +++ /dev/null @@ -1,85 +0,0 @@ -defmodule StarkInfraTest.IssuingAuthorization do - use ExUnit.Case - - @content "{\"acquirerId\": \"236090\", \"amount\": 100, \"cardId\": \"5671893688385536\", \"cardTags\": [], \"endToEndId\": \"2fa7ef9f-b889-4bae-ac02-16749c04a3b6\", \"holderId\": \"5917814565109760\", \"holderTags\": [], \"isPartialAllowed\": false, \"issuerAmount\": 100, \"issuerCurrencyCode\": \"BRL\", \"merchantAmount\": 100, \"merchantCategoryCode\": \"bookStores\", \"merchantCountryCode\": \"BRA\", \"merchantCurrencyCode\": \"BRL\", \"merchantFee\": 0, \"merchantId\": \"204933612653639\", \"merchantName\": \"COMPANY 123\", \"methodCode\": \"token\", \"purpose\": \"purchase\", \"score\": null, \"tax\": 0, \"walletId\": \"\"}" - @signature "MEUCIBxymWEpit50lDqFKFHYOgyyqvE5kiHERi0ZM6cJpcvmAiEA2wwIkxcsuexh9BjcyAbZxprpRUyjcZJ2vBAjdd7o28Q=" - @bad_signature "MEUCIQDOpo1j+V40DNZK2URL2786UQK/8mDXon9ayEd8U0/l7AIgYXtIZJBTs8zCRR3vmted6Ehz/qfw1GRut/eYyvf1yOk=" - @malformed_signature "something is definitely wrong" - - @tag :issuing_authorization - test "response issuing authorization test" do - response = StarkInfra.IssuingAuthorization.response!("denied") - assert !is_nil(response) - end - - @tag :issuing_authorization - test "parse issuing authorization test" do - {:ok, {_authorization, cache_pid_1}} = StarkInfra.IssuingAuthorization.parse( - content: @content, - signature: @signature - ) - - {:ok, {authorization, cache_pid_2}} = - StarkInfra.IssuingAuthorization.parse( - content: @content, - signature: @signature, - cache_pid: cache_pid_1 - ) - - assert Agent.get(cache_pid_1, fn map -> Map.get(map, :StarkInfra_public_key) end) == - Agent.get(cache_pid_2, fn map -> Map.get(map, :StarkInfra_public_key) end) - - assert !is_nil(authorization) - end - - @tag :issuing_authorization - test "parse bad signature issuing authorization test" do - {:error, [error]} = - StarkInfra.IssuingAuthorization.parse( - content: @content, - signature: @bad_signature - ) - assert error.code == "invalidSignature" - end - - @tag :issuing_authorization - test "parse invalid signature issuing authorization test" do - {:error, [error]} = - StarkInfra.IssuingAuthorization.parse( - content: @content, - signature: @malformed_signature - ) - - assert error.code == "invalidSignature" - end - - @tag :issuing_authorization - test "parse! issuing authorization test" do - {authorization, _cache_pid} = StarkInfra.IssuingAuthorization.parse!( - content: @content, - signature: @signature - ) - - assert !is_nil(authorization) - end - - @tag :issuing_authorization - test "parse! bad signature issuing authorization test" do - [error] = StarkInfra.IssuingAuthorization.parse!( - content: @content, - signature: @bad_signature - ) - - assert error.code == "invalidSignature" - end - - @tag :issuing_authorization - test "parse! invalid signature issuing authorization test" do - [error] = StarkInfra.IssuingAuthorization.parse( - content: @content, - signature: @malformed_signature - ) - - assert error.code == "invalidSignature" - end -end diff --git a/test/issuing_bin_test.exs b/test/issuing_bin_test.exs deleted file mode 100644 index bf17893..0000000 --- a/test/issuing_bin_test.exs +++ /dev/null @@ -1,37 +0,0 @@ -defmodule StarkInfraTest.IssuingBin do - use ExUnit.Case - - @tag :issuing_bin - test "query issuing bin" do - {:ok, issuing_bin} = StarkInfra.IssuingBin.query(limit: 10) - |> Enum.take(1) - |> hd - - assert !is_nil(issuing_bin.id) - end - - @tag :issuing_bin - test "query! issuing bin" do - issuing_bin = StarkInfra.IssuingBin.query!(limit: 10) - |> Enum.take(1) - |> hd - - assert !is_nil(issuing_bin.id) - end - - @tag :issuing_bin - test "page issuing bin" do - {:ok, {_cursor, issuings_bin}} = StarkInfra.IssuingBin.page(limit: 10) - issuing_bin = issuings_bin |> Enum.take(1) |> hd - - assert !is_nil(issuing_bin.id) - end - - @tag :issuing_bin - test "page! issuing bin" do - {nil, issuings_bin} = StarkInfra.IssuingBin.page!(limit: 10) - issuing_bin = issuings_bin |> Enum.take(1) |> hd - - assert !is_nil(issuing_bin.id) - end -end diff --git a/test/issuing_design_test.exs b/test/issuing_design_test.exs new file mode 100644 index 0000000..0a1021f --- /dev/null +++ b/test/issuing_design_test.exs @@ -0,0 +1,60 @@ +defmodule StarkInfraTest.IssuingDesign do + use ExUnit.Case + + @tag :issuing_design + test "get issuing_design" do + design = + StarkInfra.IssuingDesign.query!(limit: 1) + |> Enum.take(1) + |> hd() + + {:ok, _design} = StarkInfra.IssuingDesign.get(design.id) + end + + @tag :issuing_design + test "get! issuing_design" do + design = + StarkInfra.IssuingDesign.query!(limit: 1) + |> Enum.take(1) + |> hd() + + _design = StarkInfra.IssuingDesign.get!(design.id) + end + + @tag :issuing_design + test "query issuing_design" do + StarkInfra.IssuingDesign.query(limit: 101) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :issuing_design + test "query! issuing_design" do + StarkInfra.IssuingDesign.query!(limit: 101) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :issuing_design + test "query! issuing_design with filters" do + design = StarkInfra.IssuingDesign.query!(status: "created") + |> Enum.take(1) + |> hd() + + StarkInfra.IssuingDesign.query!(limit: 1, design_ids: [design.id], types: "created") + |> Enum.take(5) + |> (fn list -> assert length(list) == 1 end).() + end + + @tag :issuing_design + test "page issuing_design" do + {:ok, ids} = StarkInfraTest.Utils.Page.get(&StarkInfra.IssuingDesign.page/1, 2, limit: 5) + assert length(ids) <= 10 + end + + @tag :issuing_design + test "page! issuing_design" do + ids = StarkInfraTest.Utils.Page.get!(&StarkInfra.IssuingDesign.page!/1, 2, limit: 5) + assert length(ids) <= 10 + end +end diff --git a/test/issuing_embossing_kit_test.exs b/test/issuing_embossing_kit_test.exs new file mode 100644 index 0000000..b5bee75 --- /dev/null +++ b/test/issuing_embossing_kit_test.exs @@ -0,0 +1,60 @@ +defmodule StarkInfraTest.IssuingEmbossingKit do + use ExUnit.Case + + @tag :issuing_embossing_kit + test "get issuing embossing kit" do + request = + StarkInfra.IssuingEmbossingKit.query!(limit: 1) + |> Enum.take(1) + |> hd() + + {:ok, _request} = StarkInfra.IssuingEmbossingKit.get(request.id) + end + + @tag :issuing_embossing_kit + test "get! issuing embossing kit" do + request = + StarkInfra.IssuingEmbossingKit.query!(limit: 1) + |> Enum.take(1) + |> hd() + + _request = StarkInfra.IssuingEmbossingKit.get!(request.id) + end + + @tag :issuing_embossing_kit + test "query issuing embossing kit" do + StarkInfra.IssuingEmbossingKit.query(limit: 101) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :issuing_embossing_kit + test "query! issuing embossing kit" do + StarkInfra.IssuingEmbossingKit.query!(limit: 101) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :issuing_embossing_kit + test "query! issuing embossing kit with filters" do + requests = StarkInfra.IssuingEmbossingKit.query!(status: "created") + |> Enum.take(1) + |> hd() + + StarkInfra.IssuingEmbossingKit.query!(limit: 1, types: "created") + |> Enum.take(5) + |> (fn list -> assert length(list) == 1 end).() + end + + @tag :issuing_embossing_kit + test "page issuing embossing kit" do + {:ok, ids} = StarkInfraTest.Utils.Page.get(&StarkInfra.IssuingEmbossingKit.page/1, 2, limit: 5) + assert length(ids) <= 10 + end + + @tag :issuing_embossing_kit + test "page! issuing embossing kit" do + ids = StarkInfraTest.Utils.Page.get!(&StarkInfra.IssuingEmbossingKit.page!/1, 2, limit: 5) + assert length(ids) <= 10 + end +end diff --git a/test/issuing_embossing_request_log_test.exs b/test/issuing_embossing_request_log_test.exs new file mode 100644 index 0000000..377d258 --- /dev/null +++ b/test/issuing_embossing_request_log_test.exs @@ -0,0 +1,60 @@ +defmodule StarkInfraTest.IssuingEmbossingRequest.Log do + use ExUnit.Case + + @tag :issuing_embossing_request_log + test "get issuing embossing request log" do + log = + StarkInfra.IssuingEmbossingRequest.Log.query!(limit: 1) + |> Enum.take(1) + |> hd() + + {:ok, _log} = StarkInfra.IssuingEmbossingRequest.Log.get(log.id) + end + + @tag :issuing_embossing_request_log + test "get! issuing embossing request log" do + log = + StarkInfra.IssuingEmbossingRequest.Log.query!(limit: 1) + |> Enum.take(1) + |> hd() + + _log = StarkInfra.IssuingEmbossingRequest.Log.get!(log.id) + end + + @tag :issuing_embossing_request_log + test "query issuing embossing request log" do + StarkInfra.IssuingEmbossingRequest.Log.query(limit: 101) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :issuing_embossing_request_log + test "query! issuing embossing request log" do + StarkInfra.IssuingEmbossingRequest.Log.query!(limit: 101) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :issuing_embossing_request_log + test "query! issuing embossing request log with filters" do + documents = StarkInfra.IssuingEmbossingRequest.query!(status: "created") + |> Enum.take(1) + |> hd() + + StarkInfra.IssuingEmbossingRequest.Log.query!(limit: 1, documents_ids: [documents.id], types: "created") + |> Enum.take(5) + |> (fn list -> assert length(list) == 1 end).() + end + + @tag :issuing_embossing_request_log + test "page issuing embossing request log" do + {:ok, ids} = StarkInfraTest.Utils.Page.get(&StarkInfra.IssuingEmbossingRequest.Log.page/1, 2, limit: 5) + assert length(ids) <= 10 + end + + @tag :issuing_embossing_request_log + test "page! issuing embossing request log" do + ids = StarkInfraTest.Utils.Page.get!(&StarkInfra.IssuingEmbossingRequest.Log.page!/1, 2, limit: 5) + assert length(ids) <= 10 + end +end diff --git a/test/issuing_embossing_request_test.exs b/test/issuing_embossing_request_test.exs new file mode 100644 index 0000000..f5cabb8 --- /dev/null +++ b/test/issuing_embossing_request_test.exs @@ -0,0 +1,60 @@ +defmodule StarkInfraTest.IssuingEmbossingRequest do + use ExUnit.Case + + @tag :issuing_embossing_request + test "get issuing embossing request" do + request = + StarkInfra.IssuingEmbossingRequest.query!(limit: 1) + |> Enum.take(1) + |> hd() + + {:ok, _request} = StarkInfra.IssuingEmbossingRequest.get(request.id) + end + + @tag :issuing_embossing_request + test "get! issuing embossing request" do + request = + StarkInfra.IssuingEmbossingRequest.query!(limit: 1) + |> Enum.take(1) + |> hd() + + _request = StarkInfra.IssuingEmbossingRequest.get!(request.id) + end + + @tag :issuing_embossing_request + test "query issuing embossing request" do + StarkInfra.IssuingEmbossingRequest.query(limit: 101) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :issuing_embossing_request + test "query! issuing embossing request" do + StarkInfra.IssuingEmbossingRequest.query!(limit: 101) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :issuing_embossing_request + test "query! issuing embossing request with filters" do + requests = StarkInfra.IssuingEmbossingRequest.query!(status: "created") + |> Enum.take(1) + |> hd() + + StarkInfra.IssuingEmbossingRequest.query!(limit: 1, requests_ids: [requests.id], types: "created") + |> Enum.take(5) + |> (fn list -> assert length(list) == 1 end).() + end + + @tag :issuing_embossing_request + test "page issuing embossing request" do + {:ok, ids} = StarkInfraTest.Utils.Page.get(&StarkInfra.IssuingEmbossingRequest.page/1, 2, limit: 5) + assert length(ids) <= 10 + end + + @tag :issuing_embossing_request + test "page! issuing embossing request" do + ids = StarkInfraTest.Utils.Page.get!(&StarkInfra.IssuingEmbossingRequest.page!/1, 2, limit: 5) + assert length(ids) <= 10 + end +end diff --git a/test/issuing_product_test.exs b/test/issuing_product_test.exs new file mode 100644 index 0000000..0780da3 --- /dev/null +++ b/test/issuing_product_test.exs @@ -0,0 +1,37 @@ +defmodule StarkInfraTest.IssuingProduct do + use ExUnit.Case + + @tag :issuing_product + test "query issuing product" do + {:ok, issuing_product} = StarkInfra.IssuingProduct.query(limit: 10) + |> Enum.take(1) + |> hd + + assert !is_nil(issuing_product.id) + end + + @tag :issuing_product + test "query! issuing product" do + issuing_product = StarkInfra.IssuingProduct.query!(limit: 10) + |> Enum.take(1) + |> hd + + assert !is_nil(issuing_product.id) + end + + @tag :issuing_product + test "page issuing product" do + {:ok, {_cursor, issuings_product}} = StarkInfra.IssuingProduct.page(limit: 10) + issuing_product = issuings_product |> Enum.take(1) |> hd + + assert !is_nil(issuing_product.id) + end + + @tag :issuing_product + test "page! issuing product" do + {nil, issuings_product} = StarkInfra.IssuingProduct.page!(limit: 10) + issuing_product = issuings_product |> Enum.take(1) |> hd + + assert !is_nil(issuing_product.id) + end +end diff --git a/test/issuing_restock_log_test.exs b/test/issuing_restock_log_test.exs new file mode 100644 index 0000000..fda5fe1 --- /dev/null +++ b/test/issuing_restock_log_test.exs @@ -0,0 +1,60 @@ +defmodule StarkInfraTest.IssuingRestock.Log do + use ExUnit.Case + + @tag :issuing_restock_log + test "get issuing restock log" do + log = + StarkInfra.IssuingRestock.Log.query!(limit: 1) + |> Enum.take(1) + |> hd() + + {:ok, _log} = StarkInfra.IssuingRestock.Log.get(log.id) + end + + @tag :issuing_restock_log + test "get! issuing restock log" do + log = + StarkInfra.IssuingRestock.Log.query!(limit: 1) + |> Enum.take(1) + |> hd() + + _log = StarkInfra.IssuingRestock.Log.get!(log.id) + end + + @tag :issuing_restock_log + test "query issuing restock log" do + StarkInfra.IssuingRestock.Log.query(limit: 101) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :issuing_restock_log + test "query! issuing restock log" do + StarkInfra.IssuingRestock.Log.query!(limit: 101) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :issuing_restock_log + test "query! issuing restock log with filters" do + documents = StarkInfra.IssuingRestock.query!(status: "created") + |> Enum.take(1) + |> hd() + + StarkInfra.IssuingRestock.Log.query!(limit: 1, documents_ids: [documents.id], types: "created") + |> Enum.take(5) + |> (fn list -> assert length(list) == 1 end).() + end + + @tag :issuing_restock_log + test "page issuing restock log" do + {:ok, ids} = StarkInfraTest.Utils.Page.get(&StarkInfra.IssuingRestock.Log.page/1, 2, limit: 5) + assert length(ids) <= 10 + end + + @tag :issuing_restock_log + test "page! issuing restock log" do + ids = StarkInfraTest.Utils.Page.get!(&StarkInfra.IssuingRestock.Log.page!/1, 2, limit: 5) + assert length(ids) <= 10 + end +end diff --git a/test/issuing_restock_test.exs b/test/issuing_restock_test.exs new file mode 100644 index 0000000..3fd7c76 --- /dev/null +++ b/test/issuing_restock_test.exs @@ -0,0 +1,93 @@ +defmodule StarkInfraTest.IssuingRestock do + use ExUnit.Case + + @tag :issuing_restock + test "create issuing restock" do + {:ok, issuing_restocks} = StarkInfra.IssuingRestock.create([example_issuing_restock()]) + issuing_restock = issuing_restocks |> hd + assert !is_nil(issuing_restock.id) + end + + @tag :issuing_restock + test "create! issuing restock" do + issuing_restock = StarkInfra.IssuingRestock.create!([example_issuing_restock()]) |> hd + assert !is_nil(issuing_restock.id) + end + + @tag :issuing_restock + test "get issuing restock" do + issuing_restock = + StarkInfra.IssuingRestock.query!(limit: 1) + |> Enum.take(1) + |> hd() + + {:ok, restock} = StarkInfra.IssuingRestock.get(issuing_restock.id) + + assert !is_nil(restock.id) + end + + @tag :issuing_restock + test "get! issuing restock" do + issuing_restock = + StarkInfra.IssuingRestock.query!(limit: 1) + |> Enum.take(1) + |> hd() + restock = StarkInfra.IssuingRestock.get!(issuing_restock.id) + + assert !is_nil(restock.id) + end + + @tag :issuing_restock + test "query issuing restock" do + StarkInfra.IssuingRestock.query!(limit: 101, before: DateTime.utc_now()) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :issuing_restock + test "query! issuing restock" do + StarkInfra.IssuingRestock.query!(limit: 101, before: DateTime.utc_now()) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :issuing_restock + test "page issuing restock" do + {:ok, ids} = StarkInfraTest.Utils.Page.get(&StarkInfra.IssuingRestock.page/1, 2, limit: 5) + assert length(ids) <= 10 + end + + @tag :issuing_restock + test "page! issuing restock" do + ids = StarkInfraTest.Utils.Page.get!(&StarkInfra.IssuingRestock.page!/1, 2, limit: 5) + assert length(ids) <= 10 + end + + @tag :issuing_restock + test "create and cancel issuing restock" do + issuing_restock = StarkInfra.IssuingRestock.create!([example_issuing_restock()]) |> hd + + assert !is_nil(issuing_restock) + + {:ok, restock} = StarkInfra.IssuingRestock.cancel(issuing_restock.id) + assert !is_nil(restock.id) + end + + @tag :issuing_restock + test "create and cancel! issuing restock" do + issuing_restock = StarkInfra.IssuingRestock.create!([example_issuing_restock()]) |> hd + + assert !is_nil(issuing_restock) + + restock = StarkInfra.IssuingRestock.cancel!(issuing_restock.id) + assert !is_nil(restock.id) + end + + def example_issuing_restock() do + %StarkInfra.IssuingRestock{ + name: "Walter White", + tax_id: "012.345.678-90", + tags: ["breaking", "bad"] + } + end +end diff --git a/test/issuing_stock_log_test.exs b/test/issuing_stock_log_test.exs new file mode 100644 index 0000000..7c23bea --- /dev/null +++ b/test/issuing_stock_log_test.exs @@ -0,0 +1,60 @@ +defmodule StarkInfraTest.IssuingStock.Log do + use ExUnit.Case + + @tag :issuing_stock_log + test "get issuing stock log" do + log = + StarkInfra.IssuingStock.Log.query!(limit: 1) + |> Enum.take(1) + |> hd() + + {:ok, _log} = StarkInfra.IssuingStock.Log.get(log.id) + end + + @tag :issuing_stock_log + test "get! issuing stock log" do + log = + StarkInfra.IssuingStock.Log.query!(limit: 1) + |> Enum.take(1) + |> hd() + + _log = StarkInfra.IssuingStock.Log.get!(log.id) + end + + @tag :issuing_stock_log + test "query issuing stock log" do + StarkInfra.IssuingStock.Log.query(limit: 101) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :issuing_stock_log + test "query! issuing stock log" do + StarkInfra.IssuingStock.Log.query!(limit: 101) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :issuing_stock_log + test "query! issuing stock log with filters" do + documents = StarkInfra.IssuingStock.query!(status: "created") + |> Enum.take(1) + |> hd() + + StarkInfra.IssuingStock.Log.query!(limit: 1, documents_ids: [documents.id], types: "created") + |> Enum.take(5) + |> (fn list -> assert length(list) == 1 end).() + end + + @tag :issuing_stock_log + test "page issuing stock log" do + {:ok, ids} = StarkInfraTest.Utils.Page.get(&StarkInfra.IssuingStock.Log.page/1, 2, limit: 5) + assert length(ids) <= 10 + end + + @tag :issuing_stock_log + test "page! issuing stock log" do + ids = StarkInfraTest.Utils.Page.get!(&StarkInfra.IssuingStock.Log.page!/1, 2, limit: 5) + assert length(ids) <= 10 + end +end diff --git a/test/issuing_stock_test.exs b/test/issuing_stock_test.exs new file mode 100644 index 0000000..697cfa4 --- /dev/null +++ b/test/issuing_stock_test.exs @@ -0,0 +1,60 @@ +defmodule StarkInfraTest.IssuingStock do + use ExUnit.Case + + @tag :issuing_stock + test "get issuing stock" do + log = + StarkInfra.IssuingStock.query!(limit: 1) + |> Enum.take(1) + |> hd() + + {:ok, _log} = StarkInfra.IssuingStock.get(log.id) + end + + @tag :issuing_stock + test "get! issuing stock" do + log = + StarkInfra.IssuingStock.query!(limit: 1) + |> Enum.take(1) + |> hd() + + _log = StarkInfra.IssuingStock.get!(log.id) + end + + @tag :issuing_stock + test "query issuing stock" do + StarkInfra.IssuingStock.query(limit: 101) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :issuing_stock + test "query! issuing stock" do + StarkInfra.IssuingStock.query!(limit: 101) + |> Enum.take(200) + |> (fn list -> assert length(list) <= 101 end).() + end + + @tag :issuing_stock + test "query! issuing stock with filters" do + documents = StarkInfra.IssuingStock.query!(status: "created") + |> Enum.take(1) + |> hd() + + StarkInfra.IssuingStock.query!(limit: 1, documents_ids: [documents.id], types: "created") + |> Enum.take(5) + |> (fn list -> assert length(list) == 1 end).() + end + + @tag :issuing_stock + test "page issuing stock" do + {:ok, ids} = StarkInfraTest.Utils.Page.get(&StarkInfra.IssuingStock.page/1, 2, limit: 5) + assert length(ids) <= 10 + end + + @tag :issuing_stock + test "page! issuing stock" do + ids = StarkInfraTest.Utils.Page.get!(&StarkInfra.IssuingStock.page!/1, 2, limit: 5) + assert length(ids) <= 10 + end +end diff --git a/test/merchant_category_test.exs b/test/merchant_category_test.exs new file mode 100644 index 0000000..0fc55ff --- /dev/null +++ b/test/merchant_category_test.exs @@ -0,0 +1,21 @@ +defmodule StarkInfraTest.MerchantCategory do + use ExUnit.Case + + @tag :merchant_category + test "query! merchant category test" do + categories = StarkInfra.MerchantCategory.query!(search: "food") + |> Enum.take(1) + |> hd + + assert !is_nil(categories.code) + end + + @tag :merchant_category + test "query merchant category test" do + {:ok, categories} = StarkInfra.MerchantCategory.query(search: "food") + |> Enum.take(1) + |> hd + + assert !is_nil(categories.code) + end +end diff --git a/test/merchant_country_test.exs b/test/merchant_country_test.exs new file mode 100644 index 0000000..79c3b48 --- /dev/null +++ b/test/merchant_country_test.exs @@ -0,0 +1,21 @@ +defmodule StarkInfraTest.MerchantCountry do + use ExUnit.Case + + @tag :merchant_country + test "query! merchant country test" do + countries = StarkInfra.MerchantCountry.query!(search: "brazil") + |> Enum.take(1) + |> hd + + assert !is_nil(countries.code) + end + + @tag :merchant_country + test "query merchant country test" do + {:ok, countries} = StarkInfra.MerchantCountry.query(search: "brazil") + |> Enum.take(1) + |> hd + + assert !is_nil(countries.code) + end +end diff --git a/test/pix_claim_test.exs b/test/pix_claim_test.exs index 4476eea..196e029 100644 --- a/test/pix_claim_test.exs +++ b/test/pix_claim_test.exs @@ -29,6 +29,7 @@ defmodule StarkInfraTest.PixClaim do pix_claim = StarkInfra.PixClaim.query!(limit: 1) |> Enum.take(1) |> hd() + claim = StarkInfra.PixClaim.get!(pix_claim.id) assert !is_nil(claim.id) @@ -36,15 +37,14 @@ defmodule StarkInfraTest.PixClaim do @tag :pix_claim test "update pix claim" do - pix_claim = - StarkInfra.PixClaim.query!(limit: 1, status: "delivered") + pix_claim = StarkInfra.PixClaim.query!(limit: 1, status: "delivered", flow: "out") |> Enum.take(1) |> hd() {:ok, claim} = StarkInfra.PixClaim.update( - pix_claim.id, - "canceled", - reason: Enum.take_random(["fraud", "userRequested", "accountClosure"], 1) |> hd() + id: pix_claim.id, + status: "canceled", + reason: Enum.take_random(["fraud", "userRequested", "accountClosure"], 1) |> hd ) assert !is_nil(claim.id) @@ -52,14 +52,14 @@ defmodule StarkInfraTest.PixClaim do @tag :pix_claim test "update! pix claim" do - pix_claim = StarkInfra.PixClaim.query!(limit: 1, status: "delivered") + pix_claim = StarkInfra.PixClaim.query!(limit: 1, status: "delivered", flow: "out") |> Enum.take(1) - |> hd() + |> hd claim = StarkInfra.PixClaim.update!( - pix_claim.id, - "canceled", - reason: Enum.take_random(["fraud", "userRequested", "accountClosure"], 1) |> hd() + id: pix_claim.id, + status: "canceled", + reason: Enum.take_random(["fraud", "userRequested", "accountClosure"], 1) |> hd ) assert !is_nil(claim.id) @@ -70,8 +70,8 @@ defmodule StarkInfraTest.PixClaim do %StarkInfra.PixClaim{ account_created: DateTime.utc_now(), - account_number: "123456789", - account_type: "checking", + account_number: "0000-1", + account_type: "savings", branch_code: "0001", name: "Pix Claim", tax_id: pix_key.tax_id, diff --git a/test/pix_infraction_test.exs b/test/pix_infraction_test.exs index 7e0cd35..905354b 100644 --- a/test/pix_infraction_test.exs +++ b/test/pix_infraction_test.exs @@ -2,7 +2,7 @@ defmodule StarkInfraTest.PixInfraction do use ExUnit.Case @tag :pix_infraction - test "create pix infraction" do + test "create and cancel pix infraction" do {:ok, pix_infractions} = StarkInfra.PixInfraction.create(StarkInfraTest.Utils.PixInfraction.example_pix_infraction()) pix_infraction = pix_infractions |> hd {:ok, canceled_pix} = StarkInfra.PixInfraction.cancel(pix_infraction.id) @@ -10,7 +10,7 @@ defmodule StarkInfraTest.PixInfraction do end @tag :pix_infraction - test "create! pix infraction" do + test "create! and cancel pix infraction" do pix_infraction = StarkInfra.PixInfraction.create!(StarkInfraTest.Utils.PixInfraction.example_pix_infraction()) |> hd canceled_pix = StarkInfra.PixInfraction.cancel!(pix_infraction.id) assert !is_nil(canceled_pix.id) diff --git a/test/pix_key_test.exs b/test/pix_key_test.exs index 7485c70..b997f35 100644 --- a/test/pix_key_test.exs +++ b/test/pix_key_test.exs @@ -127,7 +127,7 @@ defmodule StarkInfraTest.PixKey do @tag :pix_key test "query pix and cancel" do - StarkInfra.PixKey.query(limit: 20) + StarkInfra.PixKey.query(limit: 20, status: "registered") |> Enum.take(10) |> Enum.each(fn {:ok, pix_key} -> StarkInfra.PixKey.cancel(pix_key.id) end) end diff --git a/test/static_brcode_test.exs b/test/static_brcode_test.exs new file mode 100644 index 0000000..af5cd54 --- /dev/null +++ b/test/static_brcode_test.exs @@ -0,0 +1,101 @@ +defmodule StarkInfraTest.StaticBrcode do + use ExUnit.Case + + @tag :static_brcode + test "get dynamic brcode" do + + brcodes = StarkInfra.StaticBrcode.query!(limit: 1) + |> Enum.take(1) + |> hd + + {:ok, brcode} = StarkInfra.StaticBrcode.get(brcodes.id) + + assert !is_nil(brcode.id) + end + + @tag :static_brcode + test "get! dynamic brcode" do + brcodes = StarkInfra.StaticBrcode.query!(limit: 1) + |> Enum.take(1) + |> hd + + brcode = StarkInfra.StaticBrcode.get!(brcodes.id) + + assert !is_nil(brcode.id) + end + + @tag :static_brcode + test "query static brcode test" do + {:ok, brcodes} = StarkInfra.StaticBrcode.query( + before: Date.utc_today |> Date.add(-1), + limit: 8) + |> Enum.take(1) + |> hd + + assert !is_nil(brcodes.id) + end + + @tag :static_brcode + test "query! static brcode test" do + brcodes = StarkInfra.StaticBrcode.query!(limit: 10) + |> Enum.take(1) + |> hd + + assert !is_nil(brcodes.id) + end + + @tag :static_brcode + test "page static brcode test" do + {:ok, {_cursor, brcodes}} = StarkInfra.StaticBrcode.page(limit: 10) + brcode = brcodes |> Enum.take(1) |> hd + + assert !is_nil(brcode.id) + end + + @tag :static_brcode + test "page! static brcode test" do + {_cursor, brcodes} = StarkInfra.StaticBrcode.page!(limit: 10) + brcode = brcodes |> Enum.take(1) |> hd + + assert !is_nil(brcode.id) + end + + @tag :static_brcode + test "create static brcode test" do + {:ok, brcode} = StarkInfra.StaticBrcode.create( + [example_static_brcode()] + ) + + brcode = brcode |> Enum.take(1) |> hd + + assert !is_nil(brcode.id) + end + + @tag :static_brcode + test "create! static brcode test" do + brcode = StarkInfra.StaticBrcode.create!( + [example_static_brcode()] + ) + + brcode = brcode |> Enum.take(1) |> hd + + assert !is_nil(brcode.id) + end + + def example_static_brcode do + StarkInfra.StaticBrcode.query!(limit: 10) + |> Enum.take(1) + |> hd + |> build_example + end + + def build_example(brcode) do + %StarkInfra.StaticBrcode{ + name: "Jamie Lannister", + key_id: "+5511988887777", + amount: brcode.amount, + reconciliation_id: "123", + city: "São Paulo" + } + end +end diff --git a/test/test_helper.exs b/test/test_helper.exs index f8e5bd8..c40db44 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1,9 +1,18 @@ # remove excluded tags to run specific module tests ExUnit.start( exclude: [ + # :brcode_preview, + # :card_method, + # :credit_holmes, + # :credit_holmes_log, # :credit_note, # :credit_note_log, + # :credit_preview, + # :dynamic_brcode, + # :static_brcode, # :event, + # :merchant_category, + # :merchant_country, # :pix_key, # :pix_key_log, # :pix_director, @@ -20,17 +29,28 @@ ExUnit.start( # :pix_infraction, # :pix_infraction_log, # :pix_domain, - # # :issuing_authorization, + # :individual_identity, + # :individual_identity_log, + # :individual_document, + # :individual_document_log, # :issuing_balance, - # :issuing_bin, # :issuing_card, # :issuing_card_log, + # :issuing_design, + # :issuing_embossing_request, + # :issuing_embossing_kit, + # :issuing_embossing_request_log, # :issuing_holder, # :issuing_holder_log, # :issuing_invoice, # :issuing_invoice_log, + # :issuing_product, # :issuing_purchase, # :issuing_purchase_log, + # :issuing_restock, + # :issuing_restock_log, + # :issuing_stock, + # :issuing_stock_log, # :issuing_transaction, # :issuing_transaction_log, # :issuing_withdrawal, diff --git a/test/utils/pix_reversal.exs b/test/utils/pix_reversal.exs index af6f9e3..fdbb707 100644 --- a/test/utils/pix_reversal.exs +++ b/test/utils/pix_reversal.exs @@ -3,7 +3,7 @@ defmodule StarkInfraTest.Utils.PixReversal do def generate_example_pix_reversal() do pix = StarkInfraTest.Utils.EndToEndId.get_end_to_end_id_to_reverse([], nil) |> hd %StarkInfra.PixReversal{ - amount: 10, + amount: Enum.random(1..10), end_to_end_id: pix.end_to_end_id, external_id: random_string(32), reason: "bankError"