Class: Square::TransferOrders::Client
- Inherits:
-
Object
- Object
- Square::TransferOrders::Client
- Defined in:
- lib/square/transfer_orders/client.rb
Instance Method Summary collapse
-
#cancel(request_options: {}, **params) ⇒ Square::Types::CancelTransferOrderResponse
Cancels a transfer order in [STARTED](entity:TransferOrderStatus) or [PARTIALLY_RECEIVED](entity:TransferOrderStatus) status.
-
#create(request_options: {}, **params) ⇒ Square::Types::CreateTransferOrderResponse
Creates a new transfer order in [DRAFT](entity:TransferOrderStatus) status.
-
#delete(request_options: {}, **params) ⇒ Square::Types::DeleteTransferOrderResponse
Deletes a transfer order in [DRAFT](entity:TransferOrderStatus) status.
-
#get(request_options: {}, **params) ⇒ Square::Types::RetrieveTransferOrderResponse
Retrieves a specific [TransferOrder](entity:TransferOrder) by ID.
- #initialize(client:) ⇒ Square::TransferOrders::Client constructor
-
#receive(request_options: {}, **params) ⇒ Square::Types::ReceiveTransferOrderResponse
Records receipt of [CatalogItemVariation](entity:CatalogItemVariation)s for a transfer order.
-
#search(request_options: {}, **params) ⇒ Square::Types::SearchTransferOrdersResponse
Searches for transfer orders using filters.
-
#start(request_options: {}, **params) ⇒ Square::Types::StartTransferOrderResponse
Changes a [DRAFT](entity:TransferOrderStatus) transfer order to [STARTED](entity:TransferOrderStatus) status.
-
#update(request_options: {}, **params) ⇒ Square::Types::UpdateTransferOrderResponse
Updates an existing transfer order.
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.
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/square/transfer_orders/client.rb', line 199 def cancel(request_options: {}, **params) _path_param_names = ["transfer_order_id"] _request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/transfer-orders/#{params[:transfer_order_id]}/cancel", body: params.except(*_path_param_names), 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::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 53 |
# File 'lib/square/transfer_orders/client.rb', line 33 def create(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/transfer-orders", body: 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::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.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/square/transfer_orders/client.rb', line 160 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: [:base_url], method: "DELETE", path: "v2/transfer-orders/#{params[:transfer_order_id]}", query: _query, 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::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)
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/square/transfer_orders/client.rb', line 102 def get(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/transfer-orders/#{params[:transfer_order_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::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.
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/square/transfer_orders/client.rb', line 241 def receive(request_options: {}, **params) _path_param_names = ["transfer_order_id"] _request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/transfer-orders/#{params[:transfer_order_id]}/receive", body: params.except(*_path_param_names), 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::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)
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 90 91 |
# File 'lib/square/transfer_orders/client.rb', line 64 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: [:base_url], method: "POST", path: "v2/transfer-orders/search", body: 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::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.
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/square/transfer_orders/client.rb', line 275 def start(request_options: {}, **params) _path_param_names = ["transfer_order_id"] _request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/transfer-orders/#{params[:transfer_order_id]}/start", body: params.except(*_path_param_names), 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::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.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/square/transfer_orders/client.rb', line 129 def update(request_options: {}, **params) _path_param_names = ["transfer_order_id"] _request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "PUT", path: "v2/transfer-orders/#{params[:transfer_order_id]}", body: params.except(*_path_param_names), 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::UpdateTransferOrderResponse.load(_response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(_response.body, code: code) end end |