Class: ModernTreasury::TransactionController

Inherits:
BaseController show all
Defined in:
lib/modern_treasury/controllers/transaction_controller.rb

Overview

TransactionController

Constant Summary

Constants inherited from BaseController

BaseController::GLOBAL_ERRORS

Instance Attribute Summary

Attributes inherited from BaseController

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseController

#initialize, #new_parameter, #new_request_builder, #new_response_handler, user_agent, user_agent_parameters

Constructor Details

This class inherits a constructor from ModernTreasury::BaseController

Instance Method Details

#get_transaction(id) ⇒ ApiResponse

Get details on a single transaction.

Parameters:

  • id (String)

    Required parameter: Transaction ID

Returns:

  • (ApiResponse)

    Complete http response with raw body and status code.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/modern_treasury/controllers/transaction_controller.rb', line 89

def get_transaction(id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/api/transactions/{id}',
                                 Server::DEFAULT)
               .template_param(new_parameter(id, key: 'id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('basic_auth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(Transaction.method(:from_hash))
                .is_api_response(true)
                .local_error('404',
                             'not found',
                             ErrorMessageException))
    .execute
end

#list_transactions(after_cursor: nil, per_page: nil, internal_account_id: nil, virtual_account_id: nil, posted: nil, as_of_date_start: nil, as_of_date_end: nil, direction: nil, counterparty_id: nil, payment_type: nil, transactable_type: nil, description: nil, vendor_id: nil, metadata: nil) ⇒ ApiResponse

Get a list of all transactions. here here ‘internal_account_id` if you wish to see transactions to/from a specific account. description here or `false`. with an `as_of_date` starting on or after the specified date (YYYY-MM-DD). an `as_of_date` starting on or before the specified date (YYYY-MM-DD). here description here here description here including the queried string in the description. including the queried vendor id (an identifier given to transactions by the bank). you want to query for records with metadata key `Type` and value `Loan`, the query would be `metadata%5BType%5D=Loan`. This encodes the query parameters.

Parameters:

  • after_cursor (String) (defaults to: nil)

    Optional parameter: TODO: type description

  • per_page (Integer) (defaults to: nil)

    Optional parameter: TODO: type description

  • internal_account_id (UUID | String) (defaults to: nil)

    Optional parameter: Specify

  • virtual_account_id (UUID | String) (defaults to: nil)

    Optional parameter: TODO: type

  • posted (TrueClass | FalseClass) (defaults to: nil)

    Optional parameter: Either ‘true`

  • as_of_date_start (Date) (defaults to: nil)

    Optional parameter: Filters transactions

  • as_of_date_end (Date) (defaults to: nil)

    Optional parameter: Filters transactions with

  • direction (String) (defaults to: nil)

    Optional parameter: TODO: type description

  • counterparty_id (UUID | String) (defaults to: nil)

    Optional parameter: TODO: type

  • payment_type (String) (defaults to: nil)

    Optional parameter: TODO: type description

  • transactable_type (String) (defaults to: nil)

    Optional parameter: TODO: type

  • description (String) (defaults to: nil)

    Optional parameter: Filters for transactions

  • vendor_id (String) (defaults to: nil)

    Optional parameter: Filters for transactions

  • metadata (Hash[String, String]) (defaults to: nil)

    Optional parameter: For example, if

Returns:

  • (ApiResponse)

    Complete http response with raw body and status code.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/modern_treasury/controllers/transaction_controller.rb', line 44

def list_transactions(after_cursor: nil,
                      per_page: nil,
                      internal_account_id: nil,
                      virtual_account_id: nil,
                      posted: nil,
                      as_of_date_start: nil,
                      as_of_date_end: nil,
                      direction: nil,
                      counterparty_id: nil,
                      payment_type: nil,
                      transactable_type: nil,
                      description: nil,
                      vendor_id: nil,
                      metadata: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/api/transactions',
                                 Server::DEFAULT)
               .query_param(new_parameter(after_cursor, key: 'after_cursor'))
               .query_param(new_parameter(per_page, key: 'per_page'))
               .query_param(new_parameter(, key: 'internal_account_id'))
               .query_param(new_parameter(, key: 'virtual_account_id'))
               .query_param(new_parameter(posted, key: 'posted'))
               .query_param(new_parameter(as_of_date_start, key: 'as_of_date_start'))
               .query_param(new_parameter(as_of_date_end, key: 'as_of_date_end'))
               .query_param(new_parameter(direction, key: 'direction'))
               .query_param(new_parameter(counterparty_id, key: 'counterparty_id'))
               .query_param(new_parameter(payment_type, key: 'payment_type'))
               .query_param(new_parameter(transactable_type, key: 'transactable_type'))
               .query_param(new_parameter(description, key: 'description'))
               .query_param(new_parameter(vendor_id, key: 'vendor_id'))
               .query_param(new_parameter(, key: 'metadata'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('basic_auth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(Transaction.method(:from_hash))
                .is_api_response(true)
                .is_response_array(true))
    .execute
end

#update_transaction(id, body: nil) ⇒ ApiResponse

Update a single transaction. type description here

Parameters:

Returns:

  • (ApiResponse)

    Complete http response with raw body and status code.



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/modern_treasury/controllers/transaction_controller.rb', line 114

def update_transaction(id,
                       body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::PATCH,
                                 '/api/transactions/{id}',
                                 Server::DEFAULT)
               .template_param(new_parameter(id, key: 'id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('basic_auth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(Transaction.method(:from_hash))
                .is_api_response(true)
                .local_error('404',
                             'not found',
                             ErrorMessageException))
    .execute
end