From 1869c5a793736286ad09e198596169aa9afdd09e Mon Sep 17 00:00:00 2001 From: Naman Anand Date: Wed, 4 Feb 2026 15:45:17 +0530 Subject: [PATCH 1/2] fix: remove default base_url fallback in clients Stop defaulting request base_url to Square::Environment::PRODUCTION in inventory and transfer_orders clients. The Request construction now uses request_options[:base_url] directly (no || fallback), requiring callers or a higher-level config to provide a base_url and avoiding implicit production assumptions. Files changed: lib/square/inventory/client.rb, lib/square/transfer_orders/client.rb. --- lib/square/inventory/client.rb | 26 +++++++++++++------------- lib/square/transfer_orders/client.rb | 16 ++++++++-------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/square/inventory/client.rb b/lib/square/inventory/client.rb index 20578340..c6d0f415 100644 --- a/lib/square/inventory/client.rb +++ b/lib/square/inventory/client.rb @@ -14,7 +14,7 @@ def initialize(client:) # @return [Square::Types::GetInventoryAdjustmentResponse] def deprecated_get_adjustment(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( - base_url: request_options[:base_url] || Square::Environment::PRODUCTION, + base_url: request_options[:base_url], method: "GET", path: "v2/inventory/adjustment/#{params[:adjustment_id]}" ) @@ -38,7 +38,7 @@ def deprecated_get_adjustment(request_options: {}, **params) # @return [Square::Types::GetInventoryAdjustmentResponse] def get_adjustment(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( - base_url: request_options[:base_url] || Square::Environment::PRODUCTION, + base_url: request_options[:base_url], method: "GET", path: "v2/inventory/adjustments/#{params[:adjustment_id]}" ) @@ -62,7 +62,7 @@ def get_adjustment(request_options: {}, **params) # @return [Square::Types::BatchChangeInventoryResponse] def deprecated_batch_change(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( - base_url: request_options[:base_url] || Square::Environment::PRODUCTION, + base_url: request_options[:base_url], method: "POST", path: "v2/inventory/batch-change", body: Square::Types::BatchChangeInventoryRequest.new(params).to_h @@ -87,7 +87,7 @@ def deprecated_batch_change(request_options: {}, **params) # @return [Square::Types::BatchGetInventoryChangesResponse] def deprecated_batch_get_changes(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( - base_url: request_options[:base_url] || Square::Environment::PRODUCTION, + base_url: request_options[:base_url], method: "POST", path: "v2/inventory/batch-retrieve-changes", body: Square::Types::BatchRetrieveInventoryChangesRequest.new(params).to_h @@ -112,7 +112,7 @@ def deprecated_batch_get_changes(request_options: {}, **params) # @return [Square::Types::BatchGetInventoryCountsResponse] def deprecated_batch_get_counts(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( - base_url: request_options[:base_url] || Square::Environment::PRODUCTION, + base_url: request_options[:base_url], method: "POST", path: "v2/inventory/batch-retrieve-counts", body: Square::Types::BatchGetInventoryCountsRequest.new(params).to_h @@ -140,7 +140,7 @@ def deprecated_batch_get_counts(request_options: {}, **params) # @return [Square::Types::BatchChangeInventoryResponse] def batch_create_changes(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( - base_url: request_options[:base_url] || Square::Environment::PRODUCTION, + base_url: request_options[:base_url], method: "POST", path: "v2/inventory/changes/batch-create", body: Square::Types::BatchChangeInventoryRequest.new(params).to_h @@ -177,7 +177,7 @@ def batch_get_changes(request_options: {}, **params) ) do |next_cursor| params[:cursor] = next_cursor _request = Square::Internal::JSON::Request.new( - base_url: request_options[:base_url] || Square::Environment::PRODUCTION, + base_url: request_options[:base_url], method: "POST", path: "v2/inventory/changes/batch-retrieve", body: Square::Types::BatchRetrieveInventoryChangesRequest.new(params).to_h @@ -218,7 +218,7 @@ def batch_get_counts(request_options: {}, **params) ) do |next_cursor| params[:cursor] = next_cursor _request = Square::Internal::JSON::Request.new( - base_url: request_options[:base_url] || Square::Environment::PRODUCTION, + base_url: request_options[:base_url], method: "POST", path: "v2/inventory/counts/batch-retrieve", body: Square::Types::BatchGetInventoryCountsRequest.new(params).to_h @@ -244,7 +244,7 @@ def batch_get_counts(request_options: {}, **params) # @return [Square::Types::GetInventoryPhysicalCountResponse] def deprecated_get_physical_count(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( - base_url: request_options[:base_url] || Square::Environment::PRODUCTION, + base_url: request_options[:base_url], method: "GET", path: "v2/inventory/physical-count/#{params[:physical_count_id]}" ) @@ -268,7 +268,7 @@ def deprecated_get_physical_count(request_options: {}, **params) # @return [Square::Types::GetInventoryPhysicalCountResponse] def get_physical_count(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( - base_url: request_options[:base_url] || Square::Environment::PRODUCTION, + base_url: request_options[:base_url], method: "GET", path: "v2/inventory/physical-counts/#{params[:physical_count_id]}" ) @@ -292,7 +292,7 @@ def get_physical_count(request_options: {}, **params) # @return [Square::Types::GetInventoryTransferResponse] def get_transfer(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( - base_url: request_options[:base_url] || Square::Environment::PRODUCTION, + base_url: request_options[:base_url], method: "GET", path: "v2/inventory/transfers/#{params[:transfer_id]}" ) @@ -329,7 +329,7 @@ def get(request_options: {}, **params) ) do |next_cursor| _query[:cursor] = next_cursor _request = Square::Internal::JSON::Request.new( - base_url: request_options[:base_url] || Square::Environment::PRODUCTION, + base_url: request_options[:base_url], method: "GET", path: "v2/inventory/#{params[:catalog_object_id]}", query: _query @@ -377,7 +377,7 @@ def changes(request_options: {}, **params) ) do |next_cursor| _query[:cursor] = next_cursor _request = Square::Internal::JSON::Request.new( - base_url: request_options[:base_url] || Square::Environment::PRODUCTION, + base_url: request_options[:base_url], method: "GET", path: "v2/inventory/#{params[:catalog_object_id]}/changes", query: _query diff --git a/lib/square/transfer_orders/client.rb b/lib/square/transfer_orders/client.rb index 8a52efd5..09aac299 100644 --- a/lib/square/transfer_orders/client.rb +++ b/lib/square/transfer_orders/client.rb @@ -32,7 +32,7 @@ def initialize(client:) # @return [Square::Types::CreateTransferOrderResponse] def create(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( - base_url: request_options[:base_url] || Square::Environment::PRODUCTION, + base_url: request_options[:base_url], method: "POST", path: "v2/transfer-orders", body: params @@ -68,7 +68,7 @@ def search(request_options: {}, **params) ) do |next_cursor| params[:cursor] = next_cursor _request = Square::Internal::JSON::Request.new( - base_url: request_options[:base_url] || Square::Environment::PRODUCTION, + base_url: request_options[:base_url], method: "POST", path: "v2/transfer-orders/search", body: params @@ -99,7 +99,7 @@ def search(request_options: {}, **params) # @return [Square::Types::RetrieveTransferOrderResponse] def get(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( - base_url: request_options[:base_url] || Square::Environment::PRODUCTION, + base_url: request_options[:base_url], method: "GET", path: "v2/transfer-orders/#{params[:transfer_order_id]}" ) @@ -127,7 +127,7 @@ 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, + base_url: request_options[:base_url], method: "PUT", path: "v2/transfer-orders/#{params[:transfer_order_id]}", body: params.except(*_path_param_names) @@ -160,7 +160,7 @@ def delete(request_options: {}, **params) params = params.except(*_query_param_names) _request = Square::Internal::JSON::Request.new( - base_url: request_options[:base_url] || Square::Environment::PRODUCTION, + base_url: request_options[:base_url], method: "DELETE", path: "v2/transfer-orders/#{params[:transfer_order_id]}", query: _query @@ -195,7 +195,7 @@ 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, + base_url: request_options[:base_url], method: "POST", path: "v2/transfer-orders/#{params[:transfer_order_id]}/cancel", body: params.except(*_path_param_names) @@ -236,7 +236,7 @@ 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, + base_url: request_options[:base_url], method: "POST", path: "v2/transfer-orders/#{params[:transfer_order_id]}/receive", body: params.except(*_path_param_names) @@ -269,7 +269,7 @@ 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, + base_url: request_options[:base_url], method: "POST", path: "v2/transfer-orders/#{params[:transfer_order_id]}/start", body: params.except(*_path_param_names) From c298f2913dec6caa2e5ca4700dbe9d71a2d96180 Mon Sep 17 00:00:00 2001 From: Naman Anand Date: Wed, 4 Feb 2026 15:54:30 +0530 Subject: [PATCH 2/2] Forward request_options to API requests Add request_options to Square::Internal::JSON::Request calls in lib/square/inventory/client.rb and lib/square/transfer_orders/client.rb so per-request options (e.g. base_url, headers) are properly forwarded. Updated request constructors for various GET/POST/PUT/DELETE endpoints to include request_options and adjusted argument formatting; no other business logic changes. --- lib/square/inventory/client.rb | 39 ++++++++++++++++++---------- lib/square/transfer_orders/client.rb | 24 +++++++++++------ 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/lib/square/inventory/client.rb b/lib/square/inventory/client.rb index c6d0f415..0e9dbfdf 100644 --- a/lib/square/inventory/client.rb +++ b/lib/square/inventory/client.rb @@ -16,7 +16,8 @@ def deprecated_get_adjustment(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: request_options[:base_url], method: "GET", - path: "v2/inventory/adjustment/#{params[:adjustment_id]}" + path: "v2/inventory/adjustment/#{params[:adjustment_id]}", + request_options: request_options ) begin _response = @client.send(_request) @@ -40,7 +41,8 @@ def get_adjustment(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: request_options[:base_url], method: "GET", - path: "v2/inventory/adjustments/#{params[:adjustment_id]}" + path: "v2/inventory/adjustments/#{params[:adjustment_id]}", + request_options: request_options ) begin _response = @client.send(_request) @@ -65,7 +67,8 @@ def deprecated_batch_change(request_options: {}, **params) base_url: request_options[:base_url], method: "POST", path: "v2/inventory/batch-change", - body: Square::Types::BatchChangeInventoryRequest.new(params).to_h + body: Square::Types::BatchChangeInventoryRequest.new(params).to_h, + request_options: request_options ) begin _response = @client.send(_request) @@ -90,7 +93,8 @@ def deprecated_batch_get_changes(request_options: {}, **params) base_url: request_options[:base_url], method: "POST", path: "v2/inventory/batch-retrieve-changes", - body: Square::Types::BatchRetrieveInventoryChangesRequest.new(params).to_h + body: Square::Types::BatchRetrieveInventoryChangesRequest.new(params).to_h, + request_options: request_options ) begin _response = @client.send(_request) @@ -115,7 +119,8 @@ def deprecated_batch_get_counts(request_options: {}, **params) base_url: request_options[:base_url], method: "POST", path: "v2/inventory/batch-retrieve-counts", - body: Square::Types::BatchGetInventoryCountsRequest.new(params).to_h + body: Square::Types::BatchGetInventoryCountsRequest.new(params).to_h, + request_options: request_options ) begin _response = @client.send(_request) @@ -143,7 +148,8 @@ def batch_create_changes(request_options: {}, **params) base_url: request_options[:base_url], method: "POST", path: "v2/inventory/changes/batch-create", - body: Square::Types::BatchChangeInventoryRequest.new(params).to_h + body: Square::Types::BatchChangeInventoryRequest.new(params).to_h, + request_options: request_options ) begin _response = @client.send(_request) @@ -180,7 +186,8 @@ def batch_get_changes(request_options: {}, **params) base_url: request_options[:base_url], method: "POST", path: "v2/inventory/changes/batch-retrieve", - body: Square::Types::BatchRetrieveInventoryChangesRequest.new(params).to_h + body: Square::Types::BatchRetrieveInventoryChangesRequest.new(params).to_h, + request_options: request_options ) begin _response = @client.send(_request) @@ -221,7 +228,8 @@ def batch_get_counts(request_options: {}, **params) base_url: request_options[:base_url], method: "POST", path: "v2/inventory/counts/batch-retrieve", - body: Square::Types::BatchGetInventoryCountsRequest.new(params).to_h + body: Square::Types::BatchGetInventoryCountsRequest.new(params).to_h, + request_options: request_options ) begin _response = @client.send(_request) @@ -246,7 +254,8 @@ def deprecated_get_physical_count(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: request_options[:base_url], method: "GET", - path: "v2/inventory/physical-count/#{params[:physical_count_id]}" + path: "v2/inventory/physical-count/#{params[:physical_count_id]}", + request_options: request_options ) begin _response = @client.send(_request) @@ -270,7 +279,8 @@ def get_physical_count(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: request_options[:base_url], method: "GET", - path: "v2/inventory/physical-counts/#{params[:physical_count_id]}" + path: "v2/inventory/physical-counts/#{params[:physical_count_id]}", + request_options: request_options ) begin _response = @client.send(_request) @@ -294,7 +304,8 @@ def get_transfer(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: request_options[:base_url], method: "GET", - path: "v2/inventory/transfers/#{params[:transfer_id]}" + path: "v2/inventory/transfers/#{params[:transfer_id]}", + request_options: request_options ) begin _response = @client.send(_request) @@ -332,7 +343,8 @@ def get(request_options: {}, **params) base_url: request_options[:base_url], method: "GET", path: "v2/inventory/#{params[:catalog_object_id]}", - query: _query + query: _query, + request_options: request_options ) begin _response = @client.send(_request) @@ -380,7 +392,8 @@ def changes(request_options: {}, **params) base_url: request_options[:base_url], method: "GET", path: "v2/inventory/#{params[:catalog_object_id]}/changes", - query: _query + query: _query, + request_options: request_options ) begin _response = @client.send(_request) diff --git a/lib/square/transfer_orders/client.rb b/lib/square/transfer_orders/client.rb index 09aac299..0334147a 100644 --- a/lib/square/transfer_orders/client.rb +++ b/lib/square/transfer_orders/client.rb @@ -35,7 +35,8 @@ def create(request_options: {}, **params) base_url: request_options[:base_url], method: "POST", path: "v2/transfer-orders", - body: params + body: params, + request_options: request_options ) begin _response = @client.send(_request) @@ -71,7 +72,8 @@ def search(request_options: {}, **params) base_url: request_options[:base_url], method: "POST", path: "v2/transfer-orders/search", - body: params + body: params, + request_options: request_options ) begin _response = @client.send(_request) @@ -101,7 +103,8 @@ def get(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: request_options[:base_url], method: "GET", - path: "v2/transfer-orders/#{params[:transfer_order_id]}" + path: "v2/transfer-orders/#{params[:transfer_order_id]}", + request_options: request_options ) begin _response = @client.send(_request) @@ -130,7 +133,8 @@ def update(request_options: {}, **params) base_url: request_options[:base_url], method: "PUT", path: "v2/transfer-orders/#{params[:transfer_order_id]}", - body: params.except(*_path_param_names) + body: params.except(*_path_param_names), + request_options: request_options ) begin _response = @client.send(_request) @@ -163,7 +167,8 @@ def delete(request_options: {}, **params) base_url: request_options[:base_url], method: "DELETE", path: "v2/transfer-orders/#{params[:transfer_order_id]}", - query: _query + query: _query, + request_options: request_options ) begin _response = @client.send(_request) @@ -198,7 +203,8 @@ def cancel(request_options: {}, **params) base_url: request_options[:base_url], method: "POST", path: "v2/transfer-orders/#{params[:transfer_order_id]}/cancel", - body: params.except(*_path_param_names) + body: params.except(*_path_param_names), + request_options: request_options ) begin _response = @client.send(_request) @@ -239,7 +245,8 @@ def receive(request_options: {}, **params) base_url: request_options[:base_url], method: "POST", path: "v2/transfer-orders/#{params[:transfer_order_id]}/receive", - body: params.except(*_path_param_names) + body: params.except(*_path_param_names), + request_options: request_options ) begin _response = @client.send(_request) @@ -272,7 +279,8 @@ def start(request_options: {}, **params) base_url: request_options[:base_url], method: "POST", path: "v2/transfer-orders/#{params[:transfer_order_id]}/start", - body: params.except(*_path_param_names) + body: params.except(*_path_param_names), + request_options: request_options ) begin _response = @client.send(_request)