Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(data-warehouse): add 4 missing tables to the Xsolla source (#118950)

Tom Owersaa0fc2ef1934
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index 5ab1569cdd8d..c9266966cb43 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -13353,10 +13353,10 @@ Today (9): `payouts`, `projects`, `promotions`, `reports`, `subscription_payment
Diffed against: <https://developers.xsolla.com/_bundle/api/catalog/index.json?download>
-- [ ] `Get transactions, financial registry (GET /merchant/v2/merchants/{merchant_id}/reports/transactions/registry.json)` — reconcile settlement amounts, processing commissions, taxes, refunds, and payout exchange rates beyond the transaction search results (high)
-- [ ] `Get list of virtual items (GET /v2/project/{project_id}/admin/items/virtual_items)` — join purchases to product names, SKUs, prices, and catalog attributes for product revenue analysis (medium)
-- [ ] `Get list of virtual currencies (GET /v2/project/{project_id}/admin/items/virtual_currency)` — describe currencies sold within games and compare currency pricing and sales across projects (medium)
-- [ ] `Get list of bundles (GET /v2/project/{project_id}/admin/items/bundle)` — analyze bundle contents and prices alongside purchases and promotion results (medium)
+- [x] `Get transactions, financial registry (GET /merchant/v2/merchants/{merchant_id}/reports/transactions/registry.json)` — reconcile settlement amounts, processing commissions, taxes, refunds, and payout exchange rates beyond the transaction search results (high)
+- [x] `Get list of virtual items (GET /v2/project/{project_id}/admin/items/virtual_items)` — join purchases to product names, SKUs, prices, and catalog attributes for product revenue analysis (medium)
+- [x] `Get list of virtual currencies (GET /v2/project/{project_id}/admin/items/virtual_currency)` — describe currencies sold within games and compare currency pricing and sales across projects (medium)
+- [x] `Get list of bundles (GET /v2/project/{project_id}/admin/items/bundle)` — analyze bundle contents and prices alongside purchases and promotion results (medium)
- [ ] `Get payouts breakdown in currency (GET /merchant/v2/merchants/{merchant_id}/reports/transactions/summary/transfer)` — compare currency totals for payments, commissions, taxes, and amounts due for payout (medium)
- [ ] `Get rewards (GET /merchant/v2/merchants/{merchant_id}/promotions/{promotion_id}/rewards)` — explain promotion results using item bonuses, discounts, and subscription trial rewards (medium)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/xsolla/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/xsolla/canonical_descriptions.py
index 6534c1a79306..87e3bbe1e460 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/xsolla/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/xsolla/canonical_descriptions.py
@@ -124,4 +124,83 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"id": "Project ID.",
},
},
+ "transaction_registry": {
+ "description": "Successful and canceled transactions with fees, taxes, and payout amounts for financial reconciliation.",
+ "docs_url": "https://developers.xsolla.com/api/pay-station/operation/get-transactions/",
+ "columns": {
+ "id": "Xsolla transaction ID, copied from transaction.id.",
+ "transaction": "Transaction data: project, payment method, status, refund reason, and payout date.",
+ "user": "User details: ID, name, email, phone, and country.",
+ "user_balance": "Amounts paid from the user balance.",
+ "purchase": "Purchased virtual currency, virtual items, subscription, or simple checkout amount.",
+ "payment_details": "Payment and payout amounts, exchange rate, commissions, taxes, and penalties.",
+ },
+ },
+ "virtual_items": {
+ "description": "Virtual items in the store of each project.",
+ "docs_url": "https://developers.xsolla.com/api/catalog/operation/admin-get-virtual-items-list/",
+ "columns": {
+ "project_id": "ID of the project that the item belongs to.",
+ "sku": "Unique item ID inside the project.",
+ "name": "Localized item names, keyed by language code.",
+ "description": "Localized item descriptions, keyed by language code.",
+ "type": "Item type.",
+ "groups": "Groups the item belongs to.",
+ "prices": "Prices in real currencies.",
+ "is_free": "Whether the item is free.",
+ "is_enabled": "Whether the item is available for purchase.",
+ "is_show_in_store": "Whether the item is displayed in the catalog.",
+ "regions": "Regions where the item is available. Empty means all regions.",
+ "limits": "Item purchase limits.",
+ "periods": "Item sales periods.",
+ "custom_attributes": "Custom item attributes and values.",
+ "vc_prices": "Prices in virtual currencies.",
+ },
+ },
+ "virtual_currencies": {
+ "description": "Virtual currencies in the store of each project.",
+ "docs_url": "https://developers.xsolla.com/api/catalog/operation/admin-get-virtual-currencies-list/",
+ "columns": {
+ "project_id": "ID of the project that the item belongs to.",
+ "sku": "Unique item ID inside the project.",
+ "name": "Localized item names, keyed by language code.",
+ "description": "Localized item descriptions, keyed by language code.",
+ "type": "Item type.",
+ "groups": "Groups the item belongs to.",
+ "prices": "Prices in real currencies.",
+ "is_free": "Whether the item is free.",
+ "is_enabled": "Whether the item is available for purchase.",
+ "is_show_in_store": "Whether the item is displayed in the catalog.",
+ "regions": "Regions where the item is available. Empty means all regions.",
+ "limits": "Item purchase limits.",
+ "periods": "Item sales periods.",
+ "custom_attributes": "Custom item attributes and values.",
+ "vc_prices": "Prices in other virtual currencies.",
+ },
+ },
+ "bundles": {
+ "description": "Bundles in the store of each project, with their contents and prices.",
+ "docs_url": "https://developers.xsolla.com/api/catalog/operation/admin-get-bundle-list/",
+ "columns": {
+ "project_id": "ID of the project that the item belongs to.",
+ "sku": "Unique item ID inside the project.",
+ "name": "Localized item names, keyed by language code.",
+ "description": "Localized item descriptions, keyed by language code.",
+ "type": "Item type.",
+ "groups": "Groups the item belongs to.",
+ "prices": "Prices in real currencies.",
+ "is_free": "Whether the item is free.",
+ "is_enabled": "Whether the item is available for purchase.",
+ "is_show_in_store": "Whether the item is displayed in the catalog.",
+ "regions": "Regions where the item is available. Empty means all regions.",
+ "limits": "Item purchase limits.",
+ "periods": "Item sales periods.",
+ "custom_attributes": "Custom item attributes and values.",
+ "item_id": "Internal unique item ID.",
+ "bundle_type": "Bundle type.",
+ "content": "Items in the bundle and their quantities.",
+ "virtual_prices": "Prices in virtual currencies.",
+ "total_content_price": "Sum of the prices of the bundle contents.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/xsolla/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/xsolla/settings.py
index f3c082af4e22..832ba21dafcf 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/xsolla/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/xsolla/settings.py
@@ -7,8 +7,12 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
from products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType
API_BASE_URL = "https://api.xsolla.com/merchant"
+# Xsolla documents the transaction registry on v3 only, while the other merchant endpoints stay on v2.
+REGISTRY_BASE_URL = "https://api.xsolla.com/merchant/v3/"
+STORE_BASE_URL = "https://store.xsolla.com/api/v2/"
API_DOCS_URL = "https://developers.xsolla.com/api/getting-started/"
PAGE_SIZE = 100
+STORE_PAGE_SIZE = 50
# Xsolla has no endpoint that reports when a merchant's history starts, so date-bounded endpoints
# walk forward from a fixed date that predates Pay Station.
HISTORY_START = date(2010, 1, 1)
@@ -21,6 +25,8 @@ RESPONSE_ACTIONS: list[ResponseAction] = [
{"status_code": 401, "action": "raise", "message": AUTH_ERROR},
{"status_code": 403, "action": "raise", "message": AUTH_ERROR},
]
+# A project in the merchant project list can have no store, so the Store API does not know it.
+STORE_RESPONSE_ACTIONS: list[ResponseAction] = [*RESPONSE_ACTIONS, {"status_code": 404, "action": "ignore"}]
@frozen
@@ -35,6 +41,10 @@ class XsollaEndpoint:
# Nested values copied to the row root, so that they can be primary keys or incremental fields.
lifted_fields: tuple[tuple[str, str, str], ...] = ()
partition_key: str | None = None
+ # Replaces the merchant API base URL, which follows the pinned source version.
+ base_url: str | None = None
+ # Store endpoints wrap rows in {"items": [...], "total_items_count": n}.
+ store: bool = False
ENDPOINTS: dict[str, XsollaEndpoint] = {
@@ -85,6 +95,33 @@ ENDPOINTS: dict[str, XsollaEndpoint] = {
path="merchants/{merchant_id}/projects",
paginated=False,
),
+ "transaction_registry": XsollaEndpoint(
+ path="merchants/{merchant_id}/reports/transactions/registry.json",
+ base_url=REGISTRY_BASE_URL,
+ window_days=92,
+ lifted_fields=(("id", "transaction", "id"),),
+ ),
+ "virtual_items": XsollaEndpoint(
+ path="project/{project_id}/admin/items/virtual_items",
+ primary_keys=("project_id", "sku"),
+ scope="project",
+ base_url=STORE_BASE_URL,
+ store=True,
+ ),
+ "virtual_currencies": XsollaEndpoint(
+ path="project/{project_id}/admin/items/virtual_currency",
+ primary_keys=("project_id", "sku"),
+ scope="project",
+ base_url=STORE_BASE_URL,
+ store=True,
+ ),
+ "bundles": XsollaEndpoint(
+ path="project/{project_id}/admin/items/bundle",
+ primary_keys=("project_id", "sku"),
+ scope="project",
+ base_url=STORE_BASE_URL,
+ store=True,
+ ),
}
INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/xsolla/tests/test_xsolla.py b/products/warehouse_sources/backend/temporal/data_imports/sources/xsolla/tests/test_xsolla.py
index ddd8e50b9ede..b14f55dfc899 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/xsolla/tests/test_xsolla.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/xsolla/tests/test_xsolla.py
@@ -126,6 +126,75 @@ def test_project_tables_read_each_project_and_resume_after_finished_projects(dri
assert result.saved_states[-1] == XsollaResumeConfig(project_id=31)
+ "table,path",
+ [
+ ("virtual_items", "admin/items/virtual_items"),
+ ("virtual_currencies", "admin/items/virtual_currency"),
+ ("bundles", "admin/items/bundle"),
+ ],
+)
+def test_store_tables_page_each_project_and_skip_projects_without_a_store(
+ driver: SourceDriver, table: str, path: str
+) -> None:
+ items = [{"sku": f"sku-{i}", "type": "virtual_good"} for i in range(51)]
+
+ def store_page(request: RecordedRequest) -> ScriptedResponse:
+ if request.path.endswith("/merchants/123/projects"):
+ return ScriptedResponse(json=[{"id": 20}, {"id": 10}])
+ if "/project/10/" in request.path:
+ return ScriptedResponse(status=404, json={"errorCode": 4001, "errorMessage": "Project not found"})
+ offset = int(request.param("offset") or 0)
+ return ScriptedResponse(
+ json={
+ "has_more": offset + 50 < len(items),
+ "total_items_count": len(items),
+ "items": items[offset : offset + 50],
+ }
+ )
+
+ result = driver.run(table, store_page)
+
+ assert result.raised is None
+ assert [(row["project_id"], row["sku"]) for row in result.rows] == [(20, f"sku-{i}") for i in range(51)]
+ assert [request.url.split("?")[0] for request in result.requests[1:]] == [
+ f"https://store.xsolla.com/api/v2/project/10/{path}",
+ f"https://store.xsolla.com/api/v2/project/20/{path}",
+ f"https://store.xsolla.com/api/v2/project/20/{path}",
+ ]
+ assert [(r.param("offset"), r.param("limit")) for r in result.requests[2:]] == [("0", "50"), ("50", "50")]
+ assert result.response is not None
+ assert result.response.primary_keys == ["project_id", "sku"]
+
+
+def test_transaction_registry_reads_v3_in_92_day_windows_and_pages(driver: SourceDriver) -> None:
+ rows = [
+ {"transaction": {"id": i, "status": "done"}, "payment_details": {"payout": {"amount": 1.5}}} for i in range(101)
+ ]
+
+ def registry_page(request: RecordedRequest) -> ScriptedResponse:
+ if request.param("datetime_from") != "2010-01-01":
+ return ScriptedResponse(json=[])
+ offset = int(request.param("offset") or 0)
+ return ScriptedResponse(json=rows[offset : offset + 100])
+
+ with time_machine.travel("2010-06-01T12:00:00Z", tick=False):
+ result = driver.run("transaction_registry", registry_page)
+
+ assert [row["id"] for row in result.rows] == list(range(101))
+ assert {request.url.split("?")[0] for request in result.requests} == {
+ "https://api.xsolla.com/merchant/v3/merchants/123/reports/transactions/registry.json"
+ }
+ assert [
+ (r.param("datetime_from"), r.param("datetime_to"), r.param("offset"), r.param("in_transfer_currency"))
+ for r in result.requests
+ ] == [
+ ("2010-01-01", "2010-04-02", "0", "0"),
+ ("2010-01-01", "2010-04-02", "100", "0"),
+ ("2010-04-03", "2010-06-01", "0", "0"),
+ ]
+
+
def test_report_windows_drop_rows_already_seen_in_an_earlier_window(driver: SourceDriver) -> None:
with time_machine.travel("2010-06-01T12:00:00Z", tick=False):
result = driver.run(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/xsolla/xsolla.py b/products/warehouse_sources/backend/temporal/data_imports/sources/xsolla/xsolla.py
index 8745edb129db..8686c17b608b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/xsolla/xsolla.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/xsolla/xsolla.py
@@ -9,6 +9,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
RESTAPIConfig,
rest_api_resource,
)
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import PaginatorConfig
from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManager
from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse
from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.xsolla import XsollaSourceConfig
@@ -19,6 +20,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.xsolla.set
HISTORY_START,
PAGE_SIZE,
RESPONSE_ACTIONS,
+ STORE_PAGE_SIZE,
+ STORE_RESPONSE_ACTIONS,
TRANSACTIONS_LOOKBACK_DAYS,
XsollaEndpoint,
)
@@ -69,13 +72,16 @@ def _rest_config(
api_version: str,
data_map: Callable[[dict[str, Any]], dict[str, Any]] | None,
) -> RESTAPIConfig:
+ paginator: PaginatorConfig = "single_page"
+ if endpoint.store:
+ paginator = {"type": "offset", "limit": STORE_PAGE_SIZE, "total_path": "total_items_count"}
+ elif endpoint.paginated:
+ paginator = {"type": "offset", "limit": PAGE_SIZE, "total_path": None}
return {
"client": {
- "base_url": f"{API_BASE_URL}/{api_version}/",
+ "base_url": endpoint.base_url or f"{API_BASE_URL}/{api_version}/",
"auth": {"type": "http_basic", "username": merchant_id, "password": config.api_key},
- "paginator": {"type": "offset", "limit": PAGE_SIZE, "total_path": None}
- if endpoint.paginated
- else "single_page",
+ "paginator": paginator,
},
"resources": [
{
@@ -84,9 +90,10 @@ def _rest_config(
"endpoint": {
"path": path,
"params": params,
- "response_actions": RESPONSE_ACTIONS,
+ "response_actions": STORE_RESPONSE_ACTIONS if endpoint.store else RESPONSE_ACTIONS,
# The projects list shape is not documented, so only the documented list endpoints fail loud.
"data_selector_required": name != "projects",
+ **({"data_selector": "items"} if endpoint.store else {}),
},
"table_format": "delta",
"data_map": data_map,
@@ -129,7 +136,11 @@ def _window_params(name: str, window_start: date, window_end: date) -> dict[str,
"type": "all",
}
# Report endpoints accept YYYY-MM-DD only.
- return {"datetime_from": window_start.isoformat(), "datetime_to": window_end.isoformat()}
+ params = {"datetime_from": window_start.isoformat(), "datetime_to": window_end.isoformat()}
+ if name == "transaction_registry":
+ # Required by the registry. 0 keeps amounts in the payment currency, as Xsolla does by default.
+ params["in_transfer_currency"] = "0"
+ return params
def list_project_ids(