Class: SquareLegacy::PaymentsApi
- Defined in:
- lib/square_legacy/api/payments_api.rb
Overview
PaymentsApi
Instance Attribute Summary
Attributes inherited from BaseApi
Instance Method Summary collapse
-
#cancel_payment(payment_id:) ⇒ ApiResponse
Cancels (voids) a payment.
-
#cancel_payment_by_idempotency_key(body:) ⇒ ApiResponse
Cancels (voids) a payment identified by the idempotency key that is specified in the request.
-
#complete_payment(payment_id:, body:) ⇒ ApiResponse
Completes (captures) a payment.
-
#create_payment(body:) ⇒ ApiResponse
Creates a payment using the provided source.
-
#get_payment(payment_id:) ⇒ ApiResponse
Retrieves details for a specific payment.
-
#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, updated_at_begin_time: nil, updated_at_end_time: nil, sort_field: nil) ⇒ ApiResponse
Retrieves a list of payments taken by the account making the request.
-
#update_payment(payment_id:, body:) ⇒ ApiResponse
Updates a payment with the APPROVED status.
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 SquareLegacy::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.
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/square_legacy/api/payments_api.rb', line 227 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.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/square_legacy/api/payments_api.rb', line 156 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.
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/square_legacy/api/payments_api.rb', line 254 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.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/square_legacy/api/payments_api.rb', line 120 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.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/square_legacy/api/payments_api.rb', line 177 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, updated_at_begin_time: nil, updated_at_end_time: nil, sort_field: 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 ListPaymentsRequest.sort_field: - 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](https://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.
start of the time range to retrieve payments for, in RFC 3339 format. The
range is determined using the updated_at field for each Payment.
of the time range to retrieve payments for, in RFC 3339 format. The range
is determined using the updated_at field for each Payment.
sort results by. The default is CREATED_AT.
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/square_legacy/api/payments_api.rb', line 65 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, updated_at_begin_time: nil, updated_at_end_time: nil, sort_field: 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')) .query_param(new_parameter(updated_at_begin_time, key: 'updated_at_begin_time')) .query_param(new_parameter(updated_at_end_time, key: 'updated_at_end_time')) .query_param(new_parameter(sort_field, key: 'sort_field')) .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.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/square_legacy/api/payments_api.rb', line 201 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 |