Skip to content

Feat/xendit integration#130

Open
shubham3121 wants to merge 16 commits intomainfrom
feat/xendit-integration-v2
Open

Feat/xendit integration#130
shubham3121 wants to merge 16 commits intomainfrom
feat/xendit-integration-v2

Conversation

@shubham3121
Copy link
Copy Markdown
Member

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 QueryEndpointHandler for 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:

  • Added QueryEndpointHandler class 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 a MetadataEnricher interface. (backend/syft_space/components/endpoints/query_handler.py backend/syft_space/components/endpoints/query_handler.pyR1-R343)
  • Introduced new interfaces for endpoint policy integration: DeletionCheck and MetadataEnricher, which allow the endpoints component to remain decoupled from payment logic and other cross-component dependencies. (backend/syft_space/components/endpoints/interfaces.py backend/syft_space/components/endpoints/interfaces.pyR1-R14)

Database and entity changes (Payments & archival):

API route modularization:

  • Refactored endpoint route construction to support injection of separate handler classes for CRUD, publishing, and querying, enabling better separation of concerns and easier extensibility (e.g., for payments or marketplace logic). (components/endpoints/routes.py [1] [2]

Payment entity imports for migrations:

…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.
@shubham3121 shubham3121 mentioned this pull request Apr 7, 2026
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
@shubham3121
Copy link
Copy Markdown
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)
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.

1 participant