/// <summary>
        /// Redeems the voucher.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="applicationVersion">The application version.</param>
        /// <param name="voucherCode">The voucher code.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <RedeemVoucherResponseMessage> RedeemVoucher(String accessToken,
                                                                       String applicationVersion,
                                                                       String voucherCode,
                                                                       CancellationToken cancellationToken)
        {
            RedeemVoucherResponseMessage response = null;
            String requestUri = this.BuildRequestUrl($"/api/vouchers?applicationVersion={applicationVersion}&voucherCode={voucherCode}");

            try
            {
                // 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.PutAsync(requestUri, new StringContent(string.Empty), 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 <RedeemVoucherResponseMessage>(content);
            }
            catch (Exception ex)
            {
                // An exception has occurred, add some additional information to the message
                Exception exception = new Exception($"Error redeeming voucher with voucher code {voucherCode}.", ex);

                throw exception;
            }

            return(response);
        }
        public async Task WhenIRedeemTheFollowingVouchersTheBalanceWillBeAsExpected(Table table)
        {
            foreach (TableRow tableRow in table.Rows)
            {
                EstateDetails estateDetails = this.TestingContext.GetEstateDetails(tableRow);

                String  operatorIdentifier = SpecflowTableHelper.GetStringRowValue(tableRow, "OperatorName");
                Guid    transactionId      = Guid.Parse(SpecflowTableHelper.GetStringRowValue(tableRow, "TransactionId"));
                Decimal balance            = SpecflowTableHelper.GetDecimalValue(tableRow, "Balance");

                (Guid transactionId, Decimal value, String voucherCode, Guid voucherId)voucher = estateDetails.GetVoucher(operatorIdentifier, transactionId);

                // Build URI
                String uri = $"api/vouchers?applicationVersion=1.0.0&voucherCode={voucher.voucherCode}";

                String accessToken = estateDetails.GetVoucherRedemptionUserToken(operatorIdentifier);

                StringContent content = new StringContent(String.Empty);

                this.TestingContext.DockerHelper.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                HttpResponseMessage response = await this.TestingContext.DockerHelper.HttpClient.PutAsync(uri, content, CancellationToken.None).ConfigureAwait(false);

                response.IsSuccessStatusCode.ShouldBeTrue();

                RedeemVoucherResponseMessage redeemVoucherResponse = JsonConvert.DeserializeObject <RedeemVoucherResponseMessage>(await response.Content.ReadAsStringAsync().ConfigureAwait(false));

                redeemVoucherResponse.Balance.ShouldBe(balance);
                redeemVoucherResponse.VoucherCode.ShouldBe(voucher.voucherCode);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Redeems the voucher.
        /// </summary>
        /// <param name="voucherCode">The voucher code.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        private async Task <RedeemVoucherResponseMessage> RedeemVoucher(String voucherCode,
                                                                        CancellationToken cancellationToken)
        {
            await this.Database.InsertLogMessage(DatabaseContext.CreateInformationLogMessage($"About to redeem voucher for voucher code {voucherCode}"));

            RedeemVoucherResponseMessage voucherRedemptionResponse = null;

            await
            this.Database.InsertLogMessage(DatabaseContext
                                           .CreateInformationLogMessage($"Message Sent to Host Application version [{this.Device.GetSoftwareVersion()}] Voucher code [{voucherCode}]"));

            voucherRedemptionResponse =
                await this.VoucherManagerAclClient.RedeemVoucher(App.TokenResponse.AccessToken, this.Device.GetSoftwareVersion(), voucherCode, cancellationToken);

            String responseJson = JsonConvert.SerializeObject(voucherRedemptionResponse);

            await this.Database.InsertLogMessage(DatabaseContext.CreateInformationLogMessage($"Message Rcv from Host [{responseJson}]"));

            if (voucherRedemptionResponse.ResponseCode != "0000")
            {
                return(null);
            }

            return(voucherRedemptionResponse);
        }
        public void ModelFactory_ConvertFrom_RedeemVoucherResponse_NullValue_IsConverted()
        {
            ModelFactory modelFactory = new ModelFactory();

            RedeemVoucherResponse        model = null;
            RedeemVoucherResponseMessage dto   = modelFactory.ConvertFrom(model);

            dto.ShouldBeNull();
        }
Beispiel #5
0
        /// <summary>
        /// Handles the RedeemVoucherButtonClick event of the RedemptionVoucherDetailsPage control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs" /> instance containing the event data.</param>
        private async void RedemptionVoucherDetailsPage_RedeemVoucherButtonClick(Object sender,
                                                                                 EventArgs e)
        {
            RedeemVoucherResponseMessage redemptionResponse = await this.RedeemVoucher(this.RedemptionVoucherDetailsViewModel.VoucherCode, CancellationToken.None);

            // TODO: View model with balance
            if (redemptionResponse == null)
            {
                await Application.Current.MainPage.Navigation.PushAsync((Page)this.RedemptionFailedPage);
            }
            else
            {
                await Application.Current.MainPage.Navigation.PushAsync((Page)this.RedemptionSuccessPage);
            }
        }
        public void ModelFactory_ConvertFrom_RedeemVoucherResponse_IsConverted()
        {
            ModelFactory modelFactory = new ModelFactory();

            RedeemVoucherResponse        model = TestData.RedeemVoucherResponseModel;
            RedeemVoucherResponseMessage dto   = modelFactory.ConvertFrom(model);

            dto.ShouldNotBeNull();
            dto.ContractId.ShouldBe(model.ContractId);
            dto.VoucherCode.ShouldBe(model.VoucherCode);
            dto.EstateId.ShouldBe(model.EstateId);
            dto.Balance.ShouldBe(model.Balance);
            dto.ExpiryDate.ShouldBe(model.ExpiryDate);
            dto.ResponseMessage.ShouldBe(model.ResponseMessage);
            dto.ResponseCode.ShouldBe(model.ResponseCode);
        }
        /// <summary>
        /// Converts from.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public RedeemVoucherResponseMessage ConvertFrom(RedeemVoucherResponse model)
        {
            if (model == null)
            {
                return(null);
            }

            RedeemVoucherResponseMessage responseMessage = new RedeemVoucherResponseMessage
            {
                VoucherCode     = model.VoucherCode,
                Balance         = model.Balance,
                ResponseMessage = model.ResponseMessage,
                ContractId      = model.ContractId,
                EstateId        = model.EstateId,
                ExpiryDate      = model.ExpiryDate,
                ResponseCode    = model.ResponseCode
            };

            return(responseMessage);
        }