Skip to main content
POST
/
api
/
payments
curl --request POST \
  --url https://api.ambiotec.com/api/payments \
  --header 'Authorization: Bearer YOUR_TOKEN' \
  --form 'customerId=456' \
  --form 'document=@/path/to/receipt.pdf' \
  --form 'invoiceId=789'
{
  "success": true,
  "payment": {
    "paymentId": 1234,
    "customerId": 456,
    "amount": 1500.00,
    "currency": "GTQ",
    "paymentMethod": "transferencia",
    "bankCode": "BI",
    "reference": "TRX-123456",
    "transactionDate": "2026-03-03",
    "status": "pendiente",
    "documentUrl": "https://s3.amazonaws.com/ambiotec-payments/documents/1234-receipt.pdf",
    "ocrData": {
      "extractedAmount": 1500.00,
      "extractedDate": "2026-03-03",
      "extractedReference": "TRX-123456",
      "confidence": {
        "amount": 0.95,
        "date": 0.98,
        "reference": 0.92
      }
    },
    "registeredBy": 42,
    "createdAt": "2026-03-03T15:30:00Z"
  },
  "ocrResult": {
    "requiresManualReview": false,
    "confidence": {
      "amount": 0.95,
      "date": 0.98
    }
  }
}
Creates a new payment record with support for automatic data extraction from payment receipt documents using OCR (Optical Character Recognition).

Body Parameters

Required Fields

customerId
integer
required
The ID of the customer making the payment

Document Upload (Optional)

document
file
Payment receipt or proof document (JPEG, PNG, or PDF)Supported formats:
  • image/jpeg
  • image/png
  • application/pdf
Max size: 10MBWhen provided, the system will:
  • Extract payment details using AWS Textract OCR
  • Parse amount, date, reference number, bank code
  • Upload document to S3 for record keeping

Manual Payment Data (Required if no document)

amount
number
Payment amount. Required if document is not provided or OCR fails
currency
string
default:"GTQ"
Currency code (ISO 4217)Common values:
  • GTQ: Guatemalan Quetzal
  • USD: US Dollar
paymentMethod
string
Method of payment. Required if no document providedPossible values:
  • deposito: Bank deposit
  • transferencia: Bank transfer
  • cheque: Check
  • efectivo: Cash
  • tarjeta: Card payment
bankCode
string
Bank identifier code
reference
string
Payment reference or transaction number
transactionDate
string
Date of transaction (YYYY-MM-DD format)
notes
string
Additional notes or comments about the payment
invoiceId
integer
ID of the invoice this payment is for (if applicable)

Response

success
boolean
Indicates if the payment was created successfully
payment
object
The created payment object
ocrResult
object
Details of OCR processing (if document was provided)
curl --request POST \
  --url https://api.ambiotec.com/api/payments \
  --header 'Authorization: Bearer YOUR_TOKEN' \
  --form 'customerId=456' \
  --form 'document=@/path/to/receipt.pdf' \
  --form 'invoiceId=789'
{
  "success": true,
  "payment": {
    "paymentId": 1234,
    "customerId": 456,
    "amount": 1500.00,
    "currency": "GTQ",
    "paymentMethod": "transferencia",
    "bankCode": "BI",
    "reference": "TRX-123456",
    "transactionDate": "2026-03-03",
    "status": "pendiente",
    "documentUrl": "https://s3.amazonaws.com/ambiotec-payments/documents/1234-receipt.pdf",
    "ocrData": {
      "extractedAmount": 1500.00,
      "extractedDate": "2026-03-03",
      "extractedReference": "TRX-123456",
      "confidence": {
        "amount": 0.95,
        "date": 0.98,
        "reference": 0.92
      }
    },
    "registeredBy": 42,
    "createdAt": "2026-03-03T15:30:00Z"
  },
  "ocrResult": {
    "requiresManualReview": false,
    "confidence": {
      "amount": 0.95,
      "date": 0.98
    }
  }
}

Business Logic

OCR Processing Flow

When a document is uploaded:
  1. Document Upload: File is uploaded to S3 (payments/documents/ folder)
  2. OCR Extraction: AWS Textract processes the document to extract:
    • Payment amount
    • Transaction date
    • Reference/transaction number
    • Bank code/name
    • Payment method indicators
  3. Confidence Scoring: Each extracted field receives a confidence score (0-1)
  4. Manual Review Flag: If confidence is low (below 0.85), requiresManualReview is set to true
  5. Data Override: If manualData is provided in the request, it takes precedence over OCR results
  6. Payment Creation: Record is saved with status pendiente (pending validation)

Payment Status Lifecycle

  1. pendiente: Initial state, requires validation
  2. validado: Finance team validated the payment
  3. rechazado: Payment rejected (invalid, duplicate, etc.)
  4. en_proceso_ach: ACH/bank transfer being processed
  5. conciliado: Payment reconciled with bank statement
  6. aplicado: Payment applied to customer account/invoices

Document Storage

  • All payment documents are stored in S3 bucket
  • Path format: payments/documents/{paymentId}-{filename}
  • Documents are retained for compliance and audit purposes
  • Access requires authentication

Invoice Association

When invoiceId is provided:
  • Payment is linked to a specific invoice
  • Helps with automatic payment allocation
  • Invoice balance is updated when payment status changes to aplicado

Manual vs OCR Data Priority

If both document and manual data are provided:
  • Manual data takes precedence for payment record
  • OCR data is still stored in ocrData field for comparison
  • Useful for correcting OCR errors while maintaining audit trail

Notes

  • Payments start in pendiente status and require validation
  • OCR works best with clear, high-resolution images
  • If OCR confidence is low, manual review is recommended
  • Multiple payments can be associated with the same invoice
  • The system tracks who registered each payment for accountability
  • The OCR process is automatically triggered when a payment receipt is uploaded

Build docs developers (and LLMs) love