Class: Square::Refunds::Client
- Inherits:
-
Object
- Object
- Square::Refunds::Client
- Defined in:
- lib/square/refunds/client.rb
Instance Method Summary collapse
-
#get(request_options: {}, **params) ⇒ Square::Types::GetPaymentRefundResponse
Retrieves a specific refund using the ‘refund_id`.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Square::Types::ListPaymentRefundsResponse
Retrieves a list of refunds for the account making the request.
-
#refund_payment(request_options: {}, **params) ⇒ Square::Types::RefundPaymentResponse
Refunds a payment.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/square/refunds/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#get(request_options: {}, **params) ⇒ Square::Types::GetPaymentRefundResponse
Retrieves a specific refund using the ‘refund_id`.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/square/refunds/client.rb', line 134 def get(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/refunds/#{params[:refund_id]}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::GetPaymentRefundResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list(request_options: {}, **params) ⇒ Square::Types::ListPaymentRefundsResponse
Retrieves a list of refunds for the account making the request.
Results are eventually consistent, and new refunds or changes to refunds might take several seconds to appear.
The maximum results per page is 100.
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 81 82 83 |
# File 'lib/square/refunds/client.rb', line 40 def list(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[begin_time end_time sort_order cursor location_id status source_type limit updated_at_begin_time updated_at_end_time sort_field] query_params = {} query_params["begin_time"] = params[:begin_time] if params.key?(:begin_time) query_params["end_time"] = params[:end_time] if params.key?(:end_time) query_params["sort_order"] = params[:sort_order] if params.key?(:sort_order) query_params["cursor"] = params[:cursor] if params.key?(:cursor) query_params["location_id"] = params[:location_id] if params.key?(:location_id) query_params["status"] = params[:status] if params.key?(:status) query_params["source_type"] = params[:source_type] if params.key?(:source_type) query_params["limit"] = params[:limit] if params.key?(:limit) query_params["updated_at_begin_time"] = params[:updated_at_begin_time] if params.key?(:updated_at_begin_time) query_params["updated_at_end_time"] = params[:updated_at_end_time] if params.key?(:updated_at_end_time) query_params["sort_field"] = params[:sort_field] if params.key?(:sort_field) params.except(*query_param_names) Square::Internal::CursorItemIterator.new( cursor_field: :cursor, item_field: :refunds, initial_cursor: query_params[:cursor] ) do |next_cursor| query_params[:cursor] = next_cursor request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/refunds", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::ListPaymentRefundsResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end end |
#refund_payment(request_options: {}, **params) ⇒ Square::Types::RefundPaymentResponse
Refunds a payment. You can refund the entire payment amount or a portion of it. You can use this endpoint to refund a card payment or record a refund of a cash or external payment. For more information, see [Refund Payment](developer.squareup.com/docs/payments-api/refund-payments).
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/square/refunds/client.rb', line 99 def refund_payment(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/refunds", body: Square::Refunds::Types::RefundPaymentRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::RefundPaymentResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |