Добавлена отправка NotificationURL и SuccessURL
This commit is contained in:
@@ -298,6 +298,8 @@ adapter:
|
||||
|
||||
tbank_payment:
|
||||
init_url: "https://securepay.tinkoff.ru/v2/Init"
|
||||
notification_url: "https://merchant.test/tbank/notification"
|
||||
success_url: "https://merchant.test/payment/success"
|
||||
auth:
|
||||
terminal_key: "test-terminal-key"
|
||||
password: "test-password"
|
||||
|
||||
@@ -10,6 +10,7 @@ from app.adapters.tbank.base import (
|
||||
TBankPaymentAdapterError,
|
||||
TBankPaymentRequestError,
|
||||
)
|
||||
from app.config import TBankPaymentAuthConfig, TBankPaymentConfig
|
||||
|
||||
|
||||
class SequenceHTTPClient:
|
||||
@@ -48,6 +49,8 @@ class SequenceHTTPClient:
|
||||
def _make_adapter(
|
||||
http_client: SequenceHTTPClient,
|
||||
*,
|
||||
notification_url: str = "https://example.test/tbank/notify",
|
||||
success_url: str = "https://example.test/payment/success",
|
||||
retry_attempts: int = 0,
|
||||
retry_backoff_seconds: float = 0.2,
|
||||
sleep_calls: list[float] | None = None,
|
||||
@@ -59,6 +62,8 @@ def _make_adapter(
|
||||
return TBankAdapter(
|
||||
http_client=http_client, # type: ignore[arg-type]
|
||||
init_url="https://securepay.tinkoff.ru/v2/Init",
|
||||
notification_url=notification_url,
|
||||
success_url=success_url,
|
||||
terminal_key="TBankTest",
|
||||
password="test-password",
|
||||
timeout_seconds=7.5,
|
||||
@@ -85,7 +90,14 @@ def test_create_payment_link_posts_signed_payload_and_maps_payment_url() -> None
|
||||
)
|
||||
|
||||
expected_token = hashlib.sha256(
|
||||
"125000order-uuid-1test-passwordTBankTest".encode("utf-8")
|
||||
(
|
||||
"125000"
|
||||
"https://example.test/tbank/notify"
|
||||
"order-uuid-1"
|
||||
"test-password"
|
||||
"https://example.test/payment/success"
|
||||
"TBankTest"
|
||||
).encode("utf-8")
|
||||
).hexdigest()
|
||||
assert result == "https://securepay.test/pay/1"
|
||||
assert http_client.calls == [
|
||||
@@ -96,6 +108,8 @@ def test_create_payment_link_posts_signed_payload_and_maps_payment_url() -> None
|
||||
"TerminalKey": "TBankTest",
|
||||
"Amount": 125000,
|
||||
"OrderId": "order-uuid-1",
|
||||
"NotificationURL": "https://example.test/tbank/notify",
|
||||
"SuccessURL": "https://example.test/payment/success",
|
||||
"Token": expected_token,
|
||||
},
|
||||
"data": None,
|
||||
@@ -108,6 +122,59 @@ def test_create_payment_link_posts_signed_payload_and_maps_payment_url() -> None
|
||||
]
|
||||
|
||||
|
||||
def test_from_config_posts_configured_urls_and_deterministic_token() -> None:
|
||||
response = httpx.Response(
|
||||
200,
|
||||
json={"Success": True, "PaymentURL": "https://securepay.test/pay/2"},
|
||||
request=httpx.Request("POST", "https://securepay.tinkoff.ru/v2/Init"),
|
||||
)
|
||||
http_client = SequenceHTTPClient([response])
|
||||
config = TBankPaymentConfig(
|
||||
init_url="https://securepay.tinkoff.ru/v2/Init",
|
||||
notification_url="https://merchant.test/tbank/notification",
|
||||
success_url="https://merchant.test/payment/success",
|
||||
auth=TBankPaymentAuthConfig(
|
||||
terminal_key="ConfigTerminal",
|
||||
password="config-password",
|
||||
),
|
||||
timeout_seconds=6.25,
|
||||
retry_attempts=0,
|
||||
retry_backoff_seconds=0.1,
|
||||
)
|
||||
adapter = TBankAdapter.from_config(
|
||||
http_client=http_client, # type: ignore[arg-type]
|
||||
config=config,
|
||||
)
|
||||
|
||||
result = asyncio.run(
|
||||
adapter.create_payment_link(
|
||||
order_uuid="order-uuid-2",
|
||||
amount_kopecks=9900,
|
||||
)
|
||||
)
|
||||
|
||||
expected_token = hashlib.sha256(
|
||||
(
|
||||
"9900"
|
||||
"https://merchant.test/tbank/notification"
|
||||
"order-uuid-2"
|
||||
"config-password"
|
||||
"https://merchant.test/payment/success"
|
||||
"ConfigTerminal"
|
||||
).encode("utf-8")
|
||||
).hexdigest()
|
||||
assert result == "https://securepay.test/pay/2"
|
||||
assert http_client.calls[0]["json"] == {
|
||||
"TerminalKey": "ConfigTerminal",
|
||||
"Amount": 9900,
|
||||
"OrderId": "order-uuid-2",
|
||||
"NotificationURL": "https://merchant.test/tbank/notification",
|
||||
"SuccessURL": "https://merchant.test/payment/success",
|
||||
"Token": expected_token,
|
||||
}
|
||||
assert http_client.calls[0]["timeout"] == 6.25
|
||||
|
||||
|
||||
def test_create_payment_link_maps_4xx_to_request_error() -> None:
|
||||
response = httpx.Response(
|
||||
400,
|
||||
|
||||
Reference in New Issue
Block a user