This SDK is designed to simplify integration with Craft Commerce, offering specialized modules for users, carts, payments, subscriptions, and more. Whether you're building a headless e-commerce application or enhancing an existing Craft Commerce setup, this guide will help you navigate and implement the SDK effectively.
Note: Craft Commerce version 4 or higher is required for compatibility with this SDK.
- Demo and Local Testing
- Craft CMS Configuration Guide
- Package Installation
- Client Module
- Users Module
- Cart Module
- Payment Sources Module
- Payment Module
- Subscriptions Module
- Suggestions for Craft CMS Improvements
You can see a working demo of the SDK at this link:
https://craft-commerce-headless-sdk.netlify.app/
If you want to test the SDK locally, follow these steps:
- Clone the repository.
- Navigate to the
demofolder. - Run the following commands:
This will start the demo locally. Before using the SDK, ensure that Craft CMS and Craft Commerce are correctly configured for headless usage. Follow the Craft CMS Configuration Guide for essential setup steps, including CORS configuration and cookie settings.
npm install npm run dev
This section provides details on configuring Craft CMS for headless usage, including CORS setup and other necessary settings.
To use the Craft Commerce Headless SDK in your project, you can install it using your preferred package manager. Here are the commands for different managers:
npm install craft-commerce-headless-sdkpnpm add craft-commerce-headless-sdkyarn add craft-commerce-headless-sdkAfter installation, you can import the SDK in your code:
import { craftCommerceHeadlessSdk } from 'craft-commerce-headless-sdk';The base module for API communication, handling HTTP requests with post and get methods.
This module handles user account creation, profile management, and address handling. It simplifies operations like login, password resets, and managing user-related data, all essential for e-commerce platforms.
Manage shopping cart actions, including retrieval, updates, and checkout operations. This module supports typical e-commerce workflows in Craft Commerce.
Create, manage, and assign payment methods to user accounts. This module supports common payment operations like adding or removing payment sources, tailored for Craft Commerce.
Handle payments, including support for 3D Secure and other gateway integrations. This module streamlines the process of initiating and completing payments in Craft Commerce.
Manage subscriptions, including plan creation, cancellations, switching, and reactivation. This module simplifies recurring payment setups in Craft Commerce.
While this SDK provides extensive functionality, there are a few additional features that would greatly enhance the integration experience if included directly in Craft CMS or Craft Commerce:
-
Include Available Payment Gateways in the Cart: Similar to how shipping methods are returned, having payment gateways listed directly in the cart data would streamline the checkout process and improve integration ease.
-
Return User-Associated Addresses: Adding a feature to retrieve addresses associated with a user, similar to the
actions/users/session-infomethod for session data, would simplify managing user information in headless implementations.