Purchaser Plugins Integration
The Purchaser Plugin operator is designed to coordinate merchant APIs across different platforms like Shopify and WooCommerce.
To function correctly, the purchaser plugin must be configured in the merchant's admin panel on the specific hosting docs.
While details of those platform-specific merchant configurations are explained in separate documentation, this section focuses on aspects involving the SDK and the APEX protocol, guiding developers and agents in working with the systems.
Use the links below to explore the setup workflow and runtime integration templates.
Purchaser Codegen and Dynamic Pricing Models#
1. The Dual-Registry Model
When building e-commerce and 3D product customizer applications with the Aircada SDK, the CLI generates strongly-typed helper registries in src/registry/:
src/registry/plugins.generated.ts(ProductPurchasers): Generated when one or more Pricing Models (.airpm) are compiled. Provides typed factory functions (e.g.ProductPurchasers.<MODEL>_TEST(this.air)) that link dataset option rows, calculation rules, and initial state.
src/registry/configs.generated.ts(AirConfigs): Generated for standard merchant product configs and single-item purchaser configurations without pricing models (e.g.AirConfigs.PURCHASER.<CONFIG_KEY>).
src/registry/options.generated.ts(OptionsRegistry&InitialOptionState): Maps option sets, dataset row types, and initial store values.
2. Auto-Generated plugins.generated.ts Structure
The CLI compiles pricing models and merchant purchaser configurations into typed async factories:
// ๐ข AUTO-GENERATED BY AIRCADA CLI
// This file synchronizes Studio Option Models & Purchasers with the SDK Store.
import { PurchaserPluginOperator } from "@aircada/spec";
import { AirConfigs } from "./configs.generated";
import { OptionsRegistry, InitialOptionState } from "./options.generated";
export const ProductPurchasers = {
// Test harness factory for local sandboxed development
WATCH_CONFIGURATOR_TEST: async (air: any, overrides?: any) => {
return air.ecommerce.createPurchaserPlugin({
configUrl: "TEST_watch_pricing_model",
optionsRegistryItem: OptionsRegistry.WATCH_CONFIGURATOR,
initialState: InitialOptionState.watchPricing,
...(overrides || {}),
}) as PurchaserPluginOperator;
},
// Production factory linked to merchant Shopify product config
WATCH_CONFIGURATOR_PROD: async (air: any, overrides?: any) => {
return air.ecommerce.createPurchaserPlugin({
configUrl: AirConfigs.PURCHASER.WATCH_CONFIGURATOR_PROD.configUrl,
optionsRegistryItem: OptionsRegistry.WATCH_CONFIGURATOR,
initialState: InitialOptionState.watchPricing,
...(overrides || {}),
}) as PurchaserPluginOperator;
},
} as const;3. Integrating the Purchaser Plugin into a @System Manager
The recommended best practice is to initialize the purchaser asynchronously inside a headless @System manager in response to the setup handshake event (SETUP_EVENT_EXPERIENCE_READY), rather than competing on @Setup() lifecycle hooks:
import {
System,
Context,
Input,
Dispose,
AircadaContext,
PurchaserPluginOperator
} from "@aircada/spec";
import { ProductPurchasers } from "../registry/plugins.generated";
import {
STORE_KEY_CALCULATED_PRICE,
SETUP_EVENT_EXPERIENCE_READY,
EVENT_CART_ADD_REQUESTED,
EVENT_CAPTURE_SCREENSHOT
} from "../schemas/WatchSchemas";
@System({
name: "Commercial Pricing System",
type: "COMMERCIAL_PRICING_SYSTEM"
})
export class CommercialPricingSystem {
@Context()
air!: AircadaContext;
private purchaser: PurchaserPluginOperator | null = null;
@Input({ onEvent: SETUP_EVENT_EXPERIENCE_READY })
async onExperienceReady() {
if (ProductPurchasers && this.air.ecommerce) {
// 1. Asynchronously instantiate the purchaser
this.purchaser = await (ProductPurchasers as any).WATCH_CONFIGURATOR_TEST(this.air);
if (!this.purchaser) {
console.error("[CommercialPricingSystem] Failed to instantiate PurchaserPluginOperator");
return;
}
// 2. Reactive Price Synchronization to SDK Store
this.purchaser.price?.addListener?.((newPrice: string) => {
const numericPrice = parseFloat(newPrice);
if (!isNaN(numericPrice)) {
console.log("[CommercialPricingSystem] Purchaser calculated price: $" + numericPrice.toFixed(2));
this.air.store.patch({ [STORE_KEY_CALCULATED_PRICE]: numericPrice });
}
});
// 3. Full Transaction Lifecycle Event Telemetry
this.purchaser.onSuccess?.addListener?.((response) => {
console.log("๐ [Purchaser] Checkout transaction completed successfully", response);
});
this.purchaser.onFailure?.addListener((error) => {
console.error("๐ [Purchaser] Checkout transaction failed:", error);
});
this.purchaser.onValidationPassed?.addListener(() => {
console.log("โ
[Purchaser] Option configuration passed validation");
});
this.purchaser.onValidationFailed?.addListener((err) => {
console.warn("โ ๏ธ [Purchaser] Option configuration validation failed:", err);
});
this.purchaser.issueMessage?.addListener?.((issue) => {
console.warn("โ ๏ธ [Purchaser Issue Diagnostic]:", issue);
});
}
}
@Input({ onEvent: EVENT_CART_ADD_REQUESTED })
onAddToCart() {
console.log("๐ [CommercialPricingSystem] Submitting cart checkout sequence...");
this.purchaser?.submit?.();
}
@Input({ onEvent: EVENT_CAPTURE_SCREENSHOT })
onScreenshotCaptured(mediaItemOrBlob: any) {
console.log("๐ธ [CommercialPricingSystem] Forwarding custom render screenshot for staged upload...");
this.purchaser?.screenshot?.(mediaItemOrBlob);
}
@Dispose()
dispose() {
this.purchaser?.dispose?.();
this.purchaser = null;
}
}4. Non-Pricing Model Projects (Standard Configs)
If a project does NOT define a dynamic pricing model (.airpm), external agents should inspect src/registry/configs.generated.ts to discover available standard product configurations and instantiate the purchaser directly:
import { AirConfigs } from "../registry/configs.generated";
// Programmatic instantiation for standard merchant product configs
this.purchaser = (await this.air.operators.create("PURCHASER_PLUGIN", {
configUrl: AirConfigs.PURCHASER.MAIN_PRODUCT.configUrl,
quantity: 1
})) as PurchaserPluginOperator;5. Full PurchaserPluginOperator Action & Trigger Surface
| Surface Type | Identifier | Type Signature | Purpose |
| :--- | :--- | :--- | :--- |
| Action (Input) | submit() | () => Promise<void> | Initiates checkout transaction sequence. |
| Action (Input) | screenshot(item) | (mediaItemOrBlob: any) => void | Passes custom 3D canvas render for Shopify staged background upload. |
| Action (Input) | bundledData | DataBlock[] | Ingests child component item data for multi-item bundle configurations. |
| Trigger (Output) | price | AirEvent<string> | Emits formatted calculated price string (e.g. '49.99'). |
| Trigger (Output) | onSubmit | AirEvent<InitiatePurchaseRequest> | Dispatched immediately when checkout submission begins. |
| Trigger (Output) | onSuccess | AirEvent<InitiatePurchaseResponse> | Dispatched when cart addition/checkout succeeds. |
| Trigger (Output) | onFailure | AirEvent<InitiatePurchaseResponse> | Dispatched if checkout or validation fails. |
| Trigger (Output) | onValidationPassed | AirEvent<void> | Dispatched when option selections pass validation rules. |
| Trigger (Output) | onValidationFailed | AirEvent<void> | Dispatched when invalid option combinations are selected. |
| Trigger (Output) | startupContext | AirEvent<DataBlock[]> | Emits initial Shopify window context data blocks. |
| Trigger (Output) | issueMessage | AirEvent<IPurchaserIssue> | Emits structured diagnostic issue blocks. |
Pricing Models and Purchaser Setup Workflow#
Workflow Sequence for Pricing Models
When constructing pricing models and wiring up e-commerce purchasing, developers and AI coding agents author local workspace files managed via CLI DevServer synchronization (air dev). See Dataset File Format (.airpds) and Pricing Model Manifest Format (.airpm) for detailed JSON specifications:
- Author Datasets (
datasets/*.airpds): Write.airpdsJSON files defining schema columns (STRING,FLOAT,INTEGER,COLOR,MEDIA_ITEM) and dataset row items.
- Author Option & Pricing Models (
option-models/*.airpm): Write stripped.airpmmanifests specifyingtypeVersion: 1.02,basePrice,optionSets, and relationaldatasetIdforeign keys.
- Run CLI DevServer (
air dev): Synchronize local workspace files live with Aircada Studio and Engine using atomic disk write protections (.tmp->fs.rename).
- Runtime Inspection: Use MCP inspection tools (
inspect_studio_structure) to query the live session and verify that option models and datasets are registered.
1. File Synchronization & Local Editing
Local .airpds and .airpm files serve as the authoritative single source of truth for datasets and pricing rules. The CLI DevServer automatically detects file edits, validates schemas, and broadcasts updates over WebSockets to Studio in real time.
2. Synchronization and CLI Registry Codegen
After dataset and pricing model files are synchronized with Engine, the Aircada CLI automatically updates:
src/registry/options.generated.ts: GeneratesOptionsRegistryandInitialOptionStatemapping option sets and row types.
src/registry/plugins.generated.ts: GeneratesProductPurchasersfactory functions (e.g.ProductPurchasers.<NAME>_TEST(this.air)) for async instantiation inside@Systemmanagers.
src/registry/configs.generated.ts: GeneratesAirConfigscontaining standard merchant product configs and single-item purchaser configurations.
For implementation templates, see the Purchaser Codegen & Operator Usage Guide.