Ejemplo n.º 1
0
        public ActionResult Pay(PaymentCardAdd cardInfo)
        {
            try
            {
                var token = GetToken(cardInfo);
                StripeConfiguration.ApiKey = "sk_test_ZYySFlXrQCDciqzHKybrdcWU";

                // `source` is obtained with Stripe.js; see https://stripe.com/docs/payments/accept-a-payment-charges#web-create-token
                var options = new ChargeCreateOptions
                {
                    Amount      = cardInfo.Amount * 100,
                    Currency    = "bam",
                    Source      = token,
                    Description = cardInfo.Desc,
                };

                var    service = new ChargeService();
                Charge charge  = service.Create(options);
                //service.Create(options);
                Uplata uplata = new Uplata
                {
                    ChargeId       = charge.Id,
                    Description    = charge.Description,
                    UplacenoUkupno = charge.Amount,
                    Status         = charge.Status
                };

                Donacije donacija = new Donacije
                {
                    Datum  = DateTime.Now,
                    Iznos  = cardInfo.Amount,
                    Poruka = cardInfo.Desc,
                    UserId = cardInfo.UserId
                };
                _context.Donacije.Add(donacija);
                _context.SaveChanges();

                return(Ok(uplata));
            }
            catch (StripeException e)
            {
                return(BadRequest(e.Message));
            }
        }
Ejemplo n.º 2
0
        private string GetToken(PaymentCardAdd cardInfo)
        {
            StripeConfiguration.ApiKey = "sk_test_ZYySFlXrQCDciqzHKybrdcWU";

            var options = new TokenCreateOptions
            {
                Card = new CreditCardOptions
                {
                    Number   = cardInfo.BrojKartice,
                    ExpYear  = int.Parse(20 + cardInfo.Godina.ToString()),
                    ExpMonth = cardInfo.Mjesec,
                    Cvc      = cardInfo.CVV.ToString()
                }
            };

            var   service     = new TokenService();
            Token stripeToken = service.Create(options);

            return(stripeToken.Id);
        }