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);
        }
        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);
        }
Beispiel #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);
        }
Beispiel #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 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);
        }
Beispiel #5
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);
        }
Beispiel #6
0
        public Task <HttpResponseMessage> Delete(Guid cardId)
        {
            Stopwatch callTimer = Stopwatch.StartNew();

            Task <HttpResponseMessage> result;

            // Build a context object to pass down the pipeline.
            CommerceContext context = CommerceContext.BuildAsynchronousRestContext("Remove card", Request,
                                                                                   new RemoveCardResponse(), callTimer);

            try
            {
                context[Key.CardId] = General.IntegerFromGuid(cardId);
                context.Log.Information("Processing {0} call.", context.ApiCallDescription);
                context.Log.Verbose("{0} request:\r\ncardId={1}", context.ApiCallDescription, cardId);

                // 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.
                RemoveCardExecutor removeCardExecutor = new RemoveCardExecutor(context);
                Task.Factory.StartNew(async() => await removeCardExecutor.Execute());

                result = ((TaskCompletionSource <HttpResponseMessage>)context[Key.TaskCompletionSource]).Task;
            }
            catch (Exception ex)
            {
                result = RestResponder.CreateExceptionTask(context, ex);
            }

            return(result);
        }
Beispiel #7
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);
        }
Beispiel #8
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);
        }
Beispiel #9
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);
        }
        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);
        }
Beispiel #12
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);
        }
Beispiel #13
0
        public Task <HttpResponseMessage> Claim(ClaimDealPayload claimDealPayload)
        {
            Stopwatch callTimer = Stopwatch.StartNew();

            Task <HttpResponseMessage> result;

            // Build a context object to pass down the pipeline.
            CommerceContext context = CommerceContext.BuildAsynchronousRestContext("Claim deal in partners and data store",
                                                                                   Request, new ClaimDealResponse(), 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.Log.Verbose("{0} request:\r\n{1}", context.ApiCallDescription, General.SerializeJson(claimDealPayload));

                // Add payload information to the context.
                context[Key.ClaimDealPayload] = claimDealPayload;

                // Create an executor object to execute the API invocation.
                ClaimDealExecutor claimDealExecutor = new ClaimDealExecutor(context);
                Task.Factory.StartNew(async() => await claimDealExecutor.Execute());

                result = ((TaskCompletionSource <HttpResponseMessage>)context[Key.TaskCompletionSource]).Task;
            }
            catch (Exception ex)
            {
                result = RestResponder.CreateExceptionTask(context, ex);
            }

            return(result);
        }
Beispiel #14
0
        /// <summary>
        ///     Helper Method to log incoming payload from VISA.
        /// </summary>
        /// <param name="context"></param>
        /// <returns>200 OK in all scenarios</returns>
        private HttpResponseMessage LogPayload(CommerceContext context)
        {
            string payLoad = Request.Content.ReadAsStringAsync().Result;

            context.Log.Information("Incoming POST payload from VISA : \r\n\"{0}\".", payLoad);

//TODO: Return Responses as per scenarios.
            ((ResultSummary)context[Key.ResultSummary]).SetResultCode(ResultCode.Success);
            return(RestResponder.BuildSynchronousResponse(context));
        }
        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);
        }
Beispiel #16
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);
        }
Beispiel #18
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);
        }