• Getting Started
    • Prerequisites
    • Download and Installation
    • Change Log
  • Developer Guide
    • EvenCart Plugins
      • Development Environment Setup
      • Plugin Structure
      • EvenCart MVC
      • Dependency Injection
      • Domain Entities
      • Database Versions
      • Plugin Settings
      • Data Provider Plugin
      • Payment Processing Plugin
      • Shipping Provider Plugin
      • Authentication Provider
      • Widget Plugin
    • EvenCart API
      • Authentication
      • Requests & Responses
      • API EndPoints
    • Caching
  • Designer Guide
    • How to create a theme
    • Extended Tags
      • Layout Tag
      • Widget Tag
      • Json Tag
      • Css Tag
      • Js Tag
      • Bundle Tag
      • Partial Tag
      • Control Tag
      • Route Tag
      • Global Tag
      • Component Tag
    • Extended Filters
    • Global Objects
  • Packaging & Distribution

Creating a payment processor plugin

Payment plugins provide store customers with option to pay through a particular payment processor. The following document explains the process to create a new payment processor plugin.

Creating the plugin class

A payment plugin is any class that implements EvenCart.Services.Plugins.IPaymentHandlerPlugin interface. The interface has following properties and methods that the plugin class requires to implement.

Name Description
PaymentMethodType PaymentMethodType { get; }
Property
The type of payment method. The enum PaymentMethodType holds one of the following values.
CreditCard - Specifies that payment method is a credit card processor.
DebitCard - Specifies that payment method is a debit card processor.
InternetBanking - Specifies that payment method processes payment using Internet banking provided by banks.
Bitcoin - Specifies that payment method processes Bitcoins.
GiftCard - Specifies that payment method processes GiftCards.
EWallet - Specifies that payment processor provides EWallet for processing payments.
string PaymentHandlerComponentRouteName { get; }
Property
The name of the component that is rendered to display the payment form to end customer.
PaymentOperation[] SupportedOperations { get; }
Property
The payment operations that the payment method supports. The enum PaymentOperation can have one of the following values.
Authorize - Specifies Authorize operation as supported by some payment processors.
Capture - Specifies Capture operation as supported by some payment processors.
Refund - Specifies Refund operation as supported by some payment processors.
Void - Specifies Void operation as supported by some payment processors.
decimal GetPaymentHandlerFee(Cart cart);
Method
Returns payment handler processing fee for the provided Cart object.
decimal GetPaymentHandlerFee(Order order);
Method
Returns the payment handler processing fee for the provider Order object.
bool ValidatePaymentInfo(Dictionary<string, string> parameters, out string error);
Method
Validates the payment information provided as Dictionary. This includes the parameters submitted through the checkout page.
Returns true if payment information is valid or false otherwise.
If payment information is found to be invalid, appropriate error must be set in the out error parameter. The error is displayed to the user on payment page. It should be set to null if the information is ok.
TransactionResult ProcessTransaction(TransactionRequest request);
Method
Processes a TransactionRequest and returns a TransactionResult object.

TransactionRequest Object

A transaction request object contains information about the transaction to be done with the use of payment processor. The following properties can be used to get the relevant information.

Name Description
Order An object of type Order that stores information about the order.
TransactionGuid A unique identifier of type string for the transaction
Parameters A dictionary type Dictionary<string, object>of parameters submitted during checkout process.
IsPartialRefund A bool specifying if the transaction is a partial refund request.

TransactionResult Object

The ProcessTransaction method must return a TransactionResult object which stores information about the transaction result. A result object has the following properties and method.

Name Description
bool Success
Property
Specifies if the operation succeeded or failed.
string TransactionGuid
Property
A universally unique identifier for the transaction.
string OrderGuid
Property
The unique order identifier
PaymentStatus NewStatus
Property
The PaymentStatus after the transaction is processed. It can have one of the following values.
OnHold - Specifies that payment is on hold and is yet to be confirmed.
Pending - Specifies that payment is pending.
Processing - Specifies that payment is in process.
Complete - Specifies that payment is complete.
Refunded - Specifies that payment has been refunded.
Voided - Specifies that payment has been voided.
Authorized - Specifies that payment has been authorized but not captured.
Captured - Specifies that payment has been captured.
RefundPending - Specifies that payment refund is pending.
Dictionary<string, object> ResponseParameters
Property
A dictionary object that contains various parameters related to the transaction. It may include transaction ids, authorization and capture ids and any other relevant information about the transaction.
decimal TransactionAmount
Property
The amount processed in the transaction.
string TransactionCurrencyCode
Property
The ISO currency code used for processing the transaction.
Exception Exception
Property
If the transaction resulted in any exception, the Exception object can be populated to log the exception.
TransactionResult Redirect(string url)
Method
If the payment method requires redirection to the payment processor's website, this method should be called. A string parameter for the URL to redirect is passed as parameter.
Returns the transaction result object on which the method was called.

Plugin Class Example

A sample payment class after implementation looks as follows.

using System;
using System.Collections.Generic;
using System.Linq;
using EvenCart.Core.Plugins;
using EvenCart.Data.Entity.Payments;
using EvenCart.Data.Entity.Purchases;
using EvenCart.Services.Payments;
using EvenCart.Services.Plugins;
using EvenCart.Infrastructure;

namespace Payments.MyPaymentPlugin
{
    public class MyPaymentPlugin : FoundationPlugin, IPaymentHandlerPlugin
    {
        private readonly MyPaymentSettings _paymentSettings;
        public MyPaymentPlugin(MyPaymentSettings paymentSettings)
        {
            _paymentSettings = paymentSettings;
        }

        public PaymentMethodType PaymentMethodType => PaymentMethodType.CreditCard;

        public string PaymentHandlerComponentRouteName => "MyPaymentComponent";

        public PaymentOperation[] SupportedOperations => new[]
            {PaymentOperation.Authorize, PaymentOperation.Capture, PaymentOperation.Refund, PaymentOperation.Void};

        public TransactionResult ProcessTransaction(TransactionRequest request)
        {
            var order = request.Order;
            /* do some processing here */
            var transactionResult = new TransactionResult(){
                Success = true,

            }
            return transactionResult;
        }

        public decimal GetPaymentHandlerFee(Cart cart)
        {
            //if required, you can inspect CartItems property of cart to 
            //add any additional fee based on their products
            return 0;
        }

        public decimal GetPaymentHandlerFee(Order order)
        {
            //if required, you can inspect OrderItems property of cart to 
            //add any additional fee based on their products
            return 0;
        }

        public bool ValidatePaymentInfo(Dictionary<string, string> parameters, out string error)
        {
            error = null;
            var cardNumber = parameters["CardNumber"];
            ...
            //validate card number and other info.
            return true;
        }

        public override string ConfigurationUrl => ApplicationEngine.RouteUrl("MyPaymentConfiguration");

    }
}
ON THIS PAGE
  • Creating the plugin class
  • TransactionRequest Object
  • TransactionResult Object
  • Plugin Class Example

Related Pages

  • Creating a data access plugin
  • Creating a shipping provider
  • Creating an authentication provider plugin
  • Creating a widget plugin
© 2022 Sojatia Infocrafts Pvt. Ltd. All rights reserved. Powered by onlyDoc.