public Card CreateCartdStripe(StripeCardDTO dto, string customerid)
        {
            var tokenCreate = new TokenCreateOptions
            {
                Card = new TokenCardOptions
                {
                    Number   = dto.Cardnumber,
                    ExpMonth = dto.Month,
                    ExpYear  = dto.Year,
                    Cvc      = dto.CVC,
                    Name     = dto.CardHolderName
                },
            };
            var tokenService = new TokenService();
            var token        = tokenService.Create(tokenCreate);

            var options = new CardCreateOptions
            {
                Source = token.Id
            };
            var service  = new Stripe.CardService();
            var response = service.Create(customerid, options);

            return(response);
        }
Exemplo n.º 2
0
        public CardServiceTest(
            StripeMockFixture stripeMockFixture,
            MockHttpClientFixture mockHttpClientFixture)
            : base(stripeMockFixture, mockHttpClientFixture)
        {
            this.service = new CardService(this.StripeClient);

            this.createOptions = new CardCreateOptions
            {
                Source = "tok_123",
            };

            this.updateOptions = new CardUpdateOptions
            {
                Metadata = new Dictionary <string, string>
                {
                    { "key", "value" },
                },
            };

            this.listOptions = new CardListOptions
            {
                Limit = 1,
            };
        }
Exemplo n.º 3
0
        public IssuingCardServiceTest(
            StripeMockFixture stripeMockFixture,
            MockHttpClientFixture mockHttpClientFixture)
            : base(stripeMockFixture, mockHttpClientFixture)
        {
            this.service = new CardService(this.StripeClient);

            this.createOptions = new CardCreateOptions
            {
                AuthorizationControls = new AuthorizationControlsOptions
                {
                    MaxAmount = 123,
                },
                Currency = "usd",
                Type     = "virtual",
            };

            this.updateOptions = new CardUpdateOptions
            {
                Metadata = new Dictionary <string, string>
                {
                    { "key", "value" },
                },
            };

            this.listOptions = new CardListOptions
            {
                Limit = 1,
            };
        }
Exemplo n.º 4
0
        public IssuingCardServiceTest()
        {
            this.service = new CardService();

            this.createOptions = new CardCreateOptions()
            {
                AuthorizationControls = new AuthorizationControlsOptions
                {
                    MaxAmount = 123,
                },
                Currency = "usd",
                Type     = "virtual",
            };

            this.updateOptions = new CardUpdateOptions()
            {
                Metadata = new Dictionary <string, string>()
                {
                    { "key", "value" },
                },
            };

            this.listOptions = new CardListOptions()
            {
                Limit = 1,
            };
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
		public virtual async Task<Card> Create(string customerOrRecipientId, CardCreateOptions options, bool isRecipient = false)
		{
			var url = this.SetupUrl(customerOrRecipientId, isRecipient);
			url = this.ApplyAllParameters(options, url, false);

			var response = await Requestor.Post(url);

			return Mapper<Card>.MapFromJson(response);
		}
Exemplo n.º 7
0
        /// <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;
            }
        }
        public async Task <StripePaymentCardResult> InsertStripeCardToStripeUser(PaymentCard paymentCard, string stripeuserId)
        {
            try
            {
                //Insertar tarjeta a un customer
                StripeConfiguration.ApiKey = this._configuration.GetSection("Stripe")["SecretKey"];

                //Obtenemos los valores de la tarjeta
                var tokenoptions = new TokenCreateOptions()
                {
                    Card = new CreditCardOptions()
                    {
                        Number   = paymentCard.CardNumber,
                        ExpYear  = long.Parse(paymentCard.Year),
                        ExpMonth = long.Parse(paymentCard.Month),
                        Cvc      = paymentCard.Cvc,
                        Name     = paymentCard.HolderName,
                    },
                };

                //Creamos el token de la tarjeta
                var tokenService = new TokenService();

                var stripeToken = await tokenService.CreateAsync(tokenoptions);


                //El token pasara la informacion necesaria de la tarjeta
                var CardCreateoptions = new CardCreateOptions
                {
                    Source = stripeToken.Id,
                };

                //Comenzamos a usar el servicio de la tarjeta.
                var cardservice = new CardService();

                //Creamos la tarjeta para un el customer de stripe
                var cardserviceToken = await cardservice.CreateAsync(stripeuserId, CardCreateoptions);


                //Verificamos los valores si son correctos.
                if (!string.IsNullOrEmpty(cardserviceToken.Id))
                {
                    var result = new StripePaymentCardResult(cardserviceToken.Id);
                    return(result);
                }
                else
                {
                    return(new StripePaymentCardResult(true, "Token could not be creted try again."));
                }
            }
            catch (Exception e)
            {
                return(new StripePaymentCardResult(true, e.Message));
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// discarded, this method is not required because as of now we are using vue stripe component
        /// it will be updated if required for other project in future
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <CardDto> CreateCard(CreateCardDto dto)
        {
            var cardOptions = new CardCreateOptions()
            {
                SourceToken = dto.SourceToken
            };

            var cardService = new CardService();

            return(CardMapper.MapCardToCardDto(await
                                               cardService.CreateAsync(dto.CustomerId, cardOptions)));
        }
Exemplo n.º 10
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)}");
        }
Exemplo n.º 11
0
        public IssuingCardServiceTest(
            StripeMockFixture stripeMockFixture,
            MockHttpClientFixture mockHttpClientFixture)
            : base(stripeMockFixture, mockHttpClientFixture)
        {
            this.service = new CardService(this.StripeClient);

            this.createOptions = new CardCreateOptions
            {
                Cardholder       = "ich_123",
                Currency         = "usd",
                SpendingControls = new CardSpendingControlsOptions
                {
                    SpendingLimits = new List <CardSpendingControlsSpendingLimitOptions>
                    {
                        new CardSpendingControlsSpendingLimitOptions
                        {
                            Amount     = 1000,
                            Categories = new List <string>
                            {
                                "financial_institutions",
                            },
                            Interval = "all_time",
                        },
                    },
                },
                Type = "virtual",
            };

            this.updateOptions = new CardUpdateOptions
            {
                Metadata = new Dictionary <string, string>
                {
                    { "key", "value" },
                },
            };

            this.listOptions = new CardListOptions
            {
                Limit = 1,
            };
        }
Exemplo n.º 12
0
        public CardServiceTest()
        {
            this.service = new CardService();

            this.createOptions = new CardCreateOptions()
            {
                SourceToken = "tok_123",
            };

            this.updateOptions = new CardUpdateOptions()
            {
                Metadata = new Dictionary <string, string>()
                {
                    { "key", "value" },
                },
            };

            this.listOptions = new CardListOptions()
            {
                Limit = 1,
            };
        }
Exemplo n.º 13
0
        public bool CreateCreditCard(CreaditCardCreateViewModel model)
        {
            StripeConfiguration.SetApiKey(SETTING.Value.SecretStripe);


            var customerTMP = _customerRepository.Get(x => x.Deleted == false && x.Id == model.CustomerId);

            if (customerTMP.StripeId == null || customerTMP.StripeId == "")
            {
                var options = new CustomerCreateOptions
                {
                    Email       = customerTMP.Email,
                    Description = "Customer for " + customerTMP.FullName + " " + customerTMP.Email,
                    SourceToken = model.CardId
                };
                var             service  = new Stripe.CustomerService();
                Stripe.Customer customer = service.Create(options);
                customerTMP.StripeId = customer.Id;
                _customerRepository.Update(customerTMP);
                model.CardId    = customer.DefaultSourceId;
                model.Isdefault = true;
            }
            else
            {
                var optionsCard = new CardCreateOptions
                {
                    SourceToken = model.CardId
                };
                var serviceCard = new Stripe.CardService();
                var card        = serviceCard.Create(customerTMP.StripeId, optionsCard);
                model.CardId = card.Id;
            }
            model.Last4DigitsHash = encrypt(model.Last4DigitsHash);
            var creditCard = _mapper.Map <CreaditCardCreateViewModel, CreditCard>(model);

            _creditCardRepository.Add(creditCard);
            _unitOfWork.CommitChanges();
            return(true);
        }
Exemplo n.º 14
0
        public CardServiceTest()
        {
            this.service = new CardService();

            this.createOptions = new CardCreateOptions()
            {
                Currency = "usd",
                Type     = "virtual",
            };

            this.updateOptions = new CardUpdateOptions()
            {
                Metadata = new Dictionary <string, string>()
                {
                    { "key", "value" },
                },
            };

            this.listOptions = new CardListOptions()
            {
                Limit = 1,
            };
        }
Exemplo n.º 15
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);
            }
        }
Exemplo n.º 16
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);
        }