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));
        }
Beispiel #2
0
        private static StripeEvent VerifyEventSentFromStripe(StripeEvent stripeEvent)
        {
            var eventService = new StripeEventService();

            stripeEvent = eventService.Get(stripeEvent.Id);
            return(stripeEvent);
        }
Beispiel #3
0
        public StripeEventServiceTest()
        {
            this.service = new StripeEventService();

            this.listOptions = new StripeEventListOptions()
            {
                Limit = 1,
            };
        }
Beispiel #4
0
        public static StripeEvent GetStripeEvent(string eventId)
        {
            var eventService = new StripeEventService();

            try
            {
                return(eventService.Get(eventId));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Beispiel #5
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 void SetUp()
        {
            var configuration = new Mock<IConfigurationWrapper>();
            configuration.Setup(mocked => mocked.GetConfigIntValue("DonationStatusDeposited")).Returns(999);
            configuration.Setup(mocked => mocked.GetConfigIntValue("DonationStatusSucceeded")).Returns(888);
            configuration.Setup(mocked => mocked.GetConfigIntValue("DonationStatusDeclined")).Returns(777);
            configuration.Setup(mocked => mocked.GetConfigIntValue("BatchEntryTypePaymentProcessor")).Returns(555);

            _paymentService = new Mock<IPaymentService>(MockBehavior.Strict);
            _donationService = new Mock<IDonationService>(MockBehavior.Strict);
            _donorService = new Mock<IDonorService>(MockBehavior.Strict);
            _mpDonorService = new Mock<MinistryPlatform.Translation.Services.Interfaces.IDonorService>(MockBehavior.Strict);

            _fixture = new StripeEventService(_paymentService.Object, _donationService.Object, _donorService.Object, _mpDonorService.Object, configuration.Object);
        }
Beispiel #7
0
        public void SetUp()
        {
            var configuration = new Mock <IConfigurationWrapper>();

            configuration.Setup(mocked => mocked.GetConfigIntValue("DonationStatusDeposited")).Returns(999);
            configuration.Setup(mocked => mocked.GetConfigIntValue("DonationStatusSucceeded")).Returns(888);
            configuration.Setup(mocked => mocked.GetConfigIntValue("DonationStatusDeclined")).Returns(777);
            configuration.Setup(mocked => mocked.GetConfigIntValue("BatchEntryTypePaymentProcessor")).Returns(555);

            _paymentService          = new Mock <IPaymentService>(MockBehavior.Strict);
            _paymentProcessorService = new Mock <IPaymentProcessorService>(MockBehavior.Strict);
            _donationService         = new Mock <IDonationService>(MockBehavior.Strict);
            _mpDonorService          = new Mock <MinistryPlatform.Translation.Repositories.Interfaces.IDonorRepository>(MockBehavior.Strict);

            _fixture = new StripeEventService(_paymentProcessorService.Object, _donationService.Object, _paymentService.Object, _mpDonorService.Object, configuration.Object);
        }
        // GET: Admin/Events
        public ActionResult Index()
        {
            var eventService = new StripeEventService();
            var events       = eventService.List().Select(e =>
                                                          new EventListViewModel
            {
                Id              = e.Id,
                Created         = e.Created,
                LiveMode        = e.LiveMode,
                PendingWebhooks = e.PendingWebhooks,
                Request         = e.Request,
                Type            = e.Type,
                UserId          = e.UserId
            });

            return(View(events));
        }
Beispiel #9
0
        public void ProcessRequest(HttpContext context)
        {
            var json = new StreamReader(context.Request.InputStream).ReadToEnd();

            var stripeEvent = StripeEventUtility.ParseEvent(json);

            switch (stripeEvent.Type)
            {
            case StripeEvents.ChargeRefunded:      // all of the types available are listed in StripeEvents
                var stripeCharge = Stripe.Mapper <StripeCharge> .MapFromJson(stripeEvent.Data.Object.ToString());

                break;

            case StripeEvents.CustomerSubscriptionUpdated:      // all of the types available are listed in StripeEvents
                var stripeSubscription = Stripe.Mapper <StripeCharge> .MapFromJson(stripeEvent.Data.Object.ToString());

                break;
            }

            var eventService = new StripeEventService();
            IEnumerable <StripeEvent> response = eventService.List(); // optional StripeEventListOptions
        }
 public StripeBillingEventService(string apiKey, IMapper mapper)
 {
     _service = new StripeEventService(apiKey);
     _mapper  = mapper;
 }
Beispiel #11
0
 public PaymentStripeEventService(StripeEventService stripeEventService,
                                  IRepository <PaymentStripeEvent> paymentStripeEventRepository)
 {
     _stripeEventService           = stripeEventService;
     _paymentStripeEventRepository = paymentStripeEventRepository;
 }