Class: Modulr::API::AccountsService

Inherits:
Service
  • Object
show all
Defined in:
lib/modulr/api/accounts_service.rb

Instance Attribute Summary

Attributes inherited from Service

#client

Instance Method Summary collapse

Methods inherited from Service

#format_datetime, #initialize

Constructor Details

This class inherits a constructor from Modulr::API::Service

Instance Method Details

#close(account_id:) ⇒ Object



36
37
38
39
40
# File 'lib/modulr/api/accounts_service.rb', line 36

def close(account_id:)
  client.post("/accounts/#{}/close")

  nil
end

#create(customer_id:, currency:, product_code:, **opts) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/modulr/api/accounts_service.rb', line 23

def create(customer_id:, currency:, product_code:, **opts)
  payload = {
    currency: currency,
    productCode: product_code,
  }
  payload[:externalReference] = opts[:external_reference] if opts[:external_reference]

  response = client.post("/customers/#{customer_id}/accounts", payload)
  attributes = response.body

  Resources::Accounts::Account.new(response, attributes)
end

#find(id:, **opts) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/modulr/api/accounts_service.rb', line 6

def find(id:, **opts)
  query_parameters = {}
  query_parameters[:statuses] = opts[:statuses] if opts[:statuses]
  if opts[:include_pending_transactions]
    query_parameters[:includePendingTransactions] = opts[:include_pending_transactions]
  end

  response = client.get("/accounts/#{id}", query_parameters)
  attributes = response.body

  Resources::Accounts::Account.new(
    response,
    attributes,
    { requested_at: response.headers["date"] }
  )
end