示例#1
0
        public async Task <ActionResult <Board> > CreateCard(string boardId, string laneId, Card cardIn)
        {
            var board = boardService.GetById(boardId);

            if (board == null)
            {
                return(NoContent());
            }
            var lane = laneService.Get(laneId);

            if (lane == null)
            {
                return(NoContent());
            }
            if (board.Lanes.FindIndex(l => l.Id == lane.Id) < 0)
            {
                return(NoContent());
            }

            // Create card in database
            var card = await cardService.Create(cardIn);

            // Add card to lane
            var updatedLane = await laneService.AddCard(lane.Id, card);

            // Update lane in board
            await boardService.UpdateLane(board.Id, updatedLane);

            hubContext.Clients.All.SendAsync("BroadcastMessage");

            return(Ok(new { message = "Card added" }));
        }
示例#2
0
        public static Card CreateCard(string cusId, string TokenCard)
        {
            // Set your secret key: remember to change this to your live secret key in production
            // See your keys here: https://dashboard.stripe.com/Card/apikeys
            StripeConfiguration.SetApiKey(SecretKey);

            //var TokenOptions = new TokenCreateOptions
            //{
            //    Card = new CreditCardOptions
            //    {
            //        Name = card.Name,
            //        ExpMonth = card.Exp_Month,
            //        Number = card.CardNumber,
            //        ExpYear = card.Exp_Year,
            //        Cvc = card.CVC,
            //        AddressCity = card.City,
            //        AddressLine1 = card.Address1,
            //        AddressLine2 = card.Address2,
            //        AddressCountry = card.Country,
            //        AddressZip = card.ZipCode,
            //    }
            //};
            //var TokenService = new TokenService();
            //var token = TokenService.Create(TokenOptions);

            var CardOptions = new CardCreateOptions
            {
                SourceToken = TokenCard
            };
            var Cardservice = new CardService();

            var CardCr = Cardservice.Create(cusId, CardOptions);

            return(CardCr);
        }
示例#3
0
        public void Create()
        {
            //Arrange
            var card = new Card()
            {
                Id = 1
            };
            var iRepositoryCard = new MockIRepository <Card>()
                                  .MockCreate(card);
            var iRepositoryAccount = new MockIRepository <Account>();
            var cardRepository     = new MockCardRepository();
            var accountRepository  = new MockAccountRepository();
            var cardService        = new CardService(
                cardRepository.Object,
                accountRepository.Object,
                new EncryptionService(),
                iRepositoryAccount.Object,
                iRepositoryCard.Object);

            //Act
            var createdCard = cardService.Create(card);

            //Assert
            Assert.IsNotNull(createdCard);
        }
        /// <inheritdoc />
        /// <exception cref="UserNotFoundException">Thrown when the user is not found</exception>
        public async Task <PaymentMethodViewModel> AddPaymentMethod(AddPaymentMethodBody addPaymentMethodBody)
        {
            var user = await ApplicationContext.Users.Include(x => x.PaymentMethods)
                       .FirstOrDefaultAsync(x => x.Id == addPaymentMethodBody.UserId);

            if (user == null)
            {
                throw new UserNotFoundException();
            }

            // if the user doesn't have a stripe customer create one
            if (user.StripeCustomerId == null)
            {
                var customer = CreateCustomer(user);
                user.StripeCustomerId = customer.Id;
                await ApplicationContext.SaveChangesAsync();
            }

            var options = new CardCreateOptions()
            {
                Source = addPaymentMethodBody.CardToken
            };

            var service = new CardService();

            try
            {
                // request create card to Stripe api
                var card = service.Create(user.StripeCustomerId, options);

                // create payment method using Stripe response data
                var paymentMethod = new PaymentMethod()
                {
                    StripeCardId = card.Id,
                    Brand        = card.Brand,
                    Country      = card.Country,
                    Funding      = card.Funding,
                    Name         = card.Name,
                    ExpiryMonth  = card.ExpMonth,
                    ExpiryYear   = card.ExpYear,
                    LastFour     = card.Last4,
                    NickName     = addPaymentMethodBody.NickName,
                    IsDefault    = !user.PaymentMethods.Any()
                };

                user.PaymentMethods.Add(paymentMethod);
                await ApplicationContext.SaveChangesAsync();

                return(Mapper.Map <PaymentMethodViewModel>(paymentMethod));
            }
            catch (Exception e)
            {
                Logger.LogInformation(e.Message);
                throw;
            }
        }
示例#5
0
        public void AddCard(string customerId, string cardToken)
        {
            StripeConfiguration.ApiKey = secretkey;
            var options = new CardCreateOptions
            {
                Source = cardToken,
            };
            var service = new CardService();
            var card    = service.Create(customerId, options);

            Console.WriteLine($"Card: {JsonConvert.SerializeObject(card)}");
        }
示例#6
0
        public int Create(string name, int id, string description)
        {
            var         map      = mapper.CreateMapper();
            TaskListDTO taskList = TaskListService.Get(id);
            CardDTO     card     = new CardDTO {
                Name = name, TaskListId = taskList.Id, Description = description
            };

            int i = card.Id = CardService.Create(card);

            return(i);
        }
示例#7
0
        public void Create_saves_a_card_via_context()
        {
            var mockSet = new Mock <DbSet <Card> >();

            var mockContext = new Mock <TrelloDbContext>();

            mockContext.Setup(m => m.tblCard).Returns(mockSet.Object);

            var service = new CardService(mockContext.Object);

            service.Create(new Card()
            {
                Title = "Card A"
            });

            mockSet.Verify(m => m.Add(It.IsAny <Card>()), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
        public void CreateCard_ShouldCallCreateInDalOnce()
        {
            //Arrange
            CardDTO cardDTO = new CardDTO
            {
                Description = "Description",
            };
            var          mockMapper     = new Mock <IMapper>();
            var          mockRepository = new Mock <ICardRepository>();
            ICardService service        = new CardService(mockMapper.Object, mockRepository.Object);

            mockRepository.Setup(x => x.CreateAsync(It.IsAny <Card>())).ReturnsAsync(It.IsAny <Card>());

            //Act
            service.Create(cardDTO);

            //Assert
            mockRepository.Verify(x => x.Create(It.IsAny <Card>()), Times.Once);
        }
        public ActionResult Create(CardCreateDto Card)
        {
            var result = _CardService.Create(Card);

            if (result != null)
            {
                return(new JsonResult(new
                {
                    Message = "Datos de la tarjeta ingresados correctamente. ¿Desearía que la aplicación recuerde los datos de su tarjeta?",
                    TarjetaRegistrada = result
                }));
            }
            else
            {
                return(new JsonResult(new
                {
                    Message = "Error al ingresar los datos, verifique bien si los datos que ha ingresado existen o estan correctos."
                }));
            }
        }
示例#10
0
        public ActionResult AddCard(AddCardViewModel model)
        {
            if (ModelState.IsValid)
            {
                var mapper = new MapperConfiguration(
                    cfg => cfg.CreateMap <AddCardViewModel, CreditCardDTO>()).CreateMapper();
                var card   = mapper.Map <AddCardViewModel, CreditCardDTO>(model);
                var userId = AuthenticationManager.User.Identity.GetUserId();

                OperationDetails operationDetails = CardService.Create(card, userId);

                if (operationDetails.Succedeed)
                {
                    return(Redirect("/Account/UserProfile"));
                }
                else
                {
                    ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
                }
            }
            return(View(model));
        }
示例#11
0
 public ActionResult <Card> Create(Card card)
 {
     _cardService.Create(card);
     return(CreatedAtRoute("GetCard", new { id = card.Id.ToString() }, card));
 }
示例#12
0
        public AccountPaymentMethod CreateCreditCardPaymentMethod(string cardNumber, long cardExpYear, long cardExpMonth, string cardCvc, byte usedFor)
        {
            try
            {
                /* var options = new PaymentMethodCreateOptions */
                /* { */
                /*   Type = "card", */
                /*   Card = new PaymentMethodCardOptions */
                /*   { */
                /*     Number = cardNumber, */
                /*     ExpMonth = cardExpMonth, */
                /*     ExpYear = cardExpYear, */
                /*     Cvc = cardCvc */
                /*   }, */
                /* }; */
                /* var service = new PaymentMethodService(); */
                /* PaymentMethod pm = service.Create(options); */
                var tokenOptions = new TokenCreateOptions
                {
                    Card = new CreditCardOptions
                    {
                        Number   = cardNumber,
                        ExpYear  = cardExpYear,
                        ExpMonth = cardExpMonth,
                        Cvc      = cardCvc
                    }
                };

                var   tokenService = new TokenService();
                Token token        = tokenService.Create(tokenOptions);

                var stripeCustomer = GetStripeCustomer();

                var cardOptions = new CardCreateOptions
                {
                    Source = token.Id
                };

                var  service = new CardService();
                Card card    = service.Create(stripeCustomer.Id, cardOptions);

                using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
                {
                    var paymentMehtod = new AccountPaymentMethod()
                    {
                        Id                       = Guid.NewGuid(),
                        AccountId                = _accountId,
                        PaymentMethod            = (byte)PaymentMethods.CreditCard,
                        TokenId                  = token.Id,
                        CreditCardBrand          = token.Card.Brand,
                        CreditCardLast4          = token.Card.Last4,
                        CreditCardExpMonth       = token.Card.ExpMonth,
                        CreditCardExYear         = token.Card.ExpYear,
                        UsedFor                  = usedFor,
                        ReferencePaymentMethodId = card.Id,
                        CreatedOn                = DateTime.UtcNow
                    };

                    dbContext.AccountPaymentMethods.Add(paymentMehtod);
                    dbContext.SaveChanges();

                    return(paymentMehtod);
                }
            }
            catch (StripeException e)
            {
                switch (e.StripeError.ErrorType)
                {
                case "card_error":
                    Console.WriteLine("Code: " + e.StripeError.Code);
                    Console.WriteLine("Message: " + e.StripeError.Message);
                    break;

                case "api_connection_error":
                    Console.WriteLine("Code: " + e.StripeError.Code);
                    Console.WriteLine("Message: " + e.StripeError.Message);
                    break;

                case "api_error":
                    Console.WriteLine("Code: " + e.StripeError.Code);
                    Console.WriteLine("Message: " + e.StripeError.Message);
                    break;

                case "authentication_error":
                    Console.WriteLine("Code: " + e.StripeError.Code);
                    Console.WriteLine("Message: " + e.StripeError.Message);
                    break;

                case "invalid_request_error":
                    Console.WriteLine("Code: " + e.StripeError.Code);
                    Console.WriteLine("Message: " + e.StripeError.Message);
                    break;

                case "rate_limit_error":
                    Console.WriteLine("Code: " + e.StripeError.Code);
                    Console.WriteLine("Message: " + e.StripeError.Message);
                    break;

                case "validation_error":
                    Console.WriteLine("Code: " + e.StripeError.Code);
                    Console.WriteLine("Message: " + e.StripeError.Message);
                    break;

                default:
                    Console.WriteLine("Code: " + e.StripeError.Code);
                    Console.WriteLine("Message: " + e.StripeError.Message);
                    break;
                }

                return(null);
            }
        }
示例#13
0
        public CreateResult Create(PartnerCardDTO card)
        {
            CreateResult result        = default;
            CardService  cardService   = new CardService();
            TokenService tokenService  = new TokenService();
            Token        stripeToken   = tokenService.Get(card.StripeId);
            Card         stripeNewCard = stripeToken.Card;

            if (stripeNewCard.Funding == "credit")
            {
                Connector.IsTransaction = true;
                try
                {
                    PartnerDTO partner         = card.Partner;
                    string     partnerStripeId = partner.StripeId;
                    if (partnerStripeId == null)
                    {
                        CustomerService customerService = new CustomerService();
                        PartnerBLL      partnerBLL      = new PartnerBLL(Connector);
                        Customer        customer        = customerService.Create(new CustomerCreateOptions()
                        {
                            Email = partner.EmailAddress
                        });
                        partner.StripeId = customer.Id;
                        partnerStripeId  = partner.StripeId;
                        partnerBLL.Update(card.Partner.Id, new Dictionary <string, object> {
                            { "StripeId", partner.StripeId }
                        });
                    }
                    IEnumerable <Card> stripeCards = cardService.List(partnerStripeId);
                    if (stripeCards.Count() < 10)
                    {
                        bool hasAlreadyBeenAdded = false;
                        foreach (Card stripeCard in stripeCards)
                        {
                            if (stripeCard.Fingerprint == stripeNewCard.Fingerprint)
                            {
                                hasAlreadyBeenAdded = true;
                                break;
                            }
                        }
                        if (!hasAlreadyBeenAdded)
                        {
                            CardCreateOptions cardCreateOptions = new CardCreateOptions()
                            {
                                SourceToken = card.StripeId
                            };
                            stripeNewCard = cardService.Create(card.Partner.StripeId, cardCreateOptions);
                            card.StripeId = stripeNewCard.Id;
                            Repository.Insert(card, out Guid? id);
                            card.Id = id.Value;
                            result  = CreateResult.OK;
                        }
                        else
                        {
                            result = CreateResult.CardHasAlreadyBeenAdded;
                        }
                        Connector.CommitTransaction();
                    }
                    else
                    {
                        Connector.RollbackTransaction();
                        result = CreateResult.MaximumAmountOfCardsReached;
                    }
                }
                catch (Exception exception)
                {
                    Connector.RollbackTransaction();
                    throw exception;
                }
            }
            else
            {
                result = CreateResult.CardIsNotCredit;
            }
            return(result);
        }