Step 7 of 9

Step 7: Document Upload & Automatic Payment

When delivery period arrives, supplier uploads shipping documents. Upon upload, payment request automatically appears in buyer dashboard with countdown timer. Supplier automatically receives 100% funds (30% from pool + 70% financed).

📍 Page Location

URL: /manage-contract/:contractId (supplier) → /dashboard/authenticated (buyer)

📸 Visual Representation of the Page

Step 7: Document Upload & Automatic Payment
BUYER🔔 Notifications

My Contracts

Contract IDProductValueStatusActions
contract-001Wheat$2,627,500PENDING DEPOSIT

🎨 Detailed Visual Description

Supplier uploads documents via file upload interface. Documents are stored in /uploads directory on server. After upload, buyer dashboard shows: "Payment Request: $X (70% + fees)" with countdown timer = (voyage time - 3 days). Countdown shows days/hours remaining. If countdown expires, contract automatically moves to auction page. Supplier dashboard shows "Documents Uploaded" and "Payment Received: 100%" status.

Key Visual Elements:

  • Document upload interface
  • File storage in /uploads directory
  • Automatic payment request to buyer
  • Countdown timer (voyage time - 3 days)
  • Automatic fund release to supplier
  • Auction trigger on timeout

⚙️ Backend Process

API Endpoint: POST /api/contracts/:contractId/documents

Process Flow:
1. Validates user is supplier
2. Receives files via Multer middleware
3. Stores files in /uploads directory on server filesystem
4. File path format: /uploads/contracts/{contractId}/{timestamp}-{filename}
5. Creates document records in database.documents Map
6. Each document record stores: id, contractId, filename, originalName, path, size, mimetype, uploadedBy, uploadedAt
7. Updates contract: documentsUploaded = true, documentsUploadedAt = timestamp
8. Calculates paymentDueDate = documentsUploadedAt + (voyageTime - 3 days)
9. Automatically transfers 30% from pool wallet to supplier wallet
10. Automatically transfers 70% (financed amount) to supplier wallet
11. Supplier receives 100% total payment immediately
12. Sends payment request notification to buyer with countdown
13. Logs audit event: documents_uploaded
14. Returns success with document metadata

Database Operations:

  • Table: database.documents (create records),database.contracts (update),database.wallets (transfer 30% from pool + 70% to supplier),database.transactions (create)
  • Action: undefined

➡️ Next Action

Buyer sees payment request with countdown. If buyer pays within countdown, contract completes. If countdown expires, contract automatically moves to auction with minimum bid = 70% + fees.