Develop a payment provider
This article describes how to develop your own payment provider
This page contains a summary of the tasks to do when developing your own payment provider. The links at the bottom of the page contains more detailed explanations of each step.
Implementing the IPaymentProvider interface
- Create a Visual Studio project and add references to the Litium.Studio, Litium.Foundation and Litium.Owin .dll's.
- Implement the interface Litium.Foundation.Modules.ECommerce.Plugins.Interfaces.IPaymentProvider in class. This class should also inherit from Litium.Foundation.Modules.ECommerce.Plugins.PaymentProviderBase class.
- Add the Plugin(<yourPluginName>) attribute to the above class.
- Implement IPaymentArgsCreator interface in another class and apply the Plugin(<yourPluginName) attribute to it as well. Make sure to check the API documentation of IPaymentProvider interface when implementing.
Working with the payment state machine
It is very important that your implementation sets the correct payment states using the payment state machine. Failing to do so will result in incorrect behaviour. Key points to keep in mind are:
- Before you contact the payment provider for the Authorization call, you need to set the payment status appropriately to either ExecuteReserve or ExecuteCharge depending on whether you use two phase mode or one phase mode. You will set this payment status in the ExecutePayment method of your IPaymentProvider implementation.
- When you get the response back from the payment provider to the OnProviderCallback, depending on the result, set the payment status to Reserved, ReserveFailed, ChargeFailed or Paid.
- For an already reserved transaction, (in the CompletePayment method implementation) before you call the payment provider to charge the account, set the payment status to ExecuteCapture, and when the response is received set it to either CaptureFailed or Paid.
- Check how each method is implemented in default implementation for a better understanding.
Developing the admin panel for the payment provider
The admin panel of the payment provider is displayed in back office, when an order is placed from the back office. One example is Klarna where the customer's social security number is needed to complete the payment. In this case, Klarna's admin panel is shown in back office, if you initiate a Klarna payment there.
The path to the admin panel should be returned in the AdminPanel property of the IPaymentProvider interface implementation.
Usually the locaiton for the admin panel is ~/Site/ECommerce/PaymentProviders/. Take a look at existing admin panels to get an idea of how to program it. An easy option would be to copy one and change to match your payment provier.
PaymentArgsCreator class
You need a class that implements IPaymentArgsCreator interface, and this class should have the Plugins attribute.
The purpose of this class is to convert the CheckoutFlowInfo parameters to ExecutePaymentArgs parameters. Since the payment provider is not aware of the checkout flow and is independent from it, the ExecutePayment method of the IPaymentProvider interface receives this ExecutePaymentArgs, instead of CheckoutFlowInfo.
In case you have specific info to be passed into the payment provider, extend the CheckoutFlowInfo class to provide this information.
Changing Web.config to remove a payment provider
The payment providers are recognised by the IoC implementation of Litium and are automatically loaded. If some payment provider is not desired, you may simply delete its .dll file from the bin directory.
The first step in creating a payment provider plugin is to implement the IPaymentProviderInterface and extend the PaymentProviderBase class. This article explains how to create the skeleton, and subsequent articles explain how to fill in the code.
This article explains how to implement the IPaymentArgsCreator interface, which converts the CheckoutFlowInfo into ExecutePaymentArgs.
This article explains the functions of the IPaymentProvider.ExecutePayment method and contains advice on how to implement it.
This article explains the functionality of the CompletePayment method, which completes a payment in "Reserve" mode, and provides guidelines on how to implementing the method.
This section explains how the AdminPanel of the payment provider is implemented.
This article explains how to do an HTTP post into the payment provider's website checkout flow page during the ExecutePayment step. It also explains the implementation of the IPaymentArgsCreator interface and extending the ExecutePaymentArgs class.
This article explains how to handle the payment provider callback.
When this interface is implemented, it is possible for the payment provider to send asynchronous status updates to Litium.
This article explains how to implement this interface and how to receive status updates from the payment provider.
Different ways of synchronising the payment status between Litium and the payment provider.
How to add links to downloadable PDF invoices in back office.
You can enable and disable the these buttons from the payment provider implementation logic.
When the payment mode "Reserve" is used, a reserved transaction can be cancelled at the payment provider side. This article explains how to implement the cancel operation.
When a payment has been completed, it is possible to refund the money back to the customer, usually if the order is returned. This article explains how to implement it in the payment provider plugin.