fix(пополнение): тестовый режим Robokassa не создаёт платёж без смещения номеров

Номер тестовой оплаты со стенда на копии боевой базы совпал бы с будущим боевым, и
OpStateExt отвечал бы по нему кодом 4 — деньги человека не зачислились бы никогда.
Заодно поправлено понимание кода 60 по документации xml-interfaces.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
anor
2026-10-28 15:49:45 +10:00
co-authored by Claude Opus 5.5
parent 55c50be90d
commit f0f10372e2
4 changed files with 31 additions and 1 deletions
+8
View File
@@ -34,6 +34,8 @@ _ALGOS = ("md5", "sha1", "sha256", "sha384", "sha512")
# Ошибка трактовки сдвигает срок на три часа в большую сторону — не страшно.
_MSK = timezone(timedelta(hours=3))
# 60 in xml-interfaces is "crediting to the shop refused, money returned to the buyer" — not a
# refund made later from the cabinet; such refunds are entered with the admin button.
_STATES = {100: "succeeded", 10: "canceled", 60: "refunded",
5: "pending", 20: "pending", 50: "pending", 80: "pending"}
@@ -69,6 +71,12 @@ def create(order: dict) -> dict:
cr = _need_creds()
out_sum = f"{Decimal(int(order['amount_kop'])) / 100:.2f}"
inv = str(int(order["order_no"]))
if _test_mode() and int(order["order_no"]) == int(order["topup_id"]):
# Test and live share one shop. A stand runs on a copy of the live database, so its
# unshifted test number later becomes a live one, and OpStateExt then answers code 4
# ("two operations with one InvoiceID") forever — the live payment is never credited.
raise RuntimeError("тестовый режим Robokassa без TOPUP_ORDER_OFFSET: номер совпадёт "
"с боевым, OpStateExt ответит кодом 4")
ret = order["return_url"]
expires = (datetime.now(_MSK) + timedelta(seconds=int(order.get("expires_in") or 7200)))
# Модификаторы — в порядке документации; адреса в строке подписи — закодированными,