Bacen.STA (Bacen STA v0.1.1)

Sistema de Transferência de Arquivos

The STA context.

It communicates with Bacen's STA (Sisbacen) WebService.

Link to this section Summary

Functions

Creates a new protocol and sends it to Bacen's STA WebService.

Sends a file content for given protocol number to Bacen's STA WebService.

Checks if system is defined to use the staging server

Link to this section Functions

Link to this function

create_protocol(attrs)

Specs

create_protocol(map()) :: {:ok, String.t()} | {:error, any()}

Creates a new protocol and sends it to Bacen's STA WebService.

Examples

iex> attrs = %{
iex>   parameters: %{
iex>     file_size: 1234,
iex>     file_name: "foo",
iex>     file_type: "ACCS001",
iex>     hash: "053c29ae8b823df65f5bff084f410ca70530c30112bc7590518fe421f4421443"
iex>   }
iex> }
iex> Mox.stub_with(Bacen.STA.ClientMock, FakeBacenSTA)
iex> Bacen.STA.create_protocol(attrs)
{:ok, "123456789"}

iex> attrs = %{
iex>   parameters: %{
iex>     file_size: 1234,
iex>     file_name: "invalid_xml",
iex>     file_type: "ACCS001",
iex>     hash: "053c29ae8b823df65f5bff084f410ca70530c30112bc7590518fe421f4421443"
iex>   }
iex> }
iex> Mox.stub_with(Bacen.STA.ClientMock, FakeBacenSTA)
iex> Bacen.STA.create_protocol(attrs)
{:error, :invalid_xml}

iex> attrs = %{
iex>   parameters: %{
iex>     file_size: 1234,
iex>     file_name: "error",
iex>     file_type: "ACCS001",
iex>     hash: "053c29ae8b823df65f5bff084f410ca70530c30112bc7590518fe421f4421443"
iex>   }
iex> }
iex> Mox.stub_with(Bacen.STA.ClientMock, FakeBacenSTA)
iex> Bacen.STA.create_protocol(attrs)
{:error, [%{attr: [], name: :Resultado, value: [%{attr: [], name: :Erro, value: ["bad request"]}]}]}
Link to this function

send_file_content(protocol_number, file_content)

Specs

send_file_content(String.t(), String.t()) :: :ok | {:error, any()}

Sends a file content for given protocol number to Bacen's STA WebService.

Examples

iex> Mox.stub_with(Bacen.STA.ClientMock, FakeBacenSTA)
iex> Bacen.STA.send_file_content("123456789", "some long file content")
:ok

iex> Mox.stub_with(Bacen.STA.ClientMock, FakeBacenSTA)
iex> Bacen.STA.send_file_content("123456789", "wrong file content")
{:error, [%{attr: [], name: :Resultado, value: [%{attr: [], name: :Erro, value: ["bad request"]}]}]}

Specs

test?() :: boolean()

Checks if system is defined to use the staging server

Examples

iex> Application.put_env(:bacen_sta, :test_mode, true)
iex> Bacen.STA.test?()
true

iex> Application.put_env(:bacen_sta, :test_mode, false)
iex> Bacen.STA.test?()
false