public async Task <PaymentResponse> MakeStripePayment(CreditCard creditCard, decimal salePrice)
        {
            PaymentResponse response = new PaymentResponse();

            try
            {
                CardInput cc = new CardInput();

                cc.nameonCard = creditCard.HolderName;
                ////testing 4242424242424242
                cc.cardNumber     = creditCard.Numbers;
                cc.expirationDate = new DateTime(Convert.ToInt32(creditCard.Year), Convert.ToInt32(creditCard.Month), 1).ToShortDateString();
                cc.cvc            = creditCard.Cvc;
                cc.amount         = salePrice;
                cc.customerName   = creditCard.HolderName;

                string hash = JsonConvert.SerializeObject(cc);

                PaymentRequest request = new PaymentRequest();

                Random rnd = new Random();
                request.test = rnd.Next(32, 64);

                request.payload = Encryption.EncryptStringToBytes(hash, Encryption.GetBytes(Encryption.StatsOne(request.test)), Encryption.GetBytes(Encryption.StatsTwo(request.test)));

                response = await((App)App.Current).PostRequest <PaymentRequest, PaymentResponse>("MakeStripePayment", request);
            }
            catch (Exception ex)
            {
                Exception ex2 = new Exception("MakeStripePayment", ex);
                ((App)App.Current).LogError(ex2.Message, "Card holder name is " + creditCard.HolderName);
            }

            return(response);
        }
Example #2
0
 public CreditCardControllerTests()
 {
     _logger       = new Mock <ILogger <CreditCardController> >();
     _mediatorMock = new Mock <IMediator>();
     _validInput   = CreditCardGenerator.CreateValidCardInputFaker().Generate();
     _controller   = new CreditCardController(_mediatorMock.Object, _logger.Object);
 }
        private static ValidationResult ValidateCard(CardInput cardInput)
        {
            var cardValidator = new CardModelValidator();
            var result        = cardValidator.Validate(cardInput);

            return(result);
        }
Example #4
0
        public ActionResult ViewCards(CardInput cardInput)
        {
            if (ModelState.IsValid)
            {
                CardGenerator cardGenerator = new CardGenerator(cardInput.GeneratingDate, cardInput.NumberOfCards);
                List <Card>   CardList      = cardGenerator.GetCardsList();
                CardDAO       cardDAO       = new CardDAO();
                if (!cardDAO.ISExsistCardDate(CardList[0].CardNumber))
                {
                    GridView gridView = new GridView();
                    gridView.DataSource = CardList;
                    gridView.DataBind();
                    Session["CardsListEXCEL"] = gridView;
                    Session["CardsList"]      = CardList;

                    return(View(CardList));
                }
                else
                {
                    ModelState.AddModelError("", "You have already generated cards on this date, so choose aonther date. ");
                    return(View("ShowCards"));
                }
            }
            else
            {
                ModelState.AddModelError("", "Card List is not available");
                return(View("ShowCards"));
            }
        }
Example #5
0
 public CardRegisterCommandHandlerTests()
 {
     _logger          = new Mock <ILogger <CardRegisterCommandHandler> >();
     _respositoryMock = new Mock <ICreditCardRepository>();
     _cardInput       = CreditCardGenerator.CreateValidCardInputFaker().Generate();
     _command         = new CardRegisterCommand(_cardInput);
     _handler         = new CardRegisterCommandHandler(_respositoryMock.Object, _logger.Object);
 }
Example #6
0
        public async Task <IActionResult> Create(string boardId)
        {
            var model = new CardInput
            {
                BoardId = boardId,
            };

            return(View(model));
        }
Example #7
0
            public PaymentResponse MakeStripePayment(CreditCard creditCard)
            {
                PaymentResponse response = new PaymentResponse();

                try
                {
                    CardInput cc = new CardInput();

                    cc.cardNumber     = creditCard.Numbers;
                    cc.expirationDate = new DateTime(Convert.ToInt32(creditCard.Year), Convert.ToInt32(creditCard.Month), 1).ToShortDateString();
                    cc.cvc            = creditCard.Cvc;
                    cc.amount         = 50;
                    cc.customerName   = "test buyer";

                    string hash  = JsonConvert.SerializeObject(cc);
                    byte[] hash1 = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };
                    byte[] hash2 = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };

                    PaymentRequest request = new PaymentRequest();

                    byte[] wtf = Encryption.EncryptStringToBytes(hash, hash1, hash2);
                    request.payload = wtf;

                    //HttpClient client = new HttpClient();
                    //client.BaseAddress = new Uri(((App)App.Current).LAN_Address);

                    //client.DefaultRequestHeaders.Accept.Add(
                    //   new MediaTypeWithQualityHeaderValue("application/json"));

                    //client.DefaultRequestHeaders.Add("EO-Header", ((App)App.Current).User + " : " + ((App)App.Current).Pwd);

                    //string jsonData = JsonConvert.SerializeObject(request);
                    //var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
                    //HttpResponseMessage httpResponse = client.PostAsync("api/Login/MakeStripePayment", content).Result;
                    //if (httpResponse.IsSuccessStatusCode)
                    //{
                    //    Stream streamData = httpResponse.Content.ReadAsStreamAsync().Result;
                    //    StreamReader strReader = new StreamReader(streamData);
                    //    string strData = strReader.ReadToEnd();
                    //    response = JsonConvert.DeserializeObject<PaymentResponse>(strData);
                    //}
                    //else
                    //{
                    //    //MessageBox.Show("There was an error retreiving plants");
                    //}
                }
                catch (Exception ex)
                {
                    int debug = 1;
                }

                return(response);
            }
Example #8
0
        public async Task <IActionResult> Update(CardInput input)
        {
            if (!ModelState.IsValid)
            {
                return(View(input));
            }

            var result = await _cardService.UpdateAsync(input);

            ValidateResult(result);

            return(View(input));
        }
Example #9
0
        public HttpResponseMessage Get(string cardData)
        {
            CardInput     cartInput     = JsonConvert.DeserializeObject <CardInput>(cardData);
            PayPalRequest payPalRequest = new PayPalRequest(cartInput);

            try
            {
                RequestFlow flow = payPalRequest.GetFlow();
                return(Request.CreateResponse(HttpStatusCode.OK, flow));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, "Fail"));
            }
        }
Example #10
0
        public async Task <IActionResult> Register(CardInput cardInput, CancellationToken cancellationToken)
        {
            _logger.LogTrace("Begin: Register");
            try
            {
                var command = new CardRegisterCommand(cardInput);
                await _mediator.Send(command, cancellationToken);

                return(NoContent());
            }
            catch (CreditCardRecordExistingException)
            {
                _logger.LogTrace("Throw RecordExistingException");
                return(Conflict());
            }
        }
Example #11
0
 public CardRegisterCommand(CardInput cardInput)
 {
     CardInput = cardInput;
 }
Example #12
0
        private PaymentResponse MakeStripePayment(CreditCard creditCard, decimal salePrice)
        {
            PaymentResponse response = new PaymentResponse();

            try
            {
                CardInput cc = new CardInput();

                cc.nameonCard = creditCard.HolderName;
                ////testing 4242424242424242
                cc.cardNumber     = creditCard.Numbers;
                cc.expirationDate = new DateTime(Convert.ToInt32(creditCard.Year), Convert.ToInt32(creditCard.Month), 1).ToShortDateString();
                cc.cvc            = creditCard.Cvc;
                cc.amount         = salePrice;
                cc.customerName   = creditCard.HolderName;

                string hash = JsonConvert.SerializeObject(cc);

                PaymentRequest request = new PaymentRequest();

                Random rnd = new Random();
                request.test = rnd.Next(32, 64);

                request.payload = Encryption.EncryptStringToBytes(hash, Encryption.GetBytes(Encryption.StatsOne(request.test)), Encryption.GetBytes(Encryption.StatsTwo(request.test)));

                cc.token = creditCard.token;

                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(((App)App.Current).LAN_Address);

                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));

                client.DefaultRequestHeaders.Add("EO-Header", ((App)App.Current).User + " : " + ((App)App.Current).Pwd);

                string jsonData = JsonConvert.SerializeObject(request);
                var    content  = new StringContent(jsonData, Encoding.UTF8, "application/json");
                HttpResponseMessage httpResponse = client.PostAsync("api/Login/MakeStripePayment", content).Result;
                if (httpResponse.IsSuccessStatusCode)
                {
                    Stream       streamData = httpResponse.Content.ReadAsStreamAsync().Result;
                    StreamReader strReader  = new StreamReader(streamData);
                    string       strData    = strReader.ReadToEnd();
                    response = JsonConvert.DeserializeObject <PaymentResponse>(strData);

                    if (response.success)
                    {
                        MessagingCenter.Send <PaymentResponse>(response, "CCPayment");
                    }
                }
                else
                {
                    //MessageBox.Show("There was an error processing the credit card payment.");
                }
            }
            catch (Exception ex)
            {
                Exception ex2 = new Exception("MakeStripePayment", ex);
                ((App)App.Current).LogError(ex2.Message, "Card holder name is " + creditCard.HolderName);
            }

            return(response);
        }
Example #13
0
        public PaymentResponse MakeStripePayment([FromBody] PaymentRequest request)
        {
            PaymentResponse response = new PaymentResponse();

            try
            {
                //byte[] hash1 = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };
                //byte[] hash2 = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };

                byte[] hash1 = Encryption.GetBytes(Encryption.StatsOne(request.test));
                byte[] hash2 = Encryption.GetBytes(Encryption.StatsOne(request.test));

                string cc = Encryption.DecryptStringFromBytes(request.payload, hash1, hash2);

                //If I use the harcoded hash1 and hash2 values - no deserialization problems
                //If is use custom rindjael key and IV values, the json object needs to be "fixed"
                cc = Fix(cc);

                CardInput ci = JsonConvert.DeserializeObject <CardInput>(cc);

                DateTime dt = Convert.ToDateTime(ci.expirationDate);

                StripeConfiguration.ApiKey = "pk_test_qEqBdPz6WTh3CNdcc9bgFXpz00haS1e8hC";

                var options = new TokenCreateOptions
                {
                    Card = new TokenCardOptions
                    {
                        Number   = ci.cardNumber,
                        ExpYear  = dt.Year,
                        ExpMonth = dt.Month,
                        Cvc      = ci.cvc,
                        Currency = "usd"
                    }
                };

                var tokenService = new TokenService();

                Token stripeToken = tokenService.CreateAsync(options).Result;

                string checkToken = stripeToken.Id;

                if (!String.IsNullOrEmpty(checkToken))
                {
                    decimal salePrice = ci.amount;
                    string  buyer     = ci.customerName;

                    Charge c = new Charge();

                    var chargeOptions = new ChargeCreateOptions
                    {
                        //don't know why they do this  - if your sale amount is 46.64 and you call Convert.ToInt64
                        //you'll get 47 which stripe interprets as $0.47  WTF?
                        Amount      = Convert.ToInt64(salePrice * 100),
                        Currency    = "usd",
                        Description = "Charge for " + buyer + " on " + Convert.ToString(DateTime.Now),
                        Source      = checkToken
                    };

                    //StripeConfiguration.ApiKey = "pk_test_qEqBdPz6WTh3CNdcc9bgFXpz00haS1e8hC";

                    StripeConfiguration.ApiKey = "sk_test_6vJyMV6NxHArGV6kI2EL6R7V00kzjXJ72u";

                    var service1 = new ChargeService();

                    c = service1.Create(chargeOptions);

                    if (c.Paid)
                    {
                        response.StripeChargeId = c.Id;
                        response.success        = true;
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is StripeException)
                {
                    response.Messages.Add("Stripe", new List <string>()
                    {
                        HandleStripeException(ex as StripeException)
                    });
                }
            }

            return(response);
        }
Example #14
0
        //Request and Reads the players and card details from console.
        public List <Player> ReadPlayerAndCardDetails()
        {
            // assuming that player names must be unique
            string PlayerName, CardType, CardInput, CardNumber;
            int    NumberOfPlayers;

            System.Console.WriteLine("Please enter the number of players");

            //Validate the input is a number
            while (!int.TryParse(Console.ReadLine(), out NumberOfPlayers))
            {
                Console.BackgroundColor = ConsoleColor.Red;
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Please enter a number!Try Again!");

                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Please enter the number of players again");
            }

            for (int j = 0; j < NumberOfPlayers; j++)
            {
                Console.WriteLine("Please enter a Name");
                PlayerName = Console.ReadLine();
                //SortedList<int,string> Suit = new SortedList<int,string>();
                while (PlayerName == "")
                {
                    Console.BackgroundColor = ConsoleColor.Red;
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("Please enter a name!Try Again!");

                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.ForegroundColor = ConsoleColor.White;
                    PlayerName = Console.ReadLine();
                }
                var         inputLength = 0;
                List <Card> Hand        = new List <Card>();
                if (!(PlayerCardDetails.Players.Count(x => x.Name == PlayerName) > 0))
                {
                    Console.WriteLine("Enter five card details");
                    for (int i = 0; i < 5; i++)
                    {
                        Card c           = new Card();
                        var  isValidCard = true;
                        do
                        {
                            isValidCard = true;
                            Console.WriteLine("Card " + (i + 1) + " Details");
                            CardInput   = Console.ReadLine();
                            inputLength = CardInput.Length;
                            if (inputLength == 2 || inputLength == 3) // Valid Input Length -> Proceed
                            {
                                CardNumber = CardInput.Substring(0, inputLength - 1);
                                CardType   = CardInput.Substring(inputLength - 1);
                                c          = new Card(CardType, CardNumber);
                                //Check if the card type and number are valid
                                if (!c.isValid)
                                {
                                    isValidCard = false;
                                }
                            }
                            else// InValid Input Length -> Warn and Ask Input again
                            {
                                isValidCard = false;
                            }

                            if (!isValidCard)
                            {
                                Console.BackgroundColor = ConsoleColor.Red;
                                Console.ForegroundColor = ConsoleColor.White;
                                Console.WriteLine("Card not valid! ReTry!");
                                Console.BackgroundColor = ConsoleColor.Black;
                                Console.ForegroundColor = ConsoleColor.White;
                            }
                        } while (!isValidCard);
                        Hand.Add(c);
                    }
                    PlayerCardDetails.Players.Add(new Player {
                        Name = PlayerName, Hand = Hand
                    });
                }
                else
                {
                    Console.WriteLine("Player Name needs to be unique!ReTry!");
                    j--;
                }
            }
            return(PlayerCardDetails.Players);
        }
Example #15
0
        /// <summary>
        ///
        /// </summary>
        public async Task <Result <CommandResult> > UpdateAsync(CardInput input)
        {
            var updateCommand = _mapper.Map <UpdateCardCommand>(input);

            return(await SendCommandAsync(updateCommand));
        }
Example #16
0
        /// <summary>
        ///
        /// </summary>
        public async Task <Result <CommandResult> > CreateAsync(CardInput input)
        {
            var project = _mapper.Map <CreateCardCommand>(input);

            return(await SendCommandAsync(project));
        }