Payment (v1.0.0)

Represents payment transactions for orders in the e-commerce system.

Overview

The Payment entity manages all payment transactions in the e-commerce system. It tracks payment details, status, and relationships with orders and customers, supporting various payment methods and refund scenarios.

Entity Properties

NameTypeRequiredDescription
paymentIdUUIDRequiredUnique identifier for the payment
orderIdUUIDRequiredOrder this payment is associated with
customerIdUUIDRequiredCustomer who made the payment
amountdecimalRequiredPayment amount
currencystringRequiredCurrency code (e.g., USD, EUR, GBP)
paymentMethodstringRequiredPayment method used
paymentMethodDetailsobjectOptionalAdditional payment method specific details
statusstringRequiredCurrent payment status
transactionIdstringOptionalExternal payment processor transaction ID
gatewayResponseobjectOptionalRaw response from payment gateway
billingAddressAddressRequiredBilling address for the payment
processedAtDateTimeOptionalDate and time when payment was processed
failureReasonstringOptionalReason for payment failure if applicable
refundsarrayOptionalRefunds associated with this payment
createdAtDateTimeRequiredDate and time when the payment record was created
updatedAtDateTimeOptionalDate and time when the payment record was last updated

Relationships

  • Order: Each payment belongs to one Order (identified by orderId).
  • Customer: Each payment is made by one Customer (identified by customerId).
  • Address: Each payment has a billing Address (identified by billingAddress).
  • PaymentRefund: A payment can have multiple PaymentRefund entities for partial or full refunds.

Payment States

pending → processing → completed
    ↓         ↓           ↓
cancelled  failed    refunded/partially_refunded

Examples

  • Payment #1: $299.99 credit card payment for Order #12345, completed successfully.
  • Payment #2: $150.00 PayPal payment for Order #67890, failed due to insufficient funds.
  • Payment #3: $500.00 bank transfer, completed with $50.00 partial refund.

Business Rules

  • Payment amount must match the order total
  • Payment status transitions must follow valid state machine
  • Failed payments should include failure reason
  • Completed payments cannot be cancelled
  • Refunds cannot exceed the original payment amount
  • Payment method details are encrypted and PCI compliant
  • Transaction IDs from payment gateways must be stored for reconciliation