ExPIX (ExPIX v0.1.0) View Source

Module with basic operations.

All functions in this library use the parameters in the config.exs file. By default, the configuration for building static QR-Codes is:

config :ex_pix, :static_code,
  payload_indicator: "01",
  start_method: "11",
  gui: "br.gov.bcb.pix",
  currency_code: "986",
  country_code: "BR",
  default_value: "0.00",
  category_code: "0000"

If you need to change any of these parameters, just define it in your own configuration file.

Link to this section Summary

Types

Optional parameters to build the notes of the operation.

Additional parameters to build the code.

Basic information for building static code. It must be a map with the following parameters

Functions

Generates a static raw code. This function uses the default parameters defined in the static_code configuration, but if you need a special parameter, this function can receive such parameters as well.

Link to this section Types

Specs

account_params() :: %{optional(:info) => String.t()}

Optional parameters to build the notes of the operation.

  • :info - A string with the operation notes.

Important:

  • The count of characters of the info + count of characters of the gui + count of characters of the key must not exceed the limit of 99 characters. If this limit is exceeded, an error will be returned.

Specs

additional_params() :: %{optional(:txid) => String.t()}

Additional parameters to build the code.

  • :txid - An ID to represent the operation. If not provided, the txid will be ***, that represents a random string to be generated by Banco Central.

Important:

  • Banco Central does not check if the provided ID is unique, so the recomendation here is use an UUID (ideally the v4).
  • The count of characters must not exceed the limit of 99 characters. If this limit is exceeded, an error will be returned.

Specs

static_params() :: %{
  :merchant_name => String.t(),
  :merchant_city => String.t(),
  optional(:amount) => String.t(),
  optional(:payload_indicator) => String.t(),
  optional(:initiation_method) => String.t(),
  optional(:category_code) => String.t(),
  optional(:currency_code) => String.t(),
  optional(:country_code) => String.t(),
  optional(:postal_code) => String.t()
}

Basic information for building static code. It must be a map with the following parameters:

  • :merchant_name - Required field that represents the name of the user to be charged.
  • :merchant_city - Required field that represents the city of the user to be charged.
  • :postal_code - Non-Required field that represents the user's postal code.
  • :amount - The amount of the operation. If not provided, the code will use the default value defined in the configuration. It must be a string in the format 0.00.
  • :payload_indicator - The payload indicator of the operation. If not provided, the code will use the default value defined in the configuration.
  • :initiation_method - The initiation method of the operation. If not provided, the code will use the default value defined in the configuration.
  • :category_code - The category code of the operation. If not provided, the code will use the default value defined in the configuration.
  • :currency_code - The currency code of the operation. If not provided, the code will use the default value defined in the configuration.
  • :country_code - The country code of the operation. If not provided, the code will use the default value defined in the configuration.

Link to this section Functions

Link to this function

generate_static_code(key, static_params, account_params \\ %{}, additional_params \\ %{})

View Source

Specs

generate_static_code(
  String.t(),
  static_params(),
  account_params(),
  additional_params()
) :: {:ok, String.t()} | {:error, any()}

Generates a static raw code. This function uses the default parameters defined in the static_code configuration, but if you need a special parameter, this function can receive such parameters as well.

  • key - The 'key' to be charged. It can be a CNPJ, CPF, phone number or a random binary string. It is not necessary to send the key type, but this function expects that the key is already in the format for your type (see the PIX docs for some examples).
  • static_params - Basic information to build a static code.
  • account_params - Optional parameters to build the notes of the operation.
  • additional_params - Additional parameters to build the code.

Example:

  iex> ExPIX.generate_static_code("email@email.com", %{merchant_name: "Leonardo Leite", merchant_city: "Florianopolis"})
  {:ok, "00020101021126370014br.gov.bcb.pix0115email@email.com52040000530398654040.005802BR5914Leonardo Leite6013Florianopolis62070503***6304891C"}