How to

Sana Commerce 8.1
Your provider

Create a Custom Payment Pipeline Step

If the custom payment module needs to execute custom steps then it is possible to create a custom pipeline step. This is done in the following way:

Step 1: Create a new class that inherits from 'IPaymentStep' and implement the 'Execute' method. This class will be our new payment step.

The method will look something like:
public void Execute(IOrderContext entity, IDictionary<string, object>
The first parameter is the payment context. This context contains all objects that are commonly used in any payment step. It includes the following objects:

Object Description
Order The order object that is been paid in the payment module.
ShippingAddressId The shipping address id.

Properties of payment context
Object Description
Configuration Configuration settings for the payment module calling the pipeline step.
Request The 'HttpRequest' object of the page calling the pipeline.
Pipelines All custom pipelines defined in the payment module.
PaymentModule A reference to the external payment module calling the pipeline.
All these context objects can be used in the payment step; any changes to objects in the context will also be persistent to the rest of the pipeline. Any changes made to an order in any pipeline step will be saved automatically unless this is specifically disabled at the creation of the pipeline.
The second parameter called 'properties' is a dictionary of custom objects that will to be passed to each parameter step. By default this collection is empty, but this collection can be used when implementing custom functionality and a custom object needs to be shared in the pipeline. You can fill this parameter the moment the pipeline is called by customizing this part in a customer payment module.

Step 2: In the execute method add custom code that implements the step. The step can be used in any payment pipeline now!

Below you can find an example of a complete payment step:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sana.Utilities.Validation;
/// <summary>
    /// This steps sets the order status of an order to closed.
    /// </summary>
    public class PayOrderStep : IPaymentStep
        /// <summary>
        /// Set the order status of an order to closed.
        /// </summary>
        /// <param name="entity">The strongly typed objects that should be passed to the step.</param>
        /// <param name="properties">A collection of objects that can be extended in any way.</param>
        public void Execute(IOrderContext entity, IDictionary<string, object> properties)
            //For now we only set the order status to closed...
            Guard.ThrowIfNull(entity, "entity", "PaymentContext cannot be null.");
            Guard.ThrowIfNull(entity.Order, "entity.Order", "Order in the PaymentContext cannot be null for the PayOrderStep.");
            entity.Order.PaymentStatus = PaymentStatus.Paid;
            //Note Order will be saved by the pipeline so we will not have to do it here.
            PaymentLog.Current.Add(entity.Order, string.Format("PayOrderStep - the status of the order {0} was set to closed.", entity.Order.OrderId), false);