Sunagatov / Iced-Latte

a online Marketplace for coffee retail (Backend)
https://iced-latte.uk
MIT License
602 stars 110 forks source link

GET /payment: throw error if address is not specified #341

Open annstriganova opened 3 months ago

annstriganova commented 3 months ago

At the moment an error is thrown later, when Stripe sends webhook and BE tries to create an order. Throw error earlier, before payment attempt.

2024-07-29 21:20:08,448 [http-nio-8083-exec-3] INFO  c.z.i.p.e.PaymentEndpoint       - Received Stripe payment webhook
2024-07-29 21:20:08,448 [http-nio-8083-exec-3] INFO  c.z.i.p.a.WebhookEventProcessor  - Process Stripe payment event: start Stripe payment event processing
2024-07-29 21:20:08,450 [http-nio-8083-exec-3] INFO  c.z.i.p.api.WebhookEventParser  - Trying to parse StripePaymentEvent = 'checkout.session.completed'
2024-07-29 21:20:08,453 [http-nio-8083-exec-3] INFO  c.z.i.p.a.s.SessionCompletedScenarioHandler  - Checkout stripe session with id = 'cs_test_b1qaen0XPuxUoPByqQtIhbWDBIJAmbmGNh1TwguoVeXiyBxeeVmYyGltQd' completed.
2024-07-29 21:20:08,453 [http-nio-8083-exec-3] INFO  c.z.i.p.a.s.SessionCompletedScenarioHandler  - Creating new order for user with id = '9c389f82-2614-4a0a-92ce-4fe5b6506dbe'
2024-07-29 21:20:08,461 [http-nio-8083-exec-3] WARN  c.z.i.u.a.a.UserAvatarLinkProvider  - File with id = 9c389f82-2614-4a0a-92ce-4fe5b6506dbe was not found.
2024-07-29 21:20:08,487 [http-nio-8083-exec-3] WARN  o.h.e.j.spi.SqlExceptionHelper  - SQL Error: 0, SQLState: 23502
2024-07-29 21:20:08,488 [http-nio-8083-exec-3] ERROR o.h.e.j.spi.SqlExceptionHelper  - ERROR: null value in column "address_id" of relation "orders" violates not-null constraint
  Detail: Failing row contains (dd82e34d-c941-4fc4-bb7f-43b0eba8a0d3, 9c389f82-2614-4a0a-92ce-4fe5b6506dbe, 2024-07-29 21:20:08.455477+00, CREATED, 2, null, 13.28).
2024-07-29 21:20:08,523 [http-nio-8083-exec-3] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet]  - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.dao.DataIntegrityViolationException: could not execute statement [ERROR: null value in column "address_id" of relation "orders" violates not-null constraint
  Detail: Failing row contains (dd82e34d-c941-4fc4-bb7f-43b0eba8a0d3, 9c389f82-2614-4a0a-92ce-4fe5b6506dbe, 2024-07-29 21:20:08.455477+00, CREATED, 2, null, 13.28).] [insert into orders (items_quantity,items_total_price,status,user_id,id) values (?,?,?,?,?)]; SQL [insert into orders (items_quantity,items_total_price,status,user_id,id) values (?,?,?,?,?)]; constraint [address_id" of relation "orders]] with root cause
org.postgresql.util.PSQLException: ERROR: null value in column "address_id" of relation "orders" violates not-null constraint
  Detail: Failing row contains (dd82e34d-c941-4fc4-bb7f-43b0eba8a0d3, 9c389f82-2614-4a0a-92ce-4fe5b6506dbe, 2024-07-29 21:20:08.455477+00, CREATED, 2, null, 13.28).
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2725)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2412)
github-actions[bot] commented 3 months ago

Hello there!

We truly appreciate you taking the time to create a new issue for our project on GitHub. Your input helps us improve and grow. Thank you!