Payment

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

Entity (Aggregate Root)

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

Name Type Required Description
paymentIdUUID Required Unique identifier for the payment
orderIdUUID Required Order this payment is associated with
customerIdUUID Required Customer who made the payment
amountdecimal Required Payment amount
currencystring Required Currency code (e.g., USD, EUR, GBP)
paymentMethodstring
Enum:
  • credit_card
  • debit_card
  • paypal
  • stripe
  • bank_transfer
  • apple_pay
  • google_pay
Required Payment method used
paymentMethodDetailsobject Optional Additional payment method specific details
statusstring
Enum:
  • pending
  • processing
  • completed
  • failed
  • cancelled
  • refunded
  • partially_refunded
Required Current payment status
transactionIdstring Optional External payment processor transaction ID
gatewayResponseobject Optional Raw response from payment gateway
billingAddressAddress Required Billing address for the payment
processedAtDateTime Optional Date and time when payment was processed
failureReasonstring Optional Reason for payment failure if applicable
refunds array<PaymentRefund > Optional Refunds associated with this payment
createdAtDateTime Required Date and time when the payment record was created
updatedAtDateTime Optional Date 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