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.

Legacy New Additional information
access_tokentokenThe access token used for authentication.
custom_urlbase_urlThe base URL for API requests.
square_versionversionThe Square API version to use.
additional_headersadditional_headersAdditional headers can be set at individual methods.
timeouttimeoutThe default HTTP timeout when invoking an endpoint.
environmentenvironmentThis option has been removed. Set 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 old SDK is published as square_legacy so that the two SDKs 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 = Square::LegacyClient.new( bearer_auth_credentials: BearerAuthCredentials.new( access_token: ENV['SQUARE_ACCESS_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.
  2. Run gem install square.rb.
  3. Search and replace all requires from square to square_legacy.
  4. 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.

While the before and after code snippets remain similar, 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 = customers_api.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 SquareError class.

begin result = customers_api.create_customer(body: body) rescue Square::SquareError => e puts("The server could not be reached") puts(e.cause) 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 following example shows the same code, with the legacy and new SDKs:

page = client.customers.list( body: { limit: 10, sort_field: 'DEFAULT', sort_order: 'DESC' } ) page.auto_paging_each do |customer| puts(customer.id)