Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Store the payment token when transaction failed
NyanKiyoshif66f16f2fad8
diff --git a/saleor/payment/gateways/razorpay/__init__.py b/saleor/payment/gateways/razorpay/__init__.pyindex 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 requestsfor 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_tokentransaction = _generate_transaction(payment=payment, kind=TransactionKind.CHARGE, **response)diff --git a/tests/gateway/test_razorpay.py b/tests/gateway/test_razorpay.pyindex 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 setassert txn.payment == payment_dummyassert txn.kind == TransactionKind.CHARGE+ assert txn.token == payment_token@pytest.mark.integration