-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Real payment integration #50
Real payment integration #50
Conversation
…scription-management
This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation. |
Това с try/catch в контролерите по принцип вече не се прави. Аз също го ползвам щото не ми се занимава, но сега по-добре да го направим както трябва и в контролерите да има колкото може по-малко код. Създава се един middleware, който handle-ва глобално всички Exceptions. Методът му е нещо като това: private static Task HandleExceptionAsync(HttpContext context, Exception exception)
{
context.Response.ContentType = "application/json";
context.Response.StatusCode = exception switch
{
ArgumentException => (int)HttpStatusCode.BadRequest,
StripeException => (int)HttpStatusCode.BadRequest,
_ => (int)HttpStatusCode.InternalServerError
};
return context.Response.WriteAsync(new ErrorDetails
{
StatusCode = context.Response.StatusCode,
Message = exception.Message
}.ToString());
} app.UseMiddleware<ExceptionMiddleware>(); [HttpPost("customer")]
public async Task<ApiResponse<CustomerCreationResponse>> CreateCustomerAsync([FromBody] CustomerCreation model)
{
var customer = await stripeService.CreateCustomerAsync(model.Email);
return new ApiResponse<CustomerCreationResponse>()
{
Status = 200,
Data = customer
};
} Виж в нета по-подробно или просто питай ChatGPT, специално за това ще се справи. Също този "Webhook" ако можеш да го съкратиш и да изнесеш message-ите на константи. Нещо такова: [HttpPost("webhook")]
public async Task<IActionResult> Webhook()
{
var json = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync();
var stripeEvent = ConstructStripeEvent(json);
await HandleEventAsync(stripeEvent);
return Ok();
} От Sonar има 1 Security Hotspot. |
Quality Gate failedFailed conditions |
More endpoints and webhook added