Exemplo n.º 1
0
            /// <summary>
            /// Issue new gift card.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>A response containing the gift card information.</returns>
            private static GetGiftCardServiceResponse IssueGiftCard(IssueGiftCardServiceRequest request)
            {
                if (request == null)
                {
                    throw new ArgumentNullException("request");
                }

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

                if (request.Amount <= 0)
                {
                    throw new ArgumentException("request.Amount has to be positive value.", "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("Gift card cannot be issued in currency different from channel currency. Currency requested: {0}", request.CurrencyCode));
                }

                ValidateNotAlreadyAdded(request.Transaction, request.Id);

                var issueGiftCardRequest = new IssueGiftCardRealtimeRequest(
                    request.Id,
                    request.Amount,
                    request.CurrencyCode,
                    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 issuedGiftCard = request.RequestContext.Execute <SingleEntityDataServiceResponse <GiftCard> >(issueGiftCardRequest).Entity;

                return(new GetGiftCardServiceResponse(issuedGiftCard));
            }
            /// <summary>
            /// Issue gift card.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>The <see cref="SingleEntityDataServiceResponse{GiftCard}"/> response that contains gift card.</returns>
            private static SingleEntityDataServiceResponse <GiftCard> IssueGiftCard(IssueGiftCardRealtimeRequest request)
            {
                var transactionClient = new TransactionService.TransactionServiceClient(request.RequestContext);

                string cardId;

                transactionClient.IssueGiftCard(request.GiftCardId, request.Amount, request.CurrencyCode, request.ChannelId, request.TerminalId, request.StaffId, request.TransactionId, request.ReceiptId, out cardId);

                GiftCard giftCard = new GiftCard
                {
                    Id = cardId,
                    BalanceCurrencyCode   = request.CurrencyCode,
                    Balance               = request.Amount,
                    CardCurrencyCode      = request.CurrencyCode,
                    BalanceInCardCurrency = request.Amount
                };

                return(new SingleEntityDataServiceResponse <GiftCard>(giftCard));
            }