Process payment for a delivery
POST/company/payment/pay
Generate a Stripe Payment Intent to pay the amount for a specific delivery using the company's default payment method.
Objective
Initiate the charge to the company for an awarded delivery, including the platform fee, and notify both parties by email.
Use Cases
- Company pays for a delivery awarded via auction
- Automatic settlement of completed deliveries
- Processing payments between companies and carriers
Validation Flow
flowchart TD
A[Receive Request - serviceCode] --> B{User authenticated?}
B -->|No| C[404 USER_NOT_FOUND]
B -->|Yes| D{Company found?}
D -->|No| E[401 CIA_NOT_FOUND]
D -->|Yes| F{withStripe enabled?}
F -->|No| G[403 STRIPE_PAYMENTS_DISABLED]
F -->|Yes| H{default_payment_method set?}
H -->|No| I[401 PAYMENT_METHOD_NOT_FOUND]
H -->|Yes| J{Delivery found?}
J -->|No| K[401 DELIVERY_NOT_FOUND]
J -->|Yes| L[Calculate amount + platform fee]
L --> M[Generate Payment Intent in Stripe]
M --> N[Save payment_intent to delivery]
N --> O[Send emails to both parties]
O --> P[200 success: true]
Notes
- Requires JWT authentication (bearerAuth)
- Requires
withStripe=truein the company'spayment_settings - Requires a default payment method (
default_payment_method) to be configured - The platform fee is obtained from
Settings(default 3%) - Sends emails to the company and the carrier (trucker_cia)
- The
payment_intentID is saved in thedeliverydocument
Request
Responses
- 200
- 401
- 403
- 404
- 500
Payment Intent created and payment initiated
Response Headers
Company, delivery, or payment method not found
Response Headers
Stripe payments not enabled for this company.
Response Headers
User not found
Response Headers
Error processing payment in Stripe