예제 #1
0
        /// <summary>
        /// Generates a legacy NewCardInfo object for the specified credit card number.
        /// </summary>
        /// <param name="newCardNumber">
        /// The object containing the number for which to generate a legacy NewCardInfo object.
        /// </param>
        /// <returns>
        /// The generated NewCardInfo object.
        /// </returns>
        /// <remarks>
        /// When the V1 AddCard and GetCard APIs are removed, legacy compatibility can be removed from all layers.
        /// </remarks>
        internal static NewCardInfo GenerateLegacyCardInfo(NewCardNumber newCardNumber)
        {
            string      number = newCardNumber.Number;
            NewCardInfo result = new NewCardInfo
            {
                Expiration = DateTime.MaxValue,
                Number     = number,
                FlightId   = newCardNumber.FlightId
            };

            if (String.IsNullOrWhiteSpace(number) == false)
            {
                switch (number[0])
                {
                case '4':
                    result.CardBrand = "Visa";
                    break;

                case '5':
                    result.CardBrand = "MasterCard";
                    break;

                case '3':
                    if (number[1] == '4' || number[1] == '7')
                    {
                        result.CardBrand = "AmericanExpress";
                    }
                    break;
                }
            }

            return(result);
        }
예제 #2
0
        public Task <HttpResponseMessage> Add(NewCardNumber newCardNumber)
        {
            Stopwatch callTimer = Stopwatch.StartNew();

            Task <HttpResponseMessage> result;

            // Build a context object to pass down the pipeline.
            CommerceContext context = CommerceContext.BuildAsynchronousRestContext("Add card and queue claiming already claimed deals",
                                                                                   Request, new AddCardResponse(), callTimer);

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

                context.Log.Information("Processing {0} call.", context.ApiCallDescription);

                // Generate a legacy NewCardInfo object from the specified number.
                NewCardInfo newCardInfo = ControllerUtilities.GenerateLegacyCardInfo(newCardNumber);
                ControllerUtilities.LogObfuscatedNewCardInfo(newCardInfo, context);

                // Add parameters of the call to the context.
                context[Key.QueueJob]          = true;
                context[Key.NewCardInfo]       = newCardInfo;
                context[Key.GlobalUserId]      = CommerceContext.PopulateUserId(context);
                context[Key.ReferrerId]        = newCardNumber.Referrer;
                context[Key.RewardProgramType] = ControllerUtilities.GetRewardProgramAssociatedWithRequest(this.Request);

                // Create an executor object to execute the API invocation.
                AddCardExecutor executor = new AddCardExecutor(context);
                Task.Factory.StartNew(async() => await executor.Execute());

                result = ((TaskCompletionSource <HttpResponseMessage>)context[Key.TaskCompletionSource]).Task;
            }
            catch (Exception ex)
            {
                result = RestResponder.CreateExceptionTask(context, ex);
            }

            return(result);
        }