make
This commit is contained in:
@@ -364,7 +364,11 @@ async def handle_revolut_event(event: dict):
|
|||||||
await _handle_revolut_subscription_initiated(event)
|
await _handle_revolut_subscription_initiated(event)
|
||||||
return
|
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}'.")
|
logger.info(f"Revolut subscription lifecycle event received: '{event_type}'.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
+19
-6
@@ -105,7 +105,9 @@ class RevolutWallet(FiatProvider):
|
|||||||
) -> FiatInvoiceResponse:
|
) -> FiatInvoiceResponse:
|
||||||
opts = self._parse_create_opts(extra or {})
|
opts = self._parse_create_opts(extra or {})
|
||||||
if opts is None:
|
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)
|
amount_minor = int(amount * 100)
|
||||||
checkout = opts.checkout or RevolutCheckoutOptions()
|
checkout = opts.checkout or RevolutCheckoutOptions()
|
||||||
@@ -202,10 +204,15 @@ class RevolutWallet(FiatProvider):
|
|||||||
if extra.get("trial_duration"):
|
if extra.get("trial_duration"):
|
||||||
payload["trial_duration"] = extra["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:
|
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()
|
r.raise_for_status()
|
||||||
data = r.json()
|
data = r.json()
|
||||||
revolut_subscription_id = data.get("id")
|
revolut_subscription_id = data.get("id")
|
||||||
@@ -213,7 +220,9 @@ class RevolutWallet(FiatProvider):
|
|||||||
if not revolut_subscription_id or not setup_order_id:
|
if not revolut_subscription_id or not setup_order_id:
|
||||||
return FiatSubscriptionResponse(
|
return FiatSubscriptionResponse(
|
||||||
ok=False,
|
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)
|
setup_order = await self.get_order(setup_order_id)
|
||||||
@@ -298,7 +307,9 @@ class RevolutWallet(FiatProvider):
|
|||||||
async def get_subscription_cycle(
|
async def get_subscription_cycle(
|
||||||
self, subscription_id: str, cycle_id: str
|
self, subscription_id: str, cycle_id: str
|
||||||
) -> dict[str, Any]:
|
) -> 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()
|
r.raise_for_status()
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
@@ -334,7 +345,9 @@ class RevolutWallet(FiatProvider):
|
|||||||
if not external_reference:
|
if not external_reference:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
return RevolutSubscriptionReference.parse_obj(json.loads(external_reference))
|
return RevolutSubscriptionReference.parse_obj(
|
||||||
|
json.loads(external_reference)
|
||||||
|
)
|
||||||
except (json.JSONDecodeError, ValidationError) as exc:
|
except (json.JSONDecodeError, ValidationError) as exc:
|
||||||
logger.warning(exc)
|
logger.warning(exc)
|
||||||
return None
|
return None
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
@@ -182,7 +182,9 @@ async def test_callback_api_handles_revolut_paid_events(mocker):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.anyio
|
@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(
|
user = await create_user_account(
|
||||||
Account(
|
Account(
|
||||||
id=uuid4().hex,
|
id=uuid4().hex,
|
||||||
|
|||||||
@@ -795,7 +795,9 @@ async def test_revolut_wallet_create_invoice(settings: Settings):
|
|||||||
|
|
||||||
assert response.ok is True
|
assert response.ok is True
|
||||||
assert response.checking_id == "order_ORDER123"
|
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"
|
assert client.calls[0][0] == "/api/orders"
|
||||||
payload = client.calls[0][1]["json"]
|
payload = client.calls[0][1]["json"]
|
||||||
assert payload["amount"] == 123
|
assert payload["amount"] == 123
|
||||||
|
|||||||
Reference in New Issue
Block a user