Skip to content

feat(compliance): merchant account deletion / anonymization (#314)#345

Merged
Pvsaint merged 3 commits intoMetroLogic:mainfrom
rayeberechi:feature/314-merchant-account-deletion
Mar 30, 2026
Merged

feat(compliance): merchant account deletion / anonymization (#314)#345
Pvsaint merged 3 commits intoMetroLogic:mainfrom
rayeberechi:feature/314-merchant-account-deletion

Conversation

@rayeberechi
Copy link
Copy Markdown
Contributor

@rayeberechi rayeberechi commented Mar 29, 2026

Overview

This PR implements a comprehensive workflow for merchant account closure and data erasure. It balances GDPR 'Right to Be Forgotten' requirements with financial regulatory mandates for data retention, ensuring PII is wiped while transaction integrity is preserved for audit trails.

Core Implementation (#314)

  • Data Retention Policy: Defined a strict mapping for data handling:
    • Anonymized (Retained): Merchant PII (names, emails, phones), KYC metadata, and Webhook URLs (which may contain PII in query params).
    • Hard-Deleted (Purged): KYC documents, Bank Account details, OTPs, and active Subscriptions.
    • Preserved (Legal Hold): Payments, Settlements, and Invoices remain intact to satisfy 7-year financial record-keeping obligations.
  • Two-Step Deletion Workflow:
    1. Request Phase: Merchant or Admin initiates a request (deletion_requested_at). This triggers a 'Pending' state for operational review.
    2. Execution Phase: An Admin-only action that performs the irreversible anonymization within a single database transaction.
  • Audit Logging: Integrated merchant_deletion_requested and merchant_anonymized events into the global audit log, capturing the requester's identity and timestamp.

Technical Specification

  • Database Architecture:
    • Added deletion_requested_at and anonymized_at fields to the Merchant model.
    • Introduced MerchantDeletionRequest to track the lifecycle of closure requests.
  • Transaction Safety: The anonymization logic uses a Prisma $transaction to ensure that either all PII is wiped or none of it is, preventing "partial deletions."
  • Testing: 9 new tests in merchantDeletion.service.test.ts verify that financial records remain queryable after their associated merchant has been anonymized.

Results

  • Compliance: Fully satisfies GDPR Article 17 (Right to Erasure) and Article 30 (Records of Processing).
  • Security: Hard-deletion of sensitive documents (KYC) reduces the platform's data liability.

Verification

  • Transaction records remain visible but point to anonymized profiles.
  • KYC documents are physically removed from storage/database.
  • Admin-only execution prevents unauthorized or accidental erasure.
  • All 9 tests passing.

Closes #314

…ic#314)

Schema:
- Add deletion_requested_at, anonymized_at to Merchant
- Add MerchantDeletionRequest model (tracks request + execution)
- Add AuditActionType: merchant_deletion_requested, merchant_anonymized
- Add AuditEntityType: merchant_account
- Migration: 20260329143000_merchant_deletion_anonymization

Service (merchantDeletion.service.ts):
- requestDeletion(): records request, marks merchant, writes audit log
- executeDeletion(): anonymizes PII fields, wipes KYC docs, clears
  webhook URLs, hard-deletes OTPs/bank/subs/customers; retains
  payments/settlements/refunds/invoices under legal hold
- getDeletionRequest(): status polling

Routes:
- POST /api/v1/merchants/me/deletion-request
- GET  /api/v1/merchants/me/deletion-request
- POST /api/v1/merchants/admin/:id/deletion-request
- POST /api/v1/merchants/admin/:id/anonymize

Tests: 9 unit tests, all passing
- Fix IKMSProvider/KMSFactory type errors (pre-existing)
- Fix payment.service uuid ESM issue (crypto.randomUUID)
- Add adminUser to AuthRequest type
@rayeberechi rayeberechi force-pushed the feature/314-merchant-account-deletion branch from bd3149e to fc15f51 Compare March 29, 2026 14:22
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 29, 2026

@rayeberechi Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Pvsaint Pvsaint merged commit 215a6a2 into MetroLogic:main Mar 30, 2026
2 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backend] Compliance: merchant account deletion / anonymization

2 participants