C#C
C#15mo ago
4 replies
Zee

implement stripe payment feature for asp.net core web api and wpf

so I am trying to add a payment feature using stripe but it takes me to this page for some reason I am not sure how to fix it

here is my code


 {
     private readonly PaymentService _paymentService;
     private readonly ApplicationDbContext _context;

     public PaymentController(PaymentService paymentService)
     {
         _paymentService = paymentService;

     }

     [HttpPost("create-checkout-session")]
     public ActionResult CreateCheckoutSession()
     {
         var session = _paymentService.CreateCheckoutSession(
            "https://localhost:7186/payment/success?sessionId={CHECKOUT_SESSION_ID}",
            "https://localhost:7186/payment/cancel?sessionId={CHECKOUT_SESSION_ID}", "20"

         );


         return Ok(new { sessionId = session.Url });
     }

     [HttpGet("success")]
     public async Task<IActionResult> Success(string sessionId)
     {
         /*
         var paymentRecord = await _context.PaymentRecords.FirstOrDefaultAsync(p => p.StripeSessionId == sessionId);
         if (paymentRecord != null)
         {
             paymentRecord.Status = "Success";
             await _context.SaveChangesAsync();
         }
         */

         // Redirect to a success page or return success response
         return Ok("Payment successful.");
     }

     [HttpGet("cancel")]
     public async Task<IActionResult> Cancel(string sessionId)
     {
         /*
         var paymentRecord = await _context.PaymentRecords.FirstOrDefaultAsync(p => p.StripeSessionId == sessionId);
         if (paymentRecord != null)
         {
             paymentRecord.Status = "Cancelled";
             await _context.SaveChangesAsync();
         }
         */

         // Redirect to a cancel page or return cancel response
         return Ok("Payment cancelled.");
     }
 }
image.png
Was this page helpful?