Class: Square::TransferOrders::Client

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

Instance Method Summary collapse

Constructor Details

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



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

def initialize(client:)
  @client = client
end

Instance Method Details

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

Cancels a transfer order in [STARTED](entity:TransferOrderStatus) or [PARTIALLY_RECEIVED](entity:TransferOrderStatus) status. Any unreceived quantities will no longer be receivable and will be immediately returned to the source [Location](entity:Location)‘s inventory.

Common reasons for cancellation:

  • Items no longer needed at destination

  • Source location needs the inventory

  • Order created in error

Creates a [transfer_order.updated](webhook:transfer_order.updated) webhook event.



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/square/transfer_orders/client.rb', line 194

def cancel(request_options: {}, **params)
  _path_param_names = ["transfer_order_id"]

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/transfer-orders/#{params[:transfer_order_id]}/cancel",
    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::CancelTransferOrderResponse.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::CreateTransferOrderResponse

Creates a new transfer order in [DRAFT](entity:TransferOrderStatus) status. A transfer order represents the intent to move [CatalogItemVariation](entity:CatalogItemVariation)s from one [Location](entity:Location) to another. The source and destination locations must be different and must belong to your Square account.

In [DRAFT](entity:TransferOrderStatus) status, you can:

  • Add or remove items

  • Modify quantities

  • Update shipping information

  • Delete the entire order via [DeleteTransferOrder](api-endpoint:TransferOrders-DeleteTransferOrder)

The request requires source_location_id and destination_location_id. Inventory levels are not affected until the order is started via [StartTransferOrder](api-endpoint:TransferOrders-StartTransferOrder).

Common integration points:

  • Sync with warehouse management systems

  • Automate regular stock transfers

  • Initialize transfers from inventory optimization systems

Creates a [transfer_order.created](webhook:transfer_order.created) webhook event.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/square/transfer_orders/client.rb', line 33

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

#delete(request_options: {}, **params) ⇒ Square::Types::DeleteTransferOrderResponse

Deletes a transfer order in [DRAFT](entity:TransferOrderStatus) status. Only draft orders can be deleted. Once an order is started via [StartTransferOrder](api-endpoint:TransferOrders-StartTransferOrder), it can no longer be deleted.

Creates a [transfer_order.deleted](webhook:transfer_order.deleted) webhook event.



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/square/transfer_orders/client.rb', line 156

def delete(request_options: {}, **params)
  params = Square::Internal::Types::Utils.symbolize_keys(params)
  _query_param_names = %i[version]
  _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: "DELETE",
    path: "v2/transfer-orders/#{params[:transfer_order_id]}",
    query: _query
  )
  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::DeleteTransferOrderResponse.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::RetrieveTransferOrderResponse

Retrieves a specific [TransferOrder](entity:TransferOrder) by ID. Returns the complete order details including:

  • Basic information (status, dates, notes)

  • Line items with ordered and received quantities

  • Source and destination [Location](entity:Location)s

  • Tracking information (if available)



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/square/transfer_orders/client.rb', line 100

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

#receive(request_options: {}, **params) ⇒ Square::Types::ReceiveTransferOrderResponse

Records receipt of [CatalogItemVariation](entity:CatalogItemVariation)s for a transfer order. This endpoint supports partial receiving - you can receive items in multiple batches.

For each line item, you can specify:

  • Quantity received in good condition (added to destination inventory with [InventoryState](entity:InventoryState) of IN_STOCK)

  • Quantity damaged during transit/handling (added to destination inventory with [InventoryState](entity:InventoryState) of WASTE)

  • Quantity canceled (returned to source location’s inventory)

The order must be in [STARTED](entity:TransferOrderStatus) or [PARTIALLY_RECEIVED](entity:TransferOrderStatus) status. Received quantities are added to the destination [Location](entity:Location)‘s inventory according to their condition. Canceled quantities are immediately returned to the source [Location](entity:Location)’s inventory.

When all items are either received, damaged, or canceled, the order moves to [COMPLETED](entity:TransferOrderStatus) status.

Creates a [transfer_order.updated](webhook:transfer_order.updated) webhook event.



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/square/transfer_orders/client.rb', line 235

def receive(request_options: {}, **params)
  _path_param_names = ["transfer_order_id"]

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/transfer-orders/#{params[:transfer_order_id]}/receive",
    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::ReceiveTransferOrderResponse.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::SearchTransferOrdersResponse

Searches for transfer orders using filters. Returns a paginated list of matching [TransferOrder](entity:TransferOrder)s sorted by creation date.

Common search scenarios:

  • Find orders for a source [Location](entity:Location)

  • Find orders for a destination [Location](entity:Location)

  • Find orders in a particular [TransferOrderStatus](entity:TransferOrderStatus)



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

def search(request_options: {}, **params)
  Square::Internal::CursorItemIterator.new(
    cursor_field: :cursor,
    item_field: :transfer_orders,
    initial_cursor: params[:cursor]
  ) do |next_cursor|
    params[:cursor] = next_cursor
    _request = Square::Internal::JSON::Request.new(
      base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
      method: "POST",
      path: "v2/transfer-orders/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::SearchTransferOrdersResponse.load(_response.body)
    else
      error_class = Square::Errors::ResponseError.subclass_for_code(code)
      raise error_class.new(_response.body, code: code)
    end
  end
end

#start(request_options: {}, **params) ⇒ Square::Types::StartTransferOrderResponse

Changes a [DRAFT](entity:TransferOrderStatus) transfer order to [STARTED](entity:TransferOrderStatus) status. This decrements inventory at the source [Location](entity:Location) and marks it as in-transit.

The order must be in [DRAFT](entity:TransferOrderStatus) status and have all required fields populated. Once started, the order can no longer be deleted, but it can be canceled via [CancelTransferOrder](api-endpoint:TransferOrders-CancelTransferOrder).

Creates a [transfer_order.updated](webhook:transfer_order.updated) webhook event.



268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/square/transfer_orders/client.rb', line 268

def start(request_options: {}, **params)
  _path_param_names = ["transfer_order_id"]

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/transfer-orders/#{params[:transfer_order_id]}/start",
    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::StartTransferOrderResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end

#update(request_options: {}, **params) ⇒ Square::Types::UpdateTransferOrderResponse

Updates an existing transfer order. This endpoint supports sparse updates, allowing you to modify specific fields without affecting others.

Creates a [transfer_order.updated](webhook:transfer_order.updated) webhook event.



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/square/transfer_orders/client.rb', line 126

def update(request_options: {}, **params)
  _path_param_names = ["transfer_order_id"]

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "PUT",
    path: "v2/transfer-orders/#{params[:transfer_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::UpdateTransferOrderResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end