SDKs overview

Square provides a suite of Software Development Kits (SDKs) designed to facilitate interaction with its various APIs, including Payments, Orders, Customers, and Catalog. These SDKs abstract away the complexities of direct HTTP requests, authentication, and response parsing, allowing developers to integrate Square's functionality into their applications more efficiently. The official SDKs are maintained by Square and are available across several popular programming languages, ensuring compatibility and ongoing support for developers building payment and business management solutions.

Using an SDK can streamline development by providing idiomatic language constructs, type safety, and built-in error handling. This approach contrasts with direct API calls, which require manual construction of request bodies and parsing of JSON responses. Square's SDKs are particularly useful for applications requiring secure payment processing, managing inventory, or interacting with customer data within the Square ecosystem. Developers can find detailed documentation and guides on the Square Developer documentation portal.

Official SDKs by language

Square offers official SDKs for a range of programming languages, each designed to provide a native development experience. These SDKs are regularly updated to reflect the latest API versions and features. The table below outlines the key official SDKs, their respective package names, installation commands, and general maturity status.

Language Package Name Installation Command Maturity
Java square-java-sdk Add to pom.xml (Maven) or build.gradle (Gradle) Stable
PHP square/square-php-sdk composer require square/square-php-sdk Stable
Python square pip install square Stable
Ruby square_connect gem install square_connect Stable
C# (.NET) Square.Connect dotnet add package Square.Connect Stable
Node.js square-connect npm install square-connect Stable

Installation

Installing Square's SDKs typically involves using the standard package manager for each respective language. Below are detailed instructions for each official SDK. Before installation, developers should ensure they have the correct runtime environment and package manager configured.

Java

For Java projects, the Square SDK is distributed via Maven Central. Add the following dependency to your pom.xml for Maven projects or build.gradle for Gradle projects:

<dependency>
    <groupId>com.squareup</groupId>
    <artifactId>square-java-sdk</artifactId>
    <version>[LATEST_VERSION]</version>
</dependency>

Replace [LATEST_VERSION] with the current stable version found on the Square Java SDK documentation.

PHP

The PHP SDK is installed using Composer, the dependency manager for PHP:

composer require square/square-php-sdk

After installation, Composer's autoloader will make the SDK classes available in your project.

Python

The Python SDK is available on PyPI and can be installed using pip:

pip install square

It is recommended to use a virtual environment for Python projects to manage dependencies.

Ruby

For Ruby applications, the SDK is distributed as a Rubygem:

gem install square_connect

Then, require it in your Ruby code using require 'square_connect'.

C# (.NET)

The C# SDK is available as a NuGet package:

dotnet add package Square.Connect

This command adds the package reference to your .NET project file.

Node.js

For Node.js projects, the SDK is available via npm:

npm install square-connect

You can then import the SDK into your JavaScript or TypeScript files.

Quickstart example

This example demonstrates how to create a customer using the Square Node.js SDK. This snippet illustrates client initialization, making an API call, and handling the response or potential errors. Before running, ensure you have your Square Access Token and Application ID configured, ideally as environment variables.

const { Client, Environment } = require('square-connect');

// Initialize Square client
const client = new Client({
  environment: Environment.Sandbox, // Use Environment.Production for live applications
  accessToken: process.env.SQUARE_ACCESS_TOKEN,
});

const customersApi = client.customers;

async function createCustomer() {
  const idempotencyKey = require('crypto').randomUUID(); // Unique key for idempotent requests

  const requestBody = {
    givenName: 'Jane',
    familyName: 'Doe',
    emailAddress: '[email protected]',
    phoneNumber: '+1-555-555-5555',
    referenceId: 'customer-ref-123',
  };

  try {
    const { result } = await customersApi.createCustomer(idempotencyKey, requestBody);
    console.log('Customer created successfully:', result.customer);
  } catch (error) {
    console.error('Error creating customer:', error.result.errors);
  }
}

createCustomer();

This quickstart initializes the Square client in the sandbox environment, which is suitable for development and testing without affecting live data. The idempotencyKey is crucial for ensuring that API requests are processed only once, even if the request is retried. This is a common pattern in payment processing APIs to prevent duplicate transactions, as detailed in the Stripe API documentation on idempotent requests.

Community libraries

While Square provides a comprehensive set of official SDKs, the developer community sometimes creates and maintains additional libraries or tools. These community-contributed resources can offer specialized functionalities, alternative language bindings, or integrations with specific frameworks not directly supported by Square's official offerings. Developers should exercise caution and review the codebase and maintenance status of any third-party library before integrating it into production systems, as they may not carry the same level of support or security guarantees as official SDKs.

Examples of community contributions might include:

  • Framework-specific integrations: Libraries that provide wrappers or plugins for popular web frameworks like Django, Ruby on Rails, or Laravel, making it easier to integrate Square within those ecosystems.
  • Specialized utilities: Tools for specific tasks, such as webhook validation helpers or custom UI components for payment forms.
  • Alternative language clients: SDKs for languages not officially supported by Square, developed and maintained by community members.

Developers looking for community libraries can often find them on platforms like GitHub, searching for terms like "Square API" combined with their desired language or framework. The Square Developer documentation and forums are also good places to discover and discuss community-driven projects.