Class: FluvPay::Resources::Withdrawals

Inherits:
Object
  • Object
show all
Defined in:
lib/fluvpay/resources/withdrawals.rb

Overview

Recurso de saques PIX da conta para uma chave PIX.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Withdrawals

Returns a new instance of Withdrawals.



11
12
13
# File 'lib/fluvpay/resources/withdrawals.rb', line 11

def initialize(client)
  @client = client
end

Instance Method Details

#create(amount_cents:, pix_key:, pix_key_type:, description: nil, idempotency_key: nil) ⇒ Hash

Cria um saque PIX.

Escopo exigido: withdrawals.create. Idempotency-Key gerado se omitido. Não suportado em sandbox: chaves fluv_test_ recebem 403 (SANDBOX_NOT_SUPPORTED_FOR_WITHDRAWALS).

Parameters:

  • amount_cents (Integer)

    valor bruto em centavos (100..10000000).

  • pix_key (String)

    chave PIX de destino (1..140 caracteres).

  • pix_key_type (String)

    tipo da chave: cpf, cnpj, email, phone ou evp.

  • description (String, nil) (defaults to: nil)

    descrição (até 140 caracteres).

  • idempotency_key (String, nil) (defaults to: nil)

    Idempotency-Key; gerado se omitido.

Returns:

  • (Hash)

    o saque criado.



27
28
29
30
31
32
33
34
35
36
# File 'lib/fluvpay/resources/withdrawals.rb', line 27

def create(amount_cents:, pix_key:, pix_key_type:, description: nil, idempotency_key: nil)
  body = {
    "amount_cents" => amount_cents,
    "pix_key" => pix_key,
    "pix_key_type" => pix_key_type,
    "description" => description
  }
  key = idempotency_key || FluvPay::Client.new_idempotency_key
  @client.request(:post, "/withdrawals/", body: body, idempotency_key: key)
end

#list(limit: nil, offset: nil, status: nil) ⇒ FluvPay::Resources::OffsetList

Lista saques.

Escopo exigido: withdrawals.read. Envelope: limit/offset.

Parameters:

  • limit (Integer, nil) (defaults to: nil)

    itens por página (1..100).

  • offset (Integer, nil) (defaults to: nil)

    deslocamento (>= 0).

  • status (String, nil) (defaults to: nil)

    filtra por status.

Returns:



45
46
47
48
49
50
51
52
53
# File 'lib/fluvpay/resources/withdrawals.rb', line 45

def list(limit: nil, offset: nil, status: nil)
  params = {
    "limit" => limit,
    "offset" => offset,
    "status" => status
  }
  payload = @client.request(:get, "/withdrawals/", params: params)
  OffsetList.new(payload)
end

#retrieve(withdrawal_id) ⇒ Hash

Recupera um saque por ID.

Parameters:

  • withdrawal_id (String)

    identificador do saque.

Returns:

  • (Hash)

    o saque.



59
60
61
# File 'lib/fluvpay/resources/withdrawals.rb', line 59

def retrieve(withdrawal_id)
  @client.request(:get, "/withdrawals/#{ERB::Util.url_encode(withdrawal_id.to_s)}")
end