Class: Bakong::OpenApi::Resources::Accounts

Inherits:
Base
  • Object
show all
Defined in:
lib/bakong/open_api/resources/accounts.rb

Overview

‘POST /v1/check_bakong_account` — check whether a Bakong account ID (e.g. “user@bank”) exists. The API returns responseCode 0 when the account exists, 1 + errorCode 11 when it does not. This wrapper collapses that into a Ruby boolean.

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Bakong::OpenApi::Resources::Base

Instance Method Details

#exists?(account_id:) ⇒ Boolean

Returns true if the account exists, false if not.

Parameters:

  • account_id (String)

    Bakong account ID, e.g. “vandy@aclb”

Returns:

  • (Boolean)

    true if the account exists, false if not

Raises:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bakong/open_api/resources/accounts.rb', line 17

def exists?(account_id:)
  envelope = connection.post(
    "/v1/check_bakong_account",
    body: { accountId:  }
  )
  response_code = envelope[:responseCode] || envelope[:response_code]
  error_code = envelope[:errorCode] || envelope[:error_code]
  message = envelope[:responseMessage] || envelope[:response_message]

  return true  if response_code.to_i.zero?
  return false if error_code.to_i == 11 # explicitly NOT_FOUND

  klass = Bakong::OpenApi::DOMAIN_ERROR_CLASSES[error_code.to_i] || Bakong::OpenApi::Error
  raise klass.new(message,
                  response_code: response_code, error_code: error_code,
                  response_message: message, body: envelope)
end