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:) ⇒ void

Parameters:



9
10
11
# File 'lib/square/v_1_transactions/client.rb', line 9

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.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

Returns:

Raises:

  • (error_class)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/square/v_1_transactions/client.rb', line 28

def v_1_list_orders(request_options: {}, **params)
  params = Square::Internal::Types::Utils.normalize_keys(params)
  query_param_names = %i[order limit batch_token]
  query_params = {}
  query_params["order"] = params[:order] if params.key?(:order)
  query_params["limit"] = params[:limit] if params.key?(:limit)
  query_params["batch_token"] = params[:batch_token] if params.key?(:batch_token)
  params = params.except(*query_param_names)

  request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v1/#{params[:location_id]}/orders",
    query: query_params,
    request_options: request_options
  )
  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.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :location_id (String)
  • :order_id (String)

Returns:



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

def v_1_retrieve_order(request_options: {}, **params)
  params = Square::Internal::Types::Utils.normalize_keys(params)
  request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v1/#{params[:location_id]}/orders/#{params[:order_id]}",
    request_options: 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::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:

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :location_id (String)
  • :order_id (String)

Returns:



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/square/v_1_transactions/client.rb', line 105

def v_1_update_order(request_options: {}, **params)
  params = Square::Internal::Types::Utils.normalize_keys(params)
  request_data = Square::V1Transactions::Types::V1UpdateOrderRequest.new(params).to_h
  non_body_param_names = %w[location_id order_id]
  body = request_data.except(*non_body_param_names)

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