Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the FirstDataExtractProcessor class.
 /// </summary>
 /// <param name="enableRedemptionRewards">
 /// Specifies whether redemption rewards should be enabled.
 /// </param>
 public FirstDataExtractProcessor(bool enableRedemptionRewards)
 {
     Context = new CommerceContext(string.Empty, CommerceWorkerConfig.Instance);
     RedeemedDealOperations  = CommerceOperationsFactory.RedeemedDealOperations(Context);
     RewardOperations        = CommerceOperationsFactory.RewardOperations(Context);
     EnableRedemptionRewards = enableRedemptionRewards;
 }
 /// <summary>
 /// Initializes a new instance of the TransactionLogFileProcessor class.
 /// </summary>
 /// <param name="enableRedemptionRewards">
 /// Specifies whether redemption rewards should be enabled.
 /// </param>
 public TransactionLogFileProcessor(bool enableRedemptionRewards)
 {
     Context = new CommerceContext(string.Empty, CommerceWorkerConfig.Instance);
     RedeemedDealOperations  = CommerceOperationsFactory.RedeemedDealOperations(Context);
     RewardOperations        = CommerceOperationsFactory.RewardOperations(Context);
     EnableRedemptionRewards = enableRedemptionRewards;
     Context[Key.Partner]    = Partner.Amex;
     TransactionIdSet        = new HashSet <string>();
 }
        /// <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);
        }
        /// <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);
        }
 public FirstDataAcknowledgmentProcessor()
 {
     Context = new CommerceContext(string.Empty, CommerceWorkerConfig.Instance);
     RedeemedDealOperations = CommerceOperationsFactory.RedeemedDealOperations(Context);
     RewardOperations       = CommerceOperationsFactory.RewardOperations(Context);
 }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the RewardsPtsProcessor class.
 /// </summary>
 public RewardsPtsProcessor()
 {
     Context          = new CommerceContext(string.Empty, CommerceWorkerConfig.Instance);
     RewardOperations = CommerceOperationsFactory.RewardOperations(Context);
 }