Payment gateways in Optimizely Commerce provide an interface to the payment processing system. A payment type is passed to the payment gateway, which executes the payment transaction with the payment system. One payment type is associated with each payment gateway.
When creating and configuring payment methods, you have these implementation options described below:
- Create multiple instances of the same gateway with a different configuration.
- Create a custom payment gateway.
Classes in this topic are available in the Mediachase.Commerce.Orders namespace, which contains IPaymentGateway and Payment types.
To use the various options, configure the following gateway properties:
- Id. The system-assigned unique identifier of the payment gateway.
- Name. The name to be displayed to the user.
- Description. A description to be displayed to the user.
- System Keyword. The unique name for each instance of the gateway; new, non-unique keywords will not save to the database. This is not editable after a gateway is initially created.
- Language. A language for the payment gateway.
- Class Name. Name of the gateway class to be associated with the payment.
Create a custom payment method
- Before creating a new payment method in commerce admin, create a class implementing IPaymentMethod interface.
- Set a unique SystemKeyword value.
- This class will be representation of your custom payment method.
- Create a separate project in the solution to store custom business logic implementations for your application, if this has not been done already.
- Create a class in this project that inherits from the abstract class AbstractPaymentGateway. This base class has only has one property, Settings, and one method, ProcessPayment().
- The Settings property is a dictionary type that allows other gateway information to be stored. For example, web service authentication details for connecting to the payment provider, or an indicator whether the payment provider call is for authorization or payment processing.
- ProcessPayment is the method used to contact the payment processing system and process payments.
Example: Signature for the ProcessPayment method.
bool ProcessPayment(Payment payment, ref string message);
Provide implementation for the ProcessPayment method to execute the payment transaction you need.
- Include a reference reference of payment gateway project in your website project.
- In Commerce Admin, go to the Administration tab and Payments.
- Click Create.
- Enter the value for System Keyword the same as in your corresponding payment method class.
- See the gateway properties description above for information about the fields on the first tab.
- Select the new gateway from the drop-down list.
- If you intend to start using the payment method, set IsActive to Yes.
- When all information is added to the first tab, click OK.
- Re-open the payment method from the payment method list.
- Go to the second tab and set configuration information required for this implementation of the gateway.
- Click OK.
Note: These directions do not explain how to display this information on the website. For custom gateways, implement your own method for displaying and saving payment information for this gateway. The simplest tool for retrieving payment information is the PaymentMethodDto class. You can also make use of PaymentManager helper class to retrieve payment methods from system based on language.
Adding payment types
If you need a payment type that does not correspond to one of the built-in payment types, you can extend the built-in OtherPayment payment type with whatever meta fields you need.
Last updated: Sep 28, 2021