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); }
private scpSimpleInvokeRequest CreateCapitaInvokeRequest(CapitaInvokeRequest request) { scpSimpleInvokeRequest invokeRequest = new scpSimpleInvokeRequest { credentials = new credentials { subject = new subject() { subjectType = subjectType.CapitaPortal, identifier = request.ScpId, systemCode = systemCode.SCP }, requestIdentification = new requestIdentification() { uniqueReference = Guid.NewGuid().ToString(), timeStamp = DateTime.UtcNow.ToString("yyyyMMddHHmmss") }, signature = new signature() { algorithm = algorithm.Original, hmacKeyID = request.HmacKeyId } } }; string credentialsToHash = CapitaApiHelpers.GetCredentialsToHash(invokeRequest.credentials); invokeRequest.credentials.signature.digest = CapitaApiHelpers.CalculateDigest(request.HmacKey, credentialsToHash); invokeRequest.requestType = request.SaveCard ? requestType.payAndAutoStore : requestType.payOnly; //store card details if (request.SaveCard) { invokeRequest.additionalInstructions = new additionalInstructions() { cardholderID = request.CardHolderId }; } invokeRequest.requestId = request.UniqueReference; //ECOM – Indicates that the cardholder will be interacting directly with the web pages displayed by the SCP. //CNP – Indicates that the transaction is being processed by a third party(e.g.a telesales operative) on behalf of the cardholder. //N.B. In order to comply with bank rules and to ensure that 3 - D Secure authentication is processed correctly it is important to set this element correctly. invokeRequest.panEntryMethod = request.IsMediated ? panEntryMethod.CNP : panEntryMethod.ECOM; invokeRequest.routing = new routing() { siteId = request.SiteId, scpId = request.ScpId, returnUrl = request.ReturnUrl }; invokeRequest.sale = new simpleSale() { saleSummary = new summaryData() { description = request.PurchaseDescription, reference = request.IntegraCode, amountInMinorUnits = request.PaymentTotal, displayableReference = $"Booking reference : {request.BookingRef}" }, items = new[] { new simpleItem() { itemSummary = new summaryData() { description = request.PurchaseDescription, amountInMinorUnits = request.PaymentTotal, reference = request.IntegraCode, displayableReference = $"Booking reference : {request.BookingRef}" }, lgItemDetails = new lgItemDetails() { additionalReference = request.PurchaseId, fundCode = string.IsNullOrEmpty(request.FundCode) ? null : request.FundCode, isFundItem = string.IsNullOrEmpty(request.FundCode) ? false : true }, lineId = request.PurchaseId, tax = string.IsNullOrEmpty(request.VatCode) ? null : new taxItem() { vat = new vatItem() { vatCode = request.VatCode, vatRate = request.VatRate } } } } }; return(invokeRequest); }
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)); }