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(warehouse-sources): add flutterwave banks, wallet statement and bill payment tables (#120223)

Tom Owers31f5e64b61c1
diff --git a/posthog/test/repo_invariants/source_wrapped_resource_baseline.txt b/posthog/test/repo_invariants/source_wrapped_resource_baseline.txt
index 87535bd6c11c..263f8c5cfbc6 100644
--- a/posthog/test/repo_invariants/source_wrapped_resource_baseline.txt
+++ b/posthog/test/repo_invariants/source_wrapped_resource_baseline.txt
@@ -19,7 +19,6 @@ drip/drip.py::_campaign_subscriber_pages
dynatrace/dynatrace.py::_endpoint_pages
emailoctopus/emailoctopus.py::_fan_out_items
fintoc/fintoc.py::FintocAPI.rows
-flutterwave/flutterwave.py::get_rows
freshservice/freshservice.py::_approvals_source.items
fusionauth/fusionauth.py::fusionauth_source.pages
gainsight_px/gainsight_px.py::_event_pages
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 57426b9787b9..69ba16a1f1d4 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
@@ -4842,14 +4842,14 @@ Note: developers.flowlu.com is the API host, not docs (returns 404/api-key error
## Flutterwave — gaps
-Today (9): `beneficiaries`, `chargebacks`, `payment_plans`, `refunds`, `settlements`, `subaccounts`, `subscriptions`, `transactions`, `transfers`
+Today (12): `banks`, `beneficiaries`, `bill_payments`, `chargebacks`, `payment_plans`, `refunds`, `settlements`, `subaccounts`, `subscriptions`, `transactions`, `transfers`, `wallet_statement`
Diffed against: <https://developer.flutterwave.com/v3.0.0/reference/get-all-transactions>
-- [ ] `Get all banks (GET /v3/banks/{country})` — resolve bank codes on transfers and beneficiaries into bank names (high)
-- [ ] `Query Wallet balance history (GET /v3/wallet/statement)` — reconcile wallet credits and debits with transfers and settlement activity (high)
-- [ ] `View transaction timeline (GET /v3/transactions/{id}/events)` — analyze payment processing steps and failures beyond the current transaction status (medium)
-- [ ] `Get bill payments history (GET /v3/bills/history)` — report bill payment volume, failures, reversals, and customer spending (medium)
+- [x] `Get all banks (GET /v3/banks/{country})` — resolve bank codes on transfers and beneficiaries into bank names (high). Added as `banks` (v3, one request per documented payout country: NG, GH, KE, UG, ZA, TZ).
+- [x] `Query Wallet balance history (GET /v3/wallet/statement)` — reconcile wallet credits and debits with transfers and settlement activity (high). Added as `wallet_statement` (v3, one walk per currency listed by `/balances`).
+- [ ] `View transaction timeline (GET /v3/transactions/{id}/events)` — analyze payment processing steps and failures beyond the current transaction status (medium); skipped: one request per transaction on every sync, because `transactions` has no update cursor and the timeline has no list or date filter, and the rows are checkout UI steps with IP addresses and actor emails
+- [x] `Get bill payments history (GET /v3/bills/history)` — report bill payment volume, failures, reversals, and customer spending (medium). Added as `bill_payments` (v3).
- [ ] `Fetch All Subaccounts (GET /v3/payout-subaccounts)` — identify customer wallets and payout subaccounts, which differ from collection split-payment subaccounts (medium)
- [ ] `Fetch Transactions (GET /v3/payout-subaccounts/{account_reference}/transactions)` — analyze credits and debits within each customer wallet (medium)
- [ ] `Retrieve Wallet balances (GET /v3/balances)` — report available merchant funds across currencies (medium)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/flutterwave/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/flutterwave/canonical_descriptions.py
index 08f51dd6b628..7200fd211452 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/flutterwave/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/flutterwave/canonical_descriptions.py
@@ -173,4 +173,60 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"created_at": "Date and time the beneficiary was saved, in UTC.",
},
},
+ "banks": {
+ "description": "A bank or mobile money provider that Flutterwave supports for payouts in a country, used to resolve bank codes into bank names.",
+ "docs_url": f"{_V3_REFERENCE}/get-all-banks",
+ "columns": {
+ "id": "Flutterwave's identifier for the bank.",
+ "code": "Bank code, as used in the bank_code and account_bank fields of transfers, beneficiaries, and subaccounts.",
+ "name": "Name of the bank or mobile money provider.",
+ "provider_type": "Whether the provider is a bank or a mobile money provider.",
+ "country": "ISO 3166-1 alpha-2 code of the country the bank list was fetched for.",
+ },
+ },
+ "wallet_statement": {
+ "description": "A credit or debit on the merchant's Flutterwave wallet, with the balance before and after it.",
+ "docs_url": f"{_V3_REFERENCE}/get-balance-history",
+ "columns": {
+ "type": "Direction of the entry, C for a credit or D for a debit.",
+ "amount": "Amount credited or debited, in the wallet currency.",
+ "currency": "ISO 4217 currency code of the wallet.",
+ "balance_before": "Wallet balance before the entry.",
+ "balance_after": "Wallet balance after the entry.",
+ "reference": "Reference of the payout, settlement, or other activity behind the entry.",
+ "date": "Date and time of the entry.",
+ "remarks": "Free-text note describing the entry.",
+ "sent_currency": "Currency the underlying amount was sent in.",
+ "rate_used": "Exchange rate applied when the sent currency differs from the wallet currency.",
+ "sent_amount": "Amount in the sent currency.",
+ "statement_type": "Which balance the entry affected, for example available.",
+ "payout_id": "Identifier of the payout behind the entry, where there is one.",
+ "transaction_type": "Kind of activity behind the entry, for example funding, transfer, bill, or reversal.",
+ },
+ },
+ "bill_payments": {
+ "description": "A bill payment bought through the account, such as airtime, data, cable TV, or electricity, with the commission earned.",
+ "docs_url": f"{_V3_REFERENCE}/get-bill-payments-history",
+ "columns": {
+ "id": "Unique identifier for the bill payment.",
+ "tx_id": "Identifier of the underlying Flutterwave transaction.",
+ "tx_ref": "Merchant reference for the bill payment.",
+ "flw_ref": "Flutterwave's reference for the bill payment.",
+ "customer_id": "Customer identifier at the biller, for example a phone number, meter number, or smart card number.",
+ "customer_reference": "Unique reference for the payment, supplied when it was created.",
+ "amount": "Amount paid for the bill.",
+ "currency": "ISO 4217 currency code of the payment.",
+ "commission": "Commission the merchant earned on the payment.",
+ "category": "Bill category, for example Airtime or Cable Bill Payment.",
+ "product": "Biller product that was bought.",
+ "product_name": "Display name of the biller product.",
+ "product_details": "Detailed description of the biller product.",
+ "frequency": "How often the bill is paid, for example One Time.",
+ "recurring_payment_id": "Identifier of the recurring schedule, for recurring bills.",
+ "batch_id": "Identifier of the bulk payment batch the bill belonged to.",
+ "country": "ISO country code of the biller.",
+ "status": "Outcome of the payment, one of Successful, Failed, or Reversed.",
+ "transaction_date": "Date and time the bill payment was made, in UTC.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/flutterwave/flutterwave.py b/products/warehouse_sources/backend/temporal/data_imports/sources/flutterwave/flutterwave.py
index 7ec63a6a6a70..94008f3ef5db 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/flutterwave/flutterwave.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/flutterwave/flutterwave.py
@@ -1,5 +1,5 @@
import dataclasses
-from collections.abc import Iterator
+from collections.abc import Callable, Iterator
from datetime import UTC, datetime, timedelta
from typing import Any, Optional
@@ -12,9 +12,12 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (
JSONResponseCursorPaginator,
PageNumberPaginator,
+ SinglePagePaginator,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import (
BearerTokenAuthConfig,
+ ClientConfig,
+ EndpointResource,
OAuth2AuthConfig,
ResponseAction,
)
@@ -22,9 +25,12 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
from products.warehouse_sources.backend.temporal.data_imports.sources.common.source_helpers import validate_via_probe
from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse
from products.warehouse_sources.backend.temporal.data_imports.sources.flutterwave.settings import (
+ BANK_COUNTRIES,
+ BILL_PAYMENT_STATUSES,
FLUTTERWAVE_API_V4,
FLUTTERWAVE_ENDPOINTS,
FLUTTERWAVE_V4_ENDPOINTS,
+ WALLET_STATEMENT_TYPES,
FlutterwaveV4EndpointConfig,
)
@@ -67,6 +73,8 @@ class FlutterwaveResumeConfig:
# Opaque `next` cursor for the v4 cursor-paginated endpoints. A separate field so a page number
# saved by a page-numbered endpoint is never sent as a cursor, and the reverse.
next_cursor: Optional[str] = None
+ # Country or currency that `next_page` belongs to, for endpoints queried once per value.
+ fan_out_value: Optional[str] = None
class FlutterwaveCursorPaginator(JSONResponseCursorPaginator):
@@ -188,10 +196,17 @@ def validate_credentials(
return False, "Could not reach the Flutterwave API. Try again in a few minutes."
-def _v3_endpoint_config(endpoint: str) -> Endpoint:
+def _v3_endpoint_config(endpoint: str, fan_out: Optional[dict[str, str]] = None) -> Endpoint:
config = FLUTTERWAVE_ENDPOINTS[endpoint]
- params: dict[str, Any] = {}
+ path = config.path
+ params: dict[str, Any] = dict(config.params)
+ for name, value in (fan_out or {}).items():
+ placeholder = f"{{{name}}}"
+ if placeholder in path:
+ path = path.replace(placeholder, value)
+ else:
+ params[name] = value
if config.requires_date_window:
# /transactions requires `from`/`to`, so a full refresh sends the whole history window: the
# earliest-possible floor through today (padded a day for timezones ahead of UTC).
@@ -199,18 +214,61 @@ def _v3_endpoint_config(endpoint: str) -> Endpoint:
params["to"] = _window_end()
endpoint_config: Endpoint = {
- "path": config.path,
+ "path": path,
"params": params,
- "data_selector": "data",
- # Every v3 list endpoint is page-numbered from 1 and reports the page count under
- # `meta.page_info.total_pages`, which stops pagination without paying an extra empty page.
+ "data_selector": config.data_selector,
+ # Paged v3 list endpoints count pages from 1 and report the page count under
+ # `page_info.total_pages`, which stops pagination without paying an extra empty page.
# Page size is left to the API: v3 documents no maximum, and an over-cap value 4xxs.
- "paginator": PageNumberPaginator(base_page=1, total_path="meta.page_info.total_pages"),
+ "paginator": PageNumberPaginator(base_page=1, total_path=config.total_pages_path)
+ if config.total_pages_path is not None
+ else SinglePagePaginator(),
"response_actions": _NO_RECORDS_RESPONSE_ACTIONS,
}
return endpoint_config
+def _wallet_currencies(client: ClientConfig, team_id: int, job_id: str) -> list[str]:
+ # /wallet/statement requires a currency, and /balances lists every currency the wallet holds,
+ # including ones at zero that can still have history.
+ rest_config: RESTAPIConfig = {
+ "client": client,
+ "resources": [
+ {
+ "name": "balances",
+ "endpoint": {"path": "/balances", "data_selector": "data", "paginator": SinglePagePaginator()},
+ }
+ ],
+ }
+ currencies: set[str] = set()
+ for page in rest_api_resource(rest_config, team_id, job_id, None):
+ for row in page if isinstance(page, list) else [page]:
+ currency = row.get("currency")
+ if isinstance(currency, str) and currency:
+ currencies.add(currency)
+ return sorted(currencies)
+
+
+def _v3_fan_out_values(endpoint: str, client: ClientConfig, team_id: int, job_id: str) -> list[dict[str, str]]:
+ fan_out_params = FLUTTERWAVE_ENDPOINTS[endpoint].fan_out_params
+ if fan_out_params == ("country",):
+ return [{"country": country} for country in BANK_COUNTRIES]
+ if fan_out_params == ("status",):
+ return [{"status": status} for status in BILL_PAYMENT_STATUSES]
+ if fan_out_params == ("currency", "type"):
+ return [
+ {"currency": currency, "type": statement_type}
+ for currency in _wallet_currencies(client, team_id, job_id)
+ for statement_type in WALLET_STATEMENT_TYPES
+ ]
+ return [{}]
+
+
+def _fan_out_key(fan_out: dict[str, str]) -> Optional[str]:
+ # Identifies a combination in resume state; none of the values contain the separator.
+ return "|".join(fan_out.values()) or None
+
+
def _v4_endpoint_config(config: FlutterwaveV4EndpointConfig) -> Endpoint:
params: dict[str, Any] = {}
if config.page_size is not None:
@@ -252,35 +310,68 @@ def get_rows(
client_id: Optional[str] = None,
client_secret: Optional[str] = None,
) -> Iterator[list[dict[str, Any]]]:
- is_cursor_endpoint = False
- if api_version == FLUTTERWAVE_API_V4:
- v4_config = _v4_config(endpoint)
- endpoint_config = _v4_endpoint_config(v4_config)
- is_cursor_endpoint = v4_config.cursor_data_key is not None
- else:
- endpoint_config = _v3_endpoint_config(endpoint)
-
- rest_config: RESTAPIConfig = {
- "client": {
- "base_url": base_url(api_version),
- "headers": {"Accept": "application/json"},
- "auth": _auth_config(api_version, secret_key, client_id, client_secret),
- # These bodies carry bank account numbers and transaction metadata, so keep them out of
- # the HTTP diagnostic sample store (requests are still metered and logged).
- "session": make_tracked_session(redact_values=_secret_values(secret_key, client_secret), capture=False),
- },
- "resources": [{"name": endpoint, "endpoint": endpoint_config}],
+ v4_config = _v4_config(endpoint) if api_version == FLUTTERWAVE_API_V4 else None
+ client: ClientConfig = {
+ "base_url": base_url(api_version),
+ "headers": {"Accept": "application/json"},
+ "auth": _auth_config(api_version, secret_key, client_id, client_secret),
+ # These bodies carry bank account numbers and transaction metadata, so keep them out of
+ # the HTTP diagnostic sample store (requests are still metered and logged).
+ "session": make_tracked_session(redact_values=_secret_values(secret_key, client_secret), capture=False),
}
-
resume = resumable_source_manager.load_state() if resumable_source_manager.can_resume() else None
- initial_paginator_state: Optional[dict[str, Any]] = None
- if resume is not None:
- if is_cursor_endpoint:
- if resume.next_cursor:
- initial_paginator_state = {"cursor": resume.next_cursor}
- elif resume.next_page > 1:
+
+ if v4_config is not None:
+ initial_paginator_state: Optional[dict[str, Any]] = None
+ if resume is not None:
+ if v4_config.cursor_data_key is not None:
+ if resume.next_cursor:
+ initial_paginator_state = {"cursor": resume.next_cursor}
+ elif resume.next_page > 1:
+ initial_paginator_state = {"page": resume.next_page}
+ yield from rest_api_resource(
+ {"client": client, "resources": [{"name": endpoint, "endpoint": _v4_endpoint_config(v4_config)}]},
+ team_id,
+ job_id,
+ db_incremental_field_last_value,
+ resume_hook=_checkpoint_hook(resumable_source_manager, None),
+ initial_paginator_state=initial_paginator_state,
+ )
+ return
+
+ fan_out_values = _v3_fan_out_values(endpoint, client, team_id, job_id)
+ first_index = 0
+ initial_paginator_state = None
+ resume_keys = [_fan_out_key(values) for values in fan_out_values]
+ if resume is not None and resume.fan_out_value in resume_keys:
+ first_index = resume_keys.index(resume.fan_out_value)
+ if resume.next_page > 1:
initial_paginator_state = {"page": resume.next_page}
+ for index in range(first_index, len(fan_out_values)):
+ fan_out = fan_out_values[index]
+ fan_out_key = _fan_out_key(fan_out)
+ if index > first_index:
+ # Every row of the previous value is yielded, so a hand-off here can start this value
+ # from its first page. This also keeps a run of empty values from holding the worker.
+ resumable_source_manager.save_state(FlutterwaveResumeConfig(fan_out_value=fan_out_key))
+ resumable_source_manager.safe_point()
+ resource: EndpointResource = {"name": endpoint, "endpoint": _v3_endpoint_config(endpoint, fan_out)}
+ if fan_out:
+ resource["data_map"] = _stamp_fields(fan_out)
+ yield from rest_api_resource(
+ {"client": client, "resources": [resource]},
+ team_id,
+ job_id,
+ db_incremental_field_last_value,
+ resume_hook=_checkpoint_hook(resumable_source_manager, fan_out_key),
+ initial_paginator_state=initial_paginator_state if index == first_index else None,
+ )
+
+
+def _checkpoint_hook(
+ resumable_source_manager: ResumableSourceManager[FlutterwaveResumeConfig], fan_out_value: Optional[str]
+) -> Callable[[Optional[dict[str, Any]]], None]:
def save_checkpoint(state: Optional[dict[str, Any]]) -> None:
# The framework calls this AFTER a page is yielded and only while a next page remains, so a
# crash re-yields the next page rather than skipping it (the merge dedupes on primary key).
@@ -289,16 +380,20 @@ def get_rows(
if state.get("cursor") is not None:
resumable_source_manager.save_state(FlutterwaveResumeConfig(next_cursor=str(state["cursor"])))
elif state.get("page") is not None:
- resumable_source_manager.save_state(FlutterwaveResumeConfig(next_page=int(state["page"])))
-
- yield from rest_api_resource(
- rest_config,
- team_id,
- job_id,
- db_incremental_field_last_value,
- resume_hook=save_checkpoint,
- initial_paginator_state=initial_paginator_state,
- )
+ resumable_source_manager.save_state(
+ FlutterwaveResumeConfig(next_page=int(state["page"]), fan_out_value=fan_out_value)
+ )
+
+ return save_checkpoint
+
+
+def _stamp_fields(values: dict[str, str]) -> Callable[[dict[str, Any]], dict[str, Any]]:
+ def stamp(row: dict[str, Any]) -> dict[str, Any]:
+ for name, value in values.items():
+ row.setdefault(name, value)
+ return row
+
+ return stamp
def flutterwave_source(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/flutterwave/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/flutterwave/settings.py
index e33eacf87562..da53bb6253db 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/flutterwave/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/flutterwave/settings.py
@@ -1,5 +1,5 @@
from dataclasses import dataclass, field
-from typing import Optional
+from typing import Any, Optional
from products.warehouse_sources.backend.types import IncrementalField
@@ -16,7 +16,7 @@ FLUTTERWAVE_API_V4 = "v4"
# `created_datetime`) and adds no update cursor, so the same holds there.
-@dataclass
+@dataclass(frozen=True)
class FlutterwaveEndpointConfig:
name: str
path: str
@@ -26,6 +26,12 @@ class FlutterwaveEndpointConfig:
partition_key: Optional[str] = "created_at"
# /transactions documents `from` and `to` as required, so the floor window is sent on every run.
requires_date_window: bool = False
+ data_selector: str = "data"
+ # None marks an endpoint that returns its whole list in one response.
+ total_pages_path: Optional[str] = "meta.page_info.total_pages"
+ params: dict[str, Any] = field(default_factory=dict)
+ # The endpoint is queried once per combination of values of these parameters, and each row carries them.
+ fan_out_params: tuple[str, ...] = ()
FLUTTERWAVE_ENDPOINTS: dict[str, FlutterwaveEndpointConfig] = {
@@ -51,8 +57,49 @@ FLUTTERWAVE_ENDPOINTS: dict[str, FlutterwaveEndpointConfig] = {
"subaccounts": FlutterwaveEndpointConfig(name="subaccounts", path="/subaccounts"),
# Saved payout recipients.
"beneficiaries": FlutterwaveEndpointConfig(name="beneficiaries", path="/beneficiaries"),
+ # Reference list of the banks and mobile money providers each payout country supports, used to
+ # resolve bank codes on transfers and beneficiaries. The list carries no timestamp.
+ "banks": FlutterwaveEndpointConfig(
+ name="banks",
+ path="/banks/{country}",
+ primary_keys=["country", "id"],
+ partition_key=None,
+ total_pages_path=None,
+ params={"include_provider_type": 1},
+ fan_out_params=("country",),
+ ),
+ # Credits and debits on the merchant wallet. `from`, `to` and `currency` are all required, so the
+ # endpoint is queried once per wallet currency and direction over the full history window. A
+ # statement line has no id: one reference can show up as a debit and later as its reversal credit.
+ "wallet_statement": FlutterwaveEndpointConfig(
+ name="wallet_statement",
+ path="/wallet/statement",
+ primary_keys=["currency", "reference", "type", "date"],
+ partition_key="date",
+ requires_date_window=True,
+ data_selector="data.transactions",
+ total_pages_path="data.page_info.total_pages",
+ params={"include_transaction_type": "true", "include_payout_id": "true"},
+ fan_out_params=("currency", "type"),
+ ),
+ # Airtime, data, cable and utility bills. `status` defaults to Successful, so each status is read.
+ "bill_payments": FlutterwaveEndpointConfig(
+ name="bill_payments",
+ path="/bills/history",
+ partition_key="transaction_date",
+ requires_date_window=True,
+ fan_out_params=("status",),
+ ),
}
+# The payout countries the v3 banks reference documents.
+BANK_COUNTRIES = ("NG", "GH", "KE", "UG", "ZA", "TZ")
+
+# `type` defaults to credit, so both directions are read.
+WALLET_STATEMENT_TYPES = ("C", "D")
+
+BILL_PAYMENT_STATUSES = ("Successful", "Failed", "Reversed")
+
ENDPOINTS = tuple(FLUTTERWAVE_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/flutterwave/tests/test_flutterwave.py b/products/warehouse_sources/backend/temporal/data_imports/sources/flutterwave/tests/test_flutterwave.py
index 52e588b5e7ce..9113d72029b2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/flutterwave/tests/test_flutterwave.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/flutterwave/tests/test_flutterwave.py
@@ -94,6 +94,112 @@ class TestPagination:
assert result.saved_states == [FlutterwaveResumeConfig(next_page=2)]
+def _statement_page(rows: list[dict[str, Any]], total_pages: int) -> ScriptedResponse:
+ return ScriptedResponse(
+ json={
+ "status": "success",
+ "message": "Wallet statement fetched",
+ "data": {
+ "page_info": {"total": len(rows), "current_page": 1, "total_pages": total_pages},
+ "transactions": rows,
+ },
+ }
+ )
+
+
+def _balances(*currencies: str) -> ScriptedResponse:
+ return ScriptedResponse(
+ json={"status": "success", "data": [{"currency": c, "available_balance": 0} for c in currencies]}
+ )
+
+
+class TestFanOut:
+ def test_wallet_statement_walks_every_wallet_currency(self) -> None:
+ result = _run_v3(
+ "wallet_statement",
+ route(
+ {
+ "/balances": [_balances("USD", "NGN")],
+ "/wallet/statement": [
+ _statement_page([{"reference": "a", "currency": "NGN", "type": "C"}], total_pages=2),
+ _statement_page([{"reference": "b", "currency": "NGN", "type": "C"}], total_pages=2),
+ _statement_page([{"reference": "c", "currency": "NGN", "type": "D"}], total_pages=1),
+ _statement_page([], total_pages=0),
+ _statement_page([], total_pages=0),
+ ],
+ }
+ ),
+ )
+
+ assert result.raised is None
+ assert [row["reference"] for row in result.rows] == ["a", "b", "c"]
+ statements = [request for request in result.requests if request.path == "/v3/wallet/statement"]
+ assert [(r.param("currency"), r.param("type"), r.param("page")) for r in statements] == [
+ ("NGN", "C", "1"),
+ ("NGN", "C", "2"),
+ ("NGN", "D", "1"),
+ ("USD", "C", "1"),
+ ("USD", "D", "1"),
+ ]
+ assert {r.param("from") for r in statements} == {"2016-01-01"}
+ assert result.saved_states == [
+ FlutterwaveResumeConfig(next_page=2, fan_out_value="NGN|C"),
+ FlutterwaveResumeConfig(fan_out_value="NGN|D"),
+ FlutterwaveResumeConfig(fan_out_value="USD|C"),
+ FlutterwaveResumeConfig(fan_out_value="USD|D"),
+ ]
+
+ def test_wallet_statement_resumes_at_the_saved_currency_direction_and_page(self) -> None:
+ result = _run_v3(
+ "wallet_statement",
+ route(
+ {
+ "/balances": [_balances("NGN", "USD")],
+ "/wallet/statement": [_statement_page([{"reference": "c", "currency": "USD"}], total_pages=3)],
+ }
+ ),
+ resume_state=FlutterwaveResumeConfig(next_page=3, fan_out_value="USD|D"),
+ )
+
+ assert result.raised is None
+ statements = [request for request in result.requests if request.path == "/v3/wallet/statement"]
+ assert [(r.param("currency"), r.param("type"), r.param("page")) for r in statements] == [("USD", "D", "3")]
+
+ def test_banks_reads_each_country_and_stamps_it_on_the_rows(self) -> None:
+ result = _run_v3(
+ "banks", always(ScriptedResponse(json={"status": "success", "data": [{"id": 1, "code": "044"}]}))
+ )
+
+ assert result.raised is None
+ assert [request.path for request in result.requests] == [
+ f"/v3/banks/{country}" for country in ("NG", "GH", "KE", "UG", "ZA", "TZ")
+ ]
+ assert {request.param("page") for request in result.requests} == {None}
+ assert [row["country"] for row in result.rows] == ["NG", "GH", "KE", "UG", "ZA", "TZ"]
+
+ def test_bill_payments_reads_every_status_and_keeps_the_row_status(self) -> None:
+ result = _run_v3(
+ "bill_payments",
+ route(
+ {
+ "/bills/history": [
+ _page([{"id": 1, "status": "Successful"}]),
+ _page([{"id": 2, "status": "Failed"}]),
+ _page([{"id": 3, "status": "Reversed"}]),
+ ]
+ }
+ ),
+ )
+
+ assert result.raised is None
+ assert [r.param("status") for r in result.requests] == ["Successful", "Failed", "Reversed"]
+ assert [(row["id"], row["status"]) for row in result.rows] == [
+ (1, "Successful"),
+ (2, "Failed"),
+ (3, "Reversed"),
+ ]
+
+
class TestDateWindow:
@parameterized.expand(
[
@@ -117,6 +223,14 @@ class TestDateWindow:
assert result.requests[0].param("from") is None
assert result.requests[0].param("to") is None
+ @parameterized.expand([("transactions",), ("bill_payments",)])
+ def test_required_window_endpoints_send_the_full_history_window(self, endpoint: str) -> None:
+ result = _run_v3(endpoint, always(_page([{"id": 1}])))
+
+ assert result.raised is None
+ assert result.requests[0].param("from") == "2016-01-01"
+ assert result.requests[0].param("to") is not None
+
@parameterized.expand(
[
("subscriptions",),
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/flutterwave/tests/test_flutterwave_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/flutterwave/tests/test_flutterwave_source.py
index 7c8be3a6c42a..18b67410a80e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/flutterwave/tests/test_flutterwave_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/flutterwave/tests/test_flutterwave_source.py
@@ -43,6 +43,9 @@ class TestGetSchemas:
"subscriptions",
"subaccounts",
"beneficiaries",
+ "banks",
+ "wallet_statement",
+ "bill_payments",
},
),
(