Ejemplo n.º 1
0
        public async Task <ActionResult> Stripe()
        {
            using var bodySteam = new StreamReader(HttpContext.Request.Body);
            var json = await bodySteam.ReadToEndAsync();

            var stripeEvent = EventUtility.ConstructEvent(json, Request.Headers["Stripe-Signature"], _stripeSignature);

            switch (stripeEvent.Type)
            {
            case Events.SourceChargeable:
                var source = stripeEvent.Data.Object as Source;
                await _stripeService.HandleSourceChargeable(source);

                return(Ok());

            case Events.ChargeSucceeded:
                var charge = stripeEvent.Data.Object as Charge;
                _stripeService.HandleChargeSucceeded(charge);
                return(Ok());

            default:
                return(BadRequest("Unknown event type"));
            }
        }