/// <summary>
        /// Executes the Remove card invocation.
        /// </summary>
        public async Task Execute()
        {
            try
            {
                SharedUserLogic sharedUserLogic = new SharedUserLogic(Context,
                                                                      CommerceOperationsFactory.UserOperations(Context));
                SharedCardLogic sharedCardLogic = new SharedCardLogic(Context,
                                                                      CommerceOperationsFactory.CardOperations(Context));
                RemoveCardConcluder removeCardConcluder = new RemoveCardConcluder(Context);

                User user = sharedUserLogic.RetrieveUser();
                Context[Key.User] = user;
                if (user != null)
                {
                    Card card = sharedCardLogic.RetrieveCard();
                    Context[Key.Card] = card;
                    if (card != null)
                    {
                        if (card.GlobalUserId == user.GlobalId)
                        {
                            Context.Log.Verbose("Attempting to remove the card from all current partners.");
                            RemoveCardInvoker removeCardInvoker = new RemoveCardInvoker(Context);
                            await removeCardInvoker.Invoke();
                        }
                        else
                        {
                            removeCardConcluder.Conclude(ResultCode.CardDoesNotBelongToUser);
                        }
                    }
                    else
                    {
                        removeCardConcluder.Conclude(ResultCode.UnregisteredCard);
                    }
                }
                else
                {
                    removeCardConcluder.Conclude(ResultCode.UnexpectedUnregisteredUser);
                }
            }
            catch (Exception ex)
            {
                ((ResultSummary)Context[Key.ResultSummary]).SetResultCode(ResultCode.UnknownError);
                RestResponder.BuildAsynchronousResponse(Context, ex);
            }
        }
示例#2
0
        /// <summary>
        /// Adds the card in the context for the user in the context to this partner.
        /// </summary>
        /// <returns>
        /// A task that will yield the result code for the operation.
        /// </returns>
        public async Task <ResultCode> AddCardAsync()
        {
            ResultCode result;

            // If the card has a PAN token, see if a Visa ID has already been allocated for that PAN token. We do this because Visa rejects
            //  registering a card that had previously been registered to a different account. This approach allows us to differentiate false
            //  positives (i.e. Visa rejects a card for which we already have the Visa partner card ID somewhere in our DB) from true positives
            //  (i.e. Visa rejects a card erroneously as far as we can tell.)

            ICardOperations cardOperations = CommerceOperationsFactory.CardOperations(Context);

            //Since we will comment FDC code, FDC PAN token will not be assigned to a card. So the code below is commented since RetrieveVisaPartnerCardId will never return any card
            //without FDC PAN token

            /*
             * Card card = (Card)Context[Key.Card];
             * string visaPartnerCardId = cardOperations.RetrieveVisaPartnerCardId();
             * if (String.IsNullOrWhiteSpace(visaPartnerCardId) == false)
             * {
             *  PartnerCardInfo partnerCardInfo = GetVisaCardInfo(card);
             *  partnerCardInfo.PartnerCardId = visaPartnerCardId;
             *  partnerCardInfo.PartnerCardSuffix = "00";
             *  result = ResultCode.Created;
             *  result = Task.FromResult(result).Result;
             * }
             * else
             */
            {
                var userEnrolledWithVisa = false;
                var cards = cardOperations.RetrieveCards();
                if (cards != null)
                {
                    userEnrolledWithVisa = cards.Any(c => c.CardBrand == CardBrand.Visa);
                }
                result = await InvokeVisaAddCard(userEnrolledWithVisa);
            }

            return(result);
        }
 /// <summary>
 /// Initializes a new instance of the MasterCardFilteringProcessor class.
 /// </summary>
 public MasterCardFilteringProcessor()
 {
     Context        = new CommerceContext(string.Empty, CommerceWorkerConfig.Instance);
     CardOperations = CommerceOperationsFactory.CardOperations(Context);
 }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the NotifyAuthorization class.
 /// </summary>
 /// <param name="context">
 /// The context for this API call.
 /// </param>
 public NotifyAuthorization(CommerceContext context)
     : base(context)
 {
     CardOperations = CommerceOperationsFactory.CardOperations(Context);
 }
示例#5
0
        /// <summary>
        /// Executes the Claim Deal API invocation.
        /// </summary>
        public async Task Execute()
        {
            try
            {
                SharedUserLogic sharedUserLogic = new SharedUserLogic(Context,
                                                                      CommerceOperationsFactory.UserOperations(Context));
                SharedCardLogic sharedCardLogic = new SharedCardLogic(Context,
                                                                      CommerceOperationsFactory.CardOperations(Context));
                SharedDealLogic sharedDealLogic = new SharedDealLogic(Context,
                                                                      CommerceOperationsFactory.DealOperations(Context));
                ClaimDealConcluder claimDealConcluder = new ClaimDealConcluder(Context);

                ResultCode extractionResult = ExtractClaimDealPayload();
                if (extractionResult == ResultCode.Success)
                {
                    Deal deal = sharedDealLogic.RetrieveDeal();
                    Context[Key.Deal] = deal;
                    if (deal != null)
                    {
                        Context[Key.DealDiscountSummary] = deal.DiscountSummary;
                        User user = sharedUserLogic.RetrieveUser();
                        Context[Key.User] = user;
                        if (user != null)
                        {
                            Card card = sharedCardLogic.RetrieveCard();
                            Context[Key.Card] = card;
                            if (card != null)
                            {
                                // If the deal and card have common ground, claim the deal for the card.
                                if (MustClaim(deal, card) == true)
                                {
                                    Context[Key.MerchantName] = deal.MerchantName;
                                    Context.Log.Verbose("Trying to claim the deal for the user with the appropriate partner.");
                                    ClaimDealInvoker claimDealInvoker = new ClaimDealInvoker(Context);
                                    await claimDealInvoker.Invoke();
                                }
                                else
                                {
                                    Context.Log.Verbose("It is not necessary to claim this deal for this card.");
                                    ((ResultSummary)Context[Key.ResultSummary]).SetResultCode(ResultCode.Success);
                                    RestResponder.BuildAsynchronousResponse(Context);
                                }
                            }
                            else
                            {
                                claimDealConcluder.Conclude(ResultCode.UnregisteredCard);
                            }
                        }
                        else
                        {
                            claimDealConcluder.Conclude(ResultCode.UnexpectedUnregisteredUser);
                        }
                    }
                    else
                    {
                        claimDealConcluder.Conclude(ResultCode.UnactionableDealId);
                    }
                }
                else
                {
                    claimDealConcluder.Conclude(extractionResult);
                }
            }
            catch (Exception ex)
            {
                ((ResultSummary)Context[Key.ResultSummary]).SetResultCode(ResultCode.UnknownError);
                RestResponder.BuildAsynchronousResponse(Context, ex);
            }
        }
 /// <summary>
 /// Initializes a new instance of the ServiceGetCardsExecutor class.
 /// </summary>
 /// <param name="context">
 /// The context to use while processing the request.
 /// </param>
 public ServiceGetCardsExecutor(CommerceContext context)
 {
     Context        = context;
     CardOperations = CommerceOperationsFactory.CardOperations(Context);
 }
 /// <summary>
 /// Initializes a new instance of the RemoveCardConcluder class.
 /// </summary>
 /// <param name="context">
 /// The context of the current API call.
 /// </param>
 public RemoveCardConcluder(CommerceContext context)
 {
     Context        = context;
     CardOperations = CommerceOperationsFactory.CardOperations(Context);
 }
示例#8
0
 /// <summary>
 /// Initializes a new instance of the AddCardConcluder class.
 /// </summary>
 /// <param name="context">
 /// The context of the current API call.
 /// </param>
 public AddCardConcluder(CommerceContext context)
 {
     Context        = context;
     UserOperations = CommerceOperationsFactory.UserOperations(Context);
     CardOperations = CommerceOperationsFactory.CardOperations(Context);
 }
示例#9
0
        /// <summary>
        /// Places the User object representing the person making this request to the context.
        /// </summary>
        /// <returns>
        /// The ResultCode corresponding to the result of the operation.
        /// </returns>
        /// <remarks>
        /// If flagged to do so, a user account will be created and associated with the specified e-mail address, if the e-mail
        /// address has not already been used.
        /// </remarks>
        private ResultCode PlaceUserInContext()
        {
            ResultCode result = ResultCode.Success;

            bool createUnauthenticatedAccount = false;

            if (Context[Key.CreateUnauthenticatedAccount] != null)
            {
                createUnauthenticatedAccount = (bool)Context[Key.CreateUnauthenticatedAccount];
            }

            if (createUnauthenticatedAccount == true)
            {
                string emailAddress = Context[Key.EmailAddress] as string;
                if (String.IsNullOrWhiteSpace(emailAddress) == false)
                {
                    try
                    {
                        // Ensure the e-mail address may be valid.
                        MailAddress mailAddress = new MailAddress(emailAddress);

                        // Attempt to add a user to User Services via Users Dal and obtain its authentication vector.
                        IUsersDal usersDal = PartnerFactory.UsersDal(Context.Config);
                        Users.Dal.DataModel.User fullUser = usersDal.CreateUnauthenticatedUser(mailAddress.Address, (string)Context[Key.ReferrerId],
                                                                                               (string)Context[Key.UserLocation]);
                        UnauthenticatedAddCardResponse response = (UnauthenticatedAddCardResponse)Context[Key.Response];
                        if (String.IsNullOrWhiteSpace(fullUser.MsId) == true)
                        {
                            response.AuthenticationVector = AuthenticationVector.Email.ToString();
                        }
                        else if (fullUser.MsId.StartsWith("FB-", StringComparison.OrdinalIgnoreCase) == true)
                        {
                            response.AuthenticationVector = AuthenticationVector.Facebook.ToString();
                        }
                        else
                        {
                            response.AuthenticationVector = AuthenticationVector.MicrosoftAccount.ToString();
                        }

                        Guid userId = fullUser.Id;
                        Context[Key.GlobalUserId] = userId;

                        // If the user returned by User Services has not already been registered in the Commerce system, register a new Commerce user.
                        User user = SharedUserLogic.RetrieveUser();
                        if (user == null)
                        {
                            user = new User(userId, Guid.NewGuid());
                            Context[Key.User] = user;
                            result            = SharedUserLogic.AddUser();

                            if (result == ResultCode.Created)
                            {
                                Analytics.AddRegisterUserEvent(user.GlobalId, user.AnalyticsEventId, Guid.Empty, Context[Key.ReferrerId] as string);
                                result = ResultCode.Success;
                            }
                        }
                        else
                        {
                            Context[Key.User] = user;
                        }

                        // If the user was added or retrieved successfully, proceed.
                        if (result == ResultCode.Success)
                        {
                            // If the user has not already signed up officially with Bing Offers, proceed.
                            if (response.AuthenticationVector == AuthenticationVector.Email.ToString())
                            {
                                // If the user has not already added a card, proceed.
                                SharedCardLogic sharedCardLogic = new SharedCardLogic(Context, CommerceOperationsFactory.CardOperations(Context));
                                if (sharedCardLogic.RetrieveUserCards().Count() == 0)
                                {
                                    response.ActivationToken = fullUser.ActivationToken;
                                }
                                else
                                {
                                    result = ResultCode.UnauthenticatedUserAlreadyExists;
                                }
                            }
                            else
                            {
                                result = ResultCode.UserAlreadyExists;
                            }
                        }
                    }
                    catch (FormatException)
                    {
                        result = ResultCode.InvalidParameter;
                    }
                }
                else
                {
                    result = ResultCode.ParameterCannotBeNull;
                }
            }
            else
            {
                Context[Key.User] = SharedUserLogic.RetrieveUser();
            }

            return(result);
        }