コード例 #1
0
        /// <summary>
        /// Performs the mobile topup.
        /// </summary>
        /// <returns></returns>
        private async Task <Boolean> PerformMobileTopup()
        {
            SaleTransactionRequestMessage saleTransactionRequestMessage = new SaleTransactionRequestMessage
            {
                Amount = this.MobileTopupPerformTopupViewModel.TopupAmount,
                CustomerAccountNumber = this.MobileTopupPerformTopupViewModel.CustomerMobileNumber,
                DeviceIdentifier      = this.Device.GetDeviceIdentifier(),
                OperatorIdentifier    = this.MobileTopupPerformTopupViewModel.OperatorName,
                TransactionDateTime   = DateTime.Now,
                TransactionNumber     = "1"                                                           // TODO: Need to hold txn number somewhere
            };

            String requestJson = JsonConvert.SerializeObject(saleTransactionRequestMessage);

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

            SaleTransactionResponseMessage response =
                await this.TransactionProcessorAclClient.PerformSaleTransaction(App.TokenResponse.AccessToken, saleTransactionRequestMessage, CancellationToken.None);

            String responseJson = JsonConvert.SerializeObject(response);

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

            if (response.ResponseCode != "0000")
            {
                return(false);
            }

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Performs the logon transaction.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="saleTransactionRequest"></param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <SaleTransactionResponseMessage> PerformSaleTransaction(String accessToken,
                                                                                  SaleTransactionRequestMessage saleTransactionRequest,
                                                                                  CancellationToken cancellationToken)
        {
            SaleTransactionResponseMessage response = null;
            String requestUri = this.BuildRequestUrl("/api/transactions");

            try
            {
                String requestSerialised = JsonConvert.SerializeObject(saleTransactionRequest,
                                                                       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 <SaleTransactionResponseMessage>(content);
            }
            catch (Exception ex)
            {
                // An exception has occurred, add some additional information to the message
                Exception exception = new Exception("Error posting sale transaction.", ex);

                throw exception;
            }

            return(response);
        }