Class: AbacatePay::Clients::PixClient

Inherits:
Client
  • Object
show all
Defined in:
lib/abacate_pay/clients/pix_client.rb

Overview

Client for outbound PIX transfers in the AbacatePay API.

Transfers are sent to a PIX key; see Enums::Pix::KeyTypes for the accepted key formats.

Constant Summary collapse

URI =
"pix"

Constants inherited from Client

Client::RETRIABLE_EXCEPTIONS, Client::RETRIABLE_METHODS, Client::RETRIABLE_STATUSES

Instance Method Summary collapse

Methods inherited from Client

#auto_paging_each, #each_page

Constructor Details

#initialize(client = nil) ⇒ PixClient

Returns a new instance of PixClient.



12
13
14
# File 'lib/abacate_pay/clients/pix_client.rb', line 12

def initialize(client = nil)
  super(URI, client)
end

Instance Method Details

#get(id) ⇒ Resources::PixTransfers

Parameters:

  • id (String)

    PIX transfer ID

Returns:



29
30
31
32
# File 'lib/abacate_pay/clients/pix_client.rb', line 29

def get(id)
  response = request("GET", "get", params: { id: id })
  Resources::PixTransfers.new(response)
end

#list(**params) ⇒ Array<Resources::PixTransfers>

The API requires an id on this endpoint: a bare call fails with "Expected property 'id' to be string but found: undefined". Despite the name it filters rather than lists.

Parameters:

  • params (Hash)

    Params forwarded to the API; id is required

Returns:



22
23
24
25
# File 'lib/abacate_pay/clients/pix_client.rb', line 22

def list(**params)
  response = request("GET", "list", params: params.empty? ? nil : params)
  build_list(response, Resources::PixTransfers)
end

#send_pix(data) ⇒ Resources::PixTransfers

Sends a PIX transfer to an external key. Named send_pix to avoid conflict with Ruby's Object#send.

Parameters:

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/abacate_pay/clients/pix_client.rb', line 39

def send_pix(data)
  response = request("POST", "send", json: {
                       amount: data.amount,
                       externalId: data.external_id,
                       description: data.description,
                       # The API nests the destination under `pix`, with
                       # `key` and `type`. Sending pixKey/pixKeyType at the
                       # top level fails with "Property 'pix' is missing";
                       # nesting the wrong names fails with
                       # "Property 'pix.type' is missing".
                       pix: { key: data.key, type: data.key_type }
                     })
  Resources::PixTransfers.new(response)
end