Class: ModernTreasury::ReversalController

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

Overview

ReversalController

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

Constructor Details

This class inherits a constructor from ModernTreasury::BaseController

Instance Method Details

#create_reversal(payment_order_id, idempotency_key: nil, body: nil) ⇒ Reversal

Create a reversal for a payment order. relevant Payment Order. something unique, preferably something like an UUID. description here

Parameters:

  • payment_order_id (UUID | String)

    Required parameter: The ID of the

  • idempotency_key (String) (defaults to: nil)

    Optional parameter: This key should be

  • body (ReversalCreateRequest) (defaults to: nil)

    Optional parameter: TODO: type

Returns:

  • (Reversal)

    Response from the API call.



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
# File 'lib/modern_treasury/controllers/reversal_controller.rb', line 45

def create_reversal(payment_order_id,
                    idempotency_key: nil,
                    body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/api/payment_orders/{payment_order_id}/reversals',
                                 Server::DEFAULT)
               .template_param(new_parameter(payment_order_id, key: 'payment_order_id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .header_param(new_parameter(idempotency_key, key: 'Idempotency-Key'))
               .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(Reversal.method(:from_hash))
                .local_error('404',
                             'unsuccessful',
                             ErrorMessageException)
                .local_error('422',
                             'unsuccessful',
                             ErrorMessageException))
    .execute
end

#get_reversal(payment_order_id, reversal_id) ⇒ Reversal

Get details on a single reversal of a payment order. payment order being reversed. reversal.

Parameters:

  • payment_order_id (UUID | String)

    Required parameter: The id of the

  • reversal_id (UUID | String)

    Required parameter: The ID of the

Returns:

  • (Reversal)

    Response from the API call.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/modern_treasury/controllers/reversal_controller.rb', line 78

def get_reversal(payment_order_id,
                 reversal_id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/api/payment_orders/{payment_order_id}/reversals/{reversal_id}',
                                 Server::DEFAULT)
               .template_param(new_parameter(payment_order_id, key: 'payment_order_id')
                                .should_encode(true))
               .template_param(new_parameter(reversal_id, key: 'reversal_id')
                                .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(Reversal.method(:from_hash))
                .local_error('404',
                             'not found',
                             ErrorMessageException))
    .execute
end

#list_reversals(payment_order_id, after_cursor: nil, per_page: nil) ⇒ Array[Reversal]

Get a list of all reversals of a payment order. relevant Payment Order. here here

Parameters:

  • payment_order_id (String)

    Required parameter: The ID of the

  • after_cursor (String) (defaults to: nil)

    Optional parameter: TODO: type description

  • per_page (Integer) (defaults to: nil)

    Optional parameter: TODO: type description

Returns:

  • (Array[Reversal])

    Response from the API call.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/modern_treasury/controllers/reversal_controller.rb', line 17

def list_reversals(payment_order_id,
                   after_cursor: nil,
                   per_page: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/api/payment_orders/{payment_order_id}/reversals',
                                 Server::DEFAULT)
               .template_param(new_parameter(payment_order_id, key: 'payment_order_id')
                                .should_encode(true))
               .query_param(new_parameter(after_cursor, key: 'after_cursor'))
               .query_param(new_parameter(per_page, key: 'per_page'))
               .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(Reversal.method(:from_hash))
                .is_response_array(true))
    .execute
end