Class: Square::RefundsApi

Inherits:
BaseApi
  • Object
show all
Defined in:
lib/square/api/refunds_api.rb

Overview

RefundsApi

Instance Attribute Summary

Attributes inherited from BaseApi

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseApi

#execute_request, #get_user_agent, #validate_parameters

Constructor Details

#initialize(config, http_call_back: nil) ⇒ RefundsApi

Returns a new instance of RefundsApi.



4
5
6
# File 'lib/square/api/refunds_api.rb', line 4

def initialize(config, http_call_back: nil)
  super(config, http_call_back: http_call_back)
end

Instance Method Details

#get_payment_refund(refund_id:) ⇒ GetPaymentRefundResponse Hash

Retrieves a specific refund using the ‘refund_id`. desired `PaymentRefund`.

Parameters:

  • refund_id (String)

    Required parameter: The unique ID for the

Returns:

  • (GetPaymentRefundResponse Hash)

    response from the API call



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/square/api/refunds_api.rb', line 135

def get_payment_refund(refund_id:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/refunds/{refund_id}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'refund_id' => { 'value' => refund_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#list_payment_refunds(begin_time: nil, end_time: nil, sort_order: nil, cursor: nil, location_id: nil, status: nil, source_type: nil, limit: nil) ⇒ ListPaymentRefundsResponse Hash

Retrieves a list of refunds for the account making the request. Results are eventually consistent, and new refunds or changes to refunds might take several seconds to appear. The maximum results per page is 100. beginning of the requested reporting period, in RFC 3339 format. Default: The current time minus one year. the requested reporting period, in RFC 3339 format. Default: The current time. are listed: - ‘ASC` - Oldest to newest. - `DESC` - Newest to oldest (default). a previous call to this endpoint. Provide this cursor to retrieve the next set of results for the original query. For more information, see [Pagination](developer.squareup.com/docs/basics/api101/pagination) . location supplied. By default, results are returned for all locations associated with the seller. the given status are returned. For a list of refund status values, see [PaymentRefund]($m/PaymentRefund). Default: If omitted, refunds are returned regardless of their status. refunds whose payments have the indicated source type. Current values include `CARD`, `BANK_ACCOUNT`, `WALLET`, `CASH`, and `EXTERNAL`. For information about these payment source types, see [Take Payments](developer.squareup.com/docs/payments-api/take-payments).

Default: If omitted, refunds are returned regardless of the source

type. to be returned in a single page. It is possible to receive fewer results than the specified limit on a given page. If the supplied value is greater than 100, no more than 100 results are returned. Default: 100

Parameters:

  • begin_time (String) (defaults to: nil)

    Optional parameter: The timestamp for the

  • end_time (String) (defaults to: nil)

    Optional parameter: The timestamp for the end of

  • sort_order (String) (defaults to: nil)

    Optional parameter: The order in which results

  • cursor (String) (defaults to: nil)

    Optional parameter: A pagination cursor returned by

  • location_id (String) (defaults to: nil)

    Optional parameter: Limit results to the

  • status (String) (defaults to: nil)

    Optional parameter: If provided, only refunds with

  • source_type (String) (defaults to: nil)

    Optional parameter: If provided, only returns

  • limit (Integer) (defaults to: nil)

    Optional parameter: The maximum number of results

Returns:

  • (ListPaymentRefundsResponse Hash)

    response from the API call



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
85
86
87
88
89
# File 'lib/square/api/refunds_api.rb', line 46

def list_payment_refunds(begin_time: nil,
                         end_time: nil,
                         sort_order: nil,
                         cursor: nil,
                         location_id: nil,
                         status: nil,
                         source_type: nil,
                         limit: nil)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/refunds'
  _query_builder = APIHelper.append_url_with_query_parameters(
    _query_builder,
    'begin_time' => begin_time,
    'end_time' => end_time,
    'sort_order' => sort_order,
    'cursor' => cursor,
    'location_id' => location_id,
    'status' => status,
    'source_type' => source_type,
    'limit' => limit
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#refund_payment(body:) ⇒ RefundPaymentResponse Hash

Refunds a payment. You can refund the entire payment amount or a portion of it. You can use this endpoint to refund a card payment or record a refund of a cash or external payment. For more information, see [Refund Payment](developer.squareup.com/docs/payments-api/refund-payments) . containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • body (RefundPaymentRequest)

    Required parameter: An object

Returns:

  • (RefundPaymentResponse Hash)

    response from the API call



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/square/api/refunds_api.rb', line 102

def refund_payment(body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/refunds'
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end