Ruby SDK Migration Guide

Version 44.0.0.20250820 of the Ruby SDK represents a full rewrite of the SDK, with a number of breaking changes, outlined in the following sections. When upgrading to this version or later versions, take note of the changes in the SDK, including client construction and parameter names. If necessary, you can use the legacy version of the SDK along with the latest version.

SDK versions 43.0.1.20250716 and earlier continue to function as expected, but you should plan to update your integration as soon as possible to ensure continued support.

Link to section

Client construction

The new version of the Ruby SDK introduces breaking changes in the client class.

LegacyNewAdditional information
access_tokentokenThe access token used for authentication. Defaults to the SQUARE_TOKEN environment variable.
custom_urlbase_urlThe base URL for API requests. Defaults to Square::Environment::PRODUCTION.
square_versionRemovedThis option has been removed.
additional_headersRemoved from the clientSet additional headers per call with the additional_headers request option.
timeoutRemovedThis option has been removed.
environmentRemovedSet the environment in base_url instead.
retry_intervalRemovedThis option has been removed.
backoff_factorRemovedThis option has been removed.
retry_statusesRemovedThis option has been removed.
retry_methodsRemovedThis option has been removed.
http_call_backRemovedThis option has been removed.
bearer_auth_credentialsRemovedThis option has been removed.
user_agent_detailRemovedThis option has been removed.
configRemovedThis option has been removed.
Link to section

Use the legacy and new SDK side by side

While the new SDK has many improvements, it takes time to upgrade when there are breaking changes. To make the migration easier, the square.rb gem also ships the legacy SDK under the square_legacy name, so the two can be used side by side in the same project.

The following example shows how to use the new and legacy SDKs inside a single file:

require 'square' require 'square_legacy' client = Square::Client.new(token: 'YOUR_API_KEY') legacy_client = SquareLegacy::Client.new( bearer_auth_credentials: SquareLegacy::BearerAuthCredentials.new( access_token: ENV.fetch('SQUARE_TOKEN') ) ) # List all payments with the new client. new_response = client.payments.list # List all payments with the legacy client. legacy_response = legacy_client.payments.list_payments

You should migrate to the new SDK using the following steps:

  1. Upgrade the gem to ^44.0.0 by running gem install square.rb.
  2. Search and replace all requires from square to square_legacy.
  3. Gradually move over to use the new SDK by importing it from the square module.
Link to section

Strongly-typed requests and responses

The previous version of the SDK had no strong typing, so users had to craft payloads without any help from autocomplete. The newly generated SDK comes with YARD documentation and RBS types so that developers can let their IDE guide them.

Note that the legacy client wrapped request fields in a body: hash. The new client takes request fields directly as keyword arguments, so there is no body: wrapper. Beyond that, the experience of writing in an editor is quite different.

Link to section

Exceptions

The legacy SDK represents successful calls and errors with the same ApiResponse type. Users could distinguish between successes and errors as shown:

# LEGACY result = legacy_client.customers.create_customer(body: body) if result.success? puts result.data elsif result.error? warn result.errors end

The new SDK represents errors as exceptions, all of which inherit from the Square::Errors::ApiError class. Rescue Square::Errors::ResponseError to handle any non-2xx response.

# NEW begin result = client.customers.create(given_name: 'John') rescue Square::Errors::ResponseError => e puts e.code puts e.message end
Link to section

Auto-pagination

Square's paginated endpoints now support auto-pagination with an iterator. Callers don't need to manually fetch the next page. You can now iterate over the entire list and the client automatically fetches the next page behind the scenes.

The new client returns an iterator that includes Enumerable, so iterate it with each:

# NEW customers = client.customers.list( limit: 10, sort_field: 'DEFAULT', sort_order: 'DESC' ) customers.each do |customer| puts customer.id end