Skip to content
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

Merged

Conversation

Ekrem05
Copy link
Member

@Ekrem05 Ekrem05 commented Jun 25, 2024

More endpoints and webhook added

@github-advanced-security
Copy link

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.

@dpS1lence
Copy link
Member

dpS1lence commented Jun 26, 2024

Това с 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.

@dpS1lence dpS1lence added the Stripe Integration Anything related to payment processing label Jun 28, 2024
@dpS1lence dpS1lence linked an issue Jun 28, 2024 that may be closed by this pull request
11 tasks
@dpS1lence dpS1lence removed the request for review from ImSk1 June 28, 2024 06:39
Copy link

sonarcloud bot commented Jun 28, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

@dpS1lence dpS1lence merged commit 6b954da into dev Jun 28, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stripe Integration Anything related to payment processing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Real Payment Integration and Subscription Management
2 participants