Overview
The Payments API provides endpoints for calculating order totals and processing payments. All payment endpoints require authentication.POST /api/payments/calculate
Calculate the total cost for a cart including tax and discounts.Request
Method:POST
Path: /api/payments/calculate
Authentication: JWT token required
Headers:
Authorization: Bearer <access_token>Content-Type: application/json
Cart subtotal before tax and discounts
Optional discount code to apply
Response
Original subtotal amount
Discount code applied (if any)
Amount deducted from subtotal
Subtotal after discount applied
Tax amount calculated on the subtotal
Final total amount (discounted_subtotal + tax)
Example
cURL
Without Discount Code
cURL
Error Responses
400 Bad Request - Missing required field:POST /api/payments/checkout
Process payment for an existing order.Request
Method:POST
Path: /api/payments/checkout
Authentication: JWT token required
Headers:
Authorization: Bearer <access_token>Content-Type: application/json
ID of the order to process payment for
Response
Success message
Updated order object with payment status
Order ID
User ID
Order status (updated to “paid”)
Order subtotal
Tax amount
Discount amount
Total amount charged
Discount code used
Order creation timestamp
Last update timestamp
Example
cURL
Error Responses
400 Bad Request - Missing order_id:Payment Flow
-
Calculate Total: Use
/api/payments/calculateto preview the total cost with tax and any discount codes before creating an order - Create Order: Use the Orders API to create an order with the desired items
-
Process Payment: Use
/api/payments/checkoutwith the order ID to complete the payment -
Order Status: The order status will change from
pendingtopaidupon successful payment
Order Statuses
pending- Order created but not yet paidpaid- Payment processed successfullyshipped- Order has been shippeddelivered- Order delivered to customercancelled- Order cancelled
Tax Calculation
The tax is calculated automatically by the payment service based on the subtotal. The exact tax rate depends on the implementation in thepayment_service module.