PaymentController.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using MTWorkHR.Application.Filters;
  4. using MTWorkHR.Application.Services.Interfaces;
  5. namespace MTWorkHR.API.Controllers
  6. {
  7. [Route("api/[controller]")]
  8. [ApiController]
  9. [AppAuthorize]
  10. public class PaymentController : ControllerBase
  11. {
  12. private readonly IMatchMoveService _PaymentService;
  13. public PaymentController(IMatchMoveService PaymentService)
  14. {
  15. this._PaymentService = PaymentService;
  16. }
  17. [HttpPost]
  18. public async Task<IActionResult> ProcessPayment([FromBody] object paymentRequest)
  19. {
  20. try
  21. {
  22. // Step 1: Get OAuth token
  23. var token = await _PaymentService.GetAccessTokenAsync();
  24. // Step 2: Process the payment
  25. var response = await _PaymentService.ProcessPaymentAsync(token, paymentRequest);
  26. return Ok(response); // Return the MatchMove API response
  27. }
  28. catch (Exception ex)
  29. {
  30. return BadRequest(new { error = ex.Message });
  31. }
  32. }
  33. }
  34. }