' SummaryPage2_BankingInterfaceSummary_Ezidebit
Option Explicit On
Option Strict On

' #################################################################
' Ezidebit Banking Interface Summary Page Script
'
' Version: 1.01 (22/07/2025)
'
' Usage: Various forms
' #################################################################
' Version        Date  User     Job       Description
' -------  ----------  -------  --------  -------------------------
'    1.00  30/01/2025  ISS      J025068   Created
'    1.01  22/07/2025  ISS      J035812   Updated eDDR shortcuts for Cloud integration
' #################################################################

'#Const "ShowEddrLink",Boolean,False,"Show eDDR Link?"

' Constants
Private ShowEddrLink As Boolean = False

' Special Constants
Const TestMode As Boolean = False

' Properties
Private ServiceLogs As ISServiceLogs

Public Function Main(source As Object,
                     eventId As String,
                     eventArgs As ISKeyValueList,
                     ByRef handled As Boolean,
                     ByRef returnValues As ISKeyValueList,
                     ByRef text As String) As Boolean

  Dim Response As ISBankInterfaceResponse

  ' Assume Success
  Main = True

  ' Get Constants
  With ScriptInfo.Constants
    ShowEddrLink = .GetBoolean("ShowEddrLink", ShowEddrLink)
  End With

  ' Get Service Logs
  Try
    Main = finBL.BankingInterface.GetServiceLogs(CInt(source), ServiceLogs)
  Catch ex As Exception
    Main = False
    finBL.Error.ErrorBeginFromException(ex)
  End Try
  If Main Then
    If ServiceLogs.Count = 0 Then
      Main = False
      finBL.Error.ErrorBegin("Invalid Service Log for the Banking Interface.")
    ElseIf ServiceLogs(0).RequestStatus <> iseAuditLogStatus.Success Then
      Main = False
      finBL.Error.ErrorBegin("Invalid Service Log. Initial Request was not successful.")
    Else
      Response = DirectCast(ServiceLogs(0).ExResponse, ISBankInterfaceResponse)
    End If
  End If

  ' Handle Events
  If Main Then
    Select Case eventId
      Case ""
        ' Main event, i.e., return main page content
        Main = Me.CreatePage(Response, text)
    End Select
  End If

End Function

Private Function CreatePage(response As ISBankInterfaceResponse,
                            ByRef html As String) As Boolean

  Dim HtmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Initialise ByRef
  html = ""

  ' Initialise
  HtmlSummaryPage2StringBuilder = finBL.CreateHtmlSummaryPage2StringBuilder()

  ' Initialise HTML
  With HtmlSummaryPage2StringBuilder
    ' Display test watermark
    If serviceLogs(0).TestMode Then .Watermark = "Test Mode"

    ' Note: Embed images (will also embed CSS) since we want to be able to easily produce a PDF document
    .Initialise(ScriptInfo, False, True)

    ' Begin HTML Header
    .HtmlHeaderBegin(String.Format("{0} {1}", response.ServiceName, response.ProductId), isefinSummaryPageStyle.ServiceReport)

    ' Theme
    .HtmlHeaderInsertServiceReportTheme("#6BB245", "#F0F0F0", "", "#F2F2F2")

    ' Intersoft PDF Options (including style tweaks)
    .HtmlHeaderInsertPdfGenerationHints("A4", "Portrait", 880, "1.5cm", "1.5cm", "1cm", "1cm", "font-size:0.9em")

    ' Finalise HTML Header
    .HtmlHeaderEnd()
  End With

  ' Body
  Select Case response.GetType()
    Case GetType(ISBankInterfaceResponse_Ezidebit_AddCustomer)
      Me.CreatePage_AddCustomer(DirectCast(response, ISBankInterfaceResponse_Ezidebit_AddCustomer), HtmlSummaryPage2StringBuilder)
    Case GetType(ISBankInterfaceResponse_Ezidebit_AddCustomerEddr)
      Me.CreatePage_AddCustomerEddr(DirectCast(response, ISBankInterfaceResponse_Ezidebit_AddCustomerEddr), HtmlSummaryPage2StringBuilder)
    Case GetType(ISBankInterfaceResponse_Ezidebit_AddPayment)
      Me.CreatePage_AddPayment(DirectCast(response, ISBankInterfaceResponse_Ezidebit_AddPayment), HtmlSummaryPage2StringBuilder)
    Case GetType(ISBankInterfaceResponse_Ezidebit_ChangeCustomerStatus)
      Me.CreatePage_ChangeCustomerStatus(DirectCast(response, ISBankInterfaceResponse_Ezidebit_ChangeCustomerStatus), HtmlSummaryPage2StringBuilder)
    Case GetType(ISBankInterfaceResponse_Ezidebit_ProcessRealtimeTokenPayment)
      Me.CreatePage_ProcessRealtimeTokenPayment(DirectCast(response, ISBankInterfaceResponse_Ezidebit_ProcessRealtimeTokenPayment), HtmlSummaryPage2StringBuilder)
    Case GetType(ISBankInterfaceResponse_Ezidebit_GetCustomers)
      Me.CreatePage_GetCustomers(DirectCast(response, ISBankInterfaceResponse_Ezidebit_GetCustomers), HtmlSummaryPage2StringBuilder)
    Case GetType(ISBankInterfaceResponse_Ezidebit_UpdateCustomerBankAccount)
      Me.CreatePage_UpdateCustomerBankAccount(DirectCast(response, ISBankInterfaceResponse_Ezidebit_UpdateCustomerBankAccount), HtmlSummaryPage2StringBuilder)
    Case GetType(ISBankInterfaceResponse_Ezidebit_UpdateCustomerCreditCard)
      Me.CreatePage_UpdateCustomerCreditCard(DirectCast(response, ISBankInterfaceResponse_Ezidebit_UpdateCustomerCreditCard), HtmlSummaryPage2StringBuilder)
    Case Else
      Success = False
      finBL.Error.ErrorBeginFormat("Unexpected Response Type '{0}'.", TypeName(response))
  End Select

  ' Disclaimer
  HtmlSummaryPage2StringBuilder.AppendLine("<hr>")
  HtmlSummaryPage2StringBuilder.AppendLine("{{disclaimer|finPOWER Connect version " & finBL.VersionMajorMinorBuild & " using " & response.ServiceName & " service.}}")

  ' Finalise HTML
  HtmlSummaryPage2StringBuilder.HtmlFinalise()

  ' Resolve Templates
  html = HtmlSummaryPage2StringBuilder.ToString(True)

  Return Success

End Function

Private Sub CreatePage_AddCustomer(response As ISBankInterfaceResponse_Ezidebit_AddCustomer,
                                   htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  Dim ServiceLogSourceObjects As finServiceLogSourceObjects

  ' Get Requested Account or Client from Service Log
  ServiceLogSourceObjects = finBL.CreateServiceLogSourceObjects()
  ServiceLogSourceObjects.Load(ServiceLogs(0))

  With HtmlSummaryPage2StringBuilder
    .AppendH1(String.Format("Add Customer '{0}'", response.Request_AddCustomer.Name))
    .AppendH2(String.Format("{0} - {1}", response.ProductId, response.ServiceName))

    .SummaryTablesAppend(Me.Ezidebit_AddCustomer_Details(response, ServiceLogSourceObjects))
 End With

End Sub

Private Sub CreatePage_AddCustomerEddr(response As ISBankInterfaceResponse_Ezidebit_AddCustomerEddr,
                                       htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  Dim ServiceLogSourceObjects As finServiceLogSourceObjects

  ' Get Requested Account or Client from Service Log
  ServiceLogSourceObjects = finBL.CreateServiceLogSourceObjects()
  ServiceLogSourceObjects.Load(ServiceLogs(0))

  With HtmlSummaryPage2StringBuilder
    .AppendH1(response.Request_AddCustomerEddr.Name)
    .AppendH2(String.Format("{0} Electronic Direct Debit Request (eDDR) form", response.ServiceName))

    .SummaryTablesAppend(Me.Ezidebit_AddCustomerEddr_Details(response, ServiceLogSourceObjects))
    .SummaryTablesAppend(Me.Ezidebit_HistoryClientLogs())
    .SummaryTablesAppend(Me.Ezidebit_History())
 End With

End Sub

Private Sub CreatePage_AddPayment(response As ISBankInterfaceResponse_Ezidebit_AddPayment,
                                  htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  Dim BankTransactionView As finBankTransactionView

  ' Load Bank Transaction
  If serviceLogs(0).SourceType = "BankTransaction" Then
    BankTransactionView = finBL.CreateBankTransactionView
    If Not BankTransactionView.LoadFromBankTransactionPk(serviceLogs(0).SourcePk) Then
      BankTransactionView = Nothing
    End If
  End If

  With HtmlSummaryPage2StringBuilder
    If BankTransactionView Is Nothing Then
      .AppendH1(String.Format("Payment '{0}'", response.Request_AddPayment.PaymentReference))
    Else
      .AppendH1(String.Format("Payment for Account {0}, {1}", BankTransactionView.AccountTransactions(0).AccountId, BankTransactionView.AccountTransactions(0).AccountName))
    End If
    .AppendH2(String.Format("{0} - {1}", response.ProductId, response.ServiceName))

    .SummaryTablesAppend(Me.Ezidebit_AddPayment_Details(response, BankTransactionView))
    .SummaryTablesAppend(Me.Ezidebit_History())
 End With

End Sub

Private Sub CreatePage_ChangeCustomerStatus(response As ISBankInterfaceResponse_Ezidebit_ChangeCustomerStatus,
                                            htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  Dim ServiceLogSourceObjects As finServiceLogSourceObjects

  ' Get Requested Account or Client from Service Log
  ServiceLogSourceObjects = finBL.CreateServiceLogSourceObjects()
  ServiceLogSourceObjects.Load(ServiceLogs(0))

  With HtmlSummaryPage2StringBuilder
    If serviceLogSourceObjects.Account IsNot Nothing Then
      .AppendH1(serviceLogSourceObjects.Account.Name)
    ElseIf serviceLogSourceObjects.Client IsNot Nothing Then
      .AppendH1(serviceLogSourceObjects.Client.Name)
    Else
      .AppendH1(response.Request_ChangeCustomerStatus.EzidebitCustomerId)
    End If
    .AppendH2(String.Format("{0} - {1}", response.ProductId, response.ServiceName))

    .SummaryTablesAppend(Me.Ezidebit_ChangeCustomerStatus_Request(response, ServiceLogSourceObjects))
 End With

End Sub

Private Sub CreatePage_GetCustomers(response As ISBankInterfaceResponse_Ezidebit_GetCustomers,
                                    htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  Dim ServiceLogSourceObjects As finServiceLogSourceObjects

  ' Get Requested Account or Client from Service Log
  ServiceLogSourceObjects = finBL.CreateServiceLogSourceObjects()
  ServiceLogSourceObjects.Load(ServiceLogs(0))

  With HtmlSummaryPage2StringBuilder
    Select Case response.Customers.Count
      Case 0
       .AppendH1("Customer not found")
      Case 1
       .AppendH1(response.Customers(0).Name)
      Case 2
       .AppendH1(String.Format("{0} plus 1 other", response.Customers(0).Name))
      Case Else
       .AppendH1(String.Format("{0} plus {1} others", response.Customers(0).Name, response.Customers.Count - 1))
    End Select
    .AppendH2(String.Format("{0} - {1}", response.ProductId, response.ServiceName))

    .SummaryTablesAppend(Me.Ezidebit_GetCustomers_Request(response, ServiceLogSourceObjects))
    .SummaryTablesAppend(Me.Ezidebit_GetCustomers_List(response, ServiceLogSourceObjects))
 End With

End Sub

Private Sub CreatePage_ProcessRealtimeTokenPayment(response As ISBankInterfaceResponse_Ezidebit_ProcessRealtimeTokenPayment,
                                                   htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  Dim BankTransactionView As finBankTransactionView

  ' Load Bank Transaction
  If serviceLogs(0).SourceType = "BankTransaction" Then
    BankTransactionView = finBL.CreateBankTransactionView
    If Not BankTransactionView.LoadFromBankTransactionPk(serviceLogs(0).SourcePk) Then
      BankTransactionView = Nothing
    End If
  End If

  With HtmlSummaryPage2StringBuilder
    If BankTransactionView Is Nothing Then
      .AppendH1(String.Format("Payment '{0}'", response.Request_ProcessRealtimeTokenPayment.PaymentReference))
    Else
      .AppendH1(String.Format("Payment for Account {0}, {1}", BankTransactionView.AccountTransactions(0).AccountId, BankTransactionView.AccountTransactions(0).AccountName))
    End If
    .AppendH2(String.Format("{0} - {1}", response.ProductId, response.ServiceName))

    .SummaryTablesAppend(Me.Ezidebit_ProcessRealtimeTokenPayment_Details(response, BankTransactionView))
 End With

End Sub

Private Sub CreatePage_UpdateCustomerBankAccount(response As ISBankInterfaceResponse_Ezidebit_UpdateCustomerBankAccount,
                                                 htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  Dim ServiceLogSourceObjects As finServiceLogSourceObjects

  ' Get Requested Account or Client from Service Log
  ServiceLogSourceObjects = finBL.CreateServiceLogSourceObjects()
  ServiceLogSourceObjects.Load(ServiceLogs(0))

  With HtmlSummaryPage2StringBuilder
    .AppendH1(String.Format("Update Customer '{0}' Bank Account", response.Request_UpdateCustomerBankAccount.EzidebitCustomerId))
    .AppendH2(String.Format("{0} - {1}", response.ProductId, response.ServiceName))

    .SummaryTablesAppend(Me.Ezidebit_UpdateCustomerBankAccount_Request(response, ServiceLogSourceObjects))
    .SummaryTablesAppend(Me.Ezidebit_UpdateCustomerBankAccount_BankAccount(Response))
  End With

End Sub

Private Sub CreatePage_UpdateCustomerCreditCard(response As ISBankInterfaceResponse_Ezidebit_UpdateCustomerCreditCard,
                                                htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  Dim ServiceLogSourceObjects As finServiceLogSourceObjects

  ' Get Requested Account or Client from Service Log
  ServiceLogSourceObjects = finBL.CreateServiceLogSourceObjects()
  ServiceLogSourceObjects.Load(ServiceLogs(0))

  With HtmlSummaryPage2StringBuilder
    .AppendH1(String.Format("Update Customer '{0}' Credit Card", response.Request_UpdateCustomerCreditCard.EzidebitCustomerId))
    .AppendH2(String.Format("{0} - {1}", response.ProductId, response.ServiceName))

    .SummaryTablesAppend(Me.Ezidebit_UpdateCustomerCreditCard_Request(response, ServiceLogSourceObjects))
    .SummaryTablesAppend(Me.Ezidebit_UpdateCustomerCreditCard_CreditCard(response))
 End With

End Sub

Private Function Ezidebit_AddCustomer_Details(response As ISBankInterfaceResponse_Ezidebit_AddCustomer,
                                              serviceLogSourceObjects As finServiceLogSourceObjects) As ISSummaryTables

  Dim BankAccount As finBankAccountRO
  Dim ResponseUpdateCustomerBankAccount As ISBankInterfaceResponse_Ezidebit_UpdateCustomerBankAccount
  Dim ResponseUpdateCustomerCreditCard As ISBankInterfaceResponse_Ezidebit_UpdateCustomerCreditCard
  Dim ServiceLog As ISServiceLog
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Get Bank Account
  If finBL.BankAccounts.ExistsPk(response.Request_AddCustomer.BankAccountPk) Then
    BankAccount = finBL.BankAccounts.ItemByPk(response.Request_AddCustomer.BankAccountPk)
  Else
    BankAccount = Nothing
  End If

  ' Find Update Bank Account/ Credit Card details
  For Each ServiceLog In ServiceLogs
    Select Case ServiceLog.ExResponse.GetType()
      Case GetType(ISBankInterfaceResponse_Ezidebit_UpdateCustomerBankAccount)
        ResponseUpdateCustomerBankAccount = DirectCast(ServiceLog.ExResponse, ISBankInterfaceResponse_Ezidebit_UpdateCustomerBankAccount)
      Case GetType(ISBankInterfaceResponse_Ezidebit_UpdateCustomerCreditCard)
        ResponseUpdateCustomerCreditCard = DirectCast(ServiceLog.ExResponse, ISBankInterfaceResponse_Ezidebit_UpdateCustomerCreditCard)
    End Select
  Next

  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Request", 2, , , TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Date:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
    If BankAccount IsNot Nothing Then .AddRowCaptionCodeDescription("Bank Account:", BankAccount.Pk, finBL.BankAccounts, False)
    If serviceLogSourceObjects.Account IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Account:", serviceLogSourceObjects.Account.AccountId, serviceLogSourceObjects.Account.Name)
        .Cells(1).HyperlinkSetFormShow("Accounts", serviceLogSourceObjects.Account.AccountId, "Payments")
      End With
    ElseIf serviceLogSourceObjects.Client IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Client:", serviceLogSourceObjects.Client.ClientId, serviceLogSourceObjects.Client.Name)
        .Cells(1).HyperlinkSetFormShow("Clients", serviceLogSourceObjects.Client.ClientId, "Tax & Banking")
      End With
    End If
    If Len(response.Request_AddCustomer.BusinessName) = 0 Then
      .AddRowCaptionText("First Name:", response.Request_AddCustomer.FirstName)
      .AddRowCaptionText("Last Name:", response.Request_AddCustomer.LastName)
    Else
      .AddRowCaptionText("Business Name:", response.Request_AddCustomer.BusinessName)
    End If
    .AddRowCaptionTextEmailAddress("Email:", response.Request_AddCustomer.EmailAddress, False)
    .AddRowCaptionTextPhoneNumber("Mobile:", response.Request_AddCustomer.MobilePhoneNumber, False)
    .AddRowCaptionDate("Started:", response.Request_AddCustomer.ContractStartDate)
  End With
  SummaryTables.Add("Request", SummaryTable)

  ' Bank Account/ Credit Card details
  If ResponseUpdateCustomerBankAccount IsNot Nothing Then
    SummaryTables.AppendSummaryTables(Me.Ezidebit_UpdateCustomerBankAccount_BankAccount(ResponseUpdateCustomerBankAccount))
  End If
  If ResponseUpdateCustomerCreditCard IsNot Nothing Then
    SummaryTables.AppendSummaryTables(Me.Ezidebit_UpdateCustomerCreditCard_CreditCard(ResponseUpdateCustomerCreditCard))
  End If

  ' Ezidebit Customer
  SummaryTable = SummaryTables.CreateSummaryTableInformation("Ezidebit Customer", "Customer", 2, , , TestMode)
  With SummaryTable
    .AddRowCaptionText("Customer ID:", response.EzidebitCustomerId)
  End With
  SummaryTables.Add("Customer", SummaryTable)

  Return SummaryTables

End Function

Private Function Ezidebit_AddCustomerEddr_Details(response As ISBankInterfaceResponse_Ezidebit_AddCustomerEddr,
                                                  serviceLogSourceObjects As finServiceLogSourceObjects) As ISSummaryTables

  Dim ApplicationShortCut As ISApplicationShortcut
  Dim Customer As ISBankInterfaceResponse_Ezidebit_Customer
  Dim DocumentId As String
  Dim PaymentMethod As finPaymentMethodRO
  Dim ServiceLog As ISServiceLog
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Get Payment Method
  If finBL.PaymentMethods.Exists(response.Request_AddCustomerEddr.PaymentMethodId) Then
    PaymentMethod = finBL.PaymentMethods(response.Request_AddCustomerEddr.PaymentMethodId)
  Else
    PaymentMethod = Nothing
  End If
  
  ' Find Update Bank Account/ Credit Card details
  For Each ServiceLog In ServiceLogs
    If ServiceLog.ExResponse IsNot Nothing Then
      Select Case ServiceLog.ExResponse.GetType()
        Case GetType(ISBankInterfaceResponse_Ezidebit_GetCustomers)
          With DirectCast(ServiceLog.ExResponse, ISBankInterfaceResponse_Ezidebit_GetCustomers)
            If .Customers.Count = 1 Then Customer = .Customers(0)
          End With
      End Select
    End If
  Next
  
  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Request", 2, , , TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Date:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
    .AddRowCaptionText("Reference:", response.Request_AddCustomerEddr.YourSystemReference)
    If serviceLogSourceObjects.Client IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Client:", serviceLogSourceObjects.Client.ClientId, serviceLogSourceObjects.Client.Name)
        .Cells(1).HyperlinkSetFormShow("Clients", serviceLogSourceObjects.Client.ClientId, "Tax & Banking")
      End With
    End If
    If Len(response.Request_AddCustomerEddr.BusinessName) = 0 Then
      .AddRowCaptionText("First Name:", response.Request_AddCustomerEddr.FirstName)
      .AddRowCaptionText("Last Name:", response.Request_AddCustomerEddr.LastName)
    Else
      .AddRowCaptionText("Business Name:", response.Request_AddCustomerEddr.BusinessName)
    End If
    .AddRowCaptionTextEmailAddress("Email:", response.Request_AddCustomerEddr.EmailAddress, False)
    .AddRowCaptionTextPhoneNumber("Mobile:", response.Request_AddCustomerEddr.MobilePhoneNumber, False)
    .AddRowCaptionAddressDetailsPhysical("Address:", response.Request_AddCustomerEddr.Address, False)

    Select Case response.Request_AddCustomerEddr.PaymentMethod
      Case iseBankInterface_Ezidebit_PaymentMethod.BankAccount
        .AddRowCaptionText("Payment Method:", "Bank Account")
      Case iseBankInterface_Ezidebit_PaymentMethod.CreditCard
        .AddRowCaptionText("Payment Method:", "Credit Card")
      Case Else  
        .AddRowCaptionText("Payment Method:", "Bank Account or Credit Card")
    End Select    
    
    ' Current Status
    Select Case ServiceLogs(0).ResponseStatus
      Case iseServiceLogResponseStatus.Aborted
        .Rows.AddSectionHeading3("Current Status")
        .Rows.AddCaptionText("Current Status:", "CANCELLED").BackgroundColour = "gold"
        
      Case iseServiceLogResponseStatus.Deleted
        .Rows.AddSectionHeading3("Current Status")
        .Rows.AddCaptionText("Current Status:", "DELETED").BackgroundColour = "#EECCFF"
        
      Case iseServiceLogResponseStatus.InProgress
        ' eDDR Link
        If ShowEddrLink Then 
          .AddRowCaptionText("eDDR Link:", finBL.BankingInterface.Service_Ezidebit.GeteDDRUrl(response))
        End If  
    End Select

    ' Actions
    With .Actions
      If ServiceLogs(0).ResponseStatus = iseServiceLogResponseStatus.InProgress Then
        With .AddApplicationShortcutUrl("eDDR", "Open eDDR Form", "")
          .ApplicationShortcutType = "External"
          .Parameters.SetString("File", finBL.BankingInterface.Service_Ezidebit.GeteDDRUrl(response))
          .ShowInWebInterfaces = True
        End With  
    
        If serviceLogSourceObjects.Client IsNot Nothing Then
          ' Create Application Shortcut
          ApplicationShortcut = finBL.CreateApplicationShortcut()
          With ApplicationShortCut
            .Action = "FormShow"
            With .Parameters
              .SetString("form", "DocumentCreateClient")
              .SetString("id", serviceLogSourceObjects.Client.ClientId)
              .SetInteger("serviceLogPk", ServiceLogs(0).Pk)
              If serviceLogSourceObjects.ClientLog IsNot Nothing Then .SetInteger("replyLogPk", serviceLogSourceObjects.ClientLog.Pk)
            End With
          End With

          ' Email
          If PaymentMethod IsNot Nothing Then
            DocumentId = PaymentMethod.BankAccount.ExportService_Ezidebit.EddrEmailDocumentId
            If Len(DocumentId) <> 0 Then
              ApplicationShortCut.Parameters.SetString("documentId", DocumentId)
              .AddApplicationShortcut("FormShowEmail", "Send Email", ApplicationShortCut).ShowInWebInterfaces = True
            End If
          End If  

          ' SMS
          If finBL.Settings.AddOns.Messaging AndAlso PaymentMethod IsNot Nothing Then
            DocumentId = PaymentMethod.BankAccount.ExportService_Ezidebit.EddrSmsDocumentId
            If Len(DocumentId) <> 0 Then
              ApplicationShortCut.Parameters.SetString("documentId", DocumentId)
              .AddApplicationShortcut("FormShowSms", "Send SMS", ApplicationShortCut).ShowInWebInterfaces = True
            End If
          End If
        Else
          .AddUrl("eDD2R", "Open eDDR Form", "")
        End If
      End If
    End With
  End With
  SummaryTables.Add("Request", SummaryTable)

  ' Actions
  If ServiceLogs(0).ResponseStatus = iseServiceLogResponseStatus.InProgress Then
    SummaryTable = SummaryTables.CreateSummaryTableInformation("Actions", "Actions", 2, , , TestMode)
    With SummaryTable
      With .Actions
        If finBL.CurrentUser.Permissions.Allow("Banking.BankInterface.Requests.Update") Then
          .AddApplicationShortcutUrl("UpdateStatus", "Update", String.Format("App://Global?Type=BankingInterface.eDDRUpdateStatus&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
        End If
        If finBL.CurrentUser.Permissions.Allow("Banking.BankInterface.Requests.Cancel") Then
          .AddApplicationShortcutUrl("Cancel", "Cancel", String.Format("App://Global?Type=BankingInterface.eDDRCancel&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
        End If
      End With  
    End With
    SummaryTables.Add("Actions", SummaryTable)
  End If

  ' Ezidebit Customer
  If Customer IsNot Nothing Then
    SummaryTable = SummaryTables.CreateSummaryTableInformation("Ezidebit Customer", "Customer", 2, , , TestMode)
    With SummaryTable
      .AddRowCaptionText("Ezidebit Customer:", Customer.EzidebitCustomerId)
      If Len(Customer.YourSystemReference) <> 0 Then
        With .Rows.AddCaptionText("Reference:", Customer.YourSystemReference)
          With .Cells.AddWiki("{{icon|clipboard_copy}}")
            .Hyperlink = "javascript:navigator.clipboard.writeText('" & finBL.UrlEncode(Customer.YourSystemReference) & "');"
            .Tooltip = "Copy Reference to clipboard"
          End With  
        End With
      End If  
      .AddRowCaptionText("Status:", Customer.StatusText)
      .AddRowCaptionBooleanYesNo("Can Process Payments:", Customer.CanProcessPayments)
      .AddRowCaptionDate("Contract Started:", Customer.ContractStartDate)
      .AddRowCaptionText("Payment Method:", Customer.PaymentMethodText)
    End With
    SummaryTables.Add("Customer", SummaryTable)
  End If

  Return SummaryTables

End Function

Private Function Ezidebit_AddPayment_Details(response As ISBankInterfaceResponse_Ezidebit_AddPayment,
                                             bankTransactionView As finBankTransactionView) As ISSummaryTables

  Dim Parameters As ISKeyValueList
  Dim ResponsePaymentDetail As ISBankInterfaceResponse_Ezidebit_GetPaymentDetail
  Dim ServiceLog As ISServiceLog
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Find Payment Detail
  For Each ServiceLog In serviceLogs
    If ServiceLog.RequestStatus = iseAuditLogStatus.Success Then
      Select Case TypeName(ServiceLog.ExResponse)
        Case "ISBankInterfaceResponse_Ezidebit_GetPaymentDetail"
          ResponsePaymentDetail = DirectCast(ServiceLog.ExResponse, ISBankInterfaceResponse_Ezidebit_GetPaymentDetail)
      End Select
    End If
  Next

  ' Request
  SummaryTable = SummaryTables.CreateSummaryTableInformation("Request", "Details", 3, , , TestMode)
  With SummaryTable
    .AddRowCaptionCodeDescription("Bank Account:", response.Request_AddPayment.BankAccountPk, finBL.BankAccounts, False)
    If BankTransactionView IsNot Nothing Then
      With .Rows.AddCaptionInteger("Bank Transaction:", bankTransactionView.BankTransactionPk)
        .Cells(1).HyperlinkSetFormShow("BankTransactionView", CStr(bankTransactionView.BankTransactionPk))
      End With
      .Rows.AddCaptionCodeDescriptionWithFormShow("Account:", bankTransactionView.AccountTransactions(0).AccountId, bankTransactionView.AccountTransactions(0).AccountName, "Accounts")
    End If
    .AddRowCaptionDate("Date:", response.Request_AddPayment.Date)
    With .Rows.AddCaptionText("Ezidebit Customer:", response.Request_AddPayment.EzidebitCustomerId)
      If BankTransactionView IsNot Nothing Then
        Parameters = finBL.CreateKeyValueList
        With Parameters
          .SetString("BankingDetails", bankTransactionView.BankingDetails.ToXmlString(True))
        End With
        .Cells(1).HyperlinkSetGlobalAction("BankingInterface.Verify", Parameters.ToUrlString)
      End If
    End With
    If Len(response.Request_AddPayment.YourSystemReference) <> 0 Then
      With .Rows.AddCaptionText("Reference:", response.Request_AddPayment.YourSystemReference)
        With .Cells.AddWiki("{{icon|clipboard_copy}}")
          .Hyperlink = "javascript:navigator.clipboard.writeText('" & finBL.UrlEncode(response.Request_AddPayment.YourSystemReference) & "');"
          .Tooltip = "Copy Reference to clipboard"
        End With  
      End With
    End If  
    .AddRowCaptionText("Payment Reference:", response.Request_AddPayment.PaymentReference)
    .AddRowCaptionCurrency("Amount:", response.Request_AddPayment.Amount, True)

    ' Actions
    With .actions
      If ServiceLogs(0).ResponseStatus = iseServiceLogResponseStatus.InProgress Then
        If finBL.CurrentUser.Permissions.Allow("Banking.BankInterface.Requests.Update") Then
          .AddApplicationShortcutUrl("UpdateStatus", "Update Status", String.Format("App://Global?Type=BankingInterface.UpdateStatus&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
        End If
        If finBL.CurrentUser.Permissions.Allow("Banking.BankInterface.Requests.Cancel") Then
          .AddApplicationShortcutUrl("Cancel", "Cancel", String.Format("App://Global?Type=BankingInterface.Cancel&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
        End If
      End If
    End With
  End With
  SummaryTables.Add("Request", SummaryTable)

  ' Ezidebit Details
  If ResponsePaymentDetail IsNot Nothing Then
    SummaryTable = SummaryTables.CreateSummaryTableInformation("Ezidebit Details", "EzidebitDetails", 3, , , TestMode)
    With SummaryTable
      .AddRowCaptionDateTime("Date Debited:", ResponsePaymentDetail.Payment.DebitDate)
'      .AddRowCaptionText("Ezidebit Customer:", ResponsePaymentDetail.Payment.EzidebitCustomerId)
'      .AddRowCaptionText("Reference:", ResponsePaymentDetail.Payment.YourSystemReference)
      .AddRowCaptionText("Payment Id:", ResponsePaymentDetail.Payment.PaymentId)
      .AddRowCaptionCurrency("Scheduled Amount:", ResponsePaymentDetail.Payment.ScheduledAmount, True)
      .AddRowCaptionCurrency("Payment Amount:", ResponsePaymentDetail.Payment.PaymentAmount, True)
      .AddRowCaptionText("Invoice Id:", ResponsePaymentDetail.Payment.InvoiceId)
      .AddRowCaptionCurrency("Your Fee:", ResponsePaymentDetail.Payment.TransactionFeeClient, True)
      .AddRowCaptionCurrency("Customer Fee:", ResponsePaymentDetail.Payment.TransactionFeeCustomer, True)
    End With
    SummaryTables.Add("EzidebitDetails", SummaryTable)
  End If

  ' Current Status
  Select Case ServiceLogs(0).ResponseStatus
    Case iseServiceLogResponseStatus.Aborted
      SummaryTable = SummaryTables.CreateSummaryTableInformation("Current Status", "CurrentStatus", 3, , , TestMode)
      With SummaryTable
        .Rows.AddCaptionText("Current Status:", "ABORTED").BackgroundColour = "gold"
      End With
      SummaryTables.Add("CurrentStatus", SummaryTable)

    Case iseServiceLogResponseStatus.Deleted
      SummaryTable = SummaryTables.CreateSummaryTableInformation("Current Status", "CurrentStatus", 3, , , TestMode)
      With SummaryTable
        .Rows.AddCaptionText("Current Status:", "DELETED").BackgroundColour = "#EECCFF"
      End With
      SummaryTables.Add("CurrentStatus", SummaryTable)

    Case Else
      If ResponsePaymentDetail IsNot Nothing Then
        SummaryTable = SummaryTables.CreateSummaryTableInformation("Current Status", "CurrentStatus", 3, , , TestMode)
        With SummaryTable
          With .Rows.AddCaptionText("Current Status:", ResponsePaymentDetail.Payment.PaymentStatusText)
            Select Case ResponsePaymentDetail.Payment.PaymentStatus
              Case iseBankInterface_Ezidebit_PaymentStatus.Dishonoured, iseBankInterface_Ezidebit_PaymentStatus.FatalDishonour
                .BackgroundColour = "pink"
              Case iseBankInterface_Ezidebit_PaymentStatus.Successful
                .BackgroundColour = "lightgreen"
              Case Else
                .BackgroundColour = "orange"
              End Select
          End With
          .AddRowCaptionDateTime("Settlement Date:", ResponsePaymentDetail.Payment.SettlementDate)
          .AddRowCaptionText("Failed Reason:", ResponsePaymentDetail.Payment.BankFailedReason)
        End With
        SummaryTables.Add("CurrentStatus", SummaryTable)
      End If
  End Select

  Return SummaryTables

End Function

Private Function Ezidebit_ChangeCustomerStatus_Request(response As ISBankInterfaceResponse_Ezidebit_ChangeCustomerStatus,
                                                       serviceLogSourceObjects As finServiceLogSourceObjects) As ISSummaryTables

  Dim BankAccount As finBankAccountRO
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Get Bank Account
  If finBL.BankAccounts.ExistsPk(response.Request_ChangeCustomerStatus.BankAccountPk) Then
    BankAccount = finBL.BankAccounts.ItemByPk(response.Request_ChangeCustomerStatus.BankAccountPk)
  Else
    BankAccount = Nothing
  End If

  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Request", 2, , , TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Date:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
    If BankAccount IsNot Nothing Then .AddRowCaptionCodeDescription("Bank Account:", BankAccount.Pk, finBL.BankAccounts, False)
    If serviceLogSourceObjects.Account IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Account:", serviceLogSourceObjects.Account.AccountId, serviceLogSourceObjects.Account.Name)
        .Cells(1).HyperlinkSetFormShow("Accounts", serviceLogSourceObjects.Account.AccountId, "Payments")
      End With
    ElseIf serviceLogSourceObjects.Client IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Client:", serviceLogSourceObjects.Client.ClientId, serviceLogSourceObjects.Client.Name)
        .Cells(1).HyperlinkSetFormShow("Clients", serviceLogSourceObjects.Client.ClientId, "Tax & Banking")
      End With
    End If
    .AddRowCaptionText("Ezidebit Customer:", response.Request_ChangeCustomerStatus.EzidebitCustomerId)
    .AddRowCaptionText("New Status:", response.Request_ChangeCustomerStatus.NewStatus.ToString())
  End With
  SummaryTables.Add("Request", SummaryTable)

  Return SummaryTables

End Function

Private Function Ezidebit_GetCustomers_List(response As ISBankInterfaceResponse_Ezidebit_GetCustomers,
                                            serviceLogSourceObjects As finServiceLogSourceObjects) As ISSummaryTables

  Dim Client As finClient
  Dim Customer As ISBankInterfaceResponse_Ezidebit_Customer
  Dim Row As Integer
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables
  Dim Warnings As String

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  If response.Customers.Count = 0 Then
    SummaryTables.AddSummaryTableBlank("Customers", "Customers", "No customers found.", "", 2)
  Else
    Row = 0
    For Each Customer In response.Customers
      If Row Mod 2 = 0 Then SummaryTables.AddSummaryTableBlank("CustomerStart_" & CStr(Row), "", "<div style='background-color:#F2F2F2'>", , 3)

      ' Get Related Account or Client
      finBL.BankingInterface.Service_Ezidebit.GetRelatedRecord(Customer, Client)

      SummaryTable = SummaryTables.CreateSummaryTableInformation(Customer.Name, "Customer_" & CStr(Row),3,,, TestMode)
      With SummaryTable
        ' Customer Information
        If Customer.IsIndividual Then
          .AddRowCaptionText("First Name:", Customer.FirstName)
          .AddRowCaptionText("Last Name:", Customer.LastName)
        Else
          .AddRowCaptionText("Business:", Customer.Name)
        End If
        .AddRowCaptionText("Mobile:", Customer.MobilePhone)
        .AddRowCaptionText("Email:", Customer.Email)
        .AddRowCaptionAddressDetailsPhysical("Address:", Customer.Address.ToAddressDetails())

        .AddRowCaptionText("Ezidebit Customer:", Customer.EzidebitCustomerId)
        If Len(Customer.YourSystemReference) <> 0 Then
          With .Rows.AddCaptionText("Reference:", Customer.YourSystemReference)
            With .Cells.AddWiki("{{icon|clipboard_copy}}")
              .Hyperlink = "javascript:navigator.clipboard.writeText('" & finBL.UrlEncode(Customer.YourSystemReference) & "');"
              .Tooltip = "Copy Reference to clipboard"
            End With  
          End With
        End If  
        .AddRowCaptionText("General Reference:",  Customer.YourGeneralReference)
        If Client IsNot Nothing Then
          With .Rows.AddCaptionCodeDescription("Client:", Client.ClientId, Client.Name)
            .Cells(1).HyperlinkSetFormShow("Clients", Client.ClientId, "Tax & Banking")
          End With
        End If

        .AddRowCaptionText("Status:", Customer.StatusText)
        .AddRowCaptionBooleanYesNo("Can Process Payments:", Customer.CanProcessPayments)

        .AddRowCaptionBooleanYesNo("SMS Reminder:", Customer.SmsPaymentReminder)
        .AddRowCaptionBooleanYesNo("SMS Failed Notification:", Customer.SmsFailedNotification)
        If Customer.PaymentMethod = iseBankInterface_Ezidebit_PaymentMethod.CreditCard Then
          .AddRowCaptionBooleanYesNo("SMS Card Expirying:", Customer.SmsExpiredCard)
        End If  

        .AddRowCaptionDate("Contract Started:", Customer.ContractStartDate)
        .AddRowCaptionText("Method:", Customer.PaymentMethodText)
        Select Case Customer.PaymentPeriod
          Case iseBankInterface_Ezidebit_PaymentPeriod.Undefined
          Case Else
           .AddRowCaptionText("Period:", Customer.PaymentPeriodText)
        End Select
        If Customer.TotalPaymentsSuccessful <> 0 Then
          .AddRowCaptionWiki("Total Successful:", String.format("**{0}** payments, totalling **{1}**", Format(Customer.TotalPaymentsSuccessful, "#,###,##0"), finBL.FormatCurrency(Customer.TotalPaymentsSuccessfulAmount, True)))
        End If
        If Customer.TotalPaymentsFailed <> 0 Then
          .AddRowCaptionWiki("Total Failed:", String.format("**{0}** payments, totalling **{1}**", Format(Customer.TotalPaymentsFailed, "#,###,##0"), finBL.FormatCurrency(Customer.TotalPaymentsFailedAmount, True)))
        End If

        ' Warnings
        Warnings = ""
        If Client Is Nothing Then
          Warnings &= "{{warning|Ezidebit Customer not found.|true}}"
        End If
        Select Case Customer.Status
          Case iseBankInterface_Ezidebit_CustomerStatus.Active
            If Customer.TotalPaymentsFailed <> 0 Then
            Warnings &= "{{warning|" & String.Format("{0} failed payments.", Customer.TotalPaymentsFailed) & "}}"
            End If
          Case iseBankInterface_Ezidebit_CustomerStatus.New
            Warnings &= "{{info|" & String.Format("Status is '{0}'.", Customer.StatusText) & "}}"
          Case Else
            Warnings &= "{{warning|" & String.Format("Status is '{0}'.", Customer.StatusText) & "}}"
        End Select
        If Not Customer.CanProcessPayments Then
          Warnings &= "{{warning|Payments cannot be processed.}}"
        End If

        ' Warnings from Requested Account/ Client
        If serviceLogSourceObjects.Client IsNot Nothing Then
          If Client Is Nothing Then
          ElseIf serviceLogSourceObjects.Client.Pk <> Client.Pk Then
            Warnings &= "{{warning|The Client linked to the Ezidebit Customer DOES NOT match the requested Client.|True}}"
          End If
        End If

        .TextAfter = Warnings
      End With
      SummaryTables.Add("Customer" & CStr(Row), SummaryTable)

      If Row Mod 2 = 0 Then SummaryTables.AddSummaryTableBlank("CustomerEnd_" & CStr(Row), "", "</div>", , 3)
      Row += 1
    Next
  End If

  Return SummaryTables

End Function

Private Function Ezidebit_GetCustomers_Request(response As ISBankInterfaceResponse_Ezidebit_GetCustomers,
                                               serviceLogSourceObjects As finServiceLogSourceObjects) As ISSummaryTables

  Dim BankAccount As finBankAccountRO
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables
  Dim Warnings As String

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Get Bank Account
  If finBL.BankAccounts.ExistsPk(response.Request_GetCustomerList.BankAccountPk) Then
    BankAccount = finBL.BankAccounts.ItemByPk(response.Request_GetCustomerList.BankAccountPk)
  Else
    BankAccount = Nothing
  End If

  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Request", 2, , , TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Date:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
    If BankAccount IsNot Nothing Then .AddRowCaptionCodeDescription("Bank Account:", BankAccount.Pk, finBL.BankAccounts, False)
    .AddRowCaptionText("Ezidebit Customer:", response.Request_GetCustomerList.EzidebitCustomerId, False)
    If serviceLogSourceObjects.Account IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Account:", serviceLogSourceObjects.Account.AccountId, serviceLogSourceObjects.Account.Name)
        .Cells(1).HyperlinkSetFormShow("Accounts", serviceLogSourceObjects.Account.AccountId, "Payments")
      End With
    ElseIf serviceLogSourceObjects.Client IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Client:", serviceLogSourceObjects.Client.ClientId, serviceLogSourceObjects.Client.Name)
        .Cells(1).HyperlinkSetFormShow("Clients", serviceLogSourceObjects.Client.ClientId, "Tax & Banking")
      End With
    Else
      .AddRowCaptionText("Reference:", response.Request_GetCustomerList.YourSystemReference)
    End If

    ' Warnings
    Warnings = ""
    If response.Customers.Count = 1 Then
      Warnings &= Me.GetWarnings(response.Customers(0), serviceLogSourceObjects)
    End If
    .TextAfter = Warnings
  End With
  SummaryTables.Add("Request", SummaryTable)

  Return SummaryTables

End Function

Private Function Ezidebit_History() As ISSummaryTables

  Dim ServiceLog As ISServiceLog
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  SummaryTable = SummaryTables.CreateSummaryTableTabular("History", "History", 2, TestMode)
  With SummaryTable
    ' Columns
    With .Columns
      .AddText("Service Log")
      .AddDate("Date")
      .AddText("User")
      .AddText("Type")
      .AddText("Status")
    End With

    ' Rows
    With .Rows
      For Each ServiceLog In ServiceLogs
        With .Add
          If Len(ServiceLog.ExStatusHtmlColour) <> 0 Then
            .BackgroundColour = ServiceLog.ExStatusHtmlColour
            If finBL.Runtime.ColourUtilities.HtmlColourIsDark(ServiceLog.ExStatusHtmlColour) Then .ForegroundColour = "white"
          End If
          With .Cells
            .AddText(CStr(ServiceLog.Pk)).HyperlinkSetFormShow("ServiceLog", CStr(ServiceLog.Pk))
            .AddDateTime(ServiceLog.CreatedDate,, True)
            .AddCodeDescription(ServiceLog.CreatedUserPk, finBL.Users)
            .AddText(ServiceLog.ProductId)
            .AddText(ServiceLog.ExStatus).Tooltip = ServiceLog.ExStatusTooltip
          End With
        End With
      Next
    End With
  End With
  SummaryTables.Add("History", SummaryTable)

  Return SummaryTables

End Function

Private Function Ezidebit_HistoryClientLogs() As ISSummaryTables

  Dim LinkedLogs As finLogs
  Dim Log As finLogRO
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()
  
  finBL.Utilities.GetServiceLogLinkedLogs(ServiceLogs(0).Pk, LinkedLogs)

  SummaryTable = SummaryTables.CreateSummaryTableTabular("Client Log History", "ClientLogs", 2, TestMode)
  With SummaryTable
    ' Columns
    With .Columns
      .AddText("Log")
      .AddDate("Date")
      .AddText("User")
      .AddText("Subject")
      .AddText("Status")
    End With

    ' Rows
    With .Rows
      For Each Log In LinkedLogs
        With .Add
          With .Cells
            .AddText(CStr(Log.Pk)).HyperlinkSetFormShow("ClientLog", CStr(Log.Pk))
            .AddDateTime(Log.CreatedDate,, True)
            .AddCodeDescription(Log.CreatedUserPk, finBL.Users)
            .AddText(Log.Subject)
            If Log.PublishStatus = isefinLogPublishStatus.None Then
              .AddText("")
            Else
              .AddText(log.PublishStatusText)
            End If  
          End With
        End With
      Next
    End With
  End With
  SummaryTables.Add("ClientLogs", SummaryTable)

  Return SummaryTables

End Function

Private Function Ezidebit_UpdateCustomerBankAccount_Request(response As ISBankInterfaceResponse_Ezidebit_UpdateCustomerBankAccount,
                                                            serviceLogSourceObjects As finServiceLogSourceObjects) As ISSummaryTables

  Dim BankAccount As finBankAccountRO
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Get Bank Account
  If finBL.BankAccounts.ExistsPk(response.Request_UpdateCustomerBankAccount.BankAccountPk) Then
    BankAccount = finBL.BankAccounts.ItemByPk(response.Request_UpdateCustomerBankAccount.BankAccountPk)
  Else
    BankAccount = Nothing
  End If

  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Request", 2, , , TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Date:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
    If BankAccount IsNot Nothing Then .AddRowCaptionCodeDescription("Bank Account:", BankAccount.Pk, finBL.BankAccounts, False)
    If serviceLogSourceObjects.Account IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Account:", serviceLogSourceObjects.Account.AccountId, serviceLogSourceObjects.Account.Name)
        .Cells(1).HyperlinkSetFormShow("Accounts", serviceLogSourceObjects.Account.AccountId, "Payments")
      End With
    ElseIf serviceLogSourceObjects.Client IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Client:", serviceLogSourceObjects.Client.ClientId, serviceLogSourceObjects.Client.Name)
        .Cells(1).HyperlinkSetFormShow("Clients", serviceLogSourceObjects.Client.ClientId, "Tax & Banking")
      End With
    End If
    .AddRowCaptionText("Ezidebit Customer:", response.Request_UpdateCustomerBankAccount.EzidebitCustomerId)
  End With
  SummaryTables.Add("Request", SummaryTable)

  Return SummaryTables

End Function

Private Function Ezidebit_ProcessRealtimeTokenPayment_Details(response As ISBankInterfaceResponse_Ezidebit_ProcessRealtimeTokenPayment,
                                                              bankTransactionView As finBankTransactionView) As ISSummaryTables

  Dim Parameters As ISKeyValueList
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Request
  SummaryTable = SummaryTables.CreateSummaryTableInformation("Request", "Request", 3, , , TestMode)
  With SummaryTable
    .AddRowCaptionCodeDescription("Bank Account:", response.Request_ProcessRealtimeTokenPayment.BankAccountPk, finBL.BankAccounts, False)
    If BankTransactionView IsNot Nothing Then
      With .Rows.AddCaptionInteger("Bank Transaction:", bankTransactionView.BankTransactionPk)
        .Cells(1).HyperlinkSetFormShow("BankTransactionView", CStr(bankTransactionView.BankTransactionPk))
      End With
      .Rows.AddCaptionCodeDescriptionWithFormShow("Account:", bankTransactionView.AccountTransactions(0).AccountId, bankTransactionView.AccountTransactions(0).AccountName, "Accounts")
    End If
    .AddRowCaptionDateTime("Date:", response.RequestDate)
    With .Rows.AddCaptionText("Token:", response.Request_ProcessRealtimeTokenPayment.Token)
      If BankTransactionView IsNot Nothing Then
        Parameters = finBL.CreateKeyValueList
        With Parameters
          .SetString("BankingDetails", bankTransactionView.BankingDetails.ToXmlString(True))
        End With
        .Cells(1).HyperlinkSetGlobalAction("BankingInterface.Verify", Parameters.ToUrlString)
      End If  
    End With
    .AddRowCaptionText("Payment Reference:", response.Request_ProcessRealtimeTokenPayment.PaymentReference)
    .AddRowCaptionCurrency("Amount:", response.Request_ProcessRealtimeTokenPayment.Amount, True)
  End With
  SummaryTables.Add("Request", SummaryTable)
  
  ' Result
  SummaryTable = SummaryTables.CreateSummaryTableInformation("Result", "Result", 3, , , TestMode)
  With SummaryTable
    Select Case response.RealtimePayment.PaymentResult
      Case iseBankInterface_Ezidebit_PaymentResult.Approved
        .Rows.AddCaptionText("Result:", "Approved").BackgroundColour = response.RealtimePayment.PaymentResultHtmlColour
      Case iseBankInterface_Ezidebit_PaymentResult.Failed
        .Rows.AddCaptionText("Result:", "Failed").BackgroundColour = response.RealtimePayment.PaymentResultHtmlColour
      Case iseBankInterface_Ezidebit_PaymentResult.UnableToProcess
        .Rows.AddCaptionText("Result:", "Unable to Process").BackgroundColour = response.RealtimePayment.PaymentResultHtmlColour
    End Select    
    .AddRowCaptionText("Details:", String.Format("{0} - {1}", response.RealtimePayment.PaymentResultCode, response.RealtimePayment.PaymentResultText))
    .AddRowCaptionText("Ezidebit Id:", response.RealtimePayment.ExchangePaymentId, False)
    .AddRowCaptionText("Bank Receipt Id:", response.RealtimePayment.BankReceiptId, False)
  End With
  SummaryTables.Add("Result", SummaryTable)

  Return SummaryTables

End Function

Private Function Ezidebit_UpdateCustomerBankAccount_BankAccount(response As ISBankInterfaceResponse_Ezidebit_UpdateCustomerBankAccount) As ISSummaryTables

  Dim BankingDetails As finBankingDetails
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Get Banking Details
  BankingDetails = finBL.CreateBankingDetails()
  With BankingDetails
    .PaymentTypeId = isePaymentTypeClass.BankAccount.ToString()
    .AccountSortCode = response.Request_UpdateCustomerBankAccount.BankAccountBSB
    .AccountNumber = response.Request_UpdateCustomerBankAccount.BankAccountNumber
    .AccountName = response.Request_UpdateCustomerBankAccount.BankAccountName
  End With
  BankingDetails = BankingDetails.CloneForDisplay()

  SummaryTable = SummaryTables.CreateSummaryTableInformation("Bank Account Details", "BankAccount", 2, , , TestMode)
  With SummaryTable
    .AddRowCaptionText("Account Name:", BankingDetails.AccountName)
    If finBL.CurrentCountry.SupportsBankSortCode Then
      .AddRowCaptionText(finBL.CurrentCountry.Terminology(isefinCountryTerminology.BankSortCode) & ":", BankingDetails.AccountSortCode)
      .AddRowCaptionText("Account Number:", BankingDetails.AccountNumber)
    Else
    .AddRowCaptionText("Account Number:", BankingDetails.AccountNumber)
    End If
  End With
  SummaryTables.Add("BankAccount", SummaryTable)

  Return SummaryTables

End Function

Private Function Ezidebit_UpdateCustomerCreditCard_Request(response As ISBankInterfaceResponse_Ezidebit_UpdateCustomerCreditCard,
                                                           serviceLogSourceObjects As finServiceLogSourceObjects) As ISSummaryTables

  Dim BankAccount As finBankAccountRO
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Get Bank Account
  If finBL.BankAccounts.ExistsPk(response.Request_UpdateCustomerCreditCard.BankAccountPk) Then
    BankAccount = finBL.BankAccounts.ItemByPk(response.Request_UpdateCustomerCreditCard.BankAccountPk)
  Else
    BankAccount = Nothing
  End If

  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Request", 2, , , TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Date:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
    If BankAccount IsNot Nothing Then .AddRowCaptionCodeDescription("Bank Account:", BankAccount.Pk, finBL.BankAccounts, False)
    If serviceLogSourceObjects.Account IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Account:", serviceLogSourceObjects.Account.AccountId, serviceLogSourceObjects.Account.Name)
        .Cells(1).HyperlinkSetFormShow("Accounts", serviceLogSourceObjects.Account.AccountId, "Payments")
      End With
    ElseIf serviceLogSourceObjects.Client IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Client:", serviceLogSourceObjects.Client.ClientId, serviceLogSourceObjects.Client.Name)
        .Cells(1).HyperlinkSetFormShow("Clients", serviceLogSourceObjects.Client.ClientId, "Tax & Banking")
      End With
    End If
    .AddRowCaptionText("Ezidebit Customer:", response.Request_UpdateCustomerCreditCard.EzidebitCustomerId)
  End With
  SummaryTables.Add("Request", SummaryTable)

  Return SummaryTables

End Function

Private Function Ezidebit_UpdateCustomerCreditCard_CreditCard(response As ISBankInterfaceResponse_Ezidebit_UpdateCustomerCreditCard) As ISSummaryTables

  Dim BankingDetails As finBankingDetails
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Get Banking Details
  BankingDetails = finBL.CreateBankingDetails()
  With BankingDetails
    '.PaymentTypeId = response.Request_UpdateCustomerCreditCard.PaymentTypeClass.ToString()
    .AccountName = response.Request_UpdateCustomerCreditCard.CreditCardName
    .AccountNumber = response.Request_UpdateCustomerCreditCard.CreditCardNumber
    .CardExpiryDate = response.Request_UpdateCustomerCreditCard.CreditCardExpiryDate
  End With
  BankingDetails = BankingDetails.CloneForDisplay()

  SummaryTable = SummaryTables.CreateSummaryTableInformation("Credit Card Details", "CreditCard", 2, , , TestMode)
  With SummaryTable
    .AddRowCaptionText("Card Name:", BankingDetails.AccountName)
    .AddRowCaptionText("Card Number:", BankingDetails.AccountNumber)
    .AddRowCaptionText("Card Expiry:", format(BankingDetails.CardExpiryDate,"MM/yyyy"))
  End With
  SummaryTables.Add("CreditCard", SummaryTable)

  Return SummaryTables

End Function

Private Function GetWarnings(customer As ISBankInterfaceResponse_Ezidebit_Customer,
                             serviceLogSourceObjects As finServiceLogSourceObjects) As String

  Dim Account As finAccount
  Dim AccountClient As finAccountClient
  Dim Client As finClient
  Dim Found As Boolean
  Dim MobilePhone As String

  ' Initialise
  GetWarnings = ""

  ' Account
  If serviceLogSourceObjects.Account IsNot Nothing Then
    ' Cache Account
    Account = serviceLogSourceObjects.Account
    
    Found = False
    For Each AccountClient In Account.Clients
      If AccountClient.IsOwner AndAlso StrComp(AccountClient.ClientId, customer.ClientId, CompareMethod.Text) = 0 Then
        Found = True
        'GetWarnings &= "{{info|" & String.Format("Ezidebit Customer '{0}' found and matches Client '{1}'.", customer.EzidebitCustomerId, AccountClient.ClientId) & "}}"
      End If
    Next

    If Not Found Then
      GetWarnings &= "{{warning|" & String.Format("Ezidebit Customer '{0}' found, but Reference '{1}' does not match any Client related to the Account.", customer.EzidebitCustomerId, customer.YourSystemReference) & "|true}}"
    End If
  End If
  
  ' Client
  If serviceLogSourceObjects.Client IsNot Nothing Then
    ' Cache Client
    Client = serviceLogSourceObjects.Client
    
    ' Client Status
    If Not Client.Active Then
      GetWarnings &= "{{warning|Client is inactive.}}"
    End If

    ' Test name
    If serviceLogSourceObjects.Client.IsIndividualOrSoleTrader Then
      ' Individual
      If StrComp(finBL.Runtime.Validation.ValidateStringAsciiPrintable(Client.LastName), customer.LastName, CompareMethod.Text) <> 0 Then
        GetWarnings &= "{{warning|Client's Last Name does not match Ezidebit Customer.}}"
      ElseIf StrComp(finBL.Runtime.Validation.ValidateStringAsciiPrintable(Client.FirstName), customer.FirstName, CompareMethod.Text) <> 0 Then
        GetWarnings &= "{{warning|Client's First Name does not match Ezidebit Customer.}}"
      End If
    Else
      ' Organisation
      If StrComp(finBL.Runtime.Validation.ValidateStringAsciiPrintable(Client.LegalNameResolved), customer.LastName, CompareMethod.Text) <> 0 Then
        GetWarnings &= "{{warning|Client's Name does not match Ezidebit Customer.}}"
      End If
    End If

    ' Other Checks
    If Client.ContactMethods.GetCurrentEmail().Value <> customer.Email Then
      GetWarnings &= "{{warning|Client Email address does not match Ezidebit Customer.}}"
    End If
    If Len(customer.MobilePhone) <> 0 Then
      ' Clean Phone Number
      With finBL.Runtime.CreatePhoneNumberDetails2()
        If .ParsePhoneNumber(customer.MobilePhone) Then
          MobilePhone = .GetPhoneNumberFull(False, False, False)
        End If
      End With

      If Len(MobilePhone) <> 0 AndAlso MobilePhone <> customer.MobilePhone Then
        GetWarnings &= "{{warning|Client Mobile Phone does not match Ezidebit Customer.}}"
      End If  
    End If
  End If

End Function