Overview

The Receipt model extracts and structures information from receipts, including merchant information, line items, payments, and tax details.

Schema Structure

Root Level Fields

FieldTypeDescription
MerchantNamestring?Name of the merchant issuing the receipt
MerchantPhoneNumberstring?Listed phone number of merchant
MerchantAddressAddress?Listed address of merchant
Totalnumber?Full transaction total of receipt
Subtotalnumber?Subtotal before taxes
TotalTaxnumber?Total tax amount
Tipnumber?Tip amount
TransactionDatestring?Date the receipt was issued
TransactionTimestring?Time the receipt was issued
CountryRegionstring?Country or region where receipt was issued
ReceiptTypestring?Type of receipt

Line Item Fields

Each item in the Items array contains:

FieldTypeDescription
Descriptionstring?Item description
TotalPricenumber?Total price for this line item
Quantitynumber?Quantity of each item
Pricenumber?Individual price of each item unit
ProductCodestring?Product code or SKU
QuantityUnitstring?Unit of measure

Payment Fields

Each payment in the Payments array contains:

FieldTypeDescription
Methodstring?Method of payment
Amountnumber?Amount of payment

Tax Detail Fields

Each tax detail in the TaxDetails array contains:

FieldTypeDescription
Amountnumber?Tax amount
Ratenumber?Tax rate as a percentage
NetAmountnumber?Net amount before tax
Descriptionstring?Description of the tax

Type Definitions

import type {
  ReceiptItem,
  Payment,
  ReceiptTaxDetail,
  Receipt,
  ReceiptResponse,
  StrictReceiptResponse
} from '@your-package/models';

Validation Rules

Basic Validation

  • All fields are optional by default
  • Items, Payments, and TaxDetails default to empty arrays if not specified

Strict Validation

The following fields are required in strict mode:

  • MerchantName
  • Total
  • TransactionDate
  • Items (minimum 1 item)

Example Usage

import { validateReceipt } from '@your-package/models';

// Example receipt data
const receiptData = {
  MerchantName: "Local Store",
  Total: 50.00,
  TransactionDate: "2024-01-01",
  Items: [
    {
      Description: "Office Supplies",
      Quantity: 2,
      Price: 25.00,
      TotalPrice: 50.00
    }
  ],
  Payments: [
    {
      Method: "Credit Card",
      Amount: 50.00
    }
  ]
};

// Validate the receipt
const validatedReceipt = validateReceipt(receiptData);

// Access validated data through result property
console.log(validatedReceipt.result.Total);

Date Handling

The model accepts dates in multiple formats:

  • ISO 8601 datetime strings
  • YYYY-MM-DD format

All dates are converted to ISO format during validation.

Best Practices

  1. Always validate receipts:
const receipt = validateReceipt(receiptData);
  1. Access data through the result property:
const total = receipt.result.Total;
  1. Handle optional fields appropriately:
const tip = receipt.result.Tip || 0;
  1. Check arrays before processing:
const items = receipt.result.Items || [];
const payments = receipt.result.Payments || [];
  1. Calculate totals carefully:
const totalWithTip = (receipt.result.Total || 0) + (receipt.result.Tip || 0);