Class: Payabli::Device::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/payabli/device/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



9
10
11
# File 'lib/payabli/device/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#challenge(request_options: {}, **params) ⇒ Payabli::Types::DeviceChallengeResponse

Generates a one-time, 6-digit verification code for activating a semi-integrated card-present device in a paypoint. After calling this endpoint, an operator enters the returned code on the device's terminal, along with a device name, to register the device to the paypoint resolved from {entry}.

A code expires 5 minutes after it's issued. A paypoint can have several codes active at once — for example, when activating a batch of devices — and a code binds to whichever device enters it first.

Authenticate with an OAuth2 Bearer token that has the device_registry scope.

Examples:

client.device.challenge(entry: "8cfec329267")

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :entry (String)

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/payabli/device/client.rb', line 38

def challenge(request_options: {}, **params)
  params = Payabli::Internal::Types::Utils.normalize_keys(params)
  headers = @client.auth_headers_for_endpoint(security: [{ "BearerAuth" => [] }])
  request = Payabli::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "Device/challenge/#{URI.encode_uri_component(params[:entry].to_s)}",
    headers: headers,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Payabli::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Payabli::Types::DeviceChallengeResponse.load(response.body)
  else
    error_class = Payabli::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end