Ucommerce
  • Ucommerce Next Gen
    • Getting Started
      • Prerequisites
      • Licensing
      • Ucommerce Templates
      • Headless Template
      • MVC Template
    • Headless
      • Postman Collection
      • Headless API Authentication
        • Token endpoint - Authorization Header
        • Authorization Scopes
        • Refreshing the Access Token
      • Reference
        • Cart
        • Cart / Order Line Items
        • Shipment
        • Billing
        • Promotion Codes
        • Price Groups
        • Payment Methods
        • Countries
        • Shipping Methods
        • Catalogs
        • Cart Custom Properties
        • Line Item Custom Properties
        • Orders
        • Views for Cart modifying operations
      • Custom Headless APIs
      • Error Handling
      • Pagination
      • Deprecation
    • Backoffice Authentication
      • Microsoft Entra ID Example
      • Auth0 Authentication Example
    • Definitions
      • What is a Definition
    • Search and indexing
      • Configuration
      • Indexing
        • Index Definitions
        • Facets
        • Indexing Prices
        • Suggestions
        • Custom Data
      • Searching
    • Payment Providers
      • Stripe Provider Integration
      • Implementing a custom payment provider
    • Data Import
    • Miscellaneous
      • Media
      • Price Group Inheritance
      • Price Group Criteria
      • Soft Deletion Of Entities
      • Logging
      • OpenTelemetry
    • Extensions
      • Extending Pipelines
        • Order Processing Pipelines
        • Checkout Pipelines
      • Changing Service Behavior
        • Images
        • Content
      • Custom Headless APIs
      • Extend the Backoffice
        • Custom UI Components
      • Custom Editor UI
      • Custom Promotion Criteria
      • Custom Price Group Criteria
    • How-To
      • Migrate from Classic
        • Common database issues
      • Entities from code
        • Bootstrapping data on startup
        • Product Definitions & Fields
      • Discover pipelines and their tasks
      • Executing a pipeline
    • Integrations
      • Umbraco Media Delivery API
      • App Slices
        • Product Picker
  • Release Notes
  • Contact Us
Powered by GitBook
On this page
  • Implementing a Task
  • Adding a Task
  • Use the extension method to register tasks
  • Creating a new checkout pipeline

Was this helpful?

  1. Ucommerce Next Gen
  2. Extensions
  3. Extending Pipelines

Checkout Pipelines

PreviousOrder Processing PipelinesNextChanging Service Behavior

Last updated 1 year ago

Was this helpful?

The Checkout pipeline is the workflow executed when an order is placed and can be extended with custom business logic and integrations. Ucommerce also supports multiple workflows attached to different Payment Methods by creating multiple checkout pipelines as described below.

The way to customize the checkout pipelines differs slightly from regular pipelines. It happens on a dedicated pipeline builder and requires an alias identifier for each pipeline.

Implementing a Task

Tasks are implemented in the same way as other pipelines in Ucommerce by creating a new class that inherits from the interface IPipelineTask<CheckoutInput, CheckoutOutput>. See for details.

public class MyCustomCheckoutTask : IPipelineTask<CheckoutInput, CheckoutOutput>
{
    public CascadeMode CascadeMode { get; } = CascadeMode.Continue;

    public Task Execute(PipelineContext<CheckoutInput, CheckoutOutput> context, CancellationToken cancellationToken)
    {
        // Your custom logic.
    }
}

Adding a Task

Adding a task is done through the PaymentBuilder returned by the AddPayments extension method on IUcommerceBuilder. It is recommended that you create an extension method to add your configuration.

public static class CheckoutPipelineExtensions
{
    public static PaymentBuilder AddMyCheckoutExtensions(this PaymentBuilder builder)
    {
        //These examples all modify the default 'Checkout' pipeline

        //This will insert the task 'MyCustomCheckoutTask' just before 'DefaultAssignOrderNumberPipelineTask'
        builder
            .CheckoutPipelines
            .GetByAlias("Checkout")
            .InsertBefore<MyCustomCheckoutTask>(typeof(DefaultAssignOrderNumberPipelineTask));

        //This will insert the task 'MyCustomCheckoutTask' just after 'DefaultAssignOrderNumberPipelineTask'
        builder
            .CheckoutPipelines
            .GetByAlias("Checkout")
            .InsertAfter<MyCustomCheckoutTask>(typeof(DefaultAssignOrderNumberPipelineTask));

        //This will insert the task 'MyCustomCheckoutTask' as the first task of the pipeline
        builder
            .CheckoutPipelines
            .GetByAlias("Checkout")
            .InsertFirst<MyCustomCheckoutTask>();

        //This will insert the task 'MyCustomCheckoutTask' as the last task of the pipeline
        builder
            .CheckoutPipelines
            .GetByAlias("Checkout")
            .InsertLast<MyCustomCheckoutTask>();

        //This will remove the default task 'DefaultAssignOrderNumberPipelineTask' from the pipeline
        builder
            .CheckoutPipelines
            .GetByAlias("Checkout")
            .Remove<DefaultAssignOrderNumberPipelineTask>();

        return builder;
    }
}

Replace a task by placing your custom task before or after the default task, then remove the default task.

Use the extension method to register tasks

builder.Services.AddUcommerce(builder.Configuration)
    // ... register other Ucommerce components first
    .AddPayments() // We are extending the PaymentBuilder
    .AddMyCheckoutExtensions()
    // ...
    .Build();

Creating a new checkout pipeline

Creating a new pipeline is very similar to modifying an existing one.

public static class CheckoutPipelineExtensions
{
    public static PaymentBuilder AddMyCheckoutExtensions(this PaymentBuilder builder)
    {
        // Create a new checkout pipeline with the default tasks and your custom task
        builder
            .CheckoutPipelines
            .Create("MyCheckout")
            .AddDefaultTasks() // Add the default checkout pipeline tasks
            .InsertLast<MyCustomCheckoutTask>();

        // Create a new pipeline with only your task
        builder
            .CheckoutPipelines
            .Create("MyCheckout")
            .InsertFirst<MyCustomCheckoutTask>();

        return builder;
    }
}
Implementing a Task section on the Extending Pipelines page