public HttpResponseMessage RetrieveHistory()
        {
            Stopwatch callTimer = Stopwatch.StartNew();

            HttpResponseMessage result;

            // Build a context object to pass down the pipeline.
            CommerceContext context = CommerceContext.BuildSynchronousRestContext("Get Microsoft Store voucher distribution history", Request,
                                                                                  new GetMssVoucherDistributionHistoryResponse(), callTimer);

            try
            {
                // Add request information to the call context.
                context.Log.Information("Processing {0} call.", context.ApiCallDescription);
                Guid userId = CommerceContext.PopulateUserId(context);
                context[Key.GlobalUserId] = userId;
                context.Log.Verbose("{0} request for user {1}", context.ApiCallDescription, userId);

                // Create an executor object to execute the API invocation.
                MssvDistributionHistoryExecutor executor = new MssvDistributionHistoryExecutor(context);
                executor.Execute();

                result = RestResponder.BuildSynchronousResponse(context);
            }
            catch (Exception ex)
            {
                result = RestResponder.BuildSynchronousResponse(context, ex);
            }

            return(result);
        }
Exemple #2
0
        public HttpResponseMessage Get(DealReportsQuery dealReportsQuery)
        {
            Stopwatch callTimer = Stopwatch.StartNew();

            HttpResponseMessage result;

            // Build a context object to pass down the pipeline.
            CommerceContext context = CommerceContext.BuildSynchronousRestContext("Get deal report", Request,
                                                                                  new GetDealReportsResponse(), callTimer);

            try
            {
                context.Log.Information("Processing {0} call.", context.ApiCallDescription);
                CustomIdentity clientIdentity = (CustomIdentity)Thread.CurrentPrincipal.Identity;
                context.Log.Verbose("Presented client certificate has subject \"{0}\" and thumbprint \"{1}\".",
                                    clientIdentity.Name, clientIdentity.PresentedClientToken);

                // Populate the context with call parameters.
                context[Key.DealReportsQuery] = dealReportsQuery;

                // Create an executor object to execute the API invocation.
                GetDealReportsExecutor executor = new GetDealReportsExecutor(context);
                executor.Execute();

                // Build the response from the result of API invocation.
                result = RestResponder.BuildSynchronousResponse(context);
            }
            catch (Exception ex)
            {
                result = RestResponder.BuildSynchronousResponse(context, ex);
            }

            return(result);
        }
Exemple #3
0
        public HttpResponseMessage GetEarnHistory()
        {
            Stopwatch callTimer = Stopwatch.StartNew();

            HttpResponseMessage result;

            // Build a context object to pass down the pipeline.
            CommerceContext context = CommerceContext.BuildSynchronousRestContext("Get Earn/Burn history", Request,
                                                                                  new GetEarnBurnTransactionHistoryResponse(), callTimer);

            try
            {
                context.Log.Information("Processing {0} call.", context.ApiCallDescription);

                // Add call parameters.
                context[Key.GlobalUserId]      = CommerceContext.PopulateUserId(context);
                context[Key.RewardProgramType] = RewardPrograms.EarnBurn;

                // Create an executor object to execute the API invocation.
                GetRedemptionHistoryExecutor getRedemptionHistoryExecutor = new GetRedemptionHistoryExecutor(context);
                getRedemptionHistoryExecutor.Execute();

                // Build the response from the result of API invocation.
                result = RestResponder.BuildSynchronousResponse(context);
            }
            catch (Exception ex)
            {
                result = RestResponder.BuildSynchronousResponse(context, ex);
            }

            return(result);
        }
Exemple #4
0
        public HttpResponseMessage Get()
        {
            Stopwatch callTimer = Stopwatch.StartNew();

            HttpResponseMessage result;

            // Build a context object to pass down the pipeline.
            CommerceContext context = CommerceContext.BuildSynchronousRestContext("Get cards", Request, new V2GetCardsResponse(),
                                                                                  callTimer);

            try
            {
                context.Log.Information("Processing {0} call.", context.ApiCallDescription);

                // Add ID for the user making this call to the context.
                context[Key.GlobalUserId]      = CommerceContext.PopulateUserId(context);
                context[Key.RewardProgramType] = ControllerHelper.GetRewardProgramAssociatedWithRequest(this.Request);

                // Create an executor object to execute the API invocation.
                V2GetCardsExecutor getCardsExecutor = new V2GetCardsExecutor(context);
                getCardsExecutor.Execute();

                // Build the response from the result of API invocation.
                result = RestResponder.BuildSynchronousResponse(context);
            }
            catch (Exception ex)
            {
                result = RestResponder.BuildSynchronousResponse(context, ex);
            }

            return(result);
        }
Exemple #5
0
        /// <summary>
        /// Adds the specified referral to the system.
        /// </summary>
        /// <param name="referralDataContract">
        /// The referral to add to the system.
        /// </param>
        /// <returns>
        /// An HttpResponseMessage containing an AddReferralResponse with detailed result information.
        /// </returns>
        public HttpResponseMessage Add(ReferralDataContract referralDataContract)
        {
            Stopwatch callTimer = Stopwatch.StartNew();

            HttpResponseMessage result;

            // Build a context object to pass down the pipeline.
            CommerceContext context = CommerceContext.BuildSynchronousRestContext("Add user referral", Request,
                                                                                  new AddReferralResponse(), callTimer);

            try
            {
                context.Log.Information("Processing {0} call.", context.ApiCallDescription);
                context[Key.ReferralDataContract] = referralDataContract;
                context.Log.Verbose("{0} request:\r\n{1}", context.ApiCallDescription,
                                    General.SerializeJson(referralDataContract));

                // Create an executor object to execute the API invocation.
                context[Key.ReferredUserFirstEarnRewardAmount]      = CommerceServiceConfig.Instance.ReferredUserFirstEarnRewardAmount;
                context[Key.ReferredUserFirstEarnRewardExplanation] = CommerceServiceConfig.Instance.ReferredUserFirstEarnRewardExplanation;
                AddReferralExecutor executor = new AddReferralExecutor(context);
                executor.Execute();

                // Build the response from the result of API invocation.
                result = RestResponder.BuildSynchronousResponse(context);
            }
            catch (Exception ex)
            {
                result = RestResponder.BuildSynchronousResponse(context, ex);
            }

            return(result);
        }
Exemple #6
0
        public HttpResponseMessage Get()
        {
            Stopwatch callTimer = Stopwatch.StartNew();

            HttpResponseMessage result;

            // Build a context object to pass down the pipeline.
            CommerceContext context = CommerceContext.BuildSynchronousRestContext("Get users referrals", Request,
                                                                                  new GetUsersReferralsResponse(),
                                                                                  callTimer);

            try
            {
                context.Log.Information("Processing {0} call.", context.ApiCallDescription);

                // Add ID for the user making this call to the context.
                context[Key.GlobalUserId] = CommerceContext.PopulateUserId(context);

                // Create an executor object to execute the API invocation.
                GetUsersReferralsExecutor executor = new GetUsersReferralsExecutor(context);
                executor.Execute();

                // Build the response from the result of API invocation.
                result = RestResponder.BuildSynchronousResponse(context);
            }
            catch (Exception ex)
            {
                result = RestResponder.BuildSynchronousResponse(context, ex);
            }

            return(result);
        }
Exemple #7
0
        public HttpResponseMessage ActiveDiscountIds(ReimbursementTender reimbursementTender = ReimbursementTender.DeprecatedEarn,
                                                     Partner partner = Partner.None)
        {
            Stopwatch callTimer = Stopwatch.StartNew();

            HttpResponseMessage result;

            // Build a context object to pass down the pipeline.
            CommerceContext context = CommerceContext.BuildSynchronousRestContext("Get Active Discounts", Request, new GetActiveDiscountIdsResponse(),
                                                                                  callTimer);

            try
            {
                context.Log.Information("Processing {0} call.", context.ApiCallDescription);
                CustomIdentity clientIdentity = (CustomIdentity)Thread.CurrentPrincipal.Identity;
                context.Log.Verbose("Presented credentials are for role \"{0}\" and include token \"{1}\".",
                                    clientIdentity.Name, clientIdentity.PresentedClientToken);

                context[Key.ReimbursementTender] = reimbursementTender;
                context[Key.Partner]             = partner;

                // Create an executor object to execute the API invocation.
                GetActiveDiscountsExecutor discountsExecutor = new GetActiveDiscountsExecutor(context);
                discountsExecutor.Execute();

                // Build the response from the result of API invocation.
                result = RestResponder.BuildSynchronousResponse(context);
            }
            catch (Exception ex)
            {
                result = RestResponder.BuildSynchronousResponse(context, ex);
            }

            return(result);
        }
        public HttpResponseMessage Register(V3DealDataContract dealDataContract)
        {
            Stopwatch callTimer = Stopwatch.StartNew();

            HttpResponseMessage result;

            // Build a context object to pass down the pipeline.
            CommerceContext context = CommerceContext.BuildSynchronousRestContext("Register offer", Request,
                                                                                  new V3RegisterDealResponse(), callTimer);

            try
            {
                context.Log.Information("Processing {0} call.", context.ApiCallDescription);
                CustomIdentity clientIdentity = (CustomIdentity)Thread.CurrentPrincipal.Identity;
                context.Log.Verbose("Presented client certificate has subject \"{0}\" and thumbprint \"{1}\".",
                                    clientIdentity.Name, clientIdentity.PresentedClientToken);
                context[Key.DealDataContract] = dealDataContract;
                context.Log.Verbose("{0} request:\r\n{1}", context.ApiCallDescription, General.SerializeJson(dealDataContract));

                // Create an executor object to execute the API invocation.
                V3ServiceRegisterDealExecutor registerDealExecutor = new V3ServiceRegisterDealExecutor(context);
                registerDealExecutor.Execute();

                // Build the response from the result of API invocation.
                result = RestResponder.BuildSynchronousResponse(context);
            }
            catch (Exception ex)
            {
                result = RestResponder.BuildSynchronousResponse(context, ex);
            }

            return(result);
        }
        public HttpResponseMessage Get(Guid userId)
        {
            HttpResponseMessage result;

            Stopwatch callTimer = Stopwatch.StartNew();

            // Build a context object to pass down the pipeline.
            CommerceContext context = CommerceContext.BuildSynchronousRestContext("Get redemption history", Request,
                                                                                  new GetRedemptionHistoryResponse(), callTimer);

            try
            {
                context.Log.Information("Processing {0} call.", context.ApiCallDescription);
                CustomIdentity clientIdentity = (CustomIdentity)Thread.CurrentPrincipal.Identity;
                context.Log.Verbose("Presented client certificate has subject \"{0}\" and thumbprint \"{1}\".",
                                    clientIdentity.Name, clientIdentity.PresentedClientToken);

                // Add ID for the user making this call to the context.
                context[Key.GlobalUserId]      = userId;
                context[Key.RewardProgramType] = RewardPrograms.CardLinkOffers;

                // Create an executor object to execute the API invocation.
                GetRedemptionHistoryExecutor getRedemptionHistoryExecutor = new GetRedemptionHistoryExecutor(context);
                getRedemptionHistoryExecutor.Execute();

                // Build the response from the result of API invocation.
                result = RestResponder.BuildSynchronousResponse(context);
            }
            catch (Exception ex)
            {
                result = RestResponder.BuildSynchronousResponse(context, ex);
            }

            return(result);
        }
        public HttpResponseMessage Add(int rewardRecipient)
        {
            Stopwatch callTimer = Stopwatch.StartNew();

            HttpResponseMessage result;

            // Build a context object to pass down the pipeline.
            CommerceContext context = CommerceContext.BuildSynchronousRestContext("Add user referral type", Request,
                                                                                  new AddReferralTypeResponse(), callTimer);

            try
            {
                context.Log.Information("Processing {0} call.", context.ApiCallDescription);
                context[Key.RewardRecipient] = rewardRecipient;

                // Add user ID to the context.
                context[Key.GlobalUserId] = CommerceContext.PopulateUserId(context);

                // Create an executor object to execute the API invocation.
                AddReferralTypeExecutor executor = new AddReferralTypeExecutor(context);
                executor.Execute();

                // Build the response from the result of API invocation.
                result = RestResponder.BuildSynchronousResponse(context);
            }
            catch (Exception ex)
            {
                result = RestResponder.BuildSynchronousResponse(context, ex);
            }

            return(result);
        }
Exemple #11
0
        public HttpResponseMessage Get(Guid userId)
        {
            Stopwatch callTimer = Stopwatch.StartNew();

            HttpResponseMessage result;

            // Build a context object to pass down the pipeline.
            CommerceContext context = CommerceContext.BuildSynchronousRestContext("Get claimed deals", Request,
                                                                                  new GetClaimedDealsResponse(), callTimer);

            try
            {
                context.Log.Information("Processing {0} call.", context.ApiCallDescription);
                CustomIdentity clientIdentity = (CustomIdentity)Thread.CurrentPrincipal.Identity;
                context.Log.Verbose("Presented credentials are for role \"{0}\" and include token \"{1}\".",
                                    clientIdentity.Name, clientIdentity.PresentedClientToken);

                // Add ID for the user making this call to the context.
                context[Key.GlobalUserId] = userId;

                // Create an executor object to execute the API invocation.
                GetClaimedDealsExecutor getClaimedDealsExecutor = new GetClaimedDealsExecutor(context);
                getClaimedDealsExecutor.Execute();

                // Build the response from the result of API invocation.
                result = RestResponder.BuildSynchronousResponse(context);
            }
            catch (Exception ex)
            {
                result = RestResponder.BuildSynchronousResponse(context, ex);
            }

            return(result);
        }
Exemple #12
0
        public HttpResponseMessage Put([FromBody] RewardsProgramCardEnrollment enrollment)
        {
            Stopwatch callTimer = Stopwatch.StartNew();

            // Build a context object to pass down the pipeline.
            CommerceContext context = CommerceContext.BuildSynchronousRestContext("EnrollCardsInRewardsPrograms", Request,
                                                                                  new GetEarnBurnTransactionHistoryResponse(), callTimer);

            this.cardOperations.Context = context;
            RewardPrograms rewardPrograms;

            CardBrand[] cardBrands;
            Guid        globalUserId;

            ValidateEnrollment(context, enrollment, out globalUserId, out cardBrands, out rewardPrograms);

            try
            {
                ResultCode result = this.cardOperations.EnrollCardsInRewardPrograms(
                    globalUserId,
                    rewardPrograms,
                    cardBrands);

                if (result == ResultCode.Success)
                {
                    return(this.Request.CreateResponse(HttpStatusCode.OK));
                }

                if (result == ResultCode.UnregisteredUser)
                {
                    return(this.Request.CreateResponse(HttpStatusCode.NotFound, "The user was not found."));
                }

                if (result == ResultCode.AggregateError)
                {
                    return(this.Request.CreateResponse(
                               HttpStatusCode.Conflict,
                               "One or more cards could not be enrolled in the requested programs. The card might be enrolled in the same reward program by a different user account."));
                }

                return(this.Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
            catch (HttpResponseException)
            {
                throw;
            }
            catch (Exception ex)
            {
                context.Log.Warning(
                    "Enrolling the user's cards in the reward program failed. Error = '{0}'",
                    ex.ToString());

                return(this.Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Exemple #13
0
        /// <summary>
        /// Pings the Commerce database.
        /// </summary>
        /// <returns>
        /// * True if the Commerce database could be pinged.
        /// * Else returns false.
        /// </returns>
        private static bool PingCommerce()
        {
            // Ping Commerce by attempting to retrieve cards for a user known not to exist.
            GetCardsResponse response = new GetCardsResponse();
            CommerceContext  context  = CommerceContext.BuildSynchronousRestContext(String.Empty, null, response, new Stopwatch());

            context[Key.GlobalUserId]           = Guid.Empty;
            context[Key.RewardProgramType]      = RewardPrograms.All;
            context.Log.OnlyLogIfVerbosityIsAll = true;
            V2GetCardsExecutor getCardsExecutor = new V2GetCardsExecutor(context);

            getCardsExecutor.Execute();
            return(response.ResultSummary.GetResultCode() == ResultCode.UnregisteredUser);
        }
        public HttpResponseMessage GetSecureCardOperationToken(string operation,
                                                               string eventId      = "",
                                                               string referralCode = "",
                                                               string referrer     = null)
        {
            Stopwatch callTimer = Stopwatch.StartNew();

            HttpResponseMessage result;

            // Build a context object to pass down the pipeline.
            CommerceContext context = CommerceContext.BuildSynchronousRestContext("Get secure card operation token", Request,
                                                                                  new GetSecureCardOperationTokenResponse(),
                                                                                  callTimer);

            try
            {
                context[Key.RequestedCrudOperation] = operation;
                context[Key.ReferralTypeCode]       = referralCode;
                context[Key.ReferralEvent]          = ReferralEvent.Signup;
                context.Log.Information("Processing {0} call.", context.ApiCallDescription);

                // Populate the context.
                context[Key.GlobalUserId]   = CommerceContext.PopulateUserId(context);
                context[Key.ReferredUserId] = context[Key.GlobalUserId].ToString();
                Guid eventIdGuid;
                if (Guid.TryParse(eventId, out eventIdGuid) == true)
                {
                    context[Key.CorrelationId] = eventIdGuid;
                }
                context[Key.ReferrerId] = referrer;

                // Create an executor object to execute the API invocation.
                GetSecureCardOperationTokenExecutor executor = new GetSecureCardOperationTokenExecutor(context);
                executor.Execute();

                // Build the response from the result of API invocation.
                result = RestResponder.BuildSynchronousResponse(context);
            }
            catch (Exception ex)
            {
                result = RestResponder.BuildSynchronousResponse(context, ex);
            }

            return(result);
        }
Exemple #15
0
        public HttpResponseMessage OnOfferActivation()
        {
            Stopwatch       callTimer = Stopwatch.StartNew();
            CommerceContext context   = CommerceContext.BuildSynchronousRestContext("Incoming Offer Activation Request",
                                                                                    Request,
                                                                                    new VisaResponse(),
                                                                                    callTimer);
            HttpResponseMessage result;

            try
            {
                result = LogPayload(context);
            }
            catch (Exception ex)
            {
                result = RestResponder.BuildSynchronousResponse(context, ex);
            }

            return(result);
        }
        public HttpResponseMessage Distribute(MssvDistributionDataContract request)
        {
            Stopwatch callTimer = Stopwatch.StartNew();

            HttpResponseMessage result;

            if (request == null)
            {
                throw new ArgumentNullException("request", "Parameter request cannot be null.");
            }

            // Build a context object to pass down the pipeline.
            CommerceContext context = CommerceContext.BuildSynchronousRestContext("Distribute Microsoft Store vouchers", Request,
                                                                                  new DistributeMssvResponse(), callTimer);

            try
            {
                // Add request information to the call context.
                context.Log.Information("Processing {0} call.", context.ApiCallDescription);
                context[Key.GlobalUserId]         = CommerceContext.PopulateUserId(context);
                context[Key.DistributionAmount]   = request.DistributionAmount;
                context[Key.VoucherExpirationUtc] = request.VoucherExpirationUtc;
                context[Key.Notes] = request.Notes;
                context.Log.Verbose("{0} request:\r\n{1}", context.ApiCallDescription, General.SerializeJson(request));

                // Create an executor object to execute the API invocation.
                DistributeMssvExecutor executor = new DistributeMssvExecutor(context);
                executor.Execute();

                result = RestResponder.BuildSynchronousResponse(context);
            }
            catch (Exception ex)
            {
                result = RestResponder.BuildSynchronousResponse(context, ex);
            }

            return(result);
        }
Exemple #17
0
        /// <summary>
        /// Gets cards by user if specified else all active cards
        /// </summary>
        /// <param name="userId">
        /// if userid is non empty guid, get active cards by user, else all active cards
        /// </param>
        /// <param name="rewardPrograms">
        /// The reward programs by which to filter cards.
        /// </param>
        /// <param name="partner">
        /// The partner for which to retrieve cards.
        /// </param>
        /// <returns>
        /// An HttpResponseMessage containing a ServiceGetCardsResponse with detailed result information.
        /// </returns>
        /// <remarks>
        /// The partner parameter should properly default to Partner.All, but Partner enum was never intended for bitmasking, so there is no Partner.All.
        ///  But for now, None can be used to tell the sproc not to constrain on partner. Longer term it would be a good idea to convert this enum to Flags type
        ///  and update the database accordingly.
        /// </remarks>
        private HttpResponseMessage Cards(Guid userId,
                                          RewardPrograms rewardPrograms,
                                          Partner partner)
        {
            Stopwatch callTimer = Stopwatch.StartNew();

            HttpResponseMessage result;

            // Build a context object to pass down the pipeline.
            CommerceContext context = CommerceContext.BuildSynchronousRestContext("Get cards", Request, new ServiceGetCardsResponse(),
                                                                                  callTimer);

            try
            {
                context.Log.Information("Processing {0} call.", context.ApiCallDescription);
                CustomIdentity clientIdentity = (CustomIdentity)Thread.CurrentPrincipal.Identity;
                context.Log.Verbose("Presented credentials are for role \"{0}\" and include token \"{1}\".",
                                    clientIdentity.Name, clientIdentity.PresentedClientToken);

                context[Key.GlobalUserId]      = userId;
                context[Key.RewardProgramType] = rewardPrograms;
                context[Key.Partner]           = partner;

                // Create an executor object to execute the API invocation.
                ServiceGetCardsExecutor getCardsExecutor = new ServiceGetCardsExecutor(context);
                getCardsExecutor.Execute();

                // Build the response from the result of API invocation.
                result = RestResponder.BuildSynchronousResponse(context);
            }
            catch (Exception ex)
            {
                result = RestResponder.BuildSynchronousResponse(context, ex);
            }

            return(result);
        }