Ejemplo n.º 1
0
        /// <summary>
        /// Performs the logon transaction.
        /// </summary>
        /// <exception cref="System.Exception">Error during logon transaction. Response Code [{response.ResponseCode}] Response Message [{response.ResponseMessage}]</exception>
        /// <exception cref="Exception">Error during logon transaction</exception>
        private async Task PerformLogonTransaction()
        {
            this.AnalysisLogger.TrackEvent(DebugInformationEvent.Create("About to Do Logon Transaction"));

            LogonTransactionRequestMessage logonTransactionRequestMessage = new LogonTransactionRequestMessage
            {
                DeviceIdentifier = this.Device.GetDeviceIdentifier(),
                RequireConfigurationInResponse = false,
                TransactionDateTime            = DateTime.Now,
                TransactionNumber = "1"                                                                 // TODO: Need to hold txn number somewhere
            };

            String requestJson = JsonConvert.SerializeObject(logonTransactionRequestMessage);

            this.AnalysisLogger.TrackEvent(MessageSentToHostEvent.Create(App.Configuration.TransactionProcessorACL, requestJson, DateTime.Now));

            LogonTransactionResponseMessage response =
                await this.TransactionProcessorAclClient.PerformLogonTransaction(App.TokenResponse.AccessToken, logonTransactionRequestMessage, CancellationToken.None);

            String responseJson = JsonConvert.SerializeObject(response);

            this.AnalysisLogger.TrackEvent(MessageReceivedFromHostEvent.Create(responseJson, DateTime.Now));

            if (response.ResponseCode != "0000")
            {
                throw new Exception($"Error during logon transaction. Response Code [{response.ResponseCode}] Response Message [{response.ResponseMessage}]");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Performs the logon transaction.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="logonTransactionRequest">The logon transaction request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <LogonTransactionResponseMessage> PerformLogonTransaction(String accessToken,
                                                                                    LogonTransactionRequestMessage logonTransactionRequest,
                                                                                    CancellationToken cancellationToken)
        {
            LogonTransactionResponseMessage response = null;
            String requestUri = this.BuildRequestUrl("/api/transactions");

            try
            {
                String requestSerialised = JsonConvert.SerializeObject(logonTransactionRequest,
                                                                       new JsonSerializerSettings
                {
                    TypeNameHandling = TypeNameHandling.All
                });

                StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json");

                // Add the access token to the client headers
                this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                // Make the Http Call here
                HttpResponseMessage httpResponse = await this.HttpClient.PostAsync(requestUri, httpContent, cancellationToken);

                // Process the response
                String content = await this.HandleResponse(httpResponse, cancellationToken);

                // call was successful so now deserialise the body to the response object
                response = JsonConvert.DeserializeObject <LogonTransactionResponseMessage>(content);
            }
            catch (Exception ex)
            {
                // An exception has occurred, add some additional information to the message
                Exception exception = new Exception("Error posting logon transaction.", ex);

                throw exception;
            }

            return(response);
        }