How to Create a Payment Processor
A payment processor is a pipeline component that validates and processes a payment. If you incorporate a custom payment method into your Commerce Server Core Systems application, you must create a new payment processor.
Create the pipeline component by following the instructions in the topic How to Build Pipeline Components Using C#. After you create the payment processor, configure a payment method to use the new payment processor. For more information about how to incorporate a custom payment method into your application, see How to Configure a Custom Payment Method.
The following procedure describes how to implement the aspects of a pipeline component that are required for a payment processor.
To create a payment processor
Define a class that implements the IPipelineComponent interface. If the pipeline component will store configuration information, also implement the IPersistDictionary interface. Configuration information is information about the pipeline component itself instead of information that is only needed during a single execution of the pipeline component.
Define a constructor for the class.
Define a method named GetProgID that returns the pipeline component's programmatic identifier (ProgID). The ProgID can be any unique string, although it is usually related to the namespace and class name.
Define the IPipelineComponent::Execute method. Within the Execute method, do the following:
Cast the arguments to the method to the IDictionary interface.
(IDictionary) context = (IDictionary) contextArgument;
(IDictionary) orderForm = (IDictionary) orderFormArgument;
Where contextArgument and orderFormArgument are the arguments that were passed to the Execute method.
If the pipeline component might generate errors that will be displayed to the customer, get the MessageManager object.
messageManager = (IMessageManager)context["MessageManager"];
Obtain the data that you will need in order to process the payment from the order form and the context. In particular, you can get the payments by using the following code:
(IDictionary) payment = (IDictionary)context["payment_to_process"];
Execute whatever business logic is necessary to process the payment.
Note
To determine the names of the keys in the payment dictionary, examine the OrderPipelineMappings.xml file that is located in the virtual root of the Web site. For example, use the code payment["cy_amount"] to get the amount of the payment.
If there are errors that you want to display to the customer, use the MessageManager object that you created in step b to create an error message and add it to the errors that are associated with the purchase.
Object errorMessage = messageManager.GetMessage(errorName, null);
((ISimpleList)orderForm["_Purchase_Errors"]).Add(ref errorMessage);
Where errorName is a string that contains the identifier of the error, and orderFormArgument is the order argument that you cast to the IDictionary interface in step a.
If the payment processor might generate any new errors to display to the customer, add the error messages to MessageManager. For more information about how to customize error messages, see How to Use MessageManager.
See Also
Other Resources
How to Configure a Custom Payment Method