Module: Bakong::Khqr::Helpers::CheckAccountID
- Defined in:
- lib/bakong/khqr/helpers/check_account_id.rb
Overview
Calls the Bakong Open API account-existence endpoint with a single bakong account ID. Returns true/false; raises Bakong::Khqr::Error on malformed input or transport failure.
Class Method Summary collapse
Class Method Details
.call(url, account_id) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/bakong/khqr/helpers/check_account_id.rb', line 17 def call(url, account_id) if account_id.length > EMV[:INVALID_LENGTH][:BAKONG_ACCOUNT] raise Error.from(ERROR_CODES[:BAKONG_ACCOUNT_ID_LENGTH_INVALID]) end raise Error.from(ERROR_CODES[:BAKONG_ACCOUNT_ID_INVALID]) if account_id.split("@").length != 2 response = Http.post_json(url, { accountId: account_id }) error = response[:errorCode] response_code = response[:responseCode] return { bakong_account_existed: false } if error == 11 raise Error.from(ERROR_CODES[:BAKONG_ACCOUNT_ID_INVALID]) if error == 12 { bakong_account_existed: response_code.to_i.zero? } end |