payment_event.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # app/models/payment_event.py
  2. from sqlalchemy import (
  3. Column, Integer, String, Text, DateTime, JSON, BigInteger
  4. )
  5. from datetime import datetime
  6. from app.core.database import Base
  7. class VasPaymentEvent(Base):
  8. __tablename__ = "vas_payment_event"
  9. id = Column(BigInteger, primary_key=True, autoincrement=True)
  10. # ---- 来源 ----
  11. provider = Column(String(32), nullable=False) # wechat | alipay | stripe
  12. event_type = Column(String(64)) # payment_received | checkout.session.completed
  13. event_id = Column(String(128), unique=True) # Stripe event.id / 自生成 hash
  14. # ---- 原始内容 ----
  15. title = Column(Text)
  16. content = Column(Text)
  17. raw_payload = Column(JSON)
  18. # ---- 解析结果 ----
  19. parsed_amount = Column(BigInteger) # 最小货币单位
  20. parsed_currency = Column(String(8))
  21. parsed_device = Column(String(64))
  22. # ---- 业务关联 ----
  23. matched_payment_id = Column(BigInteger)
  24. matched_order_id = Column(String(128))
  25. # ---- 状态 ----
  26. status = Column(
  27. String(32), # received | matched | applied | duplicate | failed
  28. nullable=False,
  29. default="received"
  30. )
  31. error_message = Column(Text)
  32. created_at = Column(DateTime, default=datetime.utcnow)