Cancel delivery service
DELETE/company/delivery/:service_code
Cancel an existing shipment by changing its status to 'canceled' and rejectedBy to 'cia'. Only shipments in 'planned' or 'replanned' statuses can be canceled.
Objective
Allow companies to cancel planned shipments when they will no longer be carried out, automatically processing the necessary actions in Stripe and auctions.
Use Cases
- Cancel a planned shipment that will no longer be carried out
- Stop a replanned shipment due to logistical or business issues
- Reverse a poorly planned shipment before it starts
- Cancel due to changes in cargo or destination
Side Effects
- Changes status to 'canceled'
- Sets rejectedBy='cia'
- Cancels the payment_intent in Stripe (processes refund if applicable)
- Cancels the associated auction if it exists
Validation Flow
flowchart TD
A[Receive Cancel Request] --> B{Delivery Exists?}
B -->|No| C[404 NOT_FOUND]
B -->|Yes| D{Company Owns Delivery?}
D -->|No| E[403 NOT_ALLOWED]
D -->|Yes| F{Is Final Status?}
F -->|Yes| G[401 NOT_ALLOWED]
F -->|No| H{Status is Cancelable?}
H -->|No| I[401 NOT_ALLOWED]
H -->|Yes| J[Set status=canceled]
J --> K[Set rejectedBy=cia]
K --> L{Cancel Stripe Payment}
L -->|Error| M[403 CANT_CANCEL_PAYMENT]
L -->|Success| N{Cancel Auction}
N -->|Success| O[Save - 200]
Notes
- Only shipments in 'planned' or 'replanned' statuses can be canceled
- A shipment in a final status (delivered, claimed, canceled) cannot be canceled
- If the payment cancellation in Stripe fails, the entire operation is canceled
- The associated auction is also canceled automatically
Request
Responses
- 200
- 401
- 403
- 404
- 503
Shipment successfully canceled.
Unauthorized. The shipment status does not allow cancellation.
The payment cannot be canceled in Stripe.
Shipment not found. The provided service_code does not exist or does not belong to the authenticated user's company.
Error saving changes.