How toGeneral

General

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:
  • 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(PaymentContext entity, IDictionary<string, object>
      properties)
{
}
 
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.
 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.
  • 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;
 
namespace Sana.Commerce.Payment.Pipeline
{
    /// <summary>
    /// This step sets the order status of an order to closed.
    /// </summary>
    public class PayOrderStep : IPaymentStep
    {
     public void Execute(PaymentContext entity, IDictionary<string,
     object> properties)
     {
        // 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;
 
        PaymentLog.Current.Add(entity.Order, string.Format("PayOrderStep
        the status of the order {0} was set to closed."
,   
        entity.Order.OrderId), false);
        }
    }
}
How toGeneral