Skip to content

payment / payment ​

Trang sinh tự động

Sinh từ ad83b0aea — chạy 820 migration lên PostgreSQL 17 rồi đọc pg_catalog. Mô tả bảng và cột lấy từ COMMENT ON. Không sửa tay: lần chạy docgen sau sẽ ghi đè.

13 bảng. Quay lại payment.

payment_intents ​

P3-01 / #479. Provider-agnostic payment attempt for one cash obligation (MOCK only, G-FIN). UNKNOWN is not terminal and blocks a second intent; SUCCEEDED needs a verified capture of the exact amount; NEEDS_REVIEW ends an attempt whose captured money could not be applied (Finance: payment.unapplied_captures).

public.payment_intents · 19 cột · 10 check · 1 unique · 5 index · 1 policy · 6 trigger · RLS bật

CộtKiểuKhoáMô tả
iduuidNOT NULLPK
obligation_iduuidNOT NULLFK → payment_obligations
request_idtextNOT NULL
providertextNOT NULL
provider_modetextNOT NULL
amount_vndbigintNOT NULL
currencytextNOT NULL
payload_hashbyteaNOT NULL
provider_session_reftext
result_codetext
statustextNOT NULL
status_changed_attimestamptzNOT NULL
change_sourcetextNOT NULL
change_source_idtextNOT NULL
correlation_idcorrelation_refNOT NULL
created_byuuidFK → accounts
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL

Khoá chính: id

Trỏ ra (2):

  • created_by → accounts · ON DELETE RESTRICT
  • obligation_id → payment_obligations · ON DELETE RESTRICT

Được trỏ tới (9): cashbook_entries, payment_event_conflicts, payment_events, payment_hold_releases, payment_intent_leases, payment_intent_recovery_checks, payment_intent_sessions, payment_reconciliation_items, provider_transactions

payment_obligations ​

P3-01. Per-order obligations DEPOSIT / PI_POINT / REMAINING in integer VND; immutable amounts, OPEN -> SETTLED | CANCELLED with expectedVersion; cash settles by allocations, PI_POINT by an accepted REDEEM.

public.payment_obligations · 18 cột · 11 check · 2 unique · 6 index · 2 policy · 8 trigger · RLS bật

CộtKiểuKhoáMô tả
iduuidNOT NULLPK
order_iduuidNOT NULLFK → orders
kindtextNOT NULL
methodtextNOT NULL
order_cycle_iduuidFK → order_cycles
amount_vndbigintNOT NULL
pointsinteger
point_rate_snapshot_vndnumeric
point_request_iduuidFK → point_requests
source_idtextNOT NULL
statustextNOT NULL
settled_attimestamptz
change_sourcetextNOT NULL
change_source_idtextNOT NULL
change_reasontext
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL

Khoá chính: id

Trỏ ra (3):

  • order_cycle_id → order_cycles · ON DELETE RESTRICT
  • order_id → orders · ON DELETE RESTRICT
  • point_request_id → point_requests · ON DELETE RESTRICT

Được trỏ tới (8): cashbook_entries, cod_collections, deposit_checkouts, deposit_checkouts, order_cycle_close_values, payment_allocations, payment_intents, payment_remaining_recalcs

payment_events ​

P3-01. Append-only verified provider observations per intent; unique (provider, provider_event_id).

public.payment_events · 14 cột · 8 check · 1 unique · 3 index · 1 policy · 3 trigger · RLS bật

CộtKiểuKhoáMô tả
iduuidNOT NULLPK
intent_iduuidNOT NULLFK → payment_intents
providertextNOT NULL
provider_modetextNOT NULL
provider_event_idtextNOT NULL
event_typetextNOT NULL
reported_statustextNOT NULL
provider_txn_idtext
reported_amount_vndbigint
currencytextNOT NULL
payload_hashbyteaNOT NULL
occurred_attimestamptz
recorded_attimestamptzNOT NULL
correlation_idcorrelation_refNOT NULL

Khoá chính: id

Trỏ ra (1):

  • intent_id → payment_intents · ON DELETE RESTRICT

Được trỏ tới (1): payment_event_conflicts

payment_overpayment_cases ​

P3-05, PAF-P1-18 (DEC-PAF-08). Immutable offline excess-deposit case (cọc dư), one per excess: CLOSE at the close (final price below deposit + points value), SKIP for the increase after a skipped cycle; an order may hold several. Each case has its own reference code. Records the excess in integer VND; never a refund, a provider call or a point reversal (sow/03 s7.3). OWN + Finance read.

public.payment_overpayment_cases · 14 cột · 6 check · 3 unique · 5 index · 2 policy · 4 trigger · RLS bật

CộtKiểuKhoáMô tả
iduuidNOT NULLPK
order_iduuidNOT NULLFK → orders
close_outcome_iduuidFK → order_close_outcomes
owner_account_iduuidNOT NULLFK → accounts
final_total_vndbigintNOT NULL
deposit_vndbigintNOT NULL
points_value_vndbigintNOT NULL
excess_vndbigintNOT NULLP3-05, PAF-P1-18. CLOSE: the excess at the close (constraint payment_overpayment_cases_money); SKIP: the increase over the cases already open. The excess of an order is the sum over its cases.
statustextNOT NULL
source_idtextNOT NULL
created_attimestamptzNOT NULL
versionintegerNOT NULL
kindtextNOT NULLPAF-P1-18. CLOSE: opened by the close hook payment.open_remaining (source overpayment:<order>); SKIP: the increase of the excess after a skipped cycle (PAF-P1-03, no close outcome).
reference_codetextNOT NULLPAF-P1-18 (DEC-PAF-08, BR-APP-08 / BR-MD-07). Reference of the case for the offline handling: DU + ddmmyyyy (Vietnam day of created_at) + 4 digits, from campaign.next_daily_code('excess_deposit', 'DU', 4); issued by the insert guard, never chosen by the caller.

Khoá chính: id

Trỏ ra (3):

  • close_outcome_id → order_close_outcomes · ON DELETE RESTRICT
  • order_id → orders · ON DELETE RESTRICT
  • owner_account_id → accounts · ON DELETE RESTRICT

Được trỏ tới (1): refund_cases

payment_reconciliation_runs ​

P3-13. One row per provider/mode, VN business date and rerun; immutable after COMPLETE/INCOMPLETE. Evidence and totals only: no tolerance, no ledger or transaction write. MOCK only (G-FIN).

public.payment_reconciliation_runs · 24 cột · 12 check · 1 unique · 3 index · 4 policy · 4 trigger · RLS bật

CộtKiểuKhoáMô tả
iduuidNOT NULLPK
providertextNOT NULL
provider_modetextNOT NULL
run_date_vndateNOT NULL
run_versionintegerNOT NULL
timezonetextNOT NULL
window_starttimestamptzNOT NULL
window_endtimestamptzNOT NULL
trigger_kindtextNOT NULL
requested_byuuidFK → accounts
statustextNOT NULL
started_attimestamptzNOT NULL
finished_attimestamptz
provider_snapshot_reftext
remote_dataset_hashbytea
local_totalsjsonb
remote_totalsjsonb
error_codetext
lease_ownertext
lease_expires_attimestamptz
correlation_idcorrelation_refNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL

Khoá chính: id

Trỏ ra (1):

  • requested_by → accounts · ON DELETE RESTRICT

Được trỏ tới (1): payment_reconciliation_items

payment_allocations ​

P3-01. Append-only capture -> obligation allocations; sums never exceed the capture or the obligation.

public.payment_allocations · 6 cột · 2 check · 2 unique · 4 index · 0 policy · 4 trigger · RLS bật

CộtKiểuKhoáMô tả
iduuidNOT NULLPK
transaction_iduuidNOT NULLFK → provider_transactions
obligation_iduuidNOT NULLFK → payment_obligations
amount_vndbigintNOT NULL
source_idtextNOT NULL
created_attimestamptzNOT NULL

Khoá chính: id

Trỏ ra (2):

  • obligation_id → payment_obligations · ON DELETE RESTRICT
  • transaction_id → provider_transactions · ON DELETE RESTRICT

Được trỏ tới: không có

payment_event_conflicts ​

#479 T9. Verified provider observations whose event id was already stored (payment_events.event_id) with another intent, event type, status, transaction id or amount: never applied, listed for Finance (payments_needing_attention PROVIDER_EVENT_CONFLICT). One row per payload hash. Append-only, SYSTEM_ONLY.

public.payment_event_conflicts · 14 cột · 7 check · 1 unique · 3 index · 0 policy · 2 trigger · RLS bật

CộtKiểuKhoáMô tả
iduuidNOT NULLPK
event_iduuidNOT NULLFK → payment_events
intent_iduuidNOT NULLFK → payment_intents
providertextNOT NULL
provider_modetextNOT NULL
provider_event_idtextNOT NULL
event_typetextNOT NULL
reported_statustextNOT NULL
provider_txn_idtext
reported_amount_vndbigint
payload_hashbyteaNOT NULL
occurred_attimestamptz
recorded_attimestamptzNOT NULL
correlation_idcorrelation_refNOT NULL

Khoá chính: id

Trỏ ra (2):

  • event_id → payment_events · ON DELETE RESTRICT
  • intent_id → payment_intents · ON DELETE RESTRICT

Được trỏ tới: không có

payment_hold_releases ​

#479 two-step. The release (cancelPayment) of a provider hold (AUTHORIZED) whose payment attempt ended FAILED: attempts, last result, earliest next attempt (the recovery sweep backoff). RELEASING -> RELEASED | CAPTURED (the provider captured anyway: a LATE_CAPTURE for Finance) | GAVE_UP (Finance attention HOLD_RELEASE_FAILED). Not a payment fact. SYSTEM_ONLY: RLS forced, no grant; written by payment.system_claim_hold_release and payment.system_note_hold_release (pi_worker).

public.payment_hold_releases · 10 cột · 6 check · 0 unique · 2 index · 0 policy · 3 trigger · RLS bật

CộtKiểuKhoáMô tả
intent_iduuidNOT NULLPK FK → payment_intents
statustextNOT NULL
attemptsintegerNOT NULL
last_resulttext
last_attempt_attimestamptz
next_attempt_attimestamptzNOT NULL
ended_attimestamptz
versionintegerNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

Khoá chính: intent_id

Trỏ ra (1):

  • intent_id → payment_intents · ON DELETE RESTRICT

Được trỏ tới: không có

payment_intent_leases ​

#479 T4 / two-step / buyer re-check. Who may run one provider step of an intent (SEND the create, CAPTURE an authorized session, QUERY for the buyer) until leased_until. Not a payment fact. SYSTEM_ONLY: RLS forced, no grant; written by payment.lease_core.

public.payment_intent_leases · 6 cột · 3 check · 0 unique · 1 index · 0 policy · 0 trigger · RLS bật

CộtKiểuKhoáMô tả
intent_iduuidNOT NULLPK FK → payment_intents
purposetextNOT NULLPK
holderuuidNOT NULL
leased_untiltimestamptzNOT NULL
claimsintegerNOT NULL
claimed_attimestamptzNOT NULL

Khoá chính: intent_id, purpose

Trỏ ra (1):

  • intent_id → payment_intents · ON DELETE RESTRICT

Được trỏ tới: không có

payment_intent_recovery_checks ​

#479 T8. Recovery bookkeeping of the payment.intent_recover sweep, one row per intent it checked: attempts, last check, earliest next check (backoff). Not a payment fact (the intent is unchanged). SYSTEM_ONLY: RLS forced, no grant; written by payment.system_note_intent_check (pi_worker).

public.payment_intent_recovery_checks · 4 cột · 2 check · 0 unique · 1 index · 0 policy · 0 trigger · RLS bật

CộtKiểuKhoáMô tả
intent_iduuidNOT NULLPK FK → payment_intents
attemptsintegerNOT NULL
last_checked_attimestamptzNOT NULL
next_check_attimestamptzNOT NULL

Khoá chính: intent_id

Trỏ ra (1):

  • intent_id → payment_intents · ON DELETE RESTRICT

Được trỏ tới: không có

payment_intent_sessions ​

#479 T5. How the buyer pays the open provider session of one intent (web page, app deeplink, QR string, the provider's own session end), as the provider reported it; written once (payment.session_core), append-only. Read through the intent (U-04 own, F-01 Finance).

public.payment_intent_sessions · 6 cột · 4 check · 0 unique · 1 index · 1 policy · 2 trigger · RLS bật

CộtKiểuKhoáMô tả
intent_iduuidNOT NULLPK FK → payment_intents
pay_urltext
deeplinktext
qr_datatext
provider_expires_attimestamptz
recorded_attimestamptzNOT NULL

Khoá chính: intent_id

Trỏ ra (1):

  • intent_id → payment_intents · ON DELETE RESTRICT

Được trỏ tới: không có

payment_reconciliation_items ​

P3-13. One payment discrepancy of a run (five sow/03 s12 types); evidence immutable, handling OPEN -> IN_PROGRESS -> RESOLVED. Never edits provider_transactions/intents/obligations.

public.payment_reconciliation_items · 30 cột · 14 check · 1 unique · 5 index · 4 policy · 5 trigger · RLS bật

CộtKiểuKhoáMô tả
iduuidNOT NULLPK
run_iduuidNOT NULLFK → payment_reconciliation_runs
discrepancy_typetextNOT NULL
item_keytextNOT NULL
transaction_iduuidFK → provider_transactions
intent_iduuidFK → payment_intents
provider_txn_idtext
external_request_reftext
provider_recorded_attimestamptz
local_kindtext
remote_kindtext
local_statustext
remote_statustext
local_amount_vndbigint
remote_amount_vndbigint
remote_currencytext
evidencejsonbNOT NULL
remote_payload_hashbytea
statustextNOT NULL
owner_account_iduuidFK → accounts
notetext
retry_countintegerNOT NULL
last_retry_attimestamptz
resolved_byuuidFK → accounts
resolved_attimestamptz
resolution_notetext
correlation_idcorrelation_refNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL

Khoá chính: id

Trỏ ra (5):

  • intent_id → payment_intents · ON DELETE RESTRICT
  • owner_account_id → accounts · ON DELETE RESTRICT
  • resolved_by → accounts · ON DELETE RESTRICT
  • run_id → payment_reconciliation_runs · ON DELETE RESTRICT
  • transaction_id → provider_transactions · ON DELETE RESTRICT

Được trỏ tới: không có

payment_remaining_recalcs ​

FU-SHORTAGE2. Immutable record of what a partial shortage case did to the REMAINING obligation of an Order: amended, excess refunded (online) or returned offline (COD), unchanged, or undecided with a reason. OWN + Operations read.

public.payment_remaining_recalcs · 16 cột · 5 check · 2 unique · 4 index · 2 policy · 2 trigger · RLS bật

CộtKiểuKhoáMô tả
iduuidNOT NULLPK
order_iduuidNOT NULLFK → orders
owner_account_iduuidNOT NULLFK → accounts
shortage_case_iduuidNOT NULLFK → stock_shortage_cases
obligation_iduuidNOT NULLFK → payment_obligations
methodtextNOT NULL
status_beforetextNOT NULL
previous_amount_vndbigintNOT NULL
target_vndbigintNOT NULL
new_amount_vndbigintNOT NULL
excess_vndbigintNOT NULL
actiontextNOT NULL
reasontext
request_keytextNOT NULL
source_idtextNOT NULL
created_attimestamptzNOT NULL

Khoá chính: id

Trỏ ra (4):

  • obligation_id → payment_obligations · ON DELETE RESTRICT
  • order_id → orders · ON DELETE RESTRICT
  • owner_account_id → accounts · ON DELETE RESTRICT
  • shortage_case_id → stock_shortage_cases · ON DELETE RESTRICT

Được trỏ tới: không có

Sinh từ ad83b0aea · 820 migration · PostgreSQL 17