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



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

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
)

Options Hash (options):

  • :account_numbers (String)

    The bank account numbers to validate.

  • :sort_codes (String)

    The branch sort codes for the account number.



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

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
)

Options Hash (options):

  • :account_numbers (String)

    The bank account numbers to validate.

  • :sort_codes (String)

    The branch sort codes for the account number.

Raises:

  • (Error)

    If the result is not a success



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

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')

Options Hash (options):

  • :sort_code (String)

    The branch sortcode.



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

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')

Options Hash (options):

  • :sort_code (String)

    The branch sortcode.

Raises:

  • (Error)

    If the result is not a success



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

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')

Options Hash (options):

  • :account_number (String)

    The bank account number to validate.

  • :sort_code (String)

    The branch sort code for the account number.



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

def (options)
  response = client.get(VALIDATE_ACCOUNT_ENDPOINT, 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')

Options Hash (options):

  • :account_number (String)

    The bank account number to validate.

  • :sort_code (String)

    The branch sort code for the account number.

Raises:

  • (Error)

    If the result is not a success



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

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')

Options Hash (options):

  • :card_number (String)

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



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

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')

Options Hash (options):

  • :card_number (String)

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

Raises:

  • (Error)

    If the result is not a success



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

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')

Options Hash (options):

  • :iban (String)

    The international bank account number to validate.



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

def (options)
  response = client.get(VALIDATE_INT_ACCOUNT_ENDPOINT, 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')

Options Hash (options):

  • :iban (String)

    The international bank account number to validate.

Raises:

  • (Error)

    If the result is not a success



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

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