Exemple #1
0
        /// <summary>
        /// Adds the referred redemption event to the reward subsystem.
        /// </summary>
        /// <param name="rewardOperations">
        /// The object to use to perform reward operations.
        /// </param>
        /// <param name="context">
        /// The context of the worker action being executed.
        /// </param>
        /// <returns>
        /// The ResultCode describing the result of the operation.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// * Parameter record cannot be null.
        /// -OR-
        /// * Parameter rewardOperations cannot be null.
        /// -OR-
        /// * Parameter context cannot be null.
        /// </exception>
        public static ResultCode RewardReferredRedemption(IRewardOperations rewardOperations,
                                                          CommerceContext context)
        {
            if (rewardOperations == null)
            {
                throw new ArgumentNullException("rewardOperations", "Parameter rewardOperations cannot be null.");
            }

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

            ResultCode result = ResultCode.Success;

            context.Log.Verbose("Attempting to reward for a referred redemption.");
            result = rewardOperations.AddReferredRedemptionReward();
            if (result != ResultCode.Success)
            {
                context.Log.Warning("Unable to add referred redemption reward for this settlement event.\r\n\r\nResultCode: {0}" +
                                    "\r\n\r\nExplanation: {1}", (int)result, result, ResultCodeExplanation.Get(result));
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Adds the redemption event to the reward subsystem.
        /// </summary>
        /// <param name="rewardOperations">
        /// The object to use to perform reward operations.
        /// </param>
        /// <param name="context">
        /// The context of the worker action being executed.
        /// </param>
        /// <returns>
        /// The ResultCode describing the result of the operation.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// * Parameter record cannot be null.
        /// -OR-
        /// * Parameter rewardOperations cannot be null.
        /// -OR-
        /// * Parameter context cannot be null.
        /// </exception>
        public static ResultCode RewardRedemption(IRewardOperations rewardOperations,
                                                  CommerceContext context)
        {
            if (rewardOperations == null)
            {
                throw new ArgumentNullException("rewardOperations", "Parameter rewardOperations cannot be null.");
            }

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

            ResultCode result = ResultCode.Success;

            context.Log.Verbose("Attempting to add redemption reward.");

            context[Key.RewardId] = CommerceWorkerConfig.Instance.FirstEarnRewardId;
            context[Key.FirstEarnRewardAmount]      = CommerceWorkerConfig.Instance.FirstEarnRewardAmount;
            context[Key.FirstEarnRewardExplanation] = CommerceWorkerConfig.Instance.FirstEarnRewardExplanation;
            context.Log.Verbose("Adding redemption reward to data store.");
            result = rewardOperations.AddRedemptionReward();
            if (result != ResultCode.Success)
            {
                context.Log.Warning("Unable to add redemption reward for this transaction.\r\n\r\nResultCode: {0}" +
                                    "\r\n\r\nExplanation: {1}", (int)result, result, ResultCodeExplanation.Get(result));
            }

            return(result);
        }
        /// <summary>
        /// Adds a redemption reward for the transaction in the context.
        /// </summary>
        internal void AddRedemptionRewards()
        {
            RedeemedDealInfo redeemedDealInfo = (RedeemedDealInfo)Context[Key.RedeemedDealInfo];

            if (Context.Config.EnableRedemptionRewards == true && (ReimbursementTender)redeemedDealInfo.ReimbursementTenderId == ReimbursementTender.MicrosoftEarn)
            {
                IRewardOperations rewardOperations = CommerceOperationsFactory.RewardOperations(Context);
                Context[Key.RewardId] = Context.Config.FirstEarnRewardId;
                Context[Key.FirstEarnRewardAmount]      = Context.Config.FirstEarnRewardAmount;
                Context[Key.FirstEarnRewardExplanation] = Context.Config.FirstEarnRewardExplanation;
                ConcurrentDictionary <string, string> payload = new ConcurrentDictionary <string, string>();
                IScheduler scheduler = PartnerFactory.Scheduler(Context.Config.SchedulerQueueName,
                                                                Context.Config.SchedulerTableName,
                                                                Context.Config);
                if (rewardOperations.AddRedemptionReward() == ResultCode.Success)
                {
                    // Add a job to potentially reward user for their first Earn.
                    payload[Key.RewardPayoutId.ToString()]        = ((Guid)Context[Key.RewardPayoutId]).ToString();
                    payload[Key.PartnerCardId.ToString()]         = (string)Context[Key.PartnerCardId];
                    payload[Key.PartnerRedeemedDealId.ToString()] = redeemedDealInfo.PartnerRedeemedDealId;
                    payload[Key.RewardId.ToString()] = Context.Config.FirstEarnRewardId.ToString();
                    ScheduledJobDetails scheduledJobDetails = new ScheduledJobDetails
                    {
                        JobId          = Guid.NewGuid(),
                        JobType        = ScheduledJobType.ApplyRedemptionReward,
                        JobDescription = redeemedDealInfo.GlobalUserId.ToString(),
                        Orchestrated   = true,
                        Payload        = payload
                    };
                    scheduler.ScheduleJobAsync(scheduledJobDetails).Wait();
                }

                // Add a job to potentially reward the person who referred this user for this user's first Earn.
                Context[Key.RedeemedDealId] = ((RedeemedDeal)Context[Key.RedeemedDeal]).Id;
                Guid globalUserId = ((RedeemedDealInfo)Context[Key.RedeemedDealInfo]).GlobalUserId;
                Context[Key.GlobalUserId] = globalUserId;
                string userId = globalUserId.ToString();
                if (rewardOperations.AddReferredRedemptionReward() == ResultCode.Success)
                {
                    payload[Key.GlobalUserId.ToString()]  = userId;
                    payload[Key.ReferralEvent.ToString()] = ReferralEvent.Signup.ToString();
                    ScheduledJobDetails scheduledJobDetails = new ScheduledJobDetails
                    {
                        JobId          = Guid.NewGuid(),
                        JobType        = ScheduledJobType.ApplyReferralReward,
                        JobDescription = userId,
                        Orchestrated   = true,
                        StartTime      = DateTime.UtcNow,
                        Payload        = payload
                    };
                    scheduler.ScheduleJobAsync(scheduledJobDetails).Wait();
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Applies the Earn reward according to RewardPayoutRecord parameters.
        /// </summary>
        /// <returns></returns>
        public OrchestratedExecutionResult Apply()
        {
            OrchestratedExecutionResult result = OrchestratedExecutionResult.NonTerminalError;

            CommerceContext context = new CommerceContext("Updating reward status", CommerceWorkerConfig.Instance);

            context[Key.RewardPayoutId]     = RewardPayoutRecord.RewardPayoutId;
            context[Key.RewardPayoutStatus] = RewardPayoutStatus.NoEligibleUser;
            string actionDescription = String.Empty;

            if (RewardPayoutRecord.PayeeType == PayeeType.User)
            {
                if (RewardPayoutRecord.PayeeId != Guid.Empty)
                {
                    if (RewardPayoutRecord.Rescinded == false)
                    {
                        result = OrchestratedExecutionResult.Success;
                        context[Key.RewardPayoutStatus] = RewardPayoutStatus.Paid;
                        actionDescription = "was paid";
                    }
                    else
                    {
                        context[Key.RewardPayoutStatus] = RewardPayoutStatus.Rescinded;
                        Log.Information("A rescinded reward cannot be paid out.");
                        actionDescription = "could not be paid because the reward has been rescinded";
                    }
                }
                else
                {
                    Log.Warning("Payee ID cannot be Guid.Empty.");
                    actionDescription = "could not be paid because no eligible user could be found";
                }
            }
            else
            {
                Log.Warning("Earn Rewards cannot be applied to payees of type {0}.", RewardPayoutRecord.PayeeType);
                actionDescription = String.Format("could not be paid because payees of type {0} cannot receive Earn Rewards",
                                                  RewardPayoutRecord.PayeeType);
            }

            Log.Verbose("Updating reward payout record status to indicate the reward {0}.", actionDescription);
            IRewardOperations rewardOperations = CommerceOperationsFactory.RewardOperations(context);
            ResultCode        resultCode       = rewardOperations.UpdateRewardPayoutStatus();

            if (resultCode != ResultCode.Success && resultCode != ResultCode.PayoutStatusTooAdvanced)
            {
                result = OrchestratedExecutionResult.NonTerminalError;
                Log.Warning("{0} call unsuccessfully processed.\r\n\r\nResultCode: {1}\r\n\r\nExplanation: {2}",
                            (int)resultCode, context.ApiCallDescription, resultCode,
                            ResultCodeExplanation.Get(resultCode));
            }

            return(result);
        }
Exemple #5
0
        /// <summary>
        /// Updates the reward payout records for those in the ID list to the reward payout status specified.
        /// </summary>
        /// <param name="trackedRedemptionRewardsIds">
        /// The IDs of reward payout records whose status to update.
        /// </param>
        /// <param name="rewardPayoutStatus">
        /// The reward payout status to which to set the records.
        /// </param>
        /// <param name="rewardOperations">
        /// The object to use to perform reward operations.
        /// </param>
        /// <param name="context">
        /// The context of the worker action being executed.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// * Parameter rewardOperations cannot be null.
        /// -OR-
        /// * Parameter context cannot be null.
        /// </exception>
        public static void UpdateOutstandingReferredRedemptionRewards(Collection <int> trackedRedemptionRewardsIds,
                                                                      RewardPayoutStatus rewardPayoutStatus,
                                                                      IRewardOperations rewardOperations,
                                                                      CommerceContext context)
        {
            if (rewardOperations == null)
            {
                throw new ArgumentNullException("rewardOperations", "Parameter rewardOperations cannot be null.");
            }

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

            context.Log.Verbose("Updating specified reward payout records to credit status {0}.", rewardPayoutStatus);
            context[Key.TrackedRedemptionRewardsIds] = trackedRedemptionRewardsIds;
            context[Key.RewardPayoutStatus]          = rewardPayoutStatus;
            rewardOperations.UpdatePendingReferredRedemptionRewards();
        }
        /// <summary>
        /// Executes the task.
        /// </summary>
        /// <returns>
        /// The result of the execution of the task.
        /// </returns>
        public OrchestratedExecutionResult Execute()
        {
            OrchestratedExecutionResult result = OrchestratedExecutionResult.NonTerminalError;

            switch (RewardPayoutRecord.RewardType)
            {
            case RewardType.Undefined:
            case RewardType.StatementCredit:
                Log.Verbose("Updating reward payout record status to indicate the reward is pending.");
                CommerceContext context = new CommerceContext("Updating reward status", CommerceWorkerConfig.Instance);
                context[Key.RewardPayoutId]     = RewardPayoutRecord.RewardPayoutId;
                context[Key.RewardPayoutStatus] = RewardPayoutStatus.Pending;
                IRewardOperations rewardOperations = CommerceOperationsFactory.RewardOperations(context);
                ResultCode        resultCode       = rewardOperations.UpdateRewardPayoutStatus();
                if (resultCode != ResultCode.Success)
                {
                    result = OrchestratedExecutionResult.NonTerminalError;
                    Log.Warning("{0} call unsuccessfully processed.\r\n\r\nResultCode: {1}\r\n\r\nExplanation: {2}",
                                (int)resultCode, context.ApiCallDescription, resultCode,
                                ResultCodeExplanation.Get(resultCode));
                }
                else
                {
                    result = OrchestratedExecutionResult.Success;
                }
                break;

            case RewardType.EarnCredit:
                ApplyEarnCredit applyEarnCredit = new ApplyEarnCredit(RewardPayoutRecord, Log);
                result = applyEarnCredit.Apply();
                break;

            default:
                Log.Error("Invalid reward type {0} in reward payout record.", null, RewardPayoutRecord.RewardType);
                break;
            }

            return(result);
        }
Exemple #7
0
        /// <summary>
        /// Retrieves all outstanding referred redemption reward records.
        /// </summary>
        /// <param name="rewardOperations">
        /// The object to use to perform reward operations.
        /// </param>
        /// <param name="context">
        /// The context of the worker action being executed.
        /// </param>
        /// <returns>
        /// The collection of OutstandingReferredRedemptionReward objects built from the outstanding referred redemption rewards.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// * Parameter rewardOperations cannot be null.
        /// -OR-
        /// * Parameter context cannot be null.
        /// </exception>
        public static Collection <OutstandingReferredRedemptionReward> RetrieveOutstandingReferredRedemptionRewardRecords(IRewardOperations rewardOperations,
                                                                                                                          CommerceContext context)
        {
            if (rewardOperations == null)
            {
                throw new ArgumentNullException("rewardOperations", "Parameter rewardOperations cannot be null.");
            }

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

            Collection <OutstandingReferredRedemptionReward> result = new Collection <OutstandingReferredRedemptionReward>();

            context.Log.Verbose("Retrieving outstanding referred redemption reward records.");
            result = rewardOperations.RetrieveOutstandingReferredRedemptionRewardRecords();
            context.Log.Verbose("Retrieved {0} referred redemption reward records.", result.Count);

            return(result);
        }