Admin panel
This section explains how the AdminPanel of the payment provider is implemented.
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 admin has to be created even if there is no user interface to show, but in this case will be created for not being visible.
The path to the AdminPanel should be returned in the AdminPanel property of the IPaymentProvider interface implementation.
The locaiton for the admin panel is ~/Site/ECommerce/PaymentProviders/.
To mark the user control as an admin panel, it has to implement the IPaymentProviderPanel interface. In this example we create TestPaymentsProviderDialog.ascx in the ~/Site/ECommerce/PaymentProviders/ folder.
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TestPaymentsProviderDialog.ascx.cs" Inherits="Litium.Studio.AddOns.Samples.TestPaymentsProvider.TestPaymentsProviderDialog" %>
The following is the code behind file, with the IPaymentProviderPanel implementation. Note that the custom implementation classes, such as CompleteArgs, used in the following code is explained in other articles in this section.
using System;
using Litium.Foundation.Modules.ECommerce.Plugins.Payments;
using Litium.Studio.UI.ECommerce.Common.Constants;
using Litium.Studio.UI.ECommerce.Common;
using Litium.Studio.UI.ECommerce;
namespace Litium.Studio.AddOns.Samples.TestPaymentsProvider
{
public partial class TestPaymentsProviderDialog : UserBaseControl, IPaymentProviderPanel
{
protected override void Page_Load(object sender, EventArgs e)
{
base.Page_Load(sender, e);
}
#region IPaymentProviderPanel Members
/// <summary>
/// Executes the charge operation.
/// </summary>
/// <param name="paymentInfo">The payment info.</param>
public void ExecuteCharge(Litium.Foundation.Modules.ECommerce.Payments.PaymentInfo paymentInfo)
{
bool isRedirected = false;
try
{
// If the order is already reserved, CanCompleteTransaction will be true.
// Call complete transaction on the already reserved order, else call direct charge customer account.
if (paymentInfo.PaymentProvider.CanCompleteCurrentTransaction)
paymentInfo.PaymentProvider.CompletePayment(new CompleteArgs(), FoundationContext.Token);
else
{
var args = new PaymentArgs();
args.PaymentMode = ExecutePaymentMode.Charge;
args.UserHostAddress = Request.UserHostAddress;
paymentInfo.PaymentProvider.ExecutePayment(args, FoundationContext.Token);
}
}
catch (PaymentProviderException) { }
if (!isRedirected)
{
Response.Redirect(UrlConstants.VIEW_PAYMENT + "?" + ParameterConstants.ECOM_SELECTED_NAVBAR_PAGE + "="
+ ((int)Litium.Studio.UI.ECommerce.Common.Enums.FilterType.Payments).ToString() + "&"
+ ParameterConstants.FROM_PAYMENT + "=true&"
+ ParameterConstants.ECOM_ORDER_ID + "=" + paymentInfo.OrderID + "&"
+ ParameterConstants.ECOM_PAYMENT_INFO_ID + "=" + paymentInfo.ID + "&"
+ ParameterConstants.QUERY_STRING_NAVIGATE_FROM + "=2");
}
}
/// <summary>
/// Executes the reserve operation.
/// </summary>
/// <param name="paymentInfo">The payment info.</param>
public void ExecuteReserve(Litium.Foundation.Modules.ECommerce.Payments.PaymentInfo paymentInfo)
{
bool isRedirected = false;
try
{
var args = new PaymentArgs();
args.PaymentMode = ExecutePaymentMode.Reserve;
args.UserHostAddress = Request.UserHostAddress;
paymentInfo.PaymentProvider.ExecutePayment(args, FoundationContext.Token);
}
catch (PaymentProviderException) { }
if (!isRedirected)
{
Response.Redirect(UrlConstants.VIEW_PAYMENT + "?" + ParameterConstants.ECOM_SELECTED_NAVBAR_PAGE + "="
+ ((int)Litium.Studio.UI.ECommerce.Common.Enums.FilterType.Payments).ToString() + "&"
+ ParameterConstants.FROM_PAYMENT + "=true&"
+ ParameterConstants.ECOM_ORDER_ID + "=" + paymentInfo.OrderID + "&"
+ ParameterConstants.ECOM_PAYMENT_INFO_ID + "=" + paymentInfo.ID + "&"
+ ParameterConstants.QUERY_STRING_NAVIGATE_FROM + "=2");
}
}
#endregion
}
}
When the Reserve and Charge buttons are clicked in the Payment view in back office, the ExecuteCharge and ExecuteReserve methods of the admin panel are called.
