Exemplo n.º 1
0
        public ActionResult Details(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var eventService = new StripeEventService();
            var e            = eventService.Get(id);

            if (e == null)
            {
                return(new HttpNotFoundResult());
            }

            var model = new EventDetailsViewModel
            {
                Id              = e.Id,
                Created         = e.Created,
                LiveMode        = e.LiveMode,
                PendingWebhooks = e.PendingWebhooks,
                Request         = e.Request,
                Type            = e.Type,
                UserId          = e.UserId,
                Data            = e.Data
            };

            return(View(model));
        }
Exemplo n.º 2
0
        private static StripeEvent VerifyEventSentFromStripe(StripeEvent stripeEvent)
        {
            var eventService = new StripeEventService();

            stripeEvent = eventService.Get(stripeEvent.Id);
            return(stripeEvent);
        }
Exemplo n.º 3
0
        public static StripeEvent GetStripeEvent(string eventId)
        {
            var eventService = new StripeEventService();

            try
            {
                return(eventService.Get(eventId));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                Logs.LogsInsertAction("Stripe subscription attempted");

                var json = new StreamReader(context.Request.InputStream).ReadToEnd();

                var stripeEvent = StripeEventUtility.ParseEvent(json);

                switch (stripeEvent.Type)
                {
                case StripeEvents.InvoicePaymentSucceeded:      // all of the types available are listed in StripeEvents

                    // parse first call
                    StripeInvoice insecureStripeInvoice = Stripe.Mapper <StripeInvoice> .MapFromJson(stripeEvent.Data.Object.ToString());

                    // just get id and retreive from stripe to prevent spoofing
                    var eventService = new StripeEventService();
                    StripeRequestOptions requestOptions = new StripeRequestOptions();
                    requestOptions.ApiKey = Constants.StripeSecretKey;

                    // can't be called more than once (webhooks can send multiple times)
                    requestOptions.IdempotencyKey = stripeEvent.Id;
                    StripeEvent   response      = eventService.Get(stripeEvent.Id, requestOptions);
                    StripeInvoice stripeInvoice = Stripe.Mapper <StripeInvoice> .MapFromJson(response.Data.Object.ToString());

                    if (stripeInvoice.Paid)
                    {
                        using (var db = new UniversalGymEntities())
                        {
                            var user   = db.Users.SingleOrDefault(s => s.StripeUrl == stripeInvoice.CustomerId);
                            int charge = stripeInvoice.Total;
                            new creditAdd(db).AddCredit(user, null, charge, charge);


                            Logs.LogsInsertAction(
                                "Stripe subscription successful: "
                                + stripeInvoice.Total
                                + " added to " + user.Email);
                        }
                    }

                    break;
                }
            }
            catch (Exception exception)
            {
                Logs.LogsInsertError(exception);
            }
        }
 public Task <DomainEvent> GetAsync(DomainEvent e)
 {
     return(Task.Run(() =>
     {
         try
         {
             StripeEvent eventObject = _service.Get(e.Id);
             return Task.FromResult(_mapper.Map <StripeEvent, DomainEvent>(eventObject));
         }
         catch (StripeException ex)
         {
             throw new BillingException(string.Format("Failed to get billing event data by id {0}: {1}", e.Id, ex));
         }
     }));
 }