Square PHP SDK

The official PHP client library for the Square API, covering payments, orders, catalog, and more.

SDK
Composer
v46.1.0.20260819
77stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
61/100Good
Development Activity64
Maintenance60
Community48
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
77/100Good
Architecture84
Code Quality80
Innovation80
Learning Curve64

The Square PHP SDK is the official client library for the Square API, giving PHP applications convenient, typed access to Square’s commerce platform. Through a single SquareClient, it exposes the full breadth of Square functionality, including payments, orders, catalog, inventory, customers, invoices, subscriptions, loyalty, gift cards, and payouts.

Generated with Fern from Square’s API specification, the SDK provides strongly typed request and response objects, built-in authentication, environment selection, and idempotency support. This lets developers integrate card payments and broader commerce features without manually constructing HTTP requests or parsing JSON responses.

What You Get

  • A SquareClient exposing every Square API domain (payments, orders, catalog, customers, and more)
  • Strongly typed request and response objects generated from Square’s API spec
  • Built-in authentication and environment selection (production and sandbox)
  • Idempotency-key support for safely retrying create operations
  • Coverage of commerce features including invoices, subscriptions, loyalty, gift cards, and payouts

Common Use Cases

  • Processing card, cash, and digital-wallet payments from an online or in-app checkout
  • Creating and managing orders, catalog items, and inventory for a commerce app
  • Issuing invoices and managing subscriptions for recurring billing
  • Syncing customers, loyalty accounts, and gift cards with Square

Under The Hood

Architecture - The SDK is a Fern-generated client. SquareClient (src/) aggregates per-domain sub-clients (Payments, Orders, Catalog, Customers, Invoices, and dozens more), each a namespace under src/ with Requests and Types packages holding typed models. A Core layer handles HTTP transport, serialization, authentication headers, and idempotency, while Environments.php selects production or sandbox base URLs. A Legacy namespace preserves the older client surface for migration.

Tech Stack - PHP 8.1+ library distributed as square/square on Packagist. Generated by Fern from Square’s API specification, it uses PSR-4 autoloading, PHPUnit for tests, and PHPStan for static analysis. Request/response bodies are modeled as typed PHP classes with enums (e.g. Currency) rather than raw arrays.

Code Quality - Being code-generated, the SDK is uniform and exhaustive across domains, with consistent naming and typed models reducing runtime errors. A tests/ directory and PHPStan configuration accompany the source. The generated Types and Requests classes are numerous but predictable, and a Legacy layer eases upgrades from prior versions.

API Design - The public API is ergonomic and discoverable: sub-clients group operations logically (square->payments->create(…)), and typed request objects with named constructors make calls self-documenting. Enums and Money value objects reduce ambiguity. The main friction is the sheer surface area and verbosity of constructing nested request objects, giving it a moderate learning curve offset by strong reference docs.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search