This commit is contained in:
Arc
2026-05-15 12:09:03 +01:00
parent 29b1ace1e0
commit db89a8f608
5 changed files with 31 additions and 10 deletions
+5 -1
View File
@@ -364,7 +364,11 @@ async def handle_revolut_event(event: dict):
await _handle_revolut_subscription_initiated(event)
return
if event_type in ["SUBSCRIPTION_CANCELLED", "SUBSCRIPTION_FINISHED", "SUBSCRIPTION_OVERDUE"]:
if event_type in [
"SUBSCRIPTION_CANCELLED",
"SUBSCRIPTION_FINISHED",
"SUBSCRIPTION_OVERDUE",
]:
logger.info(f"Revolut subscription lifecycle event received: '{event_type}'.")
return
+19 -6
View File
@@ -105,7 +105,9 @@ class RevolutWallet(FiatProvider):
) -> FiatInvoiceResponse:
opts = self._parse_create_opts(extra or {})
if opts is None:
return FiatInvoiceResponse(ok=False, error_message="Invalid Revolut options")
return FiatInvoiceResponse(
ok=False, error_message="Invalid Revolut options"
)
amount_minor = int(amount * 100)
checkout = opts.checkout or RevolutCheckoutOptions()
@@ -202,10 +204,15 @@ class RevolutWallet(FiatProvider):
if extra.get("trial_duration"):
payload["trial_duration"] = extra["trial_duration"]
headers = {**self.headers, "Idempotency-Key": payment_options.subscription_request_id}
headers = {
**self.headers,
"Idempotency-Key": payment_options.subscription_request_id,
}
try:
r = await self.client.post("/api/subscriptions", json=payload, headers=headers)
r = await self.client.post(
"/api/subscriptions", json=payload, headers=headers
)
r.raise_for_status()
data = r.json()
revolut_subscription_id = data.get("id")
@@ -213,7 +220,9 @@ class RevolutWallet(FiatProvider):
if not revolut_subscription_id or not setup_order_id:
return FiatSubscriptionResponse(
ok=False,
error_message="Server error: missing subscription id or setup order id",
error_message=(
"Server error: missing subscription id or setup order id"
),
)
setup_order = await self.get_order(setup_order_id)
@@ -298,7 +307,9 @@ class RevolutWallet(FiatProvider):
async def get_subscription_cycle(
self, subscription_id: str, cycle_id: str
) -> dict[str, Any]:
r = await self.client.get(f"/api/subscriptions/{subscription_id}/cycles/{cycle_id}")
r = await self.client.get(
f"/api/subscriptions/{subscription_id}/cycles/{cycle_id}"
)
r.raise_for_status()
return r.json()
@@ -334,7 +345,9 @@ class RevolutWallet(FiatProvider):
if not external_reference:
return None
try:
return RevolutSubscriptionReference.parse_obj(json.loads(external_reference))
return RevolutSubscriptionReference.parse_obj(
json.loads(external_reference)
)
except (json.JSONDecodeError, ValidationError) as exc:
logger.warning(exc)
return None
File diff suppressed because one or more lines are too long
+3 -1
View File
@@ -182,7 +182,9 @@ async def test_callback_api_handles_revolut_paid_events(mocker):
@pytest.mark.anyio
async def test_callback_api_handles_revolut_subscription_event(mocker, settings: Settings):
async def test_callback_api_handles_revolut_subscription_event(
mocker, settings: Settings
):
user = await create_user_account(
Account(
id=uuid4().hex,
+3 -1
View File
@@ -795,7 +795,9 @@ async def test_revolut_wallet_create_invoice(settings: Settings):
assert response.ok is True
assert response.checking_id == "order_ORDER123"
assert response.payment_request == "https://checkout.revolut.com/payment-link/abc123"
assert (
response.payment_request == "https://checkout.revolut.com/payment-link/abc123"
)
assert client.calls[0][0] == "/api/orders"
payload = client.calls[0][1]["json"]
assert payload["amount"] == 123