Giao diện
payment / refund
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 đè.
6 bảng. Quay lại payment.
refund_cases
P3-10. One refund case per Order, always the whole Order: cash legs per original capture, point legs per original REDEEM (refund_branches). PENDING -> APPROVED|REJECTED, APPROVED -> REFUNDED only when every leg is ACCEPTED. Maker != checker; thresholds G-FIN undecided. No provider call is made here (P3-11).
public.refund_cases · 35 cột · 16 check · 1 unique · 8 index · 2 policy · 10 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
order_id | uuid | NOT NULL | FK → orders | |
owner_account_id | uuid | NOT NULL | FK → accounts | |
origin | text | NOT NULL | ||
case_type | text | NOT NULL | ||
scope | text | NOT NULL | ||
request_key | text | NOT NULL | ||
policy_version_id | uuid | NOT NULL | FK → campaign_policy_versions | |
rule_versions | text[] | NOT NULL | ||
status | text | NOT NULL | ||
approval_required | boolean | NOT NULL | ||
requested_by | uuid | FK → accounts | ||
request_reason | text | |||
refundable_cash_vnd | bigint | NOT NULL | ||
points_to_reverse | integer | NOT NULL | ||
decided_by | uuid | FK → accounts | ||
decided_at | timestamptz | |||
decision_note | text | |||
threshold_policy_version_id | uuid | |||
evidence_media_ids | uuid[] | NOT NULL | ||
completed_at | timestamptz | |||
last_branch_id | uuid | |||
change_source | text | NOT NULL | ||
change_source_id | text | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL | ||
shortage_case_id | uuid | FK → stock_shortage_cases | FU-575. The shortage case of a PARTIAL_UNITS refund case (the amounts are the stored share of that case row). | |
forfeit_review_id | uuid | FK → recurring_forfeit_reviews | FU-FORFEIT. The approved cycle forfeit review of a PARTIAL case with origin FORFEIT (one case per review, ever). | |
return_cycle_no | integer | #479 B. The Mua định kỳ cycle of a RETURN case (scope RETURNED_CYCLE); null for every other case. | ||
returned_on | date | #479 B. Day of the return (Vietnam) Operations entered; RETURN only. | ||
kept_cash_vnd | bigint | #479 B. Cash of the unit the shop keeps (snapshot at the record); NO_REFUND = everything paid. RETURN only. | ||
kept_points | integer | #479 B. Pi-Point of the unit the buyer does not get back (snapshot at the record). RETURN only. | ||
ops_note | text | #479 B. Internal Operations note of a RETURN case (<= 500). | ||
overpayment_case_id | uuid | FK → payment_overpayment_cases | #479 C. The cọc dư case (payment_overpayment_cases) an EXCESS_DEPOSIT claim refunds; null for every other case. |
Khoá chính: id
Trỏ ra (8):
decided_by→accounts·ON DELETE RESTRICTforfeit_review_id→recurring_forfeit_reviews·ON DELETE RESTRICTorder_id→orders·ON DELETE RESTRICToverpayment_case_id→payment_overpayment_cases·ON DELETE RESTRICTowner_account_id→accounts·ON DELETE RESTRICTpolicy_version_id→campaign_policy_versions·ON DELETE RESTRICTrequested_by→accounts·ON DELETE RESTRICTshortage_case_id→stock_shortage_cases·ON DELETE RESTRICT
Được trỏ tới (6): mission_reversal_evidence, refund_branches, refund_case_events, refund_info_update_requests, refund_receiver_profiles, refund_transfer_records
refund_branches
P3-10. One leg of a refund case: CASH per original captured transaction (full amount) or POINT per original accepted REDEEM (full points, original rate). Provider request machine; ACCEPTED needs the provider refund / REVERSE_REDEEM of exactly the original on file. Never complete while a leg is UNKNOWN.
public.refund_branches · 23 cột · 9 check · 4 unique · 7 index · 1 policy · 8 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
refund_case_id | uuid | NOT NULL | FK → refund_cases | |
branch_kind | text | NOT NULL | ||
original_transaction_id | uuid | FK → provider_transactions | ||
original_point_request_id | uuid | FK → point_requests | ||
amount_vnd | bigint | |||
points | integer | |||
rate_snapshot_vnd | numeric | |||
rate_policy_version | text | |||
provider | text | |||
provider_mode | text | |||
status | text | NOT NULL | ||
attempt | integer | NOT NULL | ||
refund_transaction_id | uuid | FK → provider_transactions | ||
reverse_request_id | uuid | FK → point_requests | ||
result_code | text | |||
recovery_reason | text | |||
recovery_evidence_media_ids | uuid[] | NOT NULL | ||
change_source | text | NOT NULL | ||
change_source_id | text | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL |
Khoá chính: id
Trỏ ra (5):
original_point_request_id→point_requests·ON DELETE RESTRICToriginal_transaction_id→provider_transactions·ON DELETE RESTRICTrefund_case_id→refund_cases·ON DELETE RESTRICTrefund_transaction_id→provider_transactions·ON DELETE RESTRICTreverse_request_id→point_requests·ON DELETE RESTRICT
Được trỏ tới (1): refund_case_events
refund_case_events
P3-10. Append-only refund case history: one row per case version (case decisions, evidence, each leg change).
public.refund_case_events · 14 cột · 3 check · 1 unique · 2 index · 1 policy · 3 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
refund_case_id | uuid | NOT NULL | FK → refund_cases | |
case_version | integer | NOT NULL | ||
event_kind | text | NOT NULL | ||
branch_id | uuid | FK → refund_branches | ||
from_status | text | |||
to_status | text | NOT NULL | ||
actor_account_id | uuid | FK → accounts | ||
source_type | text | NOT NULL | ||
source_id | text | NOT NULL | ||
evidence_media_ids | uuid[] | NOT NULL | ||
recorded_at | timestamptz | NOT NULL | ||
actor_label | text | |||
actor_roles | text[] |
Khoá chính: id
Trỏ ra (3):
actor_account_id→accounts·ON DELETE RESTRICTbranch_id→refund_branches·ON DELETE RESTRICTrefund_case_id→refund_cases·ON DELETE RESTRICT
Được trỏ tới: không có
refund_info_update_requests
U19-P2-15 (DH-US-16). Operations asked the customer to send the refund request again: the rejected revision, the reason and the note shown to the customer. Append-only; written by payment.refund_ops_request_update only.
public.refund_info_update_requests · 12 cột · 6 check · 2 unique · 4 index · 0 policy · 2 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
refund_case_id | uuid | NOT NULL | FK → refund_cases | |
order_id | uuid | NOT NULL | FK → orders | |
profile_revision | integer | NOT NULL | ||
case_version | integer | NOT NULL | ||
reason | text | NOT NULL | U19-P2-15; G2I-P1-03: internal note of Operations (1..1000). Never sent to the customer; filled with the code when blank. | |
customer_note | text | |||
requested_by | uuid | NOT NULL | FK → accounts | |
requested_at | timestamptz | NOT NULL | ||
source_id | text | NOT NULL | ||
reason_code | text | NOT NULL | G2I-P1-03 O6a/E2. Why the request was sent back, as a fixed code the clients turn into a friendly sentence. | |
note_customer_visible | boolean | NOT NULL | G2I-P1-03 O6a/E2. True when Operations marked customer_note for the customer; only then does the buyer read it. |
Khoá chính: id
Trỏ ra (3):
order_id→orders·ON DELETE RESTRICTrefund_case_id→refund_cases·ON DELETE RESTRICTrequested_by→accounts·ON DELETE RESTRICT
Được trỏ tới: không có
refund_receiver_profiles
U13-P2-06d, U19-P2-14. Receiver of a refund transfer, submitted by the CUSTOMER on the app (append-only revisions per case). Citizen id and account number are stored encrypted (API key REFUND_PII_KEY) plus their last 4 digits; legacy rows keep plaintext until scripts/operator/encrypt-refund-profiles.ts seals them. Every read is masked. Names are shown in full.
public.refund_receiver_profiles · 18 cột · 10 check · 2 unique · 3 index · 0 policy · 3 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
refund_case_id | uuid | NOT NULL | FK → refund_cases | |
revision | integer | NOT NULL | ||
receiver_name | text | NOT NULL | ||
citizen_id | text | |||
bank_name | text | NOT NULL | ||
account_number | text | |||
holder_name | text | NOT NULL | ||
recorded_by | uuid | NOT NULL | FK → accounts | |
recorded_at | timestamptz | NOT NULL | ||
source_id | text | NOT NULL | ||
citizen_id_enc | bytea | |||
account_number_enc | bytea | |||
pii_key_id | text | |||
citizen_id_last4 | text | NOT NULL | ||
account_number_last4 | text | NOT NULL | ||
submitted_by_kind | text | NOT NULL | ||
holder_matches_id_name | boolean | NOT NULL | U19-P2-14. Account holder name = name on the CCCD (accent/case/blank-insensitive). A sign for Operations, never a block. |
Khoá chính: id
Trỏ ra (2):
recorded_by→accounts·ON DELETE RESTRICTrefund_case_id→refund_cases·ON DELETE RESTRICT
Được trỏ tới: không có
refund_transfer_records
U13-P2-06d (GAP-DH-V1-06). The manual external transfer fact of a refund case (code, date, evidence, the case cash at that time); it moves no leg and calls no provider. One per case, one per transaction code.
public.refund_transfer_records · 12 cột · 6 check · 2 unique · 4 index · 0 policy · 3 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
refund_case_id | uuid | NOT NULL | FK → refund_cases | |
transaction_code | text | NOT NULL | ||
transferred_on | date | NOT NULL | ||
amount_vnd | bigint | NOT NULL | ||
evidence_media_ids | uuid[] | NOT NULL | ||
profile_revision | integer | NOT NULL | ||
recorded_by | uuid | NOT NULL | FK → accounts | |
recorded_at | timestamptz | NOT NULL | ||
source_id | text | NOT NULL | ||
ops_note | text | U19-P2-15. Operations note of the confirm (Word, <= 500). | ||
settles_case | boolean | NOT NULL | U19-P2-15. True only for the Operations confirm (one step, D-SEC-01): the cash of the case is refunded by this transfer. |
Khoá chính: id
Trỏ ra (2):
recorded_by→accounts·ON DELETE RESTRICTrefund_case_id→refund_cases·ON DELETE RESTRICT
Được trỏ tới: không có