Class: Square::TransactionsApi
- Defined in:
- lib/square/api/transactions_api.rb
Overview
TransactionsApi
Instance Attribute Summary
Attributes inherited from BaseApi
Instance Method Summary collapse
-
#capture_transaction(location_id:, transaction_id:) ⇒ CaptureTransactionResponse Hash
Captures a transaction that was created with the [Charge]($e/Transactions/Charge) endpoint with a `delay_capture` value of `true`.
-
#charge(location_id:, body:) ⇒ ChargeResponse Hash
Charges a card represented by a card nonce or a customer's card on file.
-
#create_refund(location_id:, transaction_id:, body:) ⇒ CreateRefundResponse Hash
Initiates a refund for a previously charged tender.
-
#initialize(config, http_call_back: nil) ⇒ TransactionsApi
constructor
A new instance of TransactionsApi.
-
#list_refunds(location_id:, begin_time: nil, end_time: nil, sort_order: nil, cursor: nil) ⇒ ListRefundsResponse Hash
Lists refunds for one of a business's locations.
-
#list_transactions(location_id:, begin_time: nil, end_time: nil, sort_order: nil, cursor: nil) ⇒ ListTransactionsResponse Hash
Lists transactions for a particular location.
-
#retrieve_transaction(location_id:, transaction_id:) ⇒ RetrieveTransactionResponse Hash
Retrieves details for a single transaction.
-
#void_transaction(location_id:, transaction_id:) ⇒ VoidTransactionResponse Hash
Cancels a transaction that was created with the [Charge]($e/Transactions/Charge) endpoint with a `delay_capture` value of `true`.
Methods inherited from BaseApi
#execute_request, #validate_parameters
Constructor Details
#initialize(config, http_call_back: nil) ⇒ TransactionsApi
Returns a new instance of TransactionsApi.
4 5 6 |
# File 'lib/square/api/transactions_api.rb', line 4 def initialize(config, http_call_back: nil) super(config, http_call_back: http_call_back) end |
Instance Method Details
#capture_transaction(location_id:, transaction_id:) ⇒ CaptureTransactionResponse Hash
Captures a transaction that was created with the [Charge]($e/Transactions/Charge) endpoint with a `delay_capture` value of `true`. See [Delayed capture transactions](developer.squareup.com/docs/payments/transactions/ov erview#delayed-capture) for more information.
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/square/api/transactions_api.rb', line 264 def capture_transaction(location_id:, transaction_id:) warn 'Endpoint capture_transaction in TransactionsApi is deprecated' # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/locations/{location_id}/transactions/{transaction_id}/capture' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'location_id' => { 'value' => location_id, 'encode' => true }, 'transaction_id' => { 'value' => transaction_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.post( _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 |
#charge(location_id:, body:) ⇒ ChargeResponse Hash
Charges a card represented by a card nonce or a customer's card on file. Your request to this endpoint must include either:
-
A value for the `card_nonce` parameter (to charge a card payment token
generated with the Web Payments SDK)
-
Values for the `customer_card_id` and `customer_id` parameters (to
charge a customer's card on file) In order for an eCommerce payment to potentially qualify for [Square chargeback protection](squareup.com/help/article/5394), you must provide values for the following parameters in your request:
-
`buyer_email_address`
-
At least one of `billing_address` or `shipping_address`
When this response is returned, the amount of Square's processing fee might not yet be calculated. To obtain the processing fee, wait about ten seconds and call [RetrieveTransaction]($e/Transactions/RetrieveTransaction). See the `processing_fee_money` field of each [Tender included]($m/Tender) in the transaction. associate the created transaction with. fields to POST for the request. See the corresponding object definition for field details.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/square/api/transactions_api.rb', line 179 def charge(location_id:, body:) warn 'Endpoint charge in TransactionsApi is deprecated' # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/locations/{location_id}/transactions' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'location_id' => { 'value' => location_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8' } # 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 |
#create_refund(location_id:, transaction_id:, body:) ⇒ CreateRefundResponse Hash
Initiates a refund for a previously charged tender. You must issue a refund within 120 days of the associated payment. See [this article](squareup.com/help/us/en/article/5060) for more information on refund behavior. NOTE: Card-present transactions with Interac credit cards **cannot be refunded using the Connect API**. Interac transactions must refunded in-person (e.g., dipping the card using POS app). transaction's associated location. transaction that includes the tender to refund. the fields to POST for the request. See the corresponding object definition for field details.
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/square/api/transactions_api.rb', line 314 def create_refund(location_id:, transaction_id:, body:) warn 'Endpoint create_refund in TransactionsApi is deprecated' # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/locations/{location_id}/transactions/{transaction_id}/refund' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'location_id' => { 'value' => location_id, 'encode' => true }, 'transaction_id' => { 'value' => transaction_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'content-type' => 'application/json; charset=utf-8' } # 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 |
#list_refunds(location_id:, begin_time: nil, end_time: nil, sort_order: nil, cursor: nil) ⇒ ListRefundsResponse Hash
Lists refunds for one of a business's locations. In addition to full or partial tender refunds processed through Square APIs, refunds may result from itemized returns or exchanges through Square's Point of Sale applications. Refunds with a `status` of `PENDING` are not currently included in this endpoint's response. Max results per [page](developer.squareup.com/docs/working-with-apis/pagination): 50 list refunds for. requested reporting period, in RFC 3339 format. See [Date ranges](developer.squareup.com/docs/build-basics/working-with-date s) for details on date inclusivity/exclusivity. Default value: The current time minus one year. reporting period, in RFC 3339 format. See [Date ranges](developer.squareup.com/docs/build-basics/working-with-date s) for details on date inclusivity/exclusivity. Default value: The current time. results are listed in the response (`ASC` for oldest first, `DESC` for newest first). Default value: `DESC` a previous call to this endpoint. Provide this to retrieve the next set of results for your original query. See [Paginating results](developer.squareup.com/docs/working-with-apis/pagination) for more information.
39 40 41 42 43 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 |
# File 'lib/square/api/transactions_api.rb', line 39 def list_refunds(location_id:, begin_time: nil, end_time: nil, sort_order: nil, cursor: nil) warn 'Endpoint list_refunds in TransactionsApi is deprecated' # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/locations/{location_id}/refunds' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'location_id' => { 'value' => location_id, 'encode' => true } ) _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, 'begin_time' => begin_time, 'end_time' => end_time, 'sort_order' => sort_order, 'cursor' => cursor ) _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_transactions(location_id:, begin_time: nil, end_time: nil, sort_order: nil, cursor: nil) ⇒ ListTransactionsResponse Hash
Lists transactions for a particular location. Transactions include payment information from sales and exchanges and refund information from returns and exchanges. Max results per [page](developer.squareup.com/docs/working-with-apis/pagination): 50 list transactions for. requested reporting period, in RFC 3339 format. See [Date ranges](developer.squareup.com/docs/build-basics/working-with-date s) for details on date inclusivity/exclusivity. Default value: The current time minus one year. reporting period, in RFC 3339 format. See [Date ranges](developer.squareup.com/docs/build-basics/working-with-date s) for details on date inclusivity/exclusivity. Default value: The current time. results are listed in the response (`ASC` for oldest first, `DESC` for newest first). Default value: `DESC` a previous call to this endpoint. Provide this to retrieve the next set of results for your original query. See [Paginating results](developer.squareup.com/docs/working-with-apis/pagination) for more information.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/square/api/transactions_api.rb', line 110 def list_transactions(location_id:, begin_time: nil, end_time: nil, sort_order: nil, cursor: nil) warn 'Endpoint list_transactions in TransactionsApi is deprecated' # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/locations/{location_id}/transactions' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'location_id' => { 'value' => location_id, 'encode' => true } ) _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, 'begin_time' => begin_time, 'end_time' => end_time, 'sort_order' => sort_order, 'cursor' => cursor ) _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 |
#retrieve_transaction(location_id:, transaction_id:) ⇒ RetrieveTransactionResponse Hash
Retrieves details for a single transaction. transaction's associated location. transaction to retrieve.
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/square/api/transactions_api.rb', line 220 def retrieve_transaction(location_id:, transaction_id:) warn 'Endpoint retrieve_transaction in TransactionsApi is deprecated' # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/locations/{location_id}/transactions/{transaction_id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'location_id' => { 'value' => location_id, 'encode' => true }, 'transaction_id' => { 'value' => transaction_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 |
#void_transaction(location_id:, transaction_id:) ⇒ VoidTransactionResponse Hash
Cancels a transaction that was created with the [Charge]($e/Transactions/Charge) endpoint with a `delay_capture` value of `true`. See [Delayed capture transactions](developer.squareup.com/docs/payments/transactions/ov erview#delayed-capture) for more information.
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/square/api/transactions_api.rb', line 361 def void_transaction(location_id:, transaction_id:) warn 'Endpoint void_transaction in TransactionsApi is deprecated' # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/locations/{location_id}/transactions/{transaction_id}/void' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'location_id' => { 'value' => location_id, 'encode' => true }, 'transaction_id' => { 'value' => transaction_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.post( _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 |