Class: Square::Payments::Client
- Inherits:
-
Object
- Object
- Square::Payments::Client
- Defined in:
- lib/square/payments/client.rb
Instance Method Summary collapse
-
#cancel(request_options: {}, **params) ⇒ Square::Types::CancelPaymentResponse
Cancels (voids) a payment.
-
#cancel_by_idempotency_key(request_options: {}, **params) ⇒ Square::Types::CancelPaymentByIdempotencyKeyResponse
Cancels (voids) a payment identified by the idempotency key that is specified in the request.
-
#complete(request_options: {}, **params) ⇒ Square::Types::CompletePaymentResponse
Completes (captures) a payment.
-
#create(request_options: {}, **params) ⇒ Square::Types::CreatePaymentResponse
Creates a payment using the provided source.
-
#get(request_options: {}, **params) ⇒ Square::Types::GetPaymentResponse
Retrieves details for a specific payment.
- #initialize(client:) ⇒ Square::Payments::Client constructor
-
#list(request_options: {}, **params) ⇒ Square::Types::ListPaymentsResponse
Retrieves a list of payments taken by the account making the request.
-
#update(request_options: {}, **params) ⇒ Square::Types::UpdatePaymentResponse
Updates a payment with the APPROVED status.
Constructor Details
#initialize(client:) ⇒ Square::Payments::Client
7 8 9 |
# File 'lib/square/payments/client.rb', line 7 def initialize(client:) @client = client end |
Instance Method Details
#cancel(request_options: {}, **params) ⇒ Square::Types::CancelPaymentResponse
Cancels (voids) a payment. You can use this endpoint to cancel a payment with the APPROVED ‘status`.
134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/square/payments/client.rb', line 134 def cancel(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "v2/payments/#{params[:payment_id]}/cancel" ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::CancelPaymentResponse.load(_response.body) end raise _response.body end |
#cancel_by_idempotency_key(request_options: {}, **params) ⇒ Square::Types::CancelPaymentByIdempotencyKeyResponse
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.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/square/payments/client.rb', line 77 def cancel_by_idempotency_key(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "v2/payments/cancel", body: params ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::CancelPaymentByIdempotencyKeyResponse.load(_response.body) end raise _response.body end |
#complete(request_options: {}, **params) ⇒ Square::Types::CompletePaymentResponse
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`.
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/square/payments/client.rb', line 154 def complete(request_options: {}, **params) _path_param_names = ["payment_id"] _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "v2/payments/#{params[:payment_id]}/complete", body: params.except(*_path_param_names) ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::CompletePaymentResponse.load(_response.body) end raise _response.body end |
#create(request_options: {}, **params) ⇒ Square::Types::CreatePaymentResponse
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.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/square/payments/client.rb', line 49 def create(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "v2/payments", body: params ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::CreatePaymentResponse.load(_response.body) end raise _response.body end |
#get(request_options: {}, **params) ⇒ Square::Types::GetPaymentResponse
Retrieves details for a specific payment.
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/square/payments/client.rb', line 95 def get(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "GET", path: "v2/payments/#{params[:payment_id]}" ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::GetPaymentResponse.load(_response.body) end raise _response.body end |
#list(request_options: {}, **params) ⇒ Square::Types::ListPaymentsResponse
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.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/square/payments/client.rb', line 19 def list(request_options: {}, **params) _query_param_names = %w[begin_time end_time sort_order cursor location_id total last_4 card_brand limit is_offline_payment offline_begin_time offline_end_time updated_at_begin_time updated_at_end_time sort_field] _query = params.slice(*_query_param_names) params.except(*_query_param_names) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "GET", path: "v2/payments", query: _query ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::ListPaymentsResponse.load(_response.body) end raise _response.body end |
#update(request_options: {}, **params) ⇒ Square::Types::UpdatePaymentResponse
Updates a payment with the APPROVED status. You can update the ‘amount_money` and `tip_money` using this endpoint.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/square/payments/client.rb', line 113 def update(request_options: {}, **params) _path_param_names = ["payment_id"] _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "PUT", path: "v2/payments/#{params[:payment_id]}", body: params.except(*_path_param_names) ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::UpdatePaymentResponse.load(_response.body) end raise _response.body end |