Payments
Description
The Payment entity represents a payment transaction against a loan. Payments can be initiated automatically via autopay, manually by the user, or as retries of previously failed payments. Each payment tracks its lifecycle from creation through completion or failure.
Storage
| Environment | Table Name | Region |
|---|---|---|
test |
test-loc-service |
us-west-2 |
prod |
prod-loc-service |
us-east-2 |
Fields
| Field | Type | Description |
|---|---|---|
|
String |
User ID who owns the payment |
|
String |
Loan this payment applies to |
|
String |
Unique payment identifier (UUID) |
|
Integer |
Payment amount in cents |
|
String |
Payment status (see Status Values below) |
|
String |
Payment method: |
|
String |
How payment was initiated: |
|
String |
Confirmation ID from payments service |
|
String |
Last 4 digits of payment account |
|
String |
Target installment for this payment |
|
Integer |
Number of payment attempts made |
|
Array |
List of installments this payment was applied to |
|
String |
Reason for last update (for audit logging) |
|
String |
Creation timestamp (RFC3339) |
|
String |
Last update timestamp (RFC3339) |
Status Values
| Status | Description |
|---|---|
|
Payment created, not yet submitted to the payment service |
|
ACH payment submitted to the payment service, awaiting settlement confirmation via webhook |
|
Payment successfully processed and applied to installments |
|
Payment failed but is eligible for retry; re-queued for the next collection run |
|
Payment processing was skipped without submitting to the payment service. Occurs when: the loan is not in an open status, the loan balance is already zero, the payment amount is invalid or does not match the amount due, the target installment is missing, or the target installment balance is already zero |
|
Payment permanently failed; no further retries will be attempted |
|
Payment was charged back by the user’s bank (received via webhook from payment service) |
|
ACH payment was returned by the bank (reserved; set externally via payment service events) |
|
Payment was refunded (received via webhook from payment service) |
Keys and Indexes
GSI1 - Payments by User and Loan Status
Used to list payments for a specific loan filtered by status.
| Key | Pattern |
|---|---|
GSI1PK |
|
GSI1SK |
|
Query Patterns
| Query | Index | Key Condition | Sort Key Condition |
|---|---|---|---|
Get payment by loan and payment ID |
Primary |
|
|
List all payments for a loan |
Primary |
|
|
List payments for loan in status |
GSI1 |
|
|
List all payments in retry status |
GSI2 |
|
|
Get payment by confirmation ID |
GSI3 |
|
|
Status Transitions
┌───────────────────────────────────────────────┐
│ PENDING │
│ (Payment created) │
└──┬──────────────────┬─────────────┬───────────┘
│ │ │
ACH │ Pinless │ │ Validation failure
submit │ submit │ │ (loan not open,
success │ success │ │ zero balance,
│ │ │ invalid amount,
│ │ │ missing/paid target)
▼ ▼ ▼
┌─────────────┐ ┌─────────────┐ ┌──────────┐
│ ACHSENT │ │ COMPLETED │ │ SKIPPED │
│ (Submitted │ │ (Success) │ └──────────┘
│ to payment │ └──────┬──────┘
│ service) │ │
└──────┬──────┘ │
│ │ webhook: failed + AUTO ──────────►┐
│ │ webhook: failed + non-AUTO ───────►(FAILED, below)
│ │ webhook: refunded ─────────────────►(REFUNDED, below)
│ │
│
│ webhook: completed ──────────────────────► COMPLETED
│
│ webhook: failed + AUTO process ───────────┐
│ ▼
│ ┌──────────────┐
│ │ RETRY │◄── Submit error (AUTO/RETRY)
│ │ (Retrying) │◄── Balance check failed
│ └──────┬───────┘
│ │
│ │ Max retries reached /
│ │ stale (> 60 days) /
│ │ competing payment succeeded /
│ │ loan closed
│ ▼
│ webhook: failed + non-AUTO ────────► ┌──────────┐
│ │ FAILED │◄── Submit error (MANUAL)
└─────────────────────────────────────►└──────────┘
│
│ webhook: charged_back ────────────► CHARGED_BACK
│
└── webhook: refunded ──────────────► REFUNDED
Payment Applications
When a payment completes successfully, it is applied to installments. The loc_applications field tracks which installments received funds:
{
"loc_applications": [
{
"payment_id": "abc-123",
"installment_id": "inst-456",
"amount": 5000,
"payment_date": "2024-01-15T12:00:00Z"
}
]
}
Related Entities
-
Loans - Parent loan for this payment
-
Installments - Installments this payment applies to
-
Payment Logs - Audit trail for this payment