Open
Conversation
…ection Replace hardcoded PAYMENT_POLICY_TYPES set with a WalletPolicy protocol interface. Policy handler now uses issubclass check and validates wallet type matches what the policy expects, making it extensible for new payment providers without modifying the handler.
Move balance queries, transaction listing, and Tempo blockchain utils out of the wallets component into a dedicated payments component. Wallets now handle credential management only. Wire payment routes in main.py.
Register XenditAccountingPolicy as a builtin policy type, implementing the WalletPolicy protocol with required_wallet_type='xendit'.
Follows Clean Architecture SRP — each handler serves a single actor: - EndpointHandler: CRUD + archive (admin) - QueryEndpointHandler: RAG pipeline + policy enforcement (end user) - PublishEndpointHandler: marketplace publish/unpublish/sync/health Dependency inversion via callbacks (DeletionCheck, MetadataEnricher) keeps payment imports out of the endpoints component.
Remove bidirectional Relationship() between Endpoint/Tenant and Invoice/BundleUsage. FK columns (endpoint_id, tenant_id) preserved for data integrity — only ORM back_populates removed. Add archived field to Endpoint for soft-archiving endpoints with active financial state.
Instantiate InvoiceRepository, BundleUsageRepository, BundleService, PaymentHandler with XenditGateway. Pass gateway routes to payment router via build_payment_routes(). Wire deletion guard (check_endpoint_deletable) and metadata enricher (enrich_query_metadata) as closures in main.py — endpoints component has zero payment imports.
Add resolve_purchase() to PaymentGateway protocol with ResolvedTier return type. XenditGateway implements it using XenditPolicyConfig. Add applies_to_user() and get_tier() to XenditPolicyConfig — single source of truth for eligibility check and tier lookup, used by both the gateway (purchase flow) and policy pre_hook (query flow). Add get_by_endpoint_and_type() to PolicyRepository — replaces fetch-all + filter-in-Python.
Create invoices table with indexes on external_id, tenant+user, status. Create bundle_usage table with unique constraint on tenant+endpoint+user+unit_type. Add archived column to endpoints table. Import Invoice/BundleUsage entities in alembic env.py.
4 tasks
- Fix missing Depends() on tenant param in gateway dependencies - Fix get_by_type returning list — use first active wallet - Add xendit_api_url to AppSettings config
… providers - Add extract_display() and update_credentials() to WalletProvider protocol - Each provider owns its safe display logic (no more if/else in handler) - Fix Xendit webhook_url: was lost on get/list, now rebuilt via extract_display - Fix Xendit webhook path: /wallets/xendit/webhook → /payments/gateway/xendit/webhooks - Replace MPP-specific update_mpp_wallet_address with generic update_wallet_credentials - Remove phantom STRIPE/RAZORPAY from WalletType enum (no implementation existed) - Remove WalletType enum imports from routes (use plain strings)
- Add PUT /wallets/gateway/xendit/{id} route for updating API key and callback token
- Add UpdateXenditWalletRequest schema with optional fields
- Update XenditWalletProvider.update_credentials to support partial updates
Member
Author
|
Frontend Changes: #132 |
…ance Replace bundle_tiers (units + price) with price_per_request + currency as the core pricing config. Balance is now tracked as money (float) instead of request counts (int), deducted by price_per_request on each query. Bundles become purchasable money amounts with sensible defaults per currency. Key changes: - XenditPolicyConfig: bundle_tiers → price_per_request + optional bundles - BundleUsage: remaining_units/total_purchased → remaining_balance/total_deposited - Invoice: tier_name/tier_units/unit_type → bundle_name/amount/currency - Post-hook refunds on empty response (no documents and no summary) - Regenerated migration beb8d008c9c8 (replaces e5f6a7b8c9d0)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces significant enhancements to the endpoint component, focusing on modularizing the query pipeline, improving policy enforcement, and supporting new payment and archival features. The main changes include the addition of a dedicated
QueryEndpointHandlerfor orchestrating endpoint queries with policy hooks and cross-component service injection, the introduction of new database tables for invoices and bundle usage, and support for marking endpoints as archived.New endpoint query pipeline and interfaces:
QueryEndpointHandlerclass to encapsulate the RAG (Retrieval-Augmented Generation) query flow, including dataset/model orchestration and policy pre/post hooks, with support for dependency-injected cross-component services (e.g., payments) via aMetadataEnricherinterface. (backend/syft_space/components/endpoints/query_handler.pybackend/syft_space/components/endpoints/query_handler.pyR1-R343)DeletionCheckandMetadataEnricher, which allow the endpoints component to remain decoupled from payment logic and other cross-component dependencies. (backend/syft_space/components/endpoints/interfaces.pybackend/syft_space/components/endpoints/interfaces.pyR1-R14)Database and entity changes (Payments & archival):
invoicesandbundle_usagetables, and to add anarchivedboolean column to theendpointstable, supporting new payment workflows and endpoint archival. (alembic/versions/e5f6a7b8c9d0_add_invoices_bundle_usage_archived.pybackend/syft_space/alembic/versions/e5f6a7b8c9d0_add_invoices_bundle_usage_archived.pyR1-R91)Endpointentity to include the newarchivedfield, indicating whether an endpoint is archived (disables new purchases but remains queryable). (components/endpoints/entities.pybackend/syft_space/components/endpoints/entities.pyR61-R64)API route modularization:
components/endpoints/routes.py[1] [2]Payment entity imports for migrations:
InvoiceandBundleUsageentities in the Alembic environment to ensure migrations recognize the new tables. (alembic/env.pybackend/syft_space/alembic/env.pyR20-R23)