/// <summary>
        /// Executes the get redemption history invocation.
        /// </summary>
        public void Execute()
        {
            SharedUserLogic sharedUserLogic = new SharedUserLogic(Context, CommerceOperationsFactory.UserOperations(Context));

            User user = sharedUserLogic.RetrieveUser();

            Context[Key.User] = user;
            ResultSummary resultSummary = (ResultSummary)Context[Key.ResultSummary];

            if (user != null)
            {
                RewardPrograms rewardProgram = (RewardPrograms)Context[Key.RewardProgramType];

                if ((rewardProgram & RewardPrograms.CardLinkOffers) == RewardPrograms.CardLinkOffers)
                {
                    resultSummary.SetResultCode(GetRedemptionHistory());
                }
                else if ((rewardProgram & RewardPrograms.EarnBurn) == RewardPrograms.EarnBurn)
                {
                    resultSummary.SetResultCode(GetEarnBurnHistory());
                }
            }
            else
            {
                resultSummary.SetResultCode(ResultCode.UnexpectedUnregisteredUser);
            }
        }
예제 #2
0
        /// <summary>
        /// Executes the get user token for card operation invocation.
        /// </summary>
        /// <remarks>
        /// Authenticated user is automatically created within the system if necessary when obtaining a token for Create operations.
        /// </remarks>
        public void Execute()
        {
            ResultSummary resultSummary = (ResultSummary)Context[Key.ResultSummary];
            Crud          crud;

            if (Enum.TryParse <Crud>((string)Context[Key.RequestedCrudOperation], true, out crud) == true)
            {
                // Validate the user ID in the context.
                ResultCode validateUserIdResult = ValidateUserId(crud);
                if (validateUserIdResult == ResultCode.Success || validateUserIdResult == ResultCode.Created)
                {
                    Guid userId = (Guid)Context[Key.GlobalUserId];
                    LomoUserIdSecurityToken token = new LomoUserIdSecurityToken(
                        userId.ToString(),
                        CommerceServiceConfig.Instance.Environment,
                        Resource.Cards.ToString(),
                        crud.ToString(),
                        Convert.ToInt64(ConfigurationManager.AppSettings[AppSettingsKeys.SecureTokenLifetime]),
                        ConfigurationManager.AppSettings[AppSettingsKeys.SecureTokenSigningKey],
                        ConfigurationManager.AppSettings[AppSettingsKeys.SecureTokenPassword],
                        ConfigurationManager.AppSettings[AppSettingsKeys.SecureTokenSalt]);
                    ((GetSecureCardOperationTokenResponse)Context[Key.Response]).Token = token.ToString();
                    resultSummary.SetResultCode(ResultCode.Success);
                }
                else
                {
                    resultSummary.SetResultCode(validateUserIdResult);
                }
            }
            else
            {
                resultSummary.SetResultCode(ResultCode.InvalidParameter);
            }
        }
        /// <summary>
        /// Executes the get cards invocation.
        /// </summary>
        public void Execute()
        {
            // get userid if its there
            Guid userId = Context[Key.GlobalUserId] == null ? Guid.Empty : (Guid)Context[Key.GlobalUserId];

            if (userId == Guid.Empty)
            {
                // no user specified so get all active cards
                ResultSummary resultSummary = (ResultSummary)Context[Key.ResultSummary];
                resultSummary.SetResultCode(GetAllActiveCards());
            }
            else
            {
                SharedUserLogic sharedUserLogic = new SharedUserLogic(Context, CommerceOperationsFactory.UserOperations(Context));

                User user = sharedUserLogic.RetrieveUser();
                Context[Key.User] = user;
                ResultSummary resultSummary = (ResultSummary)Context[Key.ResultSummary];
                if (user != null)
                {
                    resultSummary.SetResultCode(GetCards());
                }
                else
                {
                    resultSummary.SetResultCode(ResultCode.UnregisteredUser);
                }
            }
        }
        /// <summary>
        /// Executes the distribute MSSV API invocation.
        /// </summary>
        public void Execute()
        {
            ResultSummary resultSummary = (ResultSummary)Context[Key.ResultSummary];

            // Make sure the user exists.
            SharedUserLogic sharedUserLogic = new SharedUserLogic(Context, CommerceOperationsFactory.UserOperations(Context));

            if (sharedUserLogic.RetrieveUser() != null)
            {
                // Validate the distribution amount.
                decimal distributionAmount = (decimal)Context[Key.DistributionAmount];
                if (distributionAmount >= 0 && distributionAmount % 10 == 0)
                {
                    // Validate the voucher expiration date.
                    DateTime voucherExpiration = (DateTime)Context[Key.VoucherExpirationUtc];
                    DateTime utcNow            = DateTime.UtcNow;
                    if (voucherExpiration > utcNow && voucherExpiration <= utcNow + TimeSpan.FromDays(366))
                    {
                        // HTML encode user-submitted text to prevent script injection and then truncate to maximum length. (SQL injection is prevented through use of a
                        //  paramterized stored procedure.)
                        string notes = Context[Key.Notes] as string;
                        if (String.IsNullOrWhiteSpace(notes) == false)
                        {
                            notes = HttpUtility.HtmlEncode(notes);
                            if (notes.Length > MaxNotesLength)
                            {
                                notes = notes.Substring(0, MaxNotesLength);
                            }
                        }

                        // Submit the distribution request to the database.
                        ResultCode             result   = CommerceOperationsFactory.RedeemedDealOperations(Context).DistributeMssv();
                        DistributeMssvResponse response = (DistributeMssvResponse)Context[Key.Response];
                        response.RemainingFunds = (decimal)Context[Key.RemainingFunds];
                        resultSummary.SetResultCode(result);
                    }
                    else
                    {
                        resultSummary.SetResultCode(ResultCode.InvalidExpirationDate);
                    }
                }
                else
                {
                    resultSummary.SetResultCode(ResultCode.InvalidDistributionAmount);
                }
            }
            else
            {
                resultSummary.SetResultCode(ResultCode.UnexpectedUnregisteredUser);
            }
        }
        /// <summary>
        /// Executes the get merchant report invocation.
        /// </summary>
        public void Execute()
        {
            ResultSummary resultSummary = (ResultSummary)Context[Key.ResultSummary];
            ResultCode    resultCode    = ExtractParameters();

            if (resultCode == ResultCode.Success)
            {
                resultSummary.SetResultCode(GetMerchantDealRedemptions());
            }
            else
            {
                resultSummary.SetResultCode(resultCode);
            }
        }
        /// <summary>
        /// Executes the distribute MSSV API invocation.
        /// </summary>
        public void Execute()
        {
            ResultSummary resultSummary = (ResultSummary)Context[Key.ResultSummary];

            // Make sure the user exists.
            SharedUserLogic sharedUserLogic = new SharedUserLogic(Context, CommerceOperationsFactory.UserOperations(Context));

            if (sharedUserLogic.RetrieveUser() != null)
            {
                ResultCode result = CommerceOperationsFactory.RedeemedDealOperations(Context).MssVoucherDistributionHistory();
                MssVoucherDistributionHistory history = (MssVoucherDistributionHistory)Context[Key.MssVoucherDistributionHistory];

                GetMssVoucherDistributionHistoryResponse response = (GetMssVoucherDistributionHistoryResponse)Context[Key.Response];
                response.AmountRemaining = (decimal)history.AmountRemaining / 100;

                List <DistributionHistoryDataContract> distributionHistoryList = new List <DistributionHistoryDataContract>();
                response.DistributionHistory = distributionHistoryList;
                foreach (DistributionHistory distributionHistoryItem in history.DistributionHistory)
                {
                    DistributionHistoryDataContract distributionHistoryItemDataContract = new DistributionHistoryDataContract
                    {
                        DistributionDate = distributionHistoryItem.DistributionDate,
                        Amount           = (decimal)distributionHistoryItem.Amount / 100,
                        Currency         = distributionHistoryItem.Currency,
                        ExpirationDate   = distributionHistoryItem.ExpirationDate
                    };
                    distributionHistoryList.Add(distributionHistoryItemDataContract);
                }

                List <TransactionHistoryDataContract> transactionHistoryList = new List <TransactionHistoryDataContract>();
                response.TransactionHistory = transactionHistoryList;
                foreach (TransactionHistory transactionHistoryItem in history.TransactionHistory)
                {
                    TransactionHistoryDataContract transactionHistoryItemDataContract = new TransactionHistoryDataContract
                    {
                        Business       = transactionHistoryItem.Business,
                        CreditStatus   = transactionHistoryItem.CreditStatus.ToString(),
                        PurchaseDate   = transactionHistoryItem.PurchaseDate,
                        DiscountAmount = (decimal)transactionHistoryItem.DiscountAmount / 100
                    };
                    transactionHistoryList.Add(transactionHistoryItemDataContract);
                }

                resultSummary.SetResultCode(result);
            }
            else
            {
                resultSummary.SetResultCode(ResultCode.UnexpectedUnregisteredUser);
            }
        }
        /// <summary>
        /// Executes the get deal report invocation.
        /// </summary>
        public void Execute()
        {
            ResultSummary resultSummary = (ResultSummary)Context[Key.ResultSummary];
            ResultCode    resultCode    = ValidateParameters();

            if (resultCode == ResultCode.Success)
            {
                resultSummary.SetResultCode(RetrieveDealReports());
            }
            else
            {
                resultSummary.SetResultCode(resultCode);
            }
        }
        /// <summary>
        /// Executes the add referral type API invocation.
        /// </summary>
        public virtual void Execute()
        {
            SharedUserLogic sharedUserLogic = new SharedUserLogic(Context, CommerceOperationsFactory.UserOperations(Context));
            ResultSummary   resultSummary   = (ResultSummary)Context[Key.ResultSummary];

            if (sharedUserLogic.RetrieveUser() != null)
            {
                resultSummary.SetResultCode(CoreExecute());
            }
            else
            {
                resultSummary.SetResultCode(ResultCode.UnexpectedUnregisteredUser);
            }
        }
예제 #9
0
        /// <summary>
        /// Executes the get user's referrals API invocation.
        /// </summary>
        public void Execute()
        {
            SharedUserLogic sharedUserLogic = new SharedUserLogic(Context, CommerceOperationsFactory.UserOperations(Context));
            ResultSummary   resultSummary   = (ResultSummary)Context[Key.ResultSummary];

            if (sharedUserLogic.RetrieveUser() != null)
            {
                Context[Key.ReferrerId]   = Context[Key.GlobalUserId];
                Context[Key.ReferrerType] = ReferrerType.User;
                resultSummary.SetResultCode(GetUsersReferrals());
            }
            else
            {
                resultSummary.SetResultCode(ResultCode.UnexpectedUnregisteredUser);
            }
        }
예제 #10
0
        /// <summary>
        /// Executes the add referral API invocation.
        /// </summary>
        public void Execute()
        {
            SharedReferralLogic sharedReferralLogic = new SharedReferralLogic(Context, ReferralOperations);
            ResultSummary       resultSummary       = (ResultSummary)Context[Key.ResultSummary];

            ResultCode resultCode = ValidateParameters();

            if (resultCode == ResultCode.Success)
            {
                resultSummary.SetResultCode(sharedReferralLogic.AddReferral(UserIdString));
            }
            else
            {
                resultSummary.SetResultCode(resultCode);
            }
        }
        /// <summary>
        /// Executes the get claimed deals invocation.
        /// </summary>
        public void Execute()
        {
            SharedUserLogic sharedUserLogic = new SharedUserLogic(Context, CommerceOperationsFactory.UserOperations(Context));

            User user = sharedUserLogic.RetrieveUser();

            Context[Key.User] = user;
            ResultSummary resultSummary = (ResultSummary)Context[Key.ResultSummary];

            if (user != null)
            {
                resultSummary.SetResultCode(GetClaimedDeals());
            }
            else
            {
                resultSummary.SetResultCode(ResultCode.UnregisteredUser);
            }
        }
예제 #12
0
        private static void BuildResponse(CommerceContext context,
                                          Exception ex,
                                          Action <HttpResponseMessage,
                                                  HttpStatusCode,
                                                  CallCompletionStatus> completeResponse)
        {
            ResultSummary resultSummary = (ResultSummary)context[Key.ResultSummary];

            // If an exception is specified, set the result code accordingly.
            if (ex != null)
            {
                resultSummary.SetResultCode(ResultCode.UnknownError);
            }

            // Log the response.
            object response = context[Key.Response];

            context.Log.Verbose("{0} response:\r\n{1}", context.ApiCallDescription, General.SerializeJson(response));

            // Get response status code.
            ResultCode     resultCode     = resultSummary.GetResultCode();
            HttpStatusCode httpStatusCode = MapResultToStatusCode(resultCode);

            // Log the result and get call completion status.
            CallCompletionStatus callCompletionStatus = CallCompletionStatus.Success;

            if (httpStatusCode == HttpStatusCode.OK ||
                httpStatusCode == HttpStatusCode.Created ||
                httpStatusCode == HttpStatusCode.Accepted)
            {
                context.Log.Information("{0} call processed successfully.", context.ApiCallDescription);
            }
            else
            {
                if (ex != null)
                {
                    callCompletionStatus = CallCompletionStatus.Error;
                    context.Log.Critical("{0} call ended with an error.", ex, context.ApiCallDescription);
                }
                else
                {
                    callCompletionStatus = CallCompletionStatus.SuccessWithWarnings;
                    context.Log.Warning("{0} call unsuccessfully processed.\r\n\r\nResultCode: {1}\r\n\r\nExplanation: {2}",
                                        (int)resultCode, context.ApiCallDescription, resultSummary.ResultCode,
                                        resultSummary.Explanation);
                }
            }

            // Next, build the HttpResponseMessage for the call.
            HttpResponseMessage httpResponseMessage = null;

            if (context[Key.Request] != null)
            {
                HttpRequestMessage request = (HttpRequestMessage)context[Key.Request];
                httpResponseMessage = request.CreateResponse(httpStatusCode, response);
                AddPerformanceInformation(context, request.RequestUri.Query, httpResponseMessage.Headers);
            }

            // Finally, complete the response.
            completeResponse(httpResponseMessage, httpStatusCode, callCompletionStatus);
        }
예제 #13
0
        /// <summary>
        /// Executes the get active discounts invocation.
        /// </summary>
        public void Execute()
        {
            ResultSummary resultSummary = (ResultSummary)Context[Key.ResultSummary];

            resultSummary.SetResultCode(GetActiveDiscountIds());
        }