Class: Square::Terminal::Refunds::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/square/terminal/refunds/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Square::Terminal::Refunds::Client



8
9
10
# File 'lib/square/terminal/refunds/client.rb', line 8

def initialize(client:)
  @client = client
end

Instance Method Details

#cancel(request_options: {}, **params) ⇒ Square::Types::CancelTerminalRefundResponse

Cancels an Interac Terminal refund request by refund request ID if the status of the request permits it.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/square/terminal/refunds/client.rb', line 86

def cancel(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/terminals/refunds/#{params[:terminal_refund_id]}/cancel"
  )
  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::CancelTerminalRefundResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end

#create(request_options: {}, **params) ⇒ Square::Types::CreateTerminalRefundResponse

Creates a request to refund an Interac payment completed on a Square Terminal. Refunds for Interac payments on a Square Terminal are supported only for Interac debit cards in Canada. Other refunds for Terminal payments should use the Refunds API. For more information, see [Refunds API](api:Refunds).



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/square/terminal/refunds/client.rb', line 15

def create(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/terminals/refunds",
    body: params
  )
  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::CreateTerminalRefundResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end

#get(request_options: {}, **params) ⇒ Square::Types::GetTerminalRefundResponse

Retrieves an Interac Terminal refund object by ID. Terminal refund objects are available for 30 days.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/square/terminal/refunds/client.rb', line 63

def get(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "GET",
    path: "v2/terminals/refunds/#{params[:terminal_refund_id]}"
  )
  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::GetTerminalRefundResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end

#search(request_options: {}, **params) ⇒ Square::Types::SearchTerminalRefundsResponse

Retrieves a filtered list of Interac Terminal refund requests created by the seller making the request. Terminal refund requests are available for 30 days.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/square/terminal/refunds/client.rb', line 39

def search(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/terminals/refunds/search",
    body: params
  )
  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::SearchTerminalRefundsResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end