Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Store the payment token when transaction failed

NyanKiyoshif66f16f2fad8
diff --git a/saleor/payment/gateways/razorpay/__init__.py b/saleor/payment/gateways/razorpay/__init__.py
index 1bdd87b565..10115c9551 100644
--- a/saleor/payment/gateways/razorpay/__init__.py
+++ b/saleor/payment/gateways/razorpay/__init__.py
@@ -62,7 +62,7 @@ def get_error_message_from_razorpay_error(exc: BaseException):
return ERROR_MSG_SERVER_ERROR
-def get_error_response(amount: Decimal):
+def get_error_response(amount: Decimal) -> dict:
"""Create a place holder response for invalid/ failed requests
for generated a failed transaction object."""
return {'is_success': False, 'amount': amount}
@@ -116,6 +116,7 @@ def charge(
except RAZORPAY_EXCEPTIONS as exc:
error = get_error_message_from_razorpay_error(exc)
response = get_error_response(amount)
+ response['id'] = payment_token
transaction = _generate_transaction(
payment=payment, kind=TransactionKind.CHARGE, **response)
diff --git a/tests/gateway/test_razorpay.py b/tests/gateway/test_razorpay.py
index 9dbb0034fb..610eee248f 100644
--- a/tests/gateway/test_razorpay.py
+++ b/tests/gateway/test_razorpay.py
@@ -165,6 +165,7 @@ def test_charge_invalid_request(
# Ensure the transaction is correctly set
assert txn.payment == payment_dummy
assert txn.kind == TransactionKind.CHARGE
+ assert txn.token == payment_token
@pytest.mark.integration