コード例 #1
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);
        }
コード例 #2
0
        /// <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();
                }
            }
        }