Skip to main content

Overview

Contracts are interfaces that define extension points throughout Unleash Commerce. They allow you to swap implementations, add custom logic, and extend functionality without modifying core code.

What are Contracts?

Contracts are PHP interfaces located in the src/Contracts directory. They define the API for a particular feature, allowing you to create your own implementations.

Naming Convention

Always alias contracts with a Contract suffix for clarity:
use Esign\UnleashCommerce\Core\Models\Contracts\Product as ProductContract;

Binding Contracts

Once you’ve created an implementation, bind it in a service provider:
$this->app->bind(
    ProductContract::class,
    CustomProductImplementation::class
);

Response Contracts

Controllers must return response contracts defined in src/Contracts/Http/Responses. Each distinct response type has its own interface and implementation pair.

Benefits

  • Flexibility: Swap implementations without changing code
  • Testability: Mock contracts in your tests
  • Extensibility: Add custom behavior by implementing contracts
  • Maintainability: Clear contracts define expected behavior