Class: Loqate::Bank::Gateway

Inherits:
Object
  • Object
show all
Includes:
Result::Mixin
Defined in:
lib/loqate/bank/gateway.rb

Overview

Validates bank accounts, branches and cards.

Constant Summary collapse

RETRIEVE_BY_SORTCODE_ENDPOINT =
'/BankAccountValidation/Interactive/RetrieveBySortcode/v1.00/json3.ws'.freeze
VALIDATE_CARD_ENDPOINT =
'/CardValidation/Interactive/Validate/v1/json3.ws'.freeze
VALIDATE_ACCOUNT_ENDPOINT =
'/BankAccountValidation/Interactive/Validate/v2/json3.ws'.freeze
VALIDATE_ACCOUNTS_ENDPOINT =
'/BankAccountValidation/Batch/Validate/v1/json3.ws'.freeze
VALIDATE_INT_ACCOUNT_ENDPOINT =
'/InternationalBankValidation/Interactive/Validate/v1/json3.ws'.freeze

Constants included from Result::Mixin

Result::Mixin::Failure, Result::Mixin::Success

Instance Method Summary collapse

Methods included from Result::Mixin

#Failure, #Success, #unwrap_result_or_raise

Constructor Details

#initialize(client) ⇒ Gateway

Creates a bank gateway

Parameters:

  • client (Client)

    The client responsible for the HTTP interactions



29
30
31
32
33
# File 'lib/loqate/bank/gateway.rb', line 29

def initialize(client)
  @client       = client
  @mapper       = Mappers::GenericMapper.new
  @error_mapper = Mappers::ErrorMapper.new
end

Instance Method Details

#batch_validate_accounts(options) ⇒ Result

Batch validates the bank account and sort code for an UK bank account are correct. Returns details of the holding branch, IBAN and correct BACS account details.

Examples:

 = [123456789, 987654321]
sort_codes = ['12-34-56', '65-43-21']

result = bank_gateway.batch_validate_accounts(
  account_numbers: ,
  sort_codes: sort_codes
)

Parameters:

  • options (Hash)

    The options to batch validate bank accounts.

Options Hash (options):

  • :account_numbers (String)

    The bank account numbers to validate.

  • :sort_codes (String)

    The branch sort codes for the account number.

Returns:

  • (Result)

    A result wrapping multiple account validations



53
54
55
56
57
# File 'lib/loqate/bank/gateway.rb', line 53

def batch_validate_accounts(options)
  response = client.get(VALIDATE_ACCOUNTS_ENDPOINT, options)

  response.errors? && build_error_from(response.items.first) || (response.items)
end

#batch_validate_accounts!(options) ⇒ Array<BatchAccountValidation>

Batch validates the bank account and sort code for an UK bank account are correct. Returns details of the holding branch, IBAN and correct BACS account details.

Examples:

 = [123456789, 987654321]
sort_codes = ['12-34-56', '65-43-21']

 = bank_gateway.batch_validate_accounts!(
  account_numbers: ,
  sort_codes: sort_codes
)

Parameters:

  • options (Hash)

    The options to batch validate bank accounts.

Options Hash (options):

  • :account_numbers (String)

    The bank account numbers to validate.

  • :sort_codes (String)

    The branch sort codes for the account number.

Returns:

Raises:

  • (Error)

    If the result is not a success



148
149
150
# File 'lib/loqate/bank/gateway.rb', line 148

def batch_validate_accounts!(options)
  unwrap_result_or_raise { batch_validate_accounts(options) }
end

#retrieve_by_sortcode(options) ⇒ Result

Returns details of the holding branch.

Examples:

result = bank_gateway.retrieve_by_postcode(sort_code: 'S1 2HD')

Parameters:

  • options (Hash)

    The options to retrieve the details of the holding branch.

Options Hash (options):

  • :sort_code (String)

    The branch sortcode.

Returns:

  • (Result)

    A result wrapping a bank branch



105
106
107
108
109
# File 'lib/loqate/bank/gateway.rb', line 105

def retrieve_by_sortcode(options)
  response = client.get(RETRIEVE_BY_SORTCODE_ENDPOINT, options)

  response.errors? && build_error_from(response.items.first) || build_branch_from(response.items)
end

#retrieve_by_sortcode!(options) ⇒ Branch

Returns details of the holding branch.

Examples:

branch = bank_gateway.retrieve_by_postcode!(sort_code: 'S1 2HD')

Parameters:

  • options (Hash)

    The options to retrieve the details of the holding branch.

Options Hash (options):

  • :sort_code (String)

    The branch sortcode.

Returns:

Raises:

  • (Error)

    If the result is not a success



198
199
200
# File 'lib/loqate/bank/gateway.rb', line 198

def retrieve_by_sortcode!(options)
  unwrap_result_or_raise { retrieve_by_sortcode(options) }
end

#validate_account(options) ⇒ Result

Validates the bank account and sort code for an UK bank account are correct. Returns details of the holding branch, IBAN and correct BACS account details.

Examples:

result = bank_gateway.(account_number: '123456', sort_code: '12-34-56')

Parameters:

  • options (Hash)

    The options to validate a bank account.

Options Hash (options):

  • :account_number (String)

    The bank account number to validate.

  • :sort_code (String)

    The branch sort code for the account number.

Returns:

  • (Result)

    A result wrapping a bank account validation



71
72
73
74
75
76
# File 'lib/loqate/bank/gateway.rb', line 71

def (options)
  response = client.get(, options)

  first_result = response.items.first
  response.errors? && build_error_from(first_result) || (first_result)
end

#validate_account!(options) ⇒ AccountValidation

Validates the bank account and sort code for an UK bank account are correct. Returns details of the holding branch, IBAN and correct BACS account details.

Examples:

bank_validation = bank_gateway.validate_account!(account_number: '123456', sort_code: '12-34-56')

Parameters:

  • options (Hash)

    The options to validate a bank account.

Options Hash (options):

  • :account_number (String)

    The bank account number to validate.

  • :sort_code (String)

    The branch sort code for the account number.

Returns:

Raises:

  • (Error)

    If the result is not a success



166
167
168
# File 'lib/loqate/bank/gateway.rb', line 166

def validate_account!(options)
  unwrap_result_or_raise { (options) }
end

#validate_card(options) ⇒ Result

Validates the credit card number follows the correct format for the card type.

Examples:

result = bank_gateway.validate_card(card_number: '4024 0071 7123 9865')

Parameters:

  • options (Hash)

    The options to validate an card.

Options Hash (options):

  • :card_number (String)

    The full card number. Any spaces or non numeric characters will be ignored.

Returns:

  • (Result)

    A result wrapping a card validation



122
123
124
125
126
# File 'lib/loqate/bank/gateway.rb', line 122

def validate_card(options)
  response = client.get(VALIDATE_CARD_ENDPOINT, options)

  response.errors? && build_error_from(response.items.first) || build_card_validation_from(response.items.first)
end

#validate_card!(options) ⇒ CardValidation

Validates the credit card number follows the correct format for the card type.

Examples:

card_validation = bank_gateway.validate_card!(card_number: '4024 0071 7123 9865')

Parameters:

  • options (Hash)

    The options to validate an card.

Options Hash (options):

  • :card_number (String)

    The full card number. Any spaces or non numeric characters will be ignored.

Returns:

Raises:

  • (Error)

    If the result is not a success



215
216
217
# File 'lib/loqate/bank/gateway.rb', line 215

def validate_card!(options)
  unwrap_result_or_raise { validate_card(options) }
end

#validate_international_account(options) ⇒ Result

Validates if the international bank account number for an international bank account is correct.

Examples:

result = bank_gateway.(iban: 'GB67HBUK40413151065718')

Parameters:

  • options (Hash)

    The options to validate an international bank account.

Options Hash (options):

  • :iban (String)

    The international bank account number to validate.

Returns:

  • (Result)

    A result wrapping a bank account validation



88
89
90
91
92
93
# File 'lib/loqate/bank/gateway.rb', line 88

def (options)
  response = client.get(, options)

  first_result = response.items.first
  response.errors? && build_error_from(first_result) || build_int_acc_validation_from(first_result)
end

#validate_international_account!(options) ⇒ InternationalAccountValidation

Validates if the international bank account number for an international bank account is correct.

Examples:

bank_validation = bank_gateway.validate_international_account!(iban: 'GB67HBUK40413151065718')

Parameters:

  • options (Hash)

    The options to validate an international bank account.

Options Hash (options):

  • :iban (String)

    The international bank account number to validate.

Returns:

Raises:

  • (Error)

    If the result is not a success



182
183
184
# File 'lib/loqate/bank/gateway.rb', line 182

def validate_international_account!(options)
  unwrap_result_or_raise { (options) }
end