' SummaryPage2_BankingInterfaceSummary_Split
Option Explicit On
Option Strict On

' #################################################################
' Zepto (formerly Split Payments) Banking Interface Summary Page Script
'
' Version: 1.04 (27/11/2024)
'
' Usage: Various forms
' #################################################################
' Version        Date  User     Job       Description
' -------  ----------  -------  --------  -------------------------
'    1.00  23/07/2021  ISS                Created
'    1.01  14/09/2021  ISS      J027325   Rebranded "Zepto"
'    1.02  06/09/2023  ISS      J031120   Added Receviable Contact and PayID
'          11/09/2023  ISS      J032007   Integrated permissions for Delete, Disable, Enable
'    1.03  22/02/2024  ISS      J032949   Updated PayID Permission Keys
'          27/03/2024  ISS      J032155   Added PayTo
'    1.04  27/11/2024  ISS      J034793   Incorrect button shown for PayTo Agreement
' #################################################################

' Constants

' 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
  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("#3BB287", "#F0F0F0", "", "#F2F2F2") ' 141618

    ' 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_Split_AddAnyoneContact)
      Me.CreatePage_AddAnyoneContact(DirectCast(response, ISBankInterfaceResponse_Split_AddAnyoneContact), HtmlSummaryPage2StringBuilder)
      
    Case GetType(ISBankInterfaceResponse_Split_AddReceivableContact)
      Me.CreatePage_AddReceivableContact(DirectCast(response, ISBankInterfaceResponse_Split_AddReceivableContact), HtmlSummaryPage2StringBuilder)
      
    Case GetType(ISBankInterfaceResponse_Split_CreateKycAgreement)
      Me.CreatePage_CreateKycAgreement(DirectCast(response, ISBankInterfaceResponse_Split_CreateKycAgreement), HtmlSummaryPage2StringBuilder)
      
    Case GetType(ISBankInterfaceResponse_Split_GetContact)
      Me.CreatePage_GetContact(DirectCast(response, ISBankInterfaceResponse_Split_GetContact), HtmlSummaryPage2StringBuilder)
      
    Case GetType(ISBankInterfaceResponse_Split_MakePayment)
      Me.CreatePage_MakePayment(DirectCast(response, ISBankInterfaceResponse_Split_MakePayment), HtmlSummaryPage2StringBuilder)

    Case GetType(ISBankInterfaceResponse_Split_PayToCreateAgreement)
      Me.CreatePage_PayToCreateAgreement(DirectCast(response, ISBankInterfaceResponse_Split_PayToCreateAgreement), HtmlSummaryPage2StringBuilder)
      
    Case GetType(ISBankInterfaceResponse_Split_PayToCreatePayment)
      Me.CreatePage_PayToCreatePayment(DirectCast(response, ISBankInterfaceResponse_Split_PayToCreatePayment), HtmlSummaryPage2StringBuilder)
      
    Case GetType(ISBankInterfaceResponse_Split_RequestPayment)
      Me.CreatePage_RequestPayment(DirectCast(response, ISBankInterfaceResponse_Split_RequestPayment), 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_AddAnyoneContact(response As ISBankInterfaceResponse_Split_AddAnyoneContact,
                                        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_AddAnyoneContact.Name)
    .AppendH2(String.Format("{0} - {1}", response.ProductId, response.ServiceName))

    .SummaryTablesAppend(Me.Split_AddAnyoneContact_Request(response, ServiceLogSourceObjects))
    .SummaryTablesAppend(Me.Split_Contact(response.Contact, ServiceLogSourceObjects, False))
 End With

End Sub
 
Private Sub CreatePage_PayToCreateAgreement(response As ISBankInterfaceResponse_Split_PayToCreateAgreement,
                                            htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  Dim Agreement As ISBankInterfaceResponse_Split_PayToAgreement
  Dim IsCancelling As Boolean
  Dim Response_Split_PayToCancelAgreement As ISBankInterfaceResponse_Split_PayToCancelAgreement
  Dim Response_Split_PayToSuspendAgreement As ISBankInterfaceResponse_Split_PayToSuspendAgreement
  Dim ServiceLog As ISServiceLog
  Dim ServiceLogSourceObjects As finServiceLogSourceObjects
  Dim SummaryTables As ISSummaryTables

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

  ' Get Related Service Log for List of Agreements
  IsCancelling = False
  For Each ServiceLog In ServiceLogs
    If ServiceLog.RequestStatus = iseAuditLogStatus.Success Then
      Select Case ServiceLog.ExResponse.GetType()
        Case GetType(ISBankInterfaceResponse_Split_PayToCancelAgreement)
          Response_Split_PayToCancelAgreement = DirectCast(ServiceLog.ExResponse, ISBankInterfaceResponse_Split_PayToCancelAgreement)
          
        Case GetType(ISBankInterfaceResponse_Split_PayToCreateAgreement)
          Agreement = DirectCast(ServiceLog.ExResponse, ISBankInterfaceResponse_Split_PayToCreateAgreement).Agreement

        Case GetType(ISBankInterfaceResponse_Split_PayToShowAgreement)
          Agreement = DirectCast(ServiceLog.ExResponse, ISBankInterfaceResponse_Split_PayToShowAgreement).Agreement
          
        Case GetType(ISBankInterfaceResponse_Split_PayToSuspendAgreement)
          Response_Split_PayToSuspendAgreement = DirectCast(ServiceLog.ExResponse, ISBankInterfaceResponse_Split_PayToSuspendAgreement)

        Case GetType(ISBankInterfaceResponse_Split_PayToCreateAmendment)
          ' Ignore
          
        Case GetType(ISBankInterfaceResponse_Split_PayToCancelAgreement)
          IsCancelling = True
          
      End Select
    End If
  Next

  With HtmlSummaryPage2StringBuilder
    If Not String.IsNullOrEmpty(response.Request_PayToCreateAgreement.CreditorUltimatePartyName) Then
      .AppendH1(response.Request_PayToCreateAgreement.CreditorUltimatePartyName)
    Else
      .AppendH1(response.Request_PayToCreateAgreement.CreditorPartyName)
    End If
    .AppendH2(String.Format("PayTo Agreement - {0}", response.ServiceName))

    .SummaryTablesAppend(Me.Split_PayToCreateAgreement_Request(response, ServiceLogSourceObjects))
    .SummaryTablesAppend(Me.Split_PayToAgreement(Agreement, 2, IsCancelling, Response_Split_PayToCancelAgreement, Response_Split_PayToSuspendAgreement, ServiceLogSourceObjects.Account.pk))
        
    ' History
    SummaryTables = Me.Split_History()
    If finBL.CurrentUser.IsAdministrator Then
      ' Add Force Delete option?
      Select Case ServiceLogs(0).ResponseStatus
        Case iseServiceLogResponseStatus.Complete, iseServiceLogResponseStatus.NotApplicable
          ' Only show if last Request is a failed Agreeement
          If ServiceLog.RequestStatus = iseAuditLogStatus.Failed AndAlso ServiceLogs(ServiceLogs.Count - 1).ProductId = "PayToCreateAgreement" Then
            'SummaryTables.ItemByIndex(0).Actions.AddApplicationShortcutUrl("ForceDelete", "Force Delete", String.Format("App://Global?Type=BankingInterface.Split.DeleteReceivableContact&ServiceLogPk={0}&force=true", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
          End If
      End Select
    End If  
    .SummaryTablesAppend(SummaryTables)
 End With

End Sub

Private Sub CreatePage_PayToCreatePayment(response As ISBankInterfaceResponse_Split_PayToCreatePayment,
                                          htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  Dim Name As String
  Dim Payment As ISBankInterfaceResponse_Split_PayToPayment
  Dim ServiceLog As ISServiceLog
  Dim ServiceLogSourceObjects As finServiceLogSourceObjects
  Dim SummaryTables As ISSummaryTables

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

  ' Get Related Service Log for List of Agreements
  For Each ServiceLog In ServiceLogs
    If ServiceLog.RequestStatus = iseAuditLogStatus.Success Then
      Select Case ServiceLog.ExResponse.GetType()
        Case GetType(ISBankInterfaceResponse_Split_PayToCreatePayment)
          Payment = DirectCast(ServiceLog.ExResponse, ISBankInterfaceResponse_Split_PayToCreatePayment).Payment

        Case GetType(ISBankInterfaceResponse_Split_PayToShowPayment)
          Payment = DirectCast(ServiceLog.ExResponse, ISBankInterfaceResponse_Split_PayToShowPayment).Payment
          
      End Select
    End If
  Next

  ' Get Name
  If Payment IsNot Nothing AndAlso ServiceLogSourceObjects.BankTransactionView IsNot Nothing Then
    Name = ServiceLogSourceObjects.BankTransactionView.AccountTransactions(0).AccountName
  End If
  
  With HtmlSummaryPage2StringBuilder
    .AppendH1(Name)
    .AppendH2(String.Format("PayTo Payment - {0}", response.ServiceName))

    .SummaryTablesAppend(Me.Split_PayToCreatePayment_Request(response, ServiceLogSourceObjects))
    .SummaryTablesAppend(Me.Split_PayToPayment(Payment, 2))
    
    ' History
    SummaryTables = Me.Split_History()
    .SummaryTablesAppend(SummaryTables)
 End With

End Sub

Private Function Split_PayToCreateAgreement_Request(response As ISBankInterfaceResponse_Split_PayToCreateAgreement,
                                                    serviceLogSourceObjects As finServiceLogSourceObjects) As ISSummaryTables

  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()
  
  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Request", 2, , , TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Date:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
    If serviceLogSourceObjects.AccountLog IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Account:", serviceLogSourceObjects.Account.AccountId, serviceLogSourceObjects.Account.Name)
        .Cells(1).HyperlinkSetFormShow("AccountLog", CStr(serviceLogSourceObjects.AccountLog.Pk), "Banking Interface Summary")
      End With
    ElseIf 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
    End If
    
    .AddRowCaptionText("Description:", response.Request_PayToCreateAgreement.Description)
  End With
  SummaryTables.Add("Request", SummaryTable)

  Return SummaryTables

End Function

Private Function Split_PayToCreatePayment_Request(response As ISBankInterfaceResponse_Split_PayToCreatePayment,
                                                  serviceLogSourceObjects As finServiceLogSourceObjects) As ISSummaryTables

  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Request", 2, , , TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Date:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
    If serviceLogSourceObjects.BankTransactionView IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Bank Transaction:", serviceLogSourceObjects.BankTransactionView.BankTransactionPk.ToString(), serviceLogSourceObjects.BankTransactionView.ElementTypeText)
        .Cells(1).HyperlinkSetFormShow("BankTransactionView", serviceLogSourceObjects.BankTransactionView.BankTransactionPk.ToString())
      End With
      If serviceLogSourceObjects.BankTransactionView.AccountTransactions IsNot Nothing AndAlso serviceLogSourceObjects.BankTransactionView.AccountTransactions.Count <> 0 Then
        With .Rows.AddCaptionCodeDescription("Account:", serviceLogSourceObjects.BankTransactionView.AccountTransactions(0).Account.AccountId, serviceLogSourceObjects.BankTransactionView.AccountTransactions(0).Account.Name)
          .Cells(1).HyperlinkSetFormShow("Accounts", serviceLogSourceObjects.BankTransactionView.AccountTransactions(0).Account.AccountId, "Payments")
        End With
      End If
    End If
    .AddRowCaptionText("Description:", response.Request_PayToCreatePayment.Description)
  End With
  SummaryTables.Add("Request", SummaryTable)

  Return SummaryTables

End Function

Private Function Split_PayToAgreement(agreement As ISBankInterfaceResponse_Split_PayToAgreement,
                             Optional headingLevel As Integer = 2,
                             Optional isCancelling As Boolean = False,
                             Optional response_Split_PayToCancelAgreement As ISBankInterfaceResponse_Split_PayToCancelAgreement = Nothing,
                             Optional response_Split_PayToSuspendAgreement As ISBankInterfaceResponse_Split_PayToSuspendAgreement = Nothing,
                             Optional accountPk As Integer = 0) As ISSummaryTables

  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  SummaryTable = SummaryTables.CreateSummaryTableInformation("PayTo Agreement Details", "PayToAgreement", headingLevel,,, TestMode)
  With SummaryTable
    .AddRowCaptionText("Agreement Id:", agreement.Uid)
    .AddRowCaptionText("MMS Agreement Id:", agreement.MmsAgreementId)
    With .Rows.AddCaptionText("Status:", agreement.StateText)
      .BackgroundColour = agreement.StateHtmlColour
    End With
    .AddRowCaptionText("Status Caused By:", agreement.StateCausedByText)
    .AddRowCaptionText("Status Reason:", agreement.StateReason.Title, , , , , agreement.StateReason.Detail)
    
    Select Case agreement.State
      Case iseBankInterface_Split_PayToAgreementState.Cancelled
        If response_Split_PayToCancelAgreement IsNot Nothing Then
          If Not String.IsNullOrEmpty(response_Split_PayToCancelAgreement.Request_PayToCancelAgreement.ReasonText) Then
            With .Rows.AddCaptionText("Cancellation Reason:", response_Split_PayToCancelAgreement.Request_PayToCancelAgreement.ReasonText)
              .BackgroundColour = agreement.StateHtmlColour
            End With
          End If
          If Not String.IsNullOrEmpty(response_Split_PayToCancelAgreement.Request_PayToCancelAgreement.Narrative) Then
            With .Rows.AddCaptionText("Cancellation Narrative:", response_Split_PayToCancelAgreement.Request_PayToCancelAgreement.Narrative)
              .BackgroundColour = agreement.StateHtmlColour
            End With
          End If
        End If
        
      Case iseBankInterface_Split_PayToAgreementState.Suspended
        If response_Split_PayToSuspendAgreement IsNot Nothing Then
          If Not String.IsNullOrEmpty(response_Split_PayToSuspendAgreement.Request_PayToSuspendAgreement.ReasonText) Then
            With .Rows.AddCaptionText("Suspension Reason:", response_Split_PayToSuspendAgreement.Request_PayToSuspendAgreement.ReasonText)
              .BackgroundColour = agreement.StateHtmlColour
            End With
          End If
          If Not String.IsNullOrEmpty(response_Split_PayToSuspendAgreement.Request_PayToSuspendAgreement.Narrative) Then
            With .Rows.AddCaptionText("Suspension Narrative:", response_Split_PayToSuspendAgreement.Request_PayToSuspendAgreement.Narrative)
              .BackgroundColour = agreement.StateHtmlColour
            End With
          End If
        End If
    End Select
        
    .AddRowCaptionDateTime("Created:", agreement.CreatedAtDate)
    .AddRowCaptionText("Description:", agreement.Description)
    If agreement.Purpose = iseBankInterface_Split_PayToAgreementPurpose.Undefined Then
      .AddRowCaptionText("Purpose:", agreement.PurposeRaw)
    Else
      .AddRowCaptionText("Purpose:", agreement.PurposeText)
    End If
    .AddRowCaptionDateTime("Resolution Before:", agreement.ResolutionRequestedBeforeDate, False)
    .AddRowCaptionDate("Validity Start:", agreement.ValidityStartDate, False)
    .AddRowCaptionDate("Validity End:", agreement.ValidityEndDate, False)
    
    ' Actions
    With .Actions
      Select Case agreement.State
        Case iseBankInterface_Split_PayToAgreementState.Active
          ' Refresh
          .AddApplicationShortcutUrl("Refresh", "Refresh", String.Format("App://Global?Type=BankingInterface.PayTo.RefreshAgreementStatus&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True

          ' Amend
          If finBL.CurrentUser.Permissions.Allow("Banking.BankInterface.PayTo.Amend") Then
            .AddApplicationShortcutUrl("Amend", "Amend", String.Format("App://Global?Type=BankingInterface.PayTo.AmendAgreement&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
          End If
          
          If isCancelling Then
            ' Alert if Cancelling
            SummaryTable.TextBefore = "{{alert|Agreement is being CANCELLED. Please Refresh to update the Agreement State.|true}}"
          Else  
            ' Suspend
            If finBL.CurrentUser.Permissions.Allow("Banking.BankInterface.PayTo.Suspend") Then
              .AddApplicationShortcutUrl("Suspend", "Suspend", String.Format("App://Global?Type=BankingInterface.PayTo.SuspendAgreement&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
            End If
            ' Cancel
            If finBL.CurrentUser.Permissions.Allow("Banking.BankInterface.PayTo.Cancel") Then
              .AddApplicationShortcutUrl("Cancel", "Cancel", String.Format("App://Global?Type=BankingInterface.PayTo.CancelAgreement&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
            End If
          End If  

        Case iseBankInterface_Split_PayToAgreementState.Cancelled
          ' Refresh
          .AddApplicationShortcutUrl("Refresh", "Refresh", String.Format("App://Global?Type=BankingInterface.PayTo.RefreshAgreementStatus&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True

        Case iseBankInterface_Split_PayToAgreementState.Created
          ' Update
          .AddApplicationShortcutUrl("Update", "Update", String.Format("App://Global?Type=BankingInterface.PayTo.UpdateAgreementStatus&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
          
        Case iseBankInterface_Split_PayToAgreementState.Declined
          ' Refresh
          .AddApplicationShortcutUrl("Refresh", "Refresh", String.Format("App://Global?Type=BankingInterface.PayTo.RefreshAgreementStatus&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
          
        Case iseBankInterface_Split_PayToAgreementState.Expired
          ' Refresh
          .AddApplicationShortcutUrl("Refresh", "Refresh", String.Format("App://Global?Type=BankingInterface.PayTo.RefreshAgreementStatus&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
          
        Case iseBankInterface_Split_PayToAgreementState.Failed
          
        Case iseBankInterface_Split_PayToAgreementState.Pending
          ' Update
          .AddApplicationShortcutUrl("Update", "Update", String.Format("App://Global?Type=BankingInterface.PayTo.UpdateAgreementStatus&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
          
          ' Cancel
          If finBL.CurrentUser.Permissions.Allow("Banking.BankInterface.PayTo.Cancel") Then
          .AddApplicationShortcutUrl("Cancel", "Cancel", String.Format("App://Global?Type=BankingInterface.PayTo.CancelAgreement&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
          End If
        
        Case iseBankInterface_Split_PayToAgreementState.Suspended
          ' Refresh
          .AddApplicationShortcutUrl("Refresh", "Refresh", String.Format("App://Global?Type=BankingInterface.PayTo.RefreshAgreementStatus&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
          
          ' Reactivate
          If finBL.CurrentUser.Permissions.Allow("Banking.BankInterface.PayTo.Reactivate") Then
            .AddApplicationShortcutUrl("Reactivate", "Reactivate", String.Format("App://Global?Type=BankingInterface.PayTo.ReactivateAgreement&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
          End If            
          ' Cancel
          If finBL.CurrentUser.Permissions.Allow("Banking.BankInterface.PayTo.Cancel") Then
            .AddApplicationShortcutUrl("Cancel", "Cancel", String.Format("App://Global?Type=BankingInterface.PayTo.CancelAgreement&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
          End If
      End Select
    End With
  End With
  SummaryTables.Add("PayToAgreement", SummaryTable)
  
  ' Terms
  SummaryTable = SummaryTables.CreateSummaryTableInformation("Terms", "PayToTerms",headingLevel+1,,, TestMode)
  With SummaryTable
    .AddRowCaptionText("Type:", agreement.PaymentTerms.TypeText)
    .AddRowCaptionText("Frequency:", agreement.PaymentTerms.FrequencyText)
    .AddRowCaptionInteger("Count:", agreement.PaymentTerms.Count,, False)
    .AddRowCaptionCurrency("Amount:", agreement.PaymentTerms.Amount,, False)
    .AddRowCaptionCurrency("Maximum Amount:", agreement.PaymentTerms.MaxAmount,, False)
    .AddRowCaptionCurrency("First Payment Amount:", agreement.PaymentTerms.FirstPaymentAmount,, False)
    .AddRowCaptionDate("First Payment Date:", agreement.PaymentTerms.FirstPaymentDate, False)
    .AddRowCaptionCurrency("Last Payment Amount:", agreement.PaymentTerms.LastPaymentAmount,, False)
    .AddRowCaptionDate("Last Payment Date:", agreement.PaymentTerms.LastPaymentDate, False)
  End With
  SummaryTables.Add("PayToTerms", SummaryTable)

  ' Debtor and Creditor
  SummaryTables.AppendSummaryTables(Me.Split_PayToCreditorOrDebtor("Debtor", "PayToDebtor", agreement.Debtor, headingLevel + 1))
  SummaryTables.AppendSummaryTables(Me.Split_PayToCreditorOrDebtor("Creditor", "PayToCreditor", agreement.Creditor, headingLevel + 1))

  ' Initiator
  SummaryTable = SummaryTables.CreateSummaryTableInformation("Initiator", "PayToInitiator",headingLevel+1,,, TestMode)
  With SummaryTable
    .AddRowCaptionText("Name:", agreement.Initiator.Name, False)
    .AddRowCaptionText("Legal Name:", agreement.Initiator.LegalName, False)
    .AddRowCaptionText("ABN:", agreement.Initiator.ABN, False)
  End With
  SummaryTables.Add("PayToInitiator", SummaryTable)

  Return SummaryTables

End Function

Private Function Split_PayToCreditorOrDebtor(caption As String,
                                             captionId As String,
                                             debtorOrCreditor As ISBankInterfaceResponse_Split_PayToCreditorOrDebtor,
                                             headingLevel As Integer,
                                    Optional creditorReference As String = "") As ISSummaryTables
                                    
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables
  
  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  If String.IsNullOrEmpty(debtorOrCreditor.UltimatePartyName) AndAlso String.IsNullOrEmpty(debtorOrCreditor.PartyName) Then
    SummaryTables.AddSummaryTableBlank(captionId, caption, "No information", captionId, headingLevel)
  Else
    SummaryTable = SummaryTables.CreateSummaryTableInformation(caption, captionId, headingLevel,,, TestMode)
    With SummaryTable
      .AddRowCaptionText("Creditor Reference:", creditorReference, False)
      If StrComp(debtorOrCreditor.UltimatePartyName, debtorOrCreditor.PartyName, Comparemethod.Text) <> 0 Then
        .AddRowCaptionText("Ultimate Party Name:", debtorOrCreditor.UltimatePartyName, False)
      End If
      .AddRowCaptionText("Party Name:", debtorOrCreditor.PartyName, False)
      .AddRowCaptionText("Account Identifier Type:", debtorOrCreditor.AccountIdentifier.TypeText, False)
      .AddRowCaptionText("Account Identifier Value:", debtorOrCreditor.AccountIdentifier.Value, False)
    End With
    SummaryTables.Add(captionId, SummaryTable)
  End If
  
  ' Return
  Return SummaryTables
  
End Function

Private Function Split_PayToPayment(payment As ISBankInterfaceResponse_Split_PayToPayment,
                           Optional headingLevel As Integer = 2) As ISSummaryTables

  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  SummaryTable = SummaryTables.CreateSummaryTableInformation("PayTo Payment Details", "PayToPayment", headingLevel,,, TestMode)
  With SummaryTable
    .AddRowCaptionText("Payment Id:", payment.Uid)
    .AddRowCaptionText("Agreement Id:", payment.AgreementUid)
    .Rows.AddCaptionText("State:", payment.StateText).BackgroundColour = payment.StateHtmlColour
    .AddRowCaptionText("Reference:", payment.Reference)
    .AddRowCaptionText("Description:", payment.Description)
    .AddRowCaptionText("Priority:", payment.PriorityText)
    .AddRowCaptionCurrency("Amount:", payment.Amount, True)
    If payment.LastPayment.HasValue() Then .AddRowCaptionTick("Is Last Payment:", payment.LastPayment.GetValueOrDefault())
    .AddRowCaptionDateTime("Created:", payment.CreatedAtDate, False)
  End With
  SummaryTables.Add("PayToPayment", SummaryTable)
  
  ' Failure
  If payment.Failure IsNot Nothing AndAlso Not String.IsNullOrEmpty(payment.Failure.Title) Then
    SummaryTable = SummaryTables.CreateSummaryTableInformation("Failure", "PayToFailure",headingLevel+1,,, TestMode)
    With SummaryTable
      .AddRowCaptionText("Title:", payment.Failure.Title)
      .AddRowCaptionText("Detail:", payment.Failure.Detail)
      .AddRowCaptionText("Code:", payment.Failure.Code)

'      If payment.Failure.Retryable.GetValueOrDefault() Then
'        With .Actions
'          .AddApplicationShortcutUrl("Retry", "Retry", String.Format("App://Global?Type=BankingInterface.Split.RetryPayToPayment&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
'        End With
'      End If
    End With
    SummaryTables.Add("PayToTerms", SummaryTable)
  End If

  ' Debtor and Creditor
  SummaryTables.AppendSummaryTables(Me.Split_PayToCreditorOrDebtor("Debtor", "PayToDebtor", payment.Debtor, headingLevel + 1))
  SummaryTables.AppendSummaryTables(Me.Split_PayToCreditorOrDebtor("Creditor", "PayToCreditor", payment.Creditor, headingLevel + 1, payment.CreditorReference))

  Return SummaryTables

End Function

Private Sub CreatePage_AddReceivableContact(response As ISBankInterfaceResponse_Split_AddReceivableContact,
                                            htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  Dim Contact As ISBankInterfaceResponse_Split_Contact
  Dim IsDeleted As Boolean
  Dim ServiceLog As ISServiceLog
  Dim ServiceLogSourceObjects As finServiceLogSourceObjects
  Dim SummaryTables As ISSummaryTables

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

  ' Get Related Service Log for List of Agreements
  IsDeleted = (ServiceLogs(0).ResponseStatus = iseServiceLogResponseStatus.Deleted)
  For Each ServiceLog In ServiceLogs
    If ServiceLog.RequestStatus = iseAuditLogStatus.Success Then
      Select Case ServiceLog.ExResponse.GetType()
        Case GetType(ISBankInterfaceResponse_Split_AddReceivableContact)
          Contact = DirectCast(ServiceLog.ExResponse, ISBankInterfaceResponse_Split_AddReceivableContact).Contact
        Case GetType(ISBankInterfaceResponse_Split_GetContact)
          Contact = DirectCast(ServiceLog.ExResponse, ISBankInterfaceResponse_Split_GetContact).Contact
        Case GetType(ISBankInterfaceResponse_Split_DeleteContact)
          IsDeleted = True
      End Select
    End If
  Next

  With HtmlSummaryPage2StringBuilder
    .AppendH1(response.Request_AddReceivableContact.Name)
    .AppendH2(String.Format("PayID Receivables Contact - {0}", response.ServiceName))

    .SummaryTablesAppend(Me.Split_AddReceivableContact_Request(response, ServiceLogSourceObjects))
    .SummaryTablesAppend(Me.Split_Contact(Contact, ServiceLogSourceObjects, IsDeleted))
    
    ' History
    SummaryTables = Me.Split_History()
    If finBL.CurrentUser.IsAdministrator Then
      ' Add Force Delete option?
      Select Case ServiceLogs(0).ResponseStatus
        Case iseServiceLogResponseStatus.Complete, iseServiceLogResponseStatus.NotApplicable
          ' Only show if last Request is a failed GetContact
          If ServiceLog.RequestStatus = iseAuditLogStatus.Failed AndAlso ServiceLogs(ServiceLogs.Count - 1).ProductId = "GetContact" Then
            SummaryTables.ItemByIndex(0).Actions.AddApplicationShortcutUrl("ForceDelete", "Force Delete", String.Format("App://Global?Type=BankingInterface.Split.DeleteReceivableContact&ServiceLogPk={0}&force=true", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
          End If
      End Select
    End If  
    .SummaryTablesAppend(SummaryTables)
 End With

End Sub

Private Sub CreatePage_CreateKycAgreement(response As ISBankInterfaceResponse_Split_CreateKycAgreement,
                                          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_CreateKycAgreement.Name)
    .AppendH2(String.Format("{0} - {1}", response.ProductId, response.ServiceName))

    .SummaryTablesAppend(Me.Split_CreateKycAgreement_Request(response, ServiceLogSourceObjects))
    .SummaryTablesAppend(Me.Split_Agreement(response.Agreement))
 End With

End Sub

Private Sub CreatePage_GetContact(response As ISBankInterfaceResponse_Split_GetContact,
                                  htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  Dim Agreements As ISBankInterfaceResponse_Split_Agreements
  Dim ServiceLog As ISServiceLog
  Dim ServiceLogSourceObjects As finServiceLogSourceObjects

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

  ' Get Related Service Log for List of Agreements
  For Each ServiceLog In ServiceLogs
    Select Case ServiceLog.ExResponse.GetType()
      Case GetType(ISBankInterfaceResponse_Split_ListAgreements)
        Agreements = DirectCast(ServiceLog.ExResponse, ISBankInterfaceResponse_Split_ListAgreements).Agreements
    End Select
  Next

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

    .SummaryTablesAppend(Me.Split_GetContact_Request(response, ServiceLogSourceObjects))
    .SummaryTablesAppend(Me.Split_Contact(response.Contact, ServiceLogSourceObjects, False))

    ' Agreements
    If Agreements IsNot Nothing Then
      .AppendH2("Agreements")
      .SummaryTablesAppend(Me.Split_ContactAgreements(Agreements))
    End If
 End With

End Sub

Private Sub CreatePage_MakePayment(response As ISBankInterfaceResponse_Split_MakePayment,
                                   htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  Dim Name As String
  Dim ServiceLogSourceObjects As finServiceLogSourceObjects

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

  ' Get Name
  If ServiceLogSourceObjects.BankTransactionView Is Nothing Then
    Name = Response.Request_MakePayment.Payouts(0).RecipientContactId
  Else
    Name = ServiceLogSourceObjects.BankTransactionView.AccountTransactions(0).AccountName
  End If

  With HtmlSummaryPage2StringBuilder
    .AppendH1(Name)
    .AppendH2(String.Format("{0}", response.ServiceName))

    .SummaryTablesAppend(Me.Split_MakePayment_Request(response, ServiceLogSourceObjects))
    .SummaryTablesAppend(Me.Split_MakePayment_Status(response, ServiceLogSourceObjects))
    .SummaryTablesAppend(Me.Split_History())
 End With

End Sub

Private Sub CreatePage_RequestPayment(response As ISBankInterfaceResponse_Split_RequestPayment,
                                      htmlSummaryPage2StringBuilder As finHtmlSummaryPage2StringBuilder)

  Dim Name As String
  Dim ServiceLogSourceObjects As finServiceLogSourceObjects

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

  ' Get Name
  If ServiceLogSourceObjects.BankTransactionView Is Nothing Then
    Name = Response.Request_RequestPayment.ContactId
  Else
    Name = ServiceLogSourceObjects.BankTransactionView.AccountTransactions(0).AccountName
  End If

  With HtmlSummaryPage2StringBuilder
    .AppendH1(Name)
    .AppendH2(String.Format("{0}", response.ServiceName))

    .SummaryTablesAppend(Me.Split_RequestPayment_Request(response, ServiceLogSourceObjects))
    .SummaryTablesAppend(Me.Split_RequestPayment_Status(response, ServiceLogSourceObjects))
    .SummaryTablesAppend(Me.Split_History())
 End With

End Sub

Private Function Split_AddAnyoneContact_Request(response As ISBankInterfaceResponse_Split_AddAnyoneContact,
                                                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_AddAnyoneContact.BankAccountPk) Then
    BankAccount = finBL.BankAccounts.ItemByPk(response.Request_AddAnyoneContact.BankAccountPk)
  Else
    BankAccount = Nothing
  End If

  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Request", 2, , , TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Date:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
    .AddRowCaptionCodeDescription("Bank Account:", response.Request_AddAnyoneContact.BankAccountPk, 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("Name:", response.Request_AddAnyoneContact.Name)
    .AddRowCaptionText("Email:", response.Request_AddAnyoneContact.Email)
    .AddRowCaptionText(finBL.CurrentCountry.Terminology(isefinCountryTerminology.BankSortCode, True) & ":", response.Request_AddAnyoneContact.BranchCode)
    .AddRowCaptionText("Account Number:", response.Request_AddAnyoneContact.AccountNumber)
  End With
  SummaryTables.Add("Request", SummaryTable)

  Return SummaryTables

End Function

Private Function Split_AddReceivableContact_Request(response As ISBankInterfaceResponse_Split_AddReceivableContact,
                                                    serviceLogSourceObjects As finServiceLogSourceObjects) As ISSummaryTables

  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Request", 2, , , TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Date:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
    If serviceLogSourceObjects.AccountLog IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Account:", serviceLogSourceObjects.Account.AccountId, serviceLogSourceObjects.Account.Name)
        .Cells(1).HyperlinkSetFormShow("AccountLog", CStr(serviceLogSourceObjects.AccountLog.Pk), "Banking Interface Summary")
      End With
    ElseIf 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
    End If
    .AddRowCaptionText("Name:", response.Request_AddReceivableContact.Name)
    .AddRowCaptionText("Email:", response.Request_AddReceivableContact.Email)
    .AddRowCaptionText("PayID Email:", response.Request_AddReceivableContact.PayIdEmail)
  End With
  SummaryTables.Add("Request", SummaryTable)

  Return SummaryTables

End Function

Private Function Split_CreateKycAgreement_Request(response As ISBankInterfaceResponse_Split_CreateKycAgreement,
                                                  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_CreateKycAgreement.BankAccountPk) Then
    BankAccount = finBL.BankAccounts.ItemByPk(response.Request_CreateKycAgreement.BankAccountPk)
  Else
    BankAccount = Nothing
  End If

  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Request", 2, , , TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Date:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
    .AddRowCaptionCodeDescription("Bank Account:", response.Request_CreateKycAgreement.BankAccountPk, 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("Name:", response.Request_CreateKycAgreement.Name)
    .AddRowCaptionText("Email:", response.Request_CreateKycAgreement.Email)
    .AddRowCaptionText(finBL.CurrentCountry.Terminology(isefinCountryTerminology.BankSortCode, True) & ":", response.Request_CreateKycAgreement.BranchCode)
    .AddRowCaptionText("Account Number:", response.Request_CreateKycAgreement.AccountNumber)
  End With
  SummaryTables.Add("Request", SummaryTable)

  Return SummaryTables

End Function

Private Function Split_GetContact_Request(response As ISBankInterfaceResponse_Split_GetContact,
                                          serviceLogSourceObjects As finServiceLogSourceObjects) As ISSummaryTables

  Dim AccountBankingDetail As finAccountBankingDetail
  Dim AccountClient As finAccountClient
  Dim BankAccount As finBankAccountRO
  Dim Found As Boolean
  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_GetContact.BankAccountPk) Then
    BankAccount = finBL.BankAccounts.ItemByPk(response.Request_GetContact.BankAccountPk)
  Else
    BankAccount = Nothing
  End If

  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Request", 2, , , TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Date:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
    .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

    ' Warnings
    Warnings = ""

    ' Verification Warnings
    If Len(response.Request_GetContact.VerifyBranchCode) <> 0 AndAlso StrComp(Response.Contact.BankAccount.BranchCode, response.Request_GetContact.VerifyBranchCode, CompareMethod.Text) <> 0 Then
      Warnings &= "{{warning|" & String.Format("Branch Codes do not match - '{0}' differs from '{1}'.", Response.Contact.BankAccount.BranchCode, response.Request_GetContact.VerifyBranchCode) & "|true}}"
    End If
    If Len(response.Request_GetContact.VerifyAccountNumber) <> 0 AndAlso StrComp(Response.Contact.BankAccount.AccountNumber, response.Request_GetContact.VerifyAccountNumber, CompareMethod.Text) <> 0 Then
      Warnings &= "{{warning|" & String.Format("Account Numbers do not match - '{0}' differs from '{1}'.", Response.Contact.BankAccount.AccountNumber, response.Request_GetContact.VerifyAccountNumber) & "|true}}"
    End If
    If StrComp(Response.Contact.Name, response.Request_GetContact.VerifyName, CompareMethod.Text) <> 0 Then
      Warnings &= "{{warning|" & String.Format("Names do not match - '{0}' differs from '{1}'.", Response.Contact.Name, response.Request_GetContact.VerifyName) & "|true}}"
    End If
    If StrComp(Response.Contact.Email, response.Request_GetContact.VerifyEmail, CompareMethod.Text) <> 0 Then
      Warnings &= "{{warning|" & String.Format("Emails do not match - '{0}' differs from '{1}'.", Response.Contact.Email, response.Request_GetContact.VerifyEmail) & "|true}}"
    End If

    ' Account Warnings
    If serviceLogSourceObjects.Account IsNot Nothing Then
      ' Account Status
      Select Case serviceLogSourceObjects.Account.Status
        Case isefinAccountStatus.Open
        Case Else
          Warnings &= "{{warning|" & String.Format("Status is '{0}'.", serviceLogSourceObjects.Account.StatusText) & "}}"
      End Select

      ' Client Match
      Found = False
      For Each AccountClient In serviceLogSourceObjects.Account.Clients
        If AccountClient.IsOwner Then
          If StrComp(AccountClient.Client.Name, Response.Contact.Name, CompareMethod.Text) = 0 Then
            Found = True

            ' Other Checks
            If AccountClient.Client.ContactMethods.GetCurrentEmail().Value <> Response.Contact.Email Then
              Warnings &= "{{warning|Client Email address does not match Zepto Contact.}}"
            End If
          End If
        End If
      Next
      If Not Found Then
        Warnings &= "{{warning|Cannot match Name to an Owner of the Account.}}"
      End If

      ' Used for Payments?
      Found = False
      For Each AccountBankingDetail In serviceLogSourceObjects.Account.BankingDetails
        Select Case AccountBankingDetail.BankingDetails.PaymentTypeClass
          Case isePaymentTypeClass.Split
            Found = True
        End Select
      Next
      If Not Found Then
        Warnings &= "{{warning|Zepto (formerly Split Payments) is NOT currently being used for Payments.}}"
      End If
    End If

    ' Client Warnings
    If serviceLogSourceObjects.Client IsNot Nothing Then
      ' Client Status
      If Not serviceLogSourceObjects.Client.Active Then
        Warnings &= "{{warning|Client is inactive.}}"
      End If

      ' Test name
      If StrComp(serviceLogSourceObjects.Client.Name, Response.Contact.Name, CompareMethod.Text) <> 0 Then
        Warnings &= "{{info|Client's Name does not match the Zepto Contact. Note, the Zepto Contact Name should match the Name of the Bank Account.}}"
      End If

      ' Other Checks
      If serviceLogSourceObjects.Client.ContactMethods.GetCurrentEmail().Value <> Response.Contact.Email Then
        Warnings &= "{{info|Client's current Email address does not match the Zepto Contact.}}"
      End If
    End If
    .TextAfter = Warnings
  End With
  SummaryTables.Add("Request", SummaryTable)

  Return SummaryTables

End Function

Private Function Split_Agreements(agreements As ISBankInterfaceResponse_Split_Agreements) As ISSummaryTables

  Dim Agreement As ISBankInterfaceResponse_Split_Agreement
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  For Each Agreement In agreements
    SummaryTables.AppendSummaryTables(Me.Split_Agreement(Agreement, 3))
  Next

  Return SummaryTables

End Function

Private Function Split_Agreement(agreement As ISBankInterfaceResponse_Split_Agreement,
                        Optional headingLevel As Integer = 2) As ISSummaryTables

  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  SummaryTable = SummaryTables.CreateSummaryTableInformation("Agreement Details", "Agreement",headingLevel,,, TestMode)
  With SummaryTable
    .AddRowCaptionText("Reference:", agreement.Reference)
    .AddRowCaptionText("Status:", agreement.StatusText,,, agreement.StatusReason)
    .AddRowCaptionDateTime("Created:", agreement.CreatedAtDate)
    .AddRowCaptionDateTime("Responded:", agreement.RespondedAtDate)

    .AddRowCaptionText("Initiator:", agreement.InitiatorId)
    .AddRowCaptionText("Authoriser:", agreement.AuthoriserId)
    .AddRowCaptionText("Contact:", agreement.ContactId)
    .AddRowCaptionText("Bank Account:", agreement.BankAccountId)
    .AddRowCaptionText("Open Agreement:", agreement.OpenAgreementId)
  End With
  SummaryTables.Add("Agreement", SummaryTable)

  ' Terms
  SummaryTable = SummaryTables.CreateSummaryTableInformation("Terms", "Terms",headingLevel+1,,, TestMode)
  With SummaryTable
    .AddRowCaptionCurrency("Payout Minimum:", agreement.Terms.PerPayoutAmountMinimum)
    .AddRowCaptionCurrency("Payout Maximum:", agreement.Terms.PerPayoutAmountMinimum)
    .AddRowCaptionInteger("Frequency (Days):", agreement.Terms.PerFrequencyDays)
    .AddRowCaptionCurrency("Maximum per Frequency:", agreement.Terms.PerFrequencyAmountMaximum)
  End With
  SummaryTables.Add("Terms", SummaryTable)

  Return SummaryTables

End Function

Private Function Split_Contact(contact As ISBankInterfaceResponse_Split_Contact,
                               serviceLogSourceObjects As finServiceLogSourceObjects,
                               isDeleted As Boolean) As ISSummaryTables

  Dim Account As finAccount
  Dim Client As finClient
  Dim Kvli As ISKeyValueListItem
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables
  Dim Warnings As String

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Get Related Account or Client
  finBL.BankingInterface.Service_Split.GetRelatedRecord(contact, Account, Client)

  SummaryTable = SummaryTables.CreateSummaryTableInformation("Contact Details", "Contact",2,,, TestMode)
  With SummaryTable
    ' Related Account/ Client
    If Account IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Linked Account:", Account.AccountId, Account.Name)
        .Cells(1).HyperlinkSetFormShow("Accounts", Account.AccountId, "Payments")
      End With
    ElseIf Client IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Linked Client:", Client.ClientId, Client.Name)
        .Cells(1).HyperlinkSetFormShow("Clients", Client.ClientId, "Tax & Banking")
      End With
    End If

    ' Customer Information
    .AddRowCaptionText("Id:", Contact.Id)
    .AddRowCaptionText("Reference:", Contact.Reference)
    .AddRowCaptionText("Type:", Contact.TypeText)
    .AddRowCaptionText("Name:", Contact.Name)
    .AddRowCaptionText("Email:", Contact.Email)

    .AddRowCaptionText("Anyone Account:", Contact.AnyoneAccountId)
    .AddRowCaptionText("Bank Connection:", Contact.BankConnectionId)
    
    ' Meta data
    If Contact.MetaData.Count <> 0 Then
      For Each Kvli In Contact.MetaData
        Select Case UCase(kvli.Key)
          Case "SOURCE_TYPE", "SOURCE_ID"
            ' Ignore standard Keys
          Case Else
            .AddRowCaptionText(kvli.Key & ":", kvli.ValueToString)
          End Select
      Next
    End If
    
    ' Alert if Deleted
    If isDeleted Then
      .TextBefore = "{{alert|Contact is now DELETED.|true}}"
    End If      

    ' Warnings
    Warnings = ""
    If Account Is Nothing AndAlso Client Is Nothing Then
      Warnings &= "{{warning|Contact not found.|true}}"
    End If
    If serviceLogSourceObjects.Account IsNot Nothing Then
      If Account Is Nothing Then
      ElseIf serviceLogSourceObjects.Account.Pk <> Account.Pk Then
        Warnings &= "{{warning|The Account linked to the Contact DOES NOT match the requested Account.|True}}"
      End If
    ElseIf serviceLogSourceObjects.Client IsNot Nothing Then
      If Client Is Nothing Then
      ElseIf serviceLogSourceObjects.Client.Pk <> Client.Pk Then
        Warnings &= "{{warning|The Client linked to the Contact DOES NOT match the requested Client.|True}}"
      End If
    End If
    .TextAfter = Warnings
  End With
  SummaryTables.Add("Contact", SummaryTable)

  ' Pay ID Details
  If Contact.PayIdDetails.HasData Then
    SummaryTable = SummaryTables.CreateSummaryTableInformation("PayID Details", "PayID",3,,, TestMode)
    With SummaryTable
      .Rows.AddCaptionText("State:", Contact.PayIdDetails.StateText).BackgroundColour = Contact.PayIdDetails.StateHtmlColour
      .AddRowCaptionText(Contact.PayIdDetails.AliasTypeText & ":", Contact.PayIdDetails.AliasValue)
      .AddRowCaptionText("Name:", Contact.PayIdDetails.AliasName)

      ' Actions
      If Not isDeleted Then
        With .Actions
          Select Case Contact.PayIdDetails.State
            Case iseBankInterface_Split_PayIdState.Active
              .AddApplicationShortcutUrl("Refresh", "Refresh", String.Format("App://Global?Type=BankingInterface.Split.RefreshReceivableContact&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
              If finBL.CurrentUser.Permissions.Allow("Banking.BankInterface.PayID.Disable") Then
                .AddApplicationShortcutUrl("Disable", "Disable", String.Format("App://Global?Type=BankingInterface.Split.DisableReceivableContact&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
              End If

            Case iseBankInterface_Split_PayIdState.Disabled
              .AddApplicationShortcutUrl("Refresh", "Refresh", String.Format("App://Global?Type=BankingInterface.Split.RefreshReceivableContact&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
              If finBL.CurrentUser.Permissions.Allow("Banking.BankInterface.PayID.Enable") Then
                .AddApplicationShortcutUrl("Enable", "Enable", String.Format("App://Global?Type=BankingInterface.Split.EnableReceivableContact&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
              End If
              If finBL.CurrentUser.Permissions.Allow("Banking.BankInterface.PayID.Delete") Then
                .AddApplicationShortcutUrl("Delete", "Delete", String.Format("App://Global?Type=BankingInterface.Split.DeleteReceivableContact&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
              End If
  
            Case iseBankInterface_Split_PayIdState.Pending
              .AddApplicationShortcutUrl("Activate", "Activate", String.Format("App://Global?Type=BankingInterface.Split.ActivateReceivableContact&ServiceLogPk={0}", ServiceLogs(0).Pk), True).ShowInWebInterfaces = True
          End Select  
        End With
      End If  
    End With
    SummaryTables.Add("PayID", SummaryTable)
  End If

  ' Bank Account
  If Contact.BankAccount.HasData Then
    SummaryTable = SummaryTables.CreateSummaryTableInformation("Bank Account", "BankAccount",3,,, TestMode)
    With SummaryTable
      ' Bank Information
      .AddRowCaptionText("Id:", Contact.BankAccount.Id)
      .AddRowCaptionText("Bank:", Contact.BankAccount.BankName)
      .AddRowCaptionText(finBL.CurrentCountry.Terminology(isefinCountryTerminology.BankSortCode, True) & ":", Contact.BankAccount.BranchCode)
      .AddRowCaptionText("Account Number:", Contact.BankAccount.AccountNumber)
      .AddRowCaptionText("State:", Contact.BankAccount.StateText)

      ' IAV Status
      Select Case Contact.BankAccount.IavStatus
        Case iseBankInterface_Split_IavStatus.Undefined
        Case Else
          .AddRowCaptionText("IAV Status:", Contact.BankAccount.IavStatusText)
          .AddRowCaptionText("IAV Provider:", Contact.BankAccount.IavProvider)
      End Select

      ' Warnings
      Warnings = ""
      If Contact.BankAccount.CreditsBlocked Then
        Warnings &= "{{info|Credits blocked.|True}}"
      End If
      If Contact.BankAccount.DebitsBlocked Then
        Warnings &= "{{info|Debits blocked.|True}}"
      End If
      .TextAfter = Warnings
    End With
    SummaryTables.Add("BankAccount", SummaryTable)
  End If

'  ' Links
'  If Contact.Links.Count <> 0 Then
'    SummaryTable = SummaryTables.CreateSummaryTableInformation("Links", "Links",3,,, TestMode)
'    With SummaryTable
'      For Each Kvli In Contact.Links
'        .AddRowCaptionTextWebsiteUrl(finBL.Runtime.TextUtilities.ProperCase(Replace(kvli.Key, "_", " ")) & ":", kvli.ValueToString)
'      Next
'    End With
'    SummaryTables.Add("Links", SummaryTable)
'  End If

  Return SummaryTables

End Function

Private Function Split_ContactAgreements(agreements As ISBankInterfaceResponse_Split_Agreements) As ISSummaryTables

  Dim Agreement As ISBankInterfaceResponse_Split_Agreement
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  For Each Agreement In agreements
    SummaryTables.AppendSummaryTables(Me.Split_ContactAgreement(Agreement))
  Next

  Return SummaryTables

End Function

Private Function Split_ContactAgreement(agreement As ISBankInterfaceResponse_Split_Agreement) As ISSummaryTables

  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  SummaryTable = SummaryTables.CreateSummaryTableInformation("Agreement " & agreement.Reference, "Agreement",3,,, TestMode)
  With SummaryTable
    .AddRowCaptionText("Status:", agreement.StatusText,,, agreement.StatusReason)
    .AddRowCaptionDateTime("Created:", agreement.CreatedAtDate)
    .AddRowCaptionDateTime("Responded:", agreement.RespondedAtDate)

    .AddRowCaptionText("Initiator:", agreement.InitiatorId)
    .AddRowCaptionText("Authoriser:", agreement.AuthoriserId)
'    .AddRowCaptionText("Bank Account:", agreement.BankAccountId)
    .AddRowCaptionText("Open Agreement:", agreement.OpenAgreementId)
  End With
  SummaryTables.Add("Agreement", SummaryTable)

  ' Terms
  SummaryTable = SummaryTables.CreateSummaryTableInformation("Terms", "Terms",4,,, TestMode)
  With SummaryTable
    .AddRowCaptionCurrency("Payout Minimum:", agreement.Terms.PerPayoutAmountMinimum)
    .AddRowCaptionCurrency("Payout Maximum:", agreement.Terms.PerPayoutAmountMinimum)
    .AddRowCaptionInteger("Frequency (Days):", agreement.Terms.PerFrequencyDays)
    .AddRowCaptionCurrency("Maximum per Frequency:", agreement.Terms.PerFrequencyAmountMaximum)
  End With
  SummaryTables.Add("Terms", SummaryTable)

  Return SummaryTables

End Function

Private Function Split_MakePayment_Request(response As ISBankInterfaceResponse_Split_MakePayment,
                                           serviceLogSourceObjects As finServiceLogSourceObjects) As ISSummaryTables

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

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Get Information
  If finBL.BankAccounts.ExistsPk(response.Request_MakePayment.BankAccountPk) Then
    BankAccount = finBL.BankAccounts.ItemByPk(response.Request_MakePayment.BankAccountPk)
  Else
    BankAccount = Nothing
  End If
  If serviceLogSourceObjects.BankTransactionView IsNot Nothing Then
    Account = serviceLogSourceObjects.BankTransactionView.AccountTransactions(0).Account
  Else
    Account = Nothing
  End If

  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Request", 2, , , TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Date:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
    .AddRowCaptionCodeDescription("Bank Account:", BankAccount.Pk, finBL.BankAccounts, False)
    '.AddRowCaptionText("Zepto Bank Account:", response.Request_MakePayment.YourBankAccountId)
    If serviceLogSourceObjects.BankTransactionView IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Bank Transaction:", serviceLogSourceObjects.BankTransactionView.BankTransactionPk.ToString(), serviceLogSourceObjects.BankTransactionView.ElementTypeText)
        .Cells(1).HyperlinkSetFormShow("BankTransactionView", serviceLogSourceObjects.BankTransactionView.BankTransactionPk.ToString())
      End With
    End If
  End With
  SummaryTables.Add("Request", SummaryTable)

  SummaryTable = SummaryTables.CreateSummaryTableInformation("Payment", "Transaction", 3, , , TestMode)
  With SummaryTable
    .AddRowCaptionDate("Date:", response.Request_MakePayment.MaturesAtDate)
    If Account IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Account:", Account.AccountId, Account.Name)
        .Cells(1).HyperlinkSetFormShow("Accounts", Account.AccountId)
      End With
    End If
    .AddRowCaptionText("Contact Id:", response.Request_MakePayment.Payouts(0).RecipientContactId)
    .AddRowCaptionCurrency("Amount:", response.Request_MakePayment.Payouts(0).Amount, True)
    .AddRowCaptionText("Description:", response.Request_MakePayment.Payouts(0).Description)
  End With
  SummaryTables.Add("Transaction", SummaryTable)

  Return SummaryTables

End Function

Private Function Split_MakePayment_Status(response As ISBankInterfaceResponse_Split_MakePayment,
                                          serviceLogSourceObjects As finServiceLogSourceObjects) As ISSummaryTables

  Dim BankTransactionView As finBankTransactionView
  Dim SplitCreditTransaction As ISBankInterfaceResponse_Split_Transaction
  Dim SplitDebitTransaction As ISBankInterfaceResponse_Split_Transaction
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Get Information
  If serviceLogSourceObjects.BankTransactionView IsNot Nothing Then
    BankTransactionView = serviceLogSourceObjects.BankTransactionView
  Else
    BankTransactionView = Nothing
  End If

  ' Get Latest Split Transactions
  Me.GetLatestTransactions(SplitCreditTransaction, SplitDebitTransaction)

  SummaryTable = SummaryTables.CreateSummaryTableInformation("Overall Status", "Status", 2, , , TestMode)
  With SummaryTable
    If BankTransactionView Is Nothing Then
      .AddRowCaptionText("Status:", serviceLogs(0).ResponseStatusText)
    Else
      With .Rows.AddCaptionText("Status:", BankTransactionView.BankInterfaceStatusText)
        Select Case BankTransactionView.BankInterfaceStatus
          Case isefinBankTransactionBankInterfaceStatus.Aborted
            .BackgroundColour = "gold"
          Case isefinBankTransactionBankInterfaceStatus.Failed, isefinBankTransactionBankInterfaceStatus.SendFailed
            .BackgroundColour = "pink"
          Case isefinBankTransactionBankInterfaceStatus.Pending, isefinBankTransactionBankInterfaceStatus.Queued
            .BackgroundColour = "orange"
          Case isefinBankTransactionBankInterfaceStatus.Success
            .BackgroundColour = "lightgreen"
        End Select
      End With
      .AddRowCaptionText("Reference:", BankTransactionView.BankInterfaceReference)
      If BankTransactionView.BankInterfaceSettlementDate <> Nothing Then
        .AddRowCaptionDate("Settlement Date:", BankTransactionView.BankInterfaceSettlementDate)
        .AddRowCaptionText("Settlement Reference:", BankTransactionView.BankInterfaceSettlementReference)
      End If
    End If

    ' Actions
    With .actions
      If BankTransactionView IsNot Nothing AndAlso BankTransactionView.CanSendViaBankInterface Then
        .AddApplicationShortcutUrl("Resend", "Resend", String.Format("App://Global?Type=BankingInterface.Send&BankTransactionPk={0}", bankTransactionView.BankTransactionPk), True).ShowInWebInterfaces = True
      End If

      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("Status", SummaryTable)

  ' Debit Transaction
  If SplitDebitTransaction IsNot Nothing Then
    SummaryTable = SummaryTables.CreateSummaryTableInformation("Zepto Transaction", "Transaction", 3, , , TestMode)
    With SummaryTable
      .AddRowCaptionText("Type:", SplitDebitTransaction.TypeText)
      .AddRowCaptionText("Category:", SplitDebitTransaction.CategoryText)
      .AddRowCaptionDateTime("Created:", SplitDebitTransaction.CreatedAtDate)
      .AddRowCaptionText("Bank Account Id:", SplitDebitTransaction.BankAccountId)
      .AddRowCaptionText("Reference:", SplitDebitTransaction.Reference)
      .AddRowCaptionText("Bank Reference:", SplitDebitTransaction.BankReference)
      .AddRowCaptionText("Status:", SplitDebitTransaction.StatusText)
      .AddRowCaptionText("Failure Reason:", SplitDebitTransaction.FailureReasonResolved)
      .AddRowCaptionDateTime("Matures:", SplitDebitTransaction.MaturesAtDate)
      .AddRowCaptionDateTime("Cleared:", SplitDebitTransaction.ClearedAtDate)

      .Rows.AddText("Other Party", iseSummaryTableCellClass.CaptionBold)
      .AddRowCaptionText("Contact Id:", SplitDebitTransaction.PartyContactId)
      .AddRowCaptionText("Name:", SplitDebitTransaction.PartyName)
      .AddRowCaptionText("Nickname:", SplitDebitTransaction.PartyNickname)
      .AddRowCaptionText("Bank Reference:", SplitDebitTransaction.PartyBankRef)
    End With
    SummaryTables.Add("Transaction", SummaryTable)
  End If

  Return SummaryTables

End Function

Private Function Split_RequestPayment_Request(response As ISBankInterfaceResponse_Split_RequestPayment,
                                              serviceLogSourceObjects As finServiceLogSourceObjects) As ISSummaryTables

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

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Get Information
  If finBL.BankAccounts.ExistsPk(response.Request_RequestPayment.BankAccountPk) Then
    BankAccount = finBL.BankAccounts.ItemByPk(response.Request_RequestPayment.BankAccountPk)
  Else
    BankAccount = Nothing
  End If
  If serviceLogSourceObjects.BankTransactionView IsNot Nothing Then
    Account = serviceLogSourceObjects.BankTransactionView.AccountTransactions(0).Account
  Else
    Account = Nothing
  End If

  SummaryTable = SummaryTables.CreateSummaryTableInformation("", "Request", 2, , , TestMode)
  With SummaryTable
    .AddRowCaptionUtcDateTimeWithTimeZone("Date:", response.RequestUtcDate, finBL.Settings.TimeZoneId)
    .AddRowCaptionCodeDescription("Bank Account:", BankAccount.Pk, finBL.BankAccounts, False)
    '.AddRowCaptionText("Zepto Bank Account:", response.Request_RequestPayment.YourBankAccountId)
    If serviceLogSourceObjects.BankTransactionView IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Bank Transaction:", serviceLogSourceObjects.BankTransactionView.BankTransactionPk.ToString(), serviceLogSourceObjects.BankTransactionView.ElementTypeText)
        .Cells(1).HyperlinkSetFormShow("BankTransactionView", serviceLogSourceObjects.BankTransactionView.BankTransactionPk.ToString())
      End With
    End If
  End With
  SummaryTables.Add("Request", SummaryTable)

  SummaryTable = SummaryTables.CreateSummaryTableInformation("Payment Request", "Transaction", 3, , , TestMode)
  With SummaryTable
    .AddRowCaptionDate("Date:", response.Request_RequestPayment.MaturesAtDate)
    If Account IsNot Nothing Then
      With .Rows.AddCaptionCodeDescription("Account:", Account.AccountId, Account.Name)
        .Cells(1).HyperlinkSetFormShow("Accounts", Account.AccountId)
      End With
    End If
    .AddRowCaptionText("Contact Id:", response.Request_RequestPayment.ContactId)
    .AddRowCaptionCurrency("Amount:", response.Request_RequestPayment.Amount, True)
    .AddRowCaptionText("Description:", response.Request_RequestPayment.Description)
  End With
  SummaryTables.Add("Transaction", SummaryTable)

  Return SummaryTables

End Function

Private Function Split_RequestPayment_Status(response As ISBankInterfaceResponse_Split_RequestPayment,
                                             serviceLogSourceObjects As finServiceLogSourceObjects) As ISSummaryTables

  Dim BankTransactionView As finBankTransactionView
  Dim SplitCreditTransaction As ISBankInterfaceResponse_Split_Transaction
  Dim SplitDebitTransaction As ISBankInterfaceResponse_Split_Transaction
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()

  ' Get Information
  If serviceLogSourceObjects.BankTransactionView IsNot Nothing Then
    BankTransactionView = serviceLogSourceObjects.BankTransactionView
  Else
    BankTransactionView = Nothing
  End If

  ' Get Latest Split Transactions
  Me.GetLatestTransactions(SplitCreditTransaction, SplitDebitTransaction)

  SummaryTable = SummaryTables.CreateSummaryTableInformation("Overall Status", "Status", 2, , , TestMode)
  With SummaryTable
    If BankTransactionView Is Nothing Then
      .AddRowCaptionText("Status:", serviceLogs(0).ResponseStatusText)
    Else
      With .Rows.AddCaptionText("Status:", BankTransactionView.BankInterfaceStatusText)
        Select Case BankTransactionView.BankInterfaceStatus
          Case isefinBankTransactionBankInterfaceStatus.Aborted
            .BackgroundColour = "gold"
          Case isefinBankTransactionBankInterfaceStatus.Failed, isefinBankTransactionBankInterfaceStatus.SendFailed
            .BackgroundColour = "pink"
          Case isefinBankTransactionBankInterfaceStatus.Pending, isefinBankTransactionBankInterfaceStatus.Queued
            .BackgroundColour = "orange"
          Case isefinBankTransactionBankInterfaceStatus.Success
            .BackgroundColour = "lightgreen"
        End Select
      End With
      .AddRowCaptionText("Reference:", BankTransactionView.BankInterfaceReference)
      If BankTransactionView.BankInterfaceSettlementDate <> Nothing Then
        .AddRowCaptionDate("Settlement Date:", BankTransactionView.BankInterfaceSettlementDate)
        .AddRowCaptionText("Settlement Reference:", BankTransactionView.BankInterfaceSettlementReference)
      End If
    End If

    ' Actions
    With .actions
      If BankTransactionView IsNot Nothing AndAlso BankTransactionView.CanSendViaBankInterface Then
        .AddApplicationShortcutUrl("Resend", "Resend", String.Format("App://Global?Type=BankingInterface.Send&BankTransactionPk={0}", bankTransactionView.BankTransactionPk), True).ShowInWebInterfaces = True
      End If

      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("Status", SummaryTable)

  ' Credit Transaction
  If SplitCreditTransaction IsNot Nothing Then
    SummaryTable = SummaryTables.CreateSummaryTableInformation("Zepto Transaction", "Transaction", 3, , , TestMode)
    With SummaryTable
      .AddRowCaptionText("Type:", SplitCreditTransaction.TypeText)
      .AddRowCaptionText("Category:", SplitCreditTransaction.CategoryText)
      .AddRowCaptionDateTime("Created:", SplitCreditTransaction.CreatedAtDate)
      .AddRowCaptionText("Bank Account Id:", SplitCreditTransaction.BankAccountId)
      .AddRowCaptionText("Reference:", SplitCreditTransaction.Reference)
      .AddRowCaptionText("Bank Reference:", SplitCreditTransaction.BankReference)
      .AddRowCaptionText("Status:", SplitCreditTransaction.StatusText)
      .AddRowCaptionText("Failure Reason:", SplitCreditTransaction.FailureReasonResolved)
      .AddRowCaptionDateTime("Matures:", SplitCreditTransaction.MaturesAtDate)
      .AddRowCaptionDateTime("Cleared:", SplitCreditTransaction.ClearedAtDate)

      .Rows.AddText("Other Party", iseSummaryTableCellClass.CaptionBold)
      .AddRowCaptionText("Contact Id:", SplitCreditTransaction.PartyContactId)
      .AddRowCaptionText("Name:", SplitCreditTransaction.PartyName)
      .AddRowCaptionText("Nickname:", SplitCreditTransaction.PartyNickname)
      .AddRowCaptionText("Bank Reference:", SplitCreditTransaction.PartyBankRef)
    End With
    SummaryTables.Add("Transaction", SummaryTable)
  End If

  Return SummaryTables

End Function

Private Function Split_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 Sub GetLatestTransactions(ByRef splitCreditTransaction As ISBankInterfaceResponse_Split_Transaction,
                                  ByRef splitDebitTransaction As ISBankInterfaceResponse_Split_Transaction)

  Dim ServiceLog As ISServiceLog
  Dim SplitTransaction As ISBankInterfaceResponse_Split_Transaction

  ' Initialise ByRef
  splitCreditTransaction = Nothing
  splitDebitTransaction = Nothing

  ' Find Latest Split Transactions
  For Each ServiceLog In ServiceLogs
    If Servicelog.RequestStatus = iseAuditLogStatus.Success Then
      Select Case ServiceLog.ExResponse.GetType()
        Case GetType(ISBankInterfaceResponse_Split_ListTransactions)
          With DirectCast(ServiceLog.ExResponse, ISBankInterfaceResponse_Split_ListTransactions)
            For Each SplitTransaction In .Transactions
              If SplitTransaction.ParentReference = serviceLogs(0).ResponseReference Then
                If SplitTransaction.Type = iseBankInterface_Split_TransactionType.Credit Then
                  SplitCreditTransaction = SplitTransaction
                Else
                  SplitDebitTransaction = SplitTransaction
                End If
              End If
            Next
          End With

        Case GetType(ISBankInterfaceResponse_Split_Webhook)
          With DirectCast(ServiceLog.ExResponse, ISBankInterfaceResponse_Split_Webhook)
            If .Data.ItemAsTransaction(0) IsNot Nothing Then
              If .Data.ItemAsTransaction(0).Type = iseBankInterface_Split_TransactionType.Credit Then
                SplitCreditTransaction = .Data.ItemAsTransaction(0)
              Else
                SplitDebitTransaction = .Data.ItemAsTransaction(0)
              End If
            End If
          End With
      End Select
    End If
  Next

End Sub