Documentation Index
Fetch the complete documentation index at: https://docs.gateways.app/llms.txt
Use this file to discover all available pages before exploring further.
Payments API
The Payments API provides endpoints for managing payment methods and workspace plan upgrades/downgrades using Stripe integration.Base Endpoint
Authentication
All payment endpoints require authentication. Include your JWT token in the Authorization header:Required Configuration
Add your Stripe secret key to your.env file:
sk_live_).
Payment Method Management
Create Payment Method Setup
Initialize a payment method setup to collect card information for a workspace. Only workspace owners and admins can manage payment methods. Endpoint:POST /api/payments/:workspaceSlug/payment-method
Parameters:
workspaceSlug(path) - The slug of the workspace
Confirm Payment Method
Confirm and save a payment method for a workspace after SetupIntent completion. Only workspace owners and admins can manage payment methods. Endpoint:POST /api/payments/:workspaceSlug/payment-method/confirm
Parameters:
workspaceSlug(path) - The slug of the workspace
| Field | Type | Required | Description |
|---|---|---|---|
| setupIntentId | string | Yes | Stripe SetupIntent ID from setup |
| paymentMethodId | string | Yes | Stripe PaymentMethod ID from setupIntent.payment_method |
| billingName | string | No | Cardholder / billing name (sent to Stripe and stored) |
| billingPostalCode | string | No | Billing ZIP / postal code (sent to Stripe and stored) |
400 Bad Request- Missing fields, invalid workspace slug, or setup incomplete404 Not Found- Workspace does not exist403 Forbidden- User is not an owner or admin401 Unauthorized- Missing or invalid token500 Internal Server Error- Stripe configuration error or confirmation failed
List Payment Methods
Get all payment methods for a workspace. Endpoint:GET /api/payments/:workspaceSlug/payment-methods
Parameters:
workspaceSlug(path) - The slug of the workspace
include_inactive(optional) - Include inactive payment methods (true/false, default:false)
401 Unauthorized- User ID not found400 Bad Request- Invalid workspace slug404 Not Found- Workspace does not exist403 Forbidden- User does not have access to this workspace
Set Default Payment Method
Set a payment method as the default for a workspace. Only workspace owners and admins can manage payment methods. Endpoint:PATCH /api/payments/:workspaceSlug/payment-methods/:paymentMethodId/set-default
Parameters:
workspaceSlug(path) - The slug of the workspacepaymentMethodId(path) - The ID of the payment method (database ID)
401 Unauthorized- User ID not found400 Bad Request- Invalid workspace slug or payment method ID404 Not Found- Workspace or payment method does not exist403 Forbidden- User is not an owner/admin or payment method doesn’t belong to workspace
Delete Payment Method
Delete a payment method (soft delete). If it’s the default payment method, the next available payment method will be set as default. Only workspace owners and admins can manage payment methods. Endpoint:DELETE /api/payments/:workspaceSlug/payment-methods/:paymentMethodId
Parameters:
workspaceSlug(path) - The slug of the workspacepaymentMethodId(path) - The ID of the payment method (database ID)
401 Unauthorized- User ID not found400 Bad Request- Invalid workspace slug or payment method ID404 Not Found- Workspace or payment method does not exist403 Forbidden- User is not an owner/admin or payment method doesn’t belong to workspace
Workspace Plan Management
Upgrade Workspace Plan
Upgrade a workspace to a higher-tier plan. This will immediately charge the payment method for the prorated amount and update the workspace plan. Endpoint:POST /api/payments/workspace/:workspaceSlug/upgrade-plan
Parameters:
workspaceSlug(path) - The slug of the workspace
400 Bad Request- Missing fields, invalid plan, invalid payment method, or not an upgrade (target plan must be higher than current plan)400 Bad Request- No payment method provided and no default payment method found401 Unauthorized- Missing or invalid token403 Forbidden- User is not an owner or admin of the workspace404 Not Found- Workspace or plan not found500 Internal Server Error- Payment processing error or Stripe configuration error
- Only workspace owners and admins can upgrade plans
- Target plan must be a higher tier than the current plan (use downgrade endpoint for downgrades)
- Payment is charged immediately for the full month (prorated billing can be implemented)
- Payment method is automatically attached to a Stripe customer for the workspace
- Workspace plan is updated immediately upon successful payment
Downgrade Workspace Plan
Downgrade a workspace to a lower-tier plan. This is immediate and no refund is issued for the current billing period. Endpoint:POST /api/payments/workspace/:workspaceSlug/downgrade-plan
Parameters:
workspaceSlug(path) - The slug of the workspace
400 Bad Request- Missing planSlug or not a downgrade (target plan must be lower than current plan)401 Unauthorized- Missing or invalid token403 Forbidden- User is not an owner or admin of the workspace404 Not Found- Workspace or plan not found500 Internal Server Error- Update error
- Only workspace owners and admins can downgrade plans
- Target plan must be a lower tier than the current plan (use upgrade endpoint for upgrades)
- Downgrade takes effect immediately
- No refund is issued for the current billing period
- No payment method is required for downgrades
Complete Workflow Example
Upgrade Workspace Plan
Downgrade Workspace Plan
Invoice Management
List Invoices
Get all invoices for a workspace with pagination. Invoices are automatically created when plans are upgraded. Only workspace members can view invoices. Endpoint:GET /api/payments/:workspaceSlug/invoices
Parameters:
workspaceSlug(path) - The slug of the workspace
include_all(optional): Include refunded invoices. Set to"true"to include all invoices including refunded ones. Default:falsepage(optional): Page number for pagination. Default:1, minimum:1limit(optional): Number of invoices per page. Default:20, maximum:100, minimum:1
refundedAmount(number): Total amount refunded for this invoice (0 if none; updated when admin issues full or partial refunds). When this equalsamount,statusis typicallyrefunded.
page(number): Current page numberlimit(number): Number of items per pagetotal(number): Total number of invoices matching the querytotalPages(number): Total number of pageshasNextPage(boolean): Whether there is a next pagehasPrevPage(boolean): Whether there is a previous page
Get Invoice by ID
Get details of a specific invoice. Endpoint:GET /api/payments/:workspaceSlug/invoices/:invoiceId
Parameters:
workspaceSlug(path) - The slug of the workspaceinvoiceId(path) - The ID of the invoice
plan_upgrade- Workspace plan was upgraded (charged immediately)plan_downgrade- Workspace plan was downgraded (no charge, logged for records)
pending- Payment is pendingpaid- Payment completed successfullyfailed- Payment failedrefunded- Payment was refunded
INV-YYYYMMDD-XXXX (e.g., INV-20240115-0001), where:
YYYYMMDDis the date the invoice was createdXXXXis a sequential number starting from 0001 for each day
Download Invoice (PDF)
Returns the invoice PDF as the response body (binary). The client should save it usingContent-Disposition or a default filename — do not expect a presigned S3 URL.
Endpoint: GET /api/payments/:workspaceSlug/invoices/:invoiceId/download
Parameters:
workspaceSlug(path) - The slug of the workspaceinvoiceId(path) - The ID of the invoice
Content-Type:application/pdfContent-Disposition:attachment; filename="<invoiceNumber>.pdf"- Body: raw PDF bytes
- If a PDF is already stored in the app’s S3 bucket at
invoices/{workspaceId}/{invoiceNumber}.pdf, it is streamed from S3. Otherwise the server generates the PDF on the fly and best-effort uploads it to S3 whenINVOICE_STORAGE_BUCKET/PROFILE_STORAGE_BUCKETand AWS credentials are set (caching only; download still goes through this endpoint). - If S3 is not configured, the PDF is generated in memory and returned; no direct link to S3 is exposed to the client.
- The PDF includes refund data when applicable: status (e.g. “Refunded” or “Paid (Refunded $X.XX)”), a “Refunded” row in invoice details, and in the amount section the original amount, refunded amount, and amount due.
- The “Bill to” section shows the workspace name and, when set, the workspace billing address (line1, line2, city, state, postal code, country). Configure billing address in account settings → Workspace.
Error Codes
| Status Code | Description |
|---|---|
| 200 | Success |
| 400 | Bad Request (missing fields, invalid data, wrong plan tier) |
| 401 | Unauthorized (missing or invalid token) |
| 403 | Forbidden (insufficient permissions) |
| 404 | Not Found (workspace or plan not found) |
| 500 | Internal Server Error (Stripe error, configuration error, or processing error) |
| 503 | Service Unavailable (e.g. maintenance mode) |
Stripe Integration Notes
Customer Management
- A Stripe customer is automatically created for each workspace on first upgrade
- The customer email is set to
workspace-{workspaceId}@gateways.app - Payment methods are attached to the customer and set as default for future charges
Payment Processing
- Upgrades charge immediately for the full month (prorated billing can be added)
- Payment methods are stored securely in Stripe
- Failed payments return detailed error messages
Security
- All payment processing happens server-side via Stripe API
- Payment method details are never stored directly in the database
- Only payment method IDs are referenced
- Stripe handles PCI compliance for card data
Frontend Integration Guide
Using Stripe Elements
- Include Stripe.js:
- Initialize Stripe:
- Create Setup Intent:
- Collect Payment Method:
- Confirm and Upgrade:
Testing
Use Stripe test cards for testing:- Success:
4242 4242 4242 4242 - Decline:
4000 0000 0000 0002 - Requires Authentication:
4000 0025 0000 3155
Support
For Stripe-related issues:- Stripe Dashboard: https://dashboard.stripe.com
- Stripe Docs: https://stripe.com/docs
- Stripe Support: https://support.stripe.com