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:) ⇒ ApiResponse

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:

  • (ApiResponse)

    the complete http response with raw body and status code.



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/square/api/payments_api.rb', line 213

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:) ⇒ ApiResponse

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:

  • (ApiResponse)

    the complete http response with raw body and status code.



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/square/api/payments_api.rb', line 142

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:) ⇒ ApiResponse

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:

  • (ApiResponse)

    the complete http response with raw body and status code.



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/square/api/payments_api.rb', line 240

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:) ⇒ ApiResponse

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:

  • (ApiResponse)

    the complete http response with raw body and status code.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/square/api/payments_api.rb', line 106

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:) ⇒ ApiResponse

Retrieves details for a specific payment. payment.

Parameters:

  • payment_id (String)

    Required parameter: A unique ID for the desired

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



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

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, is_offline_payment: false, offline_begin_time: nil, offline_end_time: nil) ⇒ ApiResponse

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. time range to retrieve payments for, in RFC 3339 format. The range is determined using the ‘created_at` field for each Payment. Inclusive. Default: The current time minus one year. range to retrieve payments for, in RFC 3339 format. The range is determined using the `created_at` field for each Payment. Default: The current time. are listed by `Payment.created_at`: - `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/build-basics/common-api-p atterns/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` Whether the payment was taken offline or not. of the time range for which to retrieve offline payments, in RFC 3339 format for timestamps. The range is determined using the `offline_payment_details.client_created_at` field for each Payment. If set, payments without a value set in `offline_payment_details.client_created_at` will not be returned. Default: The current time. the time range for which to retrieve offline payments, in RFC 3339 format for timestamps. The range is determined using the `offline_payment_details.client_created_at` field for each Payment. If set, payments without a value set in `offline_payment_details.client_created_at` will not be returned. Default: The current time.

Parameters:

  • begin_time (String) (defaults to: nil)

    Optional parameter: Indicates the start of the

  • end_time (String) (defaults to: nil)

    Optional parameter: Indicates the end of the time

  • 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

  • is_offline_payment (TrueClass | FalseClass) (defaults to: false)

    Optional parameter:

  • offline_begin_time (String) (defaults to: nil)

    Optional parameter: Indicates the start

  • offline_end_time (String) (defaults to: nil)

    Optional parameter: Indicates the end of

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



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

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,
                  is_offline_payment: false,
                  offline_begin_time: nil,
                  offline_end_time: 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'))
               .query_param(new_parameter(is_offline_payment, key: 'is_offline_payment'))
               .query_param(new_parameter(offline_begin_time, key: 'offline_begin_time'))
               .query_param(new_parameter(offline_end_time, key: 'offline_end_time'))
               .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:) ⇒ ApiResponse

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:

  • (ApiResponse)

    the complete http response with raw body and status code.



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

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