Checkout Pipelines

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 Implementing a Task section on the Extending Pipelines page 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

Creating a new checkout pipeline

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

Last updated

Was this helpful?