← Back to scenarios
ScenarioCatalog DB

Checkout workflow

Expose one order-placement operation that coordinates authentication, payment, inventory, and notification subsystems.

Problem

A checkout client must complete an order without coordinating multiple subsystem APIs or depending directly on authentication, payment, inventory, and notification implementation details.

Related patterns

Implementations

Facade

TypeScriptApplication

Facade in TypeScript

Provides one checkout operation that coordinates inventory, payment, and shipment subsystems without exposing their individual workflows to callers.

TypeScript
type OrderRequest = {
  orderId: string;
  sku: string;
  quantity: number;
  paymentToken: string;
};

class InventoryService {
  reserve(sku: string, quantity: number) {
    console.log(`Reserved ${quantity} of ${sku}`);
  }
}

class PaymentService {
  charge(paymentToken: string) {
    console.log(`Charged payment token ${paymentToken}`);
  }
}

class ShipmentService {
  createShipment(orderId: string) {
    console.log(`Created shipment for ${orderId}`);
  }
}

class CheckoutFacade {
  constructor(
    private readonly inventory: InventoryService,
    private readonly payments: PaymentService,
    private readonly shipments: ShipmentService,
  ) {}

  placeOrder(request: OrderRequest) {
    this.inventory.reserve(request.sku, request.quantity);
    this.payments.charge(request.paymentToken);
    this.shipments.createShipment(request.orderId);
  }
}

const checkout = new CheckoutFacade(
  new InventoryService(),
  new PaymentService(),
  new ShipmentService(),
);

checkout.placeOrder({
  orderId: "order-123",
  sku: "keyboard",
  quantity: 1,
  paymentToken: "token_abc",
});

Associated technologies