Class: Square::V1Transactions::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Square::V1Transactions::Client



7
8
9
# File 'lib/square/v_1_transactions/client.rb', line 7

def initialize(client:)
  @client = client
end

Instance Method Details

#v_1_list_orders(request_options: {}, **params) ⇒ Array[Square::Types::V1Order]

Provides summary information for a merchant’s online store orders.

Returns:

Raises:

  • (error_class)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/square/v_1_transactions/client.rb', line 14

def v_1_list_orders(request_options: {}, **params)
  _query_param_names = [
    %w[order limit batch_token],
    %i[order limit batch_token]
  ].flatten
  _query = params.slice(*_query_param_names)
  params = params.except(*_query_param_names)

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "GET",
    path: "v1/#{params[:location_id]}/orders",
    query: _query
  )
  begin
    _response = @client.send(_request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = _response.code.to_i
  return if code.between?(200, 299)

  error_class = Square::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(_response.body, code: code)
end

#v_1_retrieve_order(request_options: {}, **params) ⇒ Square::Types::V1Order

Provides comprehensive information for a single online store order, including the order’s history.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/square/v_1_transactions/client.rb', line 43

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

#v_1_update_order(request_options: {}, **params) ⇒ Square::Types::V1Order

Updates the details of an online store order. Every update you perform on an order corresponds to one of three actions:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/square/v_1_transactions/client.rb', line 66

def v_1_update_order(request_options: {}, **params)
  _path_param_names = %w[location_id order_id]

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "PUT",
    path: "v1/#{params[:location_id]}/orders/#{params[:order_id]}",
    body: params.except(*_path_param_names)
  )
  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::V1Order.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end