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.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/square/transfer_orders/client.rb', line 189 def cancel(request_options: {}, **params) _path_param_names = ["transfer_order_id"] _request = Square::Internal::JSON::Request.new( base_url: [: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: [: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.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/square/transfer_orders/client.rb', line 149 def delete(request_options: {}, **params) _query_param_names = [ ["version"], %i[version] ].flatten _query = params.slice(*_query_param_names) params = params.except(*_query_param_names) _request = Square::Internal::JSON::Request.new( base_url: [: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)
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/square/transfer_orders/client.rb', line 93 def get(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [: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.
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/square/transfer_orders/client.rb', line 230 def receive(request_options: {}, **params) _path_param_names = ["transfer_order_id"] _request = Square::Internal::JSON::Request.new( base_url: [: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 |
# File 'lib/square/transfer_orders/client.rb', line 63 def search(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [: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 |
#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.
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/square/transfer_orders/client.rb', line 263 def start(request_options: {}, **params) _path_param_names = ["transfer_order_id"] _request = Square::Internal::JSON::Request.new( base_url: [: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.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/square/transfer_orders/client.rb', line 119 def update(request_options: {}, **params) _path_param_names = ["transfer_order_id"] _request = Square::Internal::JSON::Request.new( base_url: [: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 |