Class: Modulr::API::PaymentsService

Inherits:
Service
  • Object
show all
Defined in:
lib/modulr/api/payments_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

#create(account_id:, destination:, reference:, currency:, amount:, **opts) ⇒ Object

rubocop:disable Metrics/ParameterLists



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/modulr/api/payments_service.rb', line 23

def create(account_id:, destination:, reference:, currency:, amount:, **opts) # rubocop:disable Metrics/ParameterLists
  payload = {
    sourceAccountId: ,
    destination: destination,
    reference: reference,
    currency: currency,
    amount: amount,
  }

  payload[:externalReference] = opts[:external_reference] if opts[:external_reference]
  payload[:endToEndReference] = opts[:e2e_reference] if opts[:e2e_reference]

  response = client.post("/payments", payload)
  attributes = response.body

  Resources::Payments::Payment.new(response, attributes, { network_scheme: false })
end

#find(id:) ⇒ Object

Raises:



6
7
8
9
10
11
12
# File 'lib/modulr/api/payments_service.rb', line 6

def find(id:)
  response = client.get("/payments", { id: id })
  attributes = response.body[:content]&.first
  raise ClientError, "Payment #{id} not found" unless attributes

  Resources::Payments::Payment.new(response, attributes)
end

#list(**opts) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/modulr/api/payments_service.rb', line 14

def list(**opts)
  return find(id: opts[:id]) if opts[:id]

  response = client.get("/payments", build_query_params(opts))
  attributes_collection = response.body[:content]

  Resources::Payments::Collection.new(response, attributes_collection)
end