fix: omit default PayKilla redirect urls
This commit is contained in:
@@ -347,6 +347,10 @@ def _response_invoice_data(response_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
return response_data if isinstance(response_data, dict) else {}
|
||||
|
||||
|
||||
def _debug_invoice_body(body: Dict[str, Any]) -> str:
|
||||
return json.dumps(body, ensure_ascii=True, sort_keys=True)
|
||||
|
||||
|
||||
class PaykillaService(HttpClientMixin):
|
||||
def __init__(
|
||||
self,
|
||||
@@ -449,12 +453,12 @@ class PaykillaService(HttpClientMixin):
|
||||
body["expiredAt"] = expires_at.isoformat().replace("+00:00", "Z")
|
||||
|
||||
urls: List[Dict[str, Any]] = []
|
||||
if self.success_url:
|
||||
urls.append({"type": "SUCCESS", "url": self.success_url, "autoRedirect": True})
|
||||
if self.return_url:
|
||||
urls.append({"type": "RETURN", "url": self.return_url})
|
||||
if self.cancel_url:
|
||||
urls.append({"type": "CANCEL", "url": self.cancel_url})
|
||||
if self.config.SUCCESS_URL:
|
||||
urls.append({"type": "SUCCESS", "url": self.config.SUCCESS_URL, "autoRedirect": True})
|
||||
if self.config.RETURN_URL:
|
||||
urls.append({"type": "RETURN", "url": self.config.RETURN_URL})
|
||||
if self.config.CANCEL_URL:
|
||||
urls.append({"type": "CANCEL", "url": self.config.CANCEL_URL})
|
||||
if urls:
|
||||
body["urls"] = urls
|
||||
return body
|
||||
@@ -512,9 +516,11 @@ class PaykillaService(HttpClientMixin):
|
||||
invoice_id = first_value(invoice, "id")
|
||||
if response.status not in {200, 201} or not invoice_id:
|
||||
logging.error(
|
||||
"Paykilla create_payment_link: API error (status=%s, body=%s)",
|
||||
"Paykilla create_payment_link: API error "
|
||||
"(status=%s, body=%s, request_body=%s)",
|
||||
response.status,
|
||||
response_data,
|
||||
_debug_invoice_body(body),
|
||||
)
|
||||
return False, {"status": response.status, "message": response_data}
|
||||
invoice["payment_url"] = f"{self.widget_url}/{invoice_id}"
|
||||
|
||||
@@ -182,7 +182,7 @@ PayKilla строго валидирует текстовые поля invoice.
|
||||
1. Включите `PAYKILLA_ENABLED`.
|
||||
2. Укажите `PAYKILLA_API_KEY` и `PAYKILLA_SECRET_KEY`.
|
||||
3. Проверьте `PAYKILLA_CURRENCY` и `PAYKILLA_PAYMENT_CURRENCIES`, например `USDTTRC,BTC,ETH`.
|
||||
4. При необходимости задайте `PAYKILLA_SUCCESS_URL`, `PAYKILLA_RETURN_URL` и `PAYKILLA_CANCEL_URL`.
|
||||
4. При необходимости задайте `PAYKILLA_SUCCESS_URL`, `PAYKILLA_RETURN_URL` и `PAYKILLA_CANCEL_URL`; по умолчанию Minishop не отправляет redirect URLs в PayKilla и полагается на webhook для активации платежа.
|
||||
5. Добавьте `paykilla` в `PAYMENT_METHODS_ORDER`, если хотите задать явный порядок кнопок.
|
||||
|
||||
Справочник переменных: [PayKilla](../configuration/env-vars.md#paykilla).
|
||||
|
||||
@@ -256,6 +256,31 @@ class PaykillaServiceTests(unittest.TestCase):
|
||||
self.assertEqual(body["purpose"], "Minishop payment 556")
|
||||
self.assertEqual(body["description"], body["purpose"])
|
||||
self.assertRegex(body["purpose"], r"^[A-Za-z0-9_\s.,]+$")
|
||||
self.assertNotIn("urls", body)
|
||||
|
||||
def test_invoice_body_includes_only_explicit_redirect_urls(self):
|
||||
service = self._make_service()
|
||||
service.config.SUCCESS_URL = "https://shop.example/pay/success"
|
||||
service.config.RETURN_URL = "https://shop.example/pay/return"
|
||||
|
||||
body = service._invoice_body(
|
||||
payment_db_id=556,
|
||||
amount=100,
|
||||
currency="RUB",
|
||||
description="ignored",
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
body["urls"],
|
||||
[
|
||||
{
|
||||
"type": "SUCCESS",
|
||||
"url": "https://shop.example/pay/success",
|
||||
"autoRedirect": True,
|
||||
},
|
||||
{"type": "RETURN", "url": "https://shop.example/pay/return"},
|
||||
],
|
||||
)
|
||||
|
||||
def test_verify_webhook_signature_accepts_raw_body_signature(self):
|
||||
service = self._make_service()
|
||||
|
||||
Reference in New Issue
Block a user