@garthjlancaster was spot on his suggestion. Stripe provides webhook for very similar usecase/workflows to handle. Details:
Receive event notifications with webhooks[
^]
Quote:
Listen for events on your Stripe account so your integration can automatically trigger reactions.
Your reaction here once you receive the event is to trigger the database transaction population.
Now, to you project in ASP.NET, you would need to setup the receiver and then process it.
Example snippet:
public class StripeController : Controller
{
[AllowAnonymous]
[HttpPost]
[Route("webhook")]
public IActionResult StripeWebhook()
{
try
{
var json = new StreamReader(HttpContext.Request.Body).ReadToEnd();
var stripeEvent = EventUtility.ConstructEvent(json, Request.Headers["Stripe-Signature"], "---REPLACE STRIPE WEBHOOK SECRET---");
switch (stripeEvent.Type)
{
case "customer.created":
var customer = stripeEvent.Data.Object as Customer;
break;
case "customer.subscription.created":
case "customer.subscription.updated":
case "customer.subscription.deleted":
case "customer.subscription.trial_will_end":
var subscription = stripeEvent.Data.Object as Subscription;
break;
case "invoice.created":
var newinvoice = stripeEvent.Data.Object as Invoice;
break;
case "invoice.upcoming":
case "invoice.payment_succeeded":
case "invoice.payment_failed":
var invoice = stripeEvent.Data.Object as Invoice;
break;
case "coupon.created":
case "coupon.updated":
case "coupon.deleted":
var coupon = stripeEvent.Data.Object as Coupon;
break;
}
return Ok();
}
catch (StripeException ex)
{
return BadRequest();
}
catch (Exception ex)
{
return BadRequest();
}
}
}
References of help:
Stripe WebHooks handling in ASP.NET MVC (C#)[
^]
ASP.NET WebHooks receivers | Microsoft Docs[
^]
Stripe Webhook endpoints[
^]