using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using MisIngredientesVue.Core.Services; using Stripe; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; namespace MisIngredientesVue.Controllers { [Route("api/[controller]")] [ApiController] [AllowAnonymous] public class StripeWebhookController : ControllerBase { private readonly IEmailService _emailService; public StripeWebhookController(IEmailService emailService) { _emailService = emailService; } [Route("prod")] [HttpPost] public async Task Prod() { string json = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync(); var stripeEvent = EventUtility.ConstructEvent(json, Request.Headers["Stripe-Signature"], "whsec_6ksB6Udmb0pp1dFhQpKfw4WQu0IYhLBL"); _emailService.SendEmail(false, "noreply@misingredientes.mx", new string[] { "hola@misingredientes.mx", "raulbojalil@gmail.com" }, "Evento recibido: " + stripeEvent.Type, $"Se recibió el siguiente json del webhook en prod: {json}"); return Ok(); //try //{ // var stripeEvent = EventUtility.ConstructEvent(json, // Request.Headers["Stripe-Signature"], _webhookSecret); // switch (stripeEvent.Type) // { // case Events.Failed: // //make sure payment info is valid // break; // case Events.CustomerSourceExpiring: // //send reminder email to update payment method // break; // case Events.ChargeFailed: // //do something // break; // } // return Ok(); //} //catch (StripeException e) //{ // return BadRequest(); //} } [Route("qa")] [HttpPost] public async Task Qa() { string json = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync(); var stripeEvent = EventUtility.ConstructEvent(json, Request.Headers["Stripe-Signature"], "whsec_yWyz3cZVyYcYLPWmz2YGYI9HQT2F04nr"); _emailService.SendEmail(false, "noreply@misingredientes.mx", new string[] { "hola@misingredientes.mx", "raulbojalil@gmail.com" }, "Evento recibido: " + stripeEvent.Type, $"Se recibió el siguiente json del webhook en qa: {json}"); return Ok(); //try //{ // var stripeEvent = EventUtility.ConstructEvent(json, // Request.Headers["Stripe-Signature"], _webhookSecret); // switch (stripeEvent.Type) // { // case Events.Failed: // //make sure payment info is valid // break; // case Events.CustomerSourceExpiring: // //send reminder email to update payment method // break; // case Events.ChargeFailed: // //do something // break; // } // return Ok(); //} //catch (StripeException e) //{ // return BadRequest(); //} } } }