Class: AbacatePay::Clients::TransparentClient

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

Overview

Client for transparent PIX checkout in the AbacatePay API.

Transparent checkout returns the QR code and copy-and-paste payload directly, so the payment stays inside your own UI.

Constant Summary collapse

URI =
"transparents"

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) ⇒ TransparentClient

Returns a new instance of TransparentClient.



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

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

Instance Method Details

#check(id) ⇒ Resources::Transparents

Parameters:

  • id (String)

    QR code ID

Returns:



40
41
42
43
# File 'lib/abacate_pay/clients/transparent_client.rb', line 40

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

#create(data, method: Enums::Billings::Methods::PIX) ⇒ Resources::Transparents

Creates a transparent charge.

Parameters:

  • data (Resources::Transparents)

    The charge to create

  • method (String) (defaults to: Enums::Billings::Methods::PIX)

    "PIX" or "BOLETO"

Returns:

Raises:

  • (ArgumentError)

    if the method is not supported, or if a BOLETO charge is missing the payer name/taxId the API requires



30
31
32
33
34
35
36
# File 'lib/abacate_pay/clients/transparent_client.rb', line 30

def create(data, method: Enums::Billings::Methods::PIX)
  validate_transparent_method!(method)
  validate_boleto_payer!(data) if method == Enums::Billings::Methods::BOLETO

  response = request("POST", "create", json: build_create_payload(data, method))
  Resources::Transparents.new(response)
end

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

Parameters:

  • params (Hash)

    Optional pagination params (after, before, limit)

Returns:



18
19
20
21
# File 'lib/abacate_pay/clients/transparent_client.rb', line 18

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

#refund(id) ⇒ Resources::Transparents

Refunds a transparent payment in full. AbacatePay does not support partial refunds, the original amount is always returned.

Parameters:

  • id (String)

    Public charge ID (pix_char_..., card_..., char_...)

Returns:



59
60
61
62
# File 'lib/abacate_pay/clients/transparent_client.rb', line 59

def refund(id)
  response = request("POST", "refund", json: { id: id })
  Resources::Transparents.new(response)
end

#simulate_payment(id) ⇒ Resources::Transparents

Parameters:

  • id (String)

    QR code ID (dev mode only)

Returns:



47
48
49
50
51
52
# File 'lib/abacate_pay/clients/transparent_client.rb', line 47

def simulate_payment(id)
  # The API reads the id from the query string here, like #check. Sending
  # it only in the body fails with "Expected property 'id'".
  response = request("POST", "simulate-payment", params: { id: id }, json: {})
  Resources::Transparents.new(response)
end