Example #1
0
        public async Task <IHttpActionResult> PutStripeCards(int id, StripeCards stripeCards)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != stripeCards.Card_id)
            {
                return(BadRequest());
            }

            db.Entry(stripeCards).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StripeCardsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #2
0
        public async Task <IHttpActionResult> GetStripeCards(int id)
        {
            StripeCards stripeCards = await db.StripeCards.FindAsync(id);

            if (stripeCards == null)
            {
                return(NotFound());
            }

            return(Ok(stripeCards));
        }
Example #3
0
        public async Task <IHttpActionResult> DeleteStripeCards(int id)
        {
            StripeCards stripeCards = await db.StripeCards.FindAsync(id);

            if (stripeCards == null)
            {
                return(NotFound());
            }

            db.StripeCards.Remove(stripeCards);
            await db.SaveChangesAsync();

            return(Ok(stripeCards));
        }
Example #4
0
        public async Task <IHttpActionResult> PostAddStripeCards(CardModel card)
        {
            ApplicationUser user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            //// Set your secret key: remember to change this to your live secret key in production
            //// See your keys here: https://dashboard.stripe.com/account/apikeys
            StripeConfiguration.SetApiKey("sk_test_OWXcF1GJ4STCWBuu0bade9oq");

            //// Token is created using Checkout or Elements!
            ////Get the payment token submitted by the form:
            var token = card.Token; // Using ASP.NET MVC

            var customers = new StripeCustomerService();
            var customer  = customers.Create(new StripeCustomerCreateOptions
            {
                Email       = user.UserName,
                SourceToken = token
            });
            //var cardtype = 0;
            //if (card.CardType.ToLower() == "visa")
            //    cardtype = 1;
            //else if (card.CardType.ToLower() == "master")
            //    cardtype = 2;
            //else if (card.CardType.ToLower() == "amex")
            //    cardtype = 3;
            var         last4num    = card.CardNumber.Substring(Math.Max(0, card.CardNumber.Length - 4));
            StripeCards stripeCards = new StripeCards
            {
                Last_four_digit = last4num,
                Payment_key     = customer.Id,
                User_id         = user.Id,
                Card_type_id    = card.CardType
            };

            ////    // YOUR CODE: Save the customer ID and other info in a database for later.
            db.StripeCards.Add(stripeCards);
            await db.SaveChangesAsync();


            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            return(Ok(stripeCards));
        }