Class: Square::PaymentsApi

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

Overview

PaymentsApi

Instance Attribute Summary

Attributes inherited from BaseApi

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseApi

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

Constructor Details

This class inherits a constructor from Square::BaseApi

Instance Method Details

#cancel_payment(payment_id:) ⇒ CancelPaymentResponse Hash

Cancels (voids) a payment. You can use this endpoint to cancel a payment with the APPROVED ‘status`. cancel.

Parameters:

  • payment_id (String)

    Required parameter: The ID of the payment to

Returns:

  • (CancelPaymentResponse Hash)

    response from the API call



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/square/api/payments_api.rb', line 188

def cancel_payment(payment_id:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v2/payments/{payment_id}/cancel',
                                 'default')
               .template_param(new_parameter(payment_id, key: 'payment_id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
end

#cancel_payment_by_idempotency_key(body:) ⇒ CancelPaymentByIdempotencyKeyResponse Hash

Cancels (voids) a payment identified by the idempotency key that is specified in the request. Use this method when the status of a ‘CreatePayment` request is unknown (for example, after you send a `CreatePayment` request, a network error occurs and you do not get a response). In this case, you can direct Square to cancel the payment using this endpoint. In the request, you provide the same idempotency key that you provided in your `CreatePayment` request that you want to cancel. After canceling the payment, you can submit your `CreatePayment` request again. Note that if no payment with the specified idempotency key is found, no action is taken and the endpoint returns successfully. object containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • body (CancelPaymentByIdempotencyKeyRequest)

    Required parameter: An

Returns:

  • (CancelPaymentByIdempotencyKeyResponse Hash)

    response from the API call



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/square/api/payments_api.rb', line 117

def cancel_payment_by_idempotency_key(body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v2/payments/cancel',
                                 'default')
               .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('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
end

#complete_payment(payment_id:, body:) ⇒ CompletePaymentResponse Hash

Completes (captures) a payment. By default, payments are set to complete immediately after they are created. You can use this endpoint to complete a payment with the APPROVED ‘status`. the payment to be completed. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • payment_id (String)

    Required parameter: The unique ID identifying

  • body (CompletePaymentRequest)

    Required parameter: An object

Returns:

  • (CompletePaymentResponse Hash)

    response from the API call



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/square/api/payments_api.rb', line 215

def complete_payment(payment_id:,
                     body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v2/payments/{payment_id}/complete',
                                 'default')
               .template_param(new_parameter(payment_id, key: 'payment_id')
                                .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('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
end

#create_payment(body:) ⇒ CreatePaymentResponse Hash

Creates a payment using the provided source. You can use this endpoint to charge a card (credit/debit card or Square gift card) or record a payment that the seller received outside of Square (cash payment from a buyer or a payment that an external entity processed on behalf of the seller). The endpoint creates a ‘Payment` object and returns it in the response. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • body (CreatePaymentRequest)

    Required parameter: An object

Returns:

  • (CreatePaymentResponse Hash)

    response from the API call



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/square/api/payments_api.rb', line 81

def create_payment(body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v2/payments',
                                 'default')
               .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('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
end

#get_payment(payment_id:) ⇒ GetPaymentResponse Hash

Retrieves details for a specific payment. payment.

Parameters:

  • payment_id (String)

    Required parameter: A unique ID for the desired

Returns:

  • (GetPaymentResponse Hash)

    response from the API call



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/square/api/payments_api.rb', line 138

def get_payment(payment_id:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v2/payments/{payment_id}',
                                 'default')
               .template_param(new_parameter(payment_id, key: 'payment_id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
end

#list_payments(begin_time: nil, end_time: nil, sort_order: nil, cursor: nil, location_id: nil, total: nil, last_4: nil, card_brand: nil, limit: nil) ⇒ ListPaymentsResponse Hash

Retrieves a list of payments taken by the account making the request. Results are eventually consistent, and new payments or changes to payments might take several seconds to appear. The maximum results per page is 100. beginning of the reporting period, in RFC 3339 format. Inclusive. Default: The current time minus one year. the 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 the default (main) location associated with the seller. `total_money` for a payment. payment card. card (for example, VISA). to be returned in a single page. It is possible to receive fewer results than the specified limit on a given page. The default value of 100 is also the maximum allowed value. If the provided value is greater than 100, it is ignored and the default value is used instead. 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

  • total (Integer) (defaults to: nil)

    Optional parameter: The exact amount in the

  • last_4 (String) (defaults to: nil)

    Optional parameter: The last four digits of a

  • card_brand (String) (defaults to: nil)

    Optional parameter: The brand of the payment

  • limit (Integer) (defaults to: nil)

    Optional parameter: The maximum number of results

Returns:

  • (ListPaymentsResponse Hash)

    response from the API call



38
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
# File 'lib/square/api/payments_api.rb', line 38

def list_payments(begin_time: nil,
                  end_time: nil,
                  sort_order: nil,
                  cursor: nil,
                  location_id: nil,
                  total: nil,
                  last_4: nil,
                  card_brand: nil,
                  limit: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/v2/payments',
                                 'default')
               .query_param(new_parameter(begin_time, key: 'begin_time'))
               .query_param(new_parameter(end_time, key: 'end_time'))
               .query_param(new_parameter(sort_order, key: 'sort_order'))
               .query_param(new_parameter(cursor, key: 'cursor'))
               .query_param(new_parameter(location_id, key: 'location_id'))
               .query_param(new_parameter(total, key: 'total'))
               .query_param(new_parameter(last_4, key: 'last_4'))
               .query_param(new_parameter(card_brand, key: 'card_brand'))
               .query_param(new_parameter(limit, key: 'limit'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
end

#update_payment(payment_id:, body:) ⇒ UpdatePaymentResponse Hash

Updates a payment with the APPROVED status. You can update the ‘amount_money` and `tip_money` using this endpoint. update. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • payment_id (String)

    Required parameter: The ID of the payment to

  • body (UpdatePaymentRequest)

    Required parameter: An object

Returns:

  • (UpdatePaymentResponse Hash)

    response from the API call



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/square/api/payments_api.rb', line 162

def update_payment(payment_id:,
                   body:)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/v2/payments/{payment_id}',
                                 'default')
               .template_param(new_parameter(payment_id, key: 'payment_id')
                                .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('global')))
    .response(new_response_handler
               .deserializer(APIHelper.method(:json_deserialize))
               .is_api_response(true)
               .convertor(ApiResponse.method(:create)))
    .execute
end