Class: ZaiPayment::Resources::VirtualAccount

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

Overview

VirtualAccount resource for managing Zai virtual accounts

Constant Summary collapse

CREATE_FIELD_MAPPING =

Map of attribute keys to API field names for create

{
  account_name: :account_name,
  aka_names: :aka_names
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client: nil) ⇒ VirtualAccount



17
18
19
# File 'lib/zai_payment/resources/virtual_account.rb', line 17

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

Instance Method Details

#create(wallet_account_id, **attributes) ⇒ Response

Create a Virtual Account for a given Wallet Account

Examples:

Create a virtual account

virtual_accounts = ZaiPayment::Resources::VirtualAccount.new
response = virtual_accounts.create(
  'ae07556e-22ef-11eb-adc1-0242ac120002',
  account_name: 'Real Estate Agency X',
  aka_names: ['Realestate agency X']
)
response.data # => {"id" => "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", ...}

Options Hash (**attributes):

  • :account_name (String)

    A name given for the Virtual Account (max 140 chars)

  • :aka_names (Array<String>)

    A list of AKA Names (0 to 3 items)

See Also:



72
73
74
75
76
77
78
# File 'lib/zai_payment/resources/virtual_account.rb', line 72

def create(, **attributes)
  validate_id!(, 'wallet_account_id')
  validate_create_attributes!(attributes)

  body = build_create_body(attributes)
  client.post("/wallet_accounts/#{wallet_account_id}/virtual_accounts", body: body)
end

#list(wallet_account_id) ⇒ Response

List Virtual Accounts for a given Wallet Account

Examples:

List virtual accounts

virtual_accounts = ZaiPayment::Resources::VirtualAccount.new
response = virtual_accounts.list('ae07556e-22ef-11eb-adc1-0242ac120002')
response.data # => [{"id" => "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", ...}, ...]
response.meta # => {"total" => 2}

See Also:



33
34
35
36
# File 'lib/zai_payment/resources/virtual_account.rb', line 33

def list()
  validate_id!(, 'wallet_account_id')
  client.get("/wallet_accounts/#{wallet_account_id}/virtual_accounts")
end

#show(virtual_account_id) ⇒ Response

Show a specific Virtual Account

Examples:

Get virtual account details

virtual_accounts = ZaiPayment::Resources::VirtualAccount.new
response = virtual_accounts.show('46deb476-c1a6-41eb-8eb7-26a695bbe5bc')
response.data # => {"id" => "46deb476-c1a6-41eb-8eb7-26a695bbe5bc", ...}

See Also:



49
50
51
52
# File 'lib/zai_payment/resources/virtual_account.rb', line 49

def show()
  validate_id!(, 'virtual_account_id')
  client.get("/virtual_accounts/#{virtual_account_id}")
end

#update_account_name(virtual_account_id, account_name) ⇒ Response

Update Account Name for a Virtual Account

Change the name of a Virtual Account. This is used in CoP lookups.

Examples:

Update account name

virtual_accounts = ZaiPayment::Resources::VirtualAccount.new
response = virtual_accounts.(
  '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
  'New Real Estate Agency Name'
)
response.data # => {"id" => "46deb476-c1a6-41eb-8eb7-26a695bbe5bc", ...}

See Also:



123
124
125
126
127
128
129
# File 'lib/zai_payment/resources/virtual_account.rb', line 123

def (, )
  validate_id!(, 'virtual_account_id')
  ()

  body = { account_name:  }
  client.patch("/virtual_accounts/#{virtual_account_id}/account_name", body: body)
end

#update_aka_names(virtual_account_id, aka_names) ⇒ Response

Update AKA Names for a Virtual Account

Replace the list of AKA Names for a Virtual Account. This completely replaces the existing AKA names with the new list provided.

Examples:

Update AKA names

virtual_accounts = ZaiPayment::Resources::VirtualAccount.new
response = virtual_accounts.update_aka_names(
  '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
  ['New Name 1', 'New Name 2']
)
response.data # => {"id" => "46deb476-c1a6-41eb-8eb7-26a695bbe5bc", ...}

See Also:



98
99
100
101
102
103
104
# File 'lib/zai_payment/resources/virtual_account.rb', line 98

def update_aka_names(, aka_names)
  validate_id!(, 'virtual_account_id')
  validate_aka_names!(aka_names)

  body = { aka_names: aka_names }
  client.patch("/virtual_accounts/#{virtual_account_id}/aka_names", body: body)
end

#update_status(virtual_account_id, status) ⇒ Response

Update Status for a Virtual Account

Close a Virtual Account. Once closed, the account cannot be reopened and will no longer be able to receive payments. This operation is asynchronous and returns a 202 Accepted response.

Examples:

Close a virtual account

virtual_accounts = ZaiPayment::Resources::VirtualAccount.new
response = virtual_accounts.update_status(
  '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
  'closed'
)
response.data # => {"id" => "46deb476-c1a6-41eb-8eb7-26a695bbe5bc", "message" => "...", ...}

See Also:



150
151
152
153
154
155
156
# File 'lib/zai_payment/resources/virtual_account.rb', line 150

def update_status(, status)
  validate_id!(, 'virtual_account_id')
  validate_status!(status)

  body = { status: status }
  client.patch("/virtual_accounts/#{virtual_account_id}/status", body: body)
end