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.
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.
publicstaticclassCheckoutPipelineExtensions{publicstaticPaymentBuilderAddMyCheckoutExtensions(thisPaymentBuilder 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.
publicstaticclassCheckoutPipelineExtensions{publicstaticPaymentBuilderAddMyCheckoutExtensions(thisPaymentBuilder 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; }}