private scpQueryRequest CreateCapitaQueryRequest( int customerSiteId, int customerScpId, int hmacKeyId, string secretKey, string scpUniqueReference, string callingApplicationTransactionReference) { scpQueryRequest queryRequest = new scpQueryRequest { siteId = customerSiteId, scpReference = scpUniqueReference, credentials = new credentials { subject = new subject() { subjectType = subjectType.CapitaPortal, identifier = customerScpId, systemCode = systemCode.SCP }, requestIdentification = new requestIdentification() { uniqueReference = callingApplicationTransactionReference, timeStamp = DateTime.UtcNow.ToString("yyyyMMddhhmmss") }, signature = new signature() { algorithm = algorithm.Original, hmacKeyID = hmacKeyId } } }; string credentialsToHash = CapitaApiHelpers.GetCredentialsToHash(queryRequest.credentials); queryRequest.credentials.signature.digest = CapitaApiHelpers.CalculateDigest(secretKey, credentialsToHash); return(queryRequest); }
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)); }