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.