Uninitialized constant BearerAuthCredentials

Hi there, I’ve recently updated my square gem in a rails project to:

square.rb (38.1.1.20240717)
      apimatic_core (~> 0.3.9)
      apimatic_core_interfaces (~> 0.2.1)
      apimatic_faraday_client_adapter (~> 0.1.4)

I’m aware that we need to change the authentication from:

      client = Square::Client.new(
        access_token: Rails.application.credentials.dig(Rails.env.to_sym, :square, :access_token),
        environment: 'sandbox'
      )

to:

client = Square::Client.new(
        bearer_auth_credentials: BearerAuthCredentials.new(
          access_token: Rails.application.credentials.dig(Rails.env.to_sym, :square, :access_token)
        ),
        environment: 'sandbox'
      )

however when I run this, I get an error:

NameError (uninitialized constant [ControllerName]::BearerAuthCredentials):

Any suggestions?

Cheers

:wave: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

Additional Documentation

Ruby SDK
Access Tokens and Other Credentials
Set up your SDK for a Ruby Project

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

That error indicates that you may not have the proper module or class correctly referenced or included in your code. Have you confirm that the Rails.application.credentials.dig(Rails.env.to_sym, :square, :access_token) is correctly set and fetching the access token properly?

Other things to look for:

  1. Namespace Issue: Ensure that Square::BearerAuthCredentials is being used as it might be nested within the Square module.
  2. Gem Version Verification: Ensure the gem version you are using supports BearerAuthCredentials. There may be changes or updates in the newer version. Confirm with:
bundle list | grep square.rb

:slightly_smiling_face:

1 Like

Thanks Bryan. Using the namespacing change seems to have fixed it.

Regards
Paul

Glad to hear that you figured out the issue. :slightly_smiling_face: