public CapitaInvokeResponse InvokeRequest(CapitaInvokeRequest request)
        {
            scpSimpleInvokeRequest scpInvokeRequest = CreateCapitaInvokeRequest(request);
            CapitaInvokeResponse   response         = new CapitaInvokeResponse();

            using (scpClient capitaClient = new scpClient("CapitaScpSoap", Shared.Capita.Default.CapitaWebServiceUrl))
            {
                try
                {
                    scpInvokeResponse scpResponse  = capitaClient.scpSimpleInvoke(scpInvokeRequest);
                    string            errorMessage = string.Empty;
                    if (scpResponse?.invokeResult != null)
                    {
                        if (scpResponse.requestId == request.UniqueReference)
                        {
                            if (scpResponse.transactionState == transactionState.INVALID_REFERENCE)
                            {
                                errorMessage = "Transaction aborted! It may be because of session time out or some other technical glitch from Capita";
                            }
                            else
                            {
                                response.ScpReference = scpResponse.scpReference;
                                if (scpResponse.invokeResult.status == status.SUCCESS)
                                {
                                    response.RedirectUrl = (string)scpResponse.invokeResult.Item;
                                }
                                else
                                {
                                    errorDetails item = scpResponse.invokeResult.Item as errorDetails;
                                    errorMessage = item != null ? $"ErrorId: {item.errorId}, Message: {item.errorMessage}" : "Transaction failed for some unknown reason.";
                                }
                            }
                        }
                        else
                        {
                            errorMessage = "Transaction is being invalidated b/c the unique reference returned from Capita is wrong.";
                        }
                    }

                    if (!string.IsNullOrEmpty(errorMessage))
                    {
                        response.Error        = true;
                        response.ErrorMessage = errorMessage;
                    }
                }
                catch (Exception ex)
                {
                    response.Error        = true;
                    response.ErrorMessage = "Fatal error";
                }

                return(response);
            }
        }
        protected async Task <PaymentAuthorizationResponse> CheckAuthorizationInternal(
            PaymentProviderConfiguration configuration,
            string uniqueIdentifier, string scpUniqueReference)
        {
            int    siteId;
            int    scpId;
            int    hmacKeyId;
            string hmacSecretKey;

            int.TryParse(configuration.AccountIdentifer, out siteId);
            int.TryParse(configuration.SubAccountNumber, out scpId);

            CapitaApiHelpers.GetHmacIdAndSecretKey(configuration.SharedSecret, out hmacKeyId, out hmacSecretKey);

            scpQueryRequest         request = CreateCapitaQueryRequest(siteId, scpId, hmacKeyId, hmacSecretKey, scpUniqueReference, uniqueIdentifier);
            scpSimpleQueryResponse1 response;

            try
            {
                using (CapitaSimple.scpClient capitaClient = new scpClient("CapitaScpSoap", Shared.Capita.Default.CapitaWebServiceUrl))
                {
                    try
                    {
                        response = await capitaClient.scpSimpleQueryAsync(request);
                    }
                    catch (Exception ex)
                    {
                        this.Logger.CreateEntry(typeof(CapitaApiProvider), LogLevel.Error, $"Token:{uniqueIdentifier},ProviderToken:{scpUniqueReference}", ex);
                        return(new PaymentAuthorizationResponse(false, PaymentAuthorizationResult.ErrorUnknownStatus, 0, "Error occurred: Provider returned an error in response", null));
                    }
                }
            }
            //This is a quick fix to cover the scenario where we're calling from AzureFunction and AzureFunction does not have any app.config
            //So we need to build the bindings and endpoint in the code
            catch (InvalidOperationException invalidOperationException)
            {
                // Create endpoint address gathered from functions app settings
                var address = new EndpointAddress(Shared.Capita.Default.CapitaWebServiceUrl);

                // Create binding to match the client proxy configuration
                var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
                binding.Security.Mode = BasicHttpSecurityMode.Transport;

                using (CapitaSimple.scpClient capitaClient = new scpClient(binding, address))
                {
                    try
                    {
                        response = await capitaClient.scpSimpleQueryAsync(request);
                    }
                    catch (Exception ex)
                    {
                        this.Logger.CreateEntry(typeof(CapitaApiProvider), LogLevel.Error, $"Token:{uniqueIdentifier},ProviderToken:{scpUniqueReference}", ex);
                        return(new PaymentAuthorizationResponse(false, PaymentAuthorizationResult.ErrorUnknownStatus, 0, "Error occurred: Provider returned an error in response", null));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }



            return(ParseResponseFromCapitaResponse(response));
        }