Class: ZaiPayment::Resources::BankAccount

Inherits:
Object
  • Object
show all
Defined in:
lib/zai_payment/resources/bank_account.rb

Overview

BankAccount resource for managing Zai bank accounts

Constant Summary collapse

FIELD_MAPPING =

Map of attribute keys to API field names

{
  user_id: :user_id,
  bank_name: :bank_name,
  account_name: :account_name,
  routing_number: :routing_number,
  account_number: :account_number,
  account_type: :account_type,
  holder_type: :holder_type,
  country: :country,
  payout_currency: :payout_currency,
  currency: :currency
}.freeze
UK_FIELD_MAPPING =

Map of UK-specific attribute keys to API field names

{
  user_id: :user_id,
  bank_name: :bank_name,
  account_name: :account_name,
  routing_number: :routing_number,
  account_number: :account_number,
  account_type: :account_type,
  holder_type: :holder_type,
  country: :country,
  payout_currency: :payout_currency,
  currency: :currency,
  iban: :iban,
  swift_code: :swift_code
}.freeze
VALID_ACCOUNT_TYPES =

Valid account types

%w[savings checking].freeze
VALID_HOLDER_TYPES =

Valid holder types

%w[personal business].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client: nil) ⇒ BankAccount

Returns a new instance of BankAccount.



47
48
49
# File 'lib/zai_payment/resources/bank_account.rb', line 47

def initialize(client: nil)
  @client = client || Client.new
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



9
10
11
# File 'lib/zai_payment/resources/bank_account.rb', line 9

def client
  @client
end

Instance Method Details

#create_au(**attributes) ⇒ Response

Create a new bank account for Australia

Examples:

Create an Australian bank account

bank_accounts = ZaiPayment::Resources::BankAccount.new
response = bank_accounts.create_au(
  user_id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
  bank_name: 'Bank of Australia',
  account_name: 'Samuel Seller',
  routing_number: '111123',
  account_number: '111234',
  account_type: 'checking',
  holder_type: 'personal',
  country: 'AUS',
  payout_currency: 'AUD',
  currency: 'AUD'
)

Parameters:

  • attributes (Hash)

    bank account attributes

Options Hash (**attributes):

  • :user_id (String) — default: Required

    User ID

  • :bank_name (String) — default: Required

    Bank name (defaults to Bank of Australia)

  • :account_name (String) — default: Required

    Account name (defaults to Samuel Seller)

  • :routing_number (String) — default: Required

    Routing number / BSB number (defaults to 111123)

  • :account_number (String) — default: Required

    Account number (defaults to 111234)

  • :account_type (String) — default: Required

    Account type ('savings' or 'checking', defaults to checking)

  • :holder_type (String) — default: Required

    Holder type ('personal' or 'business', defaults to personal)

  • :country (String) — default: Required

    Country code (ISO 3166-1 alpha-3, max 3 chars, defaults to AUS)

  • :payout_currency (String)

    Optional currency code for payouts (ISO 4217 alpha-3)

  • :currency (String)

    Optional currency code (ISO 4217 alpha-3)

Returns:

  • (Response)

    the API response containing created bank account

See Also:



111
112
113
114
115
116
# File 'lib/zai_payment/resources/bank_account.rb', line 111

def create_au(**attributes)
  validate_create_au_attributes!(attributes)

  body = (attributes, :au)
  client.post('/bank_accounts', body: body)
end

#create_uk(**attributes) ⇒ Response

Create a new bank account for UK

Examples:

Create a UK bank account

bank_accounts = ZaiPayment::Resources::BankAccount.new
response = bank_accounts.create_uk(
  user_id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
  bank_name: 'Bank of UK',
  account_name: 'Samuel Seller',
  routing_number: '111123',
  account_number: '111234',
  account_type: 'checking',
  holder_type: 'personal',
  country: 'GBR',
  payout_currency: 'GBP',
  currency: 'GBP',
  iban: 'GB25QHWM02498765432109',
  swift_code: 'BUKBGB22'
)

Parameters:

  • attributes (Hash)

    bank account attributes

Options Hash (**attributes):

  • :user_id (String) — default: Required

    User ID

  • :bank_name (String) — default: Required

    Bank name (defaults to Bank of UK)

  • :account_name (String) — default: Required

    Account name (defaults to Samuel Seller)

  • :routing_number (String) — default: Required

    Routing number / Sort Code / BSB number (defaults to 111123)

  • :account_number (String) — default: Required

    Account number (defaults to 111234)

  • :account_type (String) — default: Required

    Account type ('savings' or 'checking', defaults to checking)

  • :holder_type (String) — default: Required

    Holder type ('personal' or 'business', defaults to personal)

  • :country (String) — default: Required

    Country code (ISO 3166-1 alpha-3, max 3 chars, defaults to GBR)

  • :payout_currency (String)

    Optional currency code for payouts (ISO 4217 alpha-3)

  • :currency (String)

    Optional currency code (ISO 4217 alpha-3)

  • :iban (String) — default: Required for UK

    IBAN number

  • :swift_code (String) — default: Required for UK

    SWIFT Code / BIC

Returns:

  • (Response)

    the API response containing created bank account

See Also:



156
157
158
159
160
161
# File 'lib/zai_payment/resources/bank_account.rb', line 156

def create_uk(**attributes)
  validate_create_uk_attributes!(attributes)

  body = (attributes, :uk)
  client.post('/bank_accounts', body: body)
end

#redact(bank_account_id) ⇒ Response

Redact a bank account

Redacts a bank account using the given bank_account_id. Redacted bank accounts can no longer be used as a funding source or a disbursement destination.

Examples:

bank_accounts = ZaiPayment::Resources::BankAccount.new
response = bank_accounts.redact("bank_account_id")

Parameters:

  • bank_account_id (String)

    the bank account ID

Returns:

See Also:



176
177
178
179
# File 'lib/zai_payment/resources/bank_account.rb', line 176

def redact()
  validate_id!(, 'bank_account_id')
  client.delete("/bank_accounts/#{bank_account_id}")
end

#show(bank_account_id, include_decrypted_fields: false) ⇒ Response

Get a specific bank account by ID

Examples:

bank_accounts = ZaiPayment::Resources::BankAccount.new
response = bank_accounts.show("bank_account_id")
response.data # => {"id" => "bank_account_id", "active" => true, ...}

with decrypted fields

response = bank_accounts.show("bank_account_id", include_decrypted_fields: true)
# Returns full account number instead of masked version

Parameters:

  • bank_account_id (String)

    the bank account ID

  • include_decrypted_fields (Boolean) (defaults to: false)

    if true, the API will decrypt and return sensitive bank account fields (for example, the full account number). Defaults to false

Returns:

  • (Response)

    the API response containing bank account details

See Also:



68
69
70
71
72
73
74
75
# File 'lib/zai_payment/resources/bank_account.rb', line 68

def show(, include_decrypted_fields: false)
  validate_id!(, 'bank_account_id')

  params = {}
  params[:include_decrypted_fields] = include_decrypted_fields if include_decrypted_fields

  client.get("/bank_accounts/#{bank_account_id}", params: params)
end

#validate_routing_number(routing_number) ⇒ Response

Validate a US bank routing number

Validates a US bank routing number before creating an account. This can be used to provide on-demand verification and further information of the bank information a user is providing.

Examples:

bank_accounts = ZaiPayment::Resources::BankAccount.new
response = bank_accounts.validate_routing_number("122235821")
response.data # => {"routing_number" => "122235821", "customer_name" => "US BANK NA", ...}

Parameters:

  • routing_number (String)

    the US bank routing number

Returns:

  • (Response)

    the API response containing routing number details

See Also:



196
197
198
199
200
201
# File 'lib/zai_payment/resources/bank_account.rb', line 196

def validate_routing_number(routing_number)
  validate_presence!(routing_number, 'routing_number')

  params = { routing_number: routing_number }
  client.get('/tools/routing_number', params: params)
end