/// <summary>
            /// Get the gift card.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>A response containing the gift card information.</returns>
            private static GetGiftCardServiceResponse GetGiftCard(GetGiftCardServiceRequest request)
            {
                if (request == null)
                {
                    throw new ArgumentNullException("request");
                }

                if (string.IsNullOrWhiteSpace(request.GiftCardId))
                {
                    throw new ArgumentException("request.Id is null or empty.", "request");
                }

                var      requestGetGiftCardBalance = new GetGiftCardRealtimeRequest(request.GiftCardId);
                GiftCard card = request.RequestContext.Execute <SingleEntityDataServiceResponse <GiftCard> >(requestGetGiftCardBalance).Entity;

                GetCurrencyValueServiceResponse convertBalanceToChannelCurrencyResponse = FromGiftCardCurrency(request.RequestContext, card.BalanceInCardCurrency, card.CardCurrencyCode);

                GiftCard giftCard = new GiftCard
                {
                    Id = request.GiftCardId,
                    BalanceCurrencyCode   = convertBalanceToChannelCurrencyResponse.ToCurrencyCode,
                    Balance               = convertBalanceToChannelCurrencyResponse.RoundedConvertedAmount,
                    CardCurrencyCode      = card.CardCurrencyCode,
                    BalanceInCardCurrency = card.BalanceInCardCurrency
                };

                return(new GetGiftCardServiceResponse(giftCard));
            }
            /// <summary>
            /// Gets gift card by id.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>The <see cref="SingleEntityDataServiceResponse{GiftCard}"/> response.</returns>
            private static SingleEntityDataServiceResponse <GiftCard> GetGiftCard(GetGiftCardRealtimeRequest request)
            {
                var transactionClient = new TransactionService.TransactionServiceClient(request.RequestContext);

                string  currencyCode;
                decimal balance;

                transactionClient.GetGiftCardBalance(request.GiftCardId, out currencyCode, out balance);

                var giftCard = new GiftCard
                {
                    Id = request.GiftCardId,
                    CardCurrencyCode      = currencyCode,
                    BalanceInCardCurrency = balance
                };

                return(new SingleEntityDataServiceResponse <GiftCard>(giftCard));
            }
            /// <summary>
            /// Add balance to existing gift card.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>A response containing the gift card information.</returns>
            private static GetGiftCardServiceResponse AddToGiftCard(AddToGiftCardServiceRequest request)
            {
                if (request == null)
                {
                    throw new ArgumentNullException("request");
                }

                if (string.IsNullOrWhiteSpace(request.GiftCardId))
                {
                    throw new ArgumentException("request.Id is null or empty.", "request");
                }

                if (string.IsNullOrWhiteSpace(request.CurrencyCode))
                {
                    throw new ArgumentException("request.Id is null or empty.", "request");
                }

                if (!request.CurrencyCode.Equals(request.RequestContext.GetChannelConfiguration().Currency, StringComparison.OrdinalIgnoreCase))
                {
                    throw new PaymentException(
                              PaymentErrors.Microsoft_Dynamics_Commerce_Runtime_GiftCardCurrencyMismatch,
                              string.Format("Amount cannot be added to gift in currency different from channel currency. Currency requested: {0}", request.CurrencyCode));
                }

                // Skip validation if we are reversing operation.
                if (request.Amount > 0)
                {
                    ValidateNotAlreadyAdded(request.Transaction, request.GiftCardId);
                }

                string   giftCardCurrencyCode;
                GiftCard currentGiftCard;

                if (request.IsReversal)
                {
                    // In case of reversal (voiding gift card sales line) gift card we already know gift card currency
                    // so call to GetGiftCardBalance() can be skipped.
                    giftCardCurrencyCode = request.CardCurrencyCode;
                }
                else
                {
                    var getGiftCardBalanceRequest = new GetGiftCardRealtimeRequest(request.GiftCardId);
                    currentGiftCard      = request.RequestContext.Execute <SingleEntityDataServiceResponse <GiftCard> >(getGiftCardBalanceRequest).Entity;
                    giftCardCurrencyCode = currentGiftCard.CardCurrencyCode;
                }

                GetCurrencyValueServiceResponse convertAmountToGiftCardCurrencyResponse = ToGiftCardCurrency(request.RequestContext, request.Amount, giftCardCurrencyCode);

                var addToGiftCardRequest = new AddToGiftCardRealtimeRequest(
                    request.GiftCardId,
                    convertAmountToGiftCardCurrencyResponse.RoundedConvertedAmount,
                    convertAmountToGiftCardCurrencyResponse.ToCurrencyCode,
                    request.RequestContext.GetPrincipal().ChannelId,
                    request.RequestContext.GetTerminal() == null ? string.Empty : request.RequestContext.GetTerminal().TerminalId,
                    request.RequestContext.GetPrincipal().UserId,
                    request.Transaction.Id,
                    string.Empty); // ReceiptId is passed as an empty string in EPOS too at this point.
                GiftCard card = request.RequestContext.Execute <SingleEntityDataServiceResponse <GiftCard> >(addToGiftCardRequest).Entity;

                GetCurrencyValueServiceResponse convertBalanceToChannelCurrencyResponse = FromGiftCardCurrency(request.RequestContext, card.BalanceInCardCurrency, card.BalanceCurrencyCode);

                GiftCard giftCard = new GiftCard
                {
                    Id = request.GiftCardId,
                    BalanceCurrencyCode   = convertBalanceToChannelCurrencyResponse.ToCurrencyCode,
                    Balance               = convertBalanceToChannelCurrencyResponse.RoundedConvertedAmount,
                    CardCurrencyCode      = giftCardCurrencyCode,
                    BalanceInCardCurrency = card.BalanceInCardCurrency
                };

                return(new GetGiftCardServiceResponse(giftCard));
            }