```
chore: remove obsolete payment architecture and integration test documentation - Remove AITBC_PAYMENT_ARCHITECTURE.md (dual-currency system documentation) - Remove IMPLEMENTATION_COMPLETE_SUMMARY.md (integration test completion summary) - Remove INTEGRATION_TEST_FIXES.md (test fixes documentation) - Remove INTEGRATION_TEST_UPDATES.md (real features implementation notes) - Remove PAYMENT_INTEGRATION_COMPLETE.md (wallet-coordinator integration docs) - Remove WALLET_COORDINATOR_INTEGRATION.md (payment
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
|
||||
from ..deps import require_client_key
|
||||
from ..schemas import JobCreate, JobView, JobResult
|
||||
from ..schemas.payments import JobPaymentCreate, PaymentMethod
|
||||
from ..schemas import JobCreate, JobView, JobResult, JobPaymentCreate
|
||||
from ..types import JobState
|
||||
from ..services import JobService
|
||||
from ..services.payments import PaymentService
|
||||
@@ -27,11 +26,11 @@ async def submit_job(
|
||||
job_id=job.id,
|
||||
amount=req.payment_amount,
|
||||
currency=req.payment_currency,
|
||||
payment_method=PaymentMethod.AITBC_TOKEN # Jobs use AITBC tokens
|
||||
payment_method="aitbc_token" # Jobs use AITBC tokens
|
||||
)
|
||||
payment = await payment_service.create_payment(job.id, payment_create)
|
||||
job.payment_id = payment.id
|
||||
job.payment_status = payment.status.value
|
||||
job.payment_status = payment.status
|
||||
session.commit()
|
||||
session.refresh(job)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlmodel import Session, select
|
||||
|
||||
from ..deps import require_admin_key
|
||||
from ..domain import MarketplaceOffer, Miner, OfferStatus
|
||||
from ..domain import MarketplaceOffer, Miner
|
||||
from ..schemas import MarketplaceOfferView
|
||||
from ..storage import SessionDep
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
import logging
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Response, status
|
||||
|
||||
@@ -9,6 +10,8 @@ from ..services import JobService, MinerService
|
||||
from ..services.receipts import ReceiptService
|
||||
from ..storage import SessionDep
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
router = APIRouter(tags=["miner"])
|
||||
|
||||
|
||||
@@ -78,6 +81,23 @@ async def submit_result(
|
||||
job.receipt_id = receipt["receipt_id"] if receipt else None
|
||||
session.add(job)
|
||||
session.commit()
|
||||
|
||||
# Auto-release payment if job has payment
|
||||
if job.payment_id and job.payment_status == "escrowed":
|
||||
from ..services.payments import PaymentService
|
||||
payment_service = PaymentService(session)
|
||||
success = await payment_service.release_payment(
|
||||
job.id,
|
||||
job.payment_id,
|
||||
reason="Job completed successfully"
|
||||
)
|
||||
if success:
|
||||
job.payment_status = "released"
|
||||
session.commit()
|
||||
logger.info(f"Auto-released payment {job.payment_id} for completed job {job.id}")
|
||||
else:
|
||||
logger.error(f"Failed to auto-release payment {job.payment_id} for job {job.id}")
|
||||
|
||||
miner_service.release(
|
||||
miner_id,
|
||||
success=True,
|
||||
@@ -106,5 +126,22 @@ async def submit_failure(
|
||||
job.assigned_miner_id = miner_id
|
||||
session.add(job)
|
||||
session.commit()
|
||||
|
||||
# Auto-refund payment if job has payment
|
||||
if job.payment_id and job.payment_status in ["pending", "escrowed"]:
|
||||
from ..services.payments import PaymentService
|
||||
payment_service = PaymentService(session)
|
||||
success = await payment_service.refund_payment(
|
||||
job.id,
|
||||
job.payment_id,
|
||||
reason=f"Job failed: {req.error_code}: {req.error_message}"
|
||||
)
|
||||
if success:
|
||||
job.payment_status = "refunded"
|
||||
session.commit()
|
||||
logger.info(f"Auto-refunded payment {job.payment_id} for failed job {job.id}")
|
||||
else:
|
||||
logger.error(f"Failed to auto-refund payment {job.payment_id} for job {job.id}")
|
||||
|
||||
miner_service.release(miner_id, success=False)
|
||||
return {"status": "ok"}
|
||||
|
||||
@@ -37,7 +37,7 @@ class PartnerResponse(BaseModel):
|
||||
class WebhookCreate(BaseModel):
|
||||
"""Create a webhook subscription"""
|
||||
url: str = Field(..., pattern=r'^https?://')
|
||||
events: List[str] = Field(..., min_items=1)
|
||||
events: List[str] = Field(..., min_length=1)
|
||||
secret: Optional[str] = Field(max_length=100)
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from typing import List
|
||||
|
||||
from ..deps import require_client_key
|
||||
from ..schemas.payments import (
|
||||
from ..schemas import (
|
||||
JobPaymentCreate,
|
||||
JobPaymentView,
|
||||
PaymentRequest,
|
||||
|
||||
Reference in New Issue
Block a user