Share via


How to Create a Payment Processor

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

A payment processor is a pipeline component that validates and processes a payment. If you incorporate a custom payment method into your Commerce Server 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

  1. 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.

  2. Define a constructor for the class.

  3. 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.

  4. Define the IPipelineComponent::Execute method. Within the Execute method, do the following:

    1. 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.

    2. If the pipeline component might generate errors that will be displayed to the customer, get the MessageManager object.

      messageManager = (IMessageManager)context["MessageManager"];

    3. 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"];

    4. 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.

    5. 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.

  5. 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

Creating a Custom Payment Method

PaymentMethodRouter