Skip to content

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

Add handler for report error in transaction reregistration

Mateusz Grzyba9a42e23db99
diff --git a/saleor/payment/gateways/np_atobarai/__init__.py b/saleor/payment/gateways/np_atobarai/__init__.py
index 1c89094f9f..20bc3b8974 100644
--- a/saleor/payment/gateways/np_atobarai/__init__.py
+++ b/saleor/payment/gateways/np_atobarai/__init__.py
@@ -44,7 +44,7 @@ def process_payment(
kind=TransactionKind.CAPTURE,
amount=payment_information.amount,
currency=payment_information.currency,
- transaction_id=result.psp_reference,
+ transaction_id=result.psp_reference or "",
error=parse_errors(result.errors),
raw_response=result.raw_response,
psp_reference=result.psp_reference,
@@ -155,7 +155,7 @@ def refund(payment_information: PaymentData, config: ApiConfig) -> GatewayRespon
kind=TransactionKind.REFUND,
amount=payment_information.amount,
currency=payment_information.currency,
- transaction_id=result.psp_reference,
+ transaction_id=result.psp_reference or "",
error=parse_errors(result.errors),
raw_response=result.raw_response,
psp_reference=result.psp_reference,
diff --git a/saleor/payment/gateways/np_atobarai/api.py b/saleor/payment/gateways/np_atobarai/api.py
index 133e5c45db..97fb72e2fc 100644
--- a/saleor/payment/gateways/np_atobarai/api.py
+++ b/saleor/payment/gateways/np_atobarai/api.py
@@ -201,7 +201,15 @@ def reregister_transaction_for_partial_return(
if not error_codes:
new_psp_reference = result["np_transaction_id"]
- report(config, shipping_company_code, new_psp_reference, tracking_number)
+ result, error_codes = report(
+ config, shipping_company_code, new_psp_reference, tracking_number
+ )
+
+ if error_codes:
+ error_messages = get_error_messages_from_codes(
+ FULFILLMENT_REPORT, error_codes=error_codes
+ )
+ return errors_payment_result(error_messages)
return PaymentResult(
status=PaymentStatus.SUCCESS,
diff --git a/saleor/payment/gateways/np_atobarai/tests/test_api.py b/saleor/payment/gateways/np_atobarai/tests/test_api.py
index a3b513ed94..c838d623c3 100644
--- a/saleor/payment/gateways/np_atobarai/tests/test_api.py
+++ b/saleor/payment/gateways/np_atobarai/tests/test_api.py
@@ -671,6 +671,7 @@ def test_reregister_transaction_success(
},
error_codes=[],
)
+ mocked_report.return_value = NPResponse(result={}, error_codes=[])
# when
payment_response = api.reregister_transaction_for_partial_return(
@@ -728,6 +729,48 @@ def test_reregister_transaction_cancel_error(
assert payment_response.errors == [f"TC#{code}" for code in error_codes]
+@patch("saleor.payment.gateways.np_atobarai.api.report")
+@patch("saleor.payment.gateways.np_atobarai.api.register")
+@patch("saleor.payment.gateways.np_atobarai.api.cancel")
+def test_reregister_transaction_report_error(
+ mocked_cancel,
+ mocked_register,
+ mocked_report,
+ config,
+ payment_dummy,
+ np_payment_data,
+):
+ # given
+ refund_data = None
+ tracking_number = "123"
+ shipping_company_code = "50000"
+ payment_dummy.psp_reference = "123"
+ new_psp_reference = "234"
+ error_codes = ["1", "2", "3"]
+ mocked_cancel.return_value = NPResponse(result={}, error_codes=[])
+ mocked_register.return_value = NPResponse(
+ result={
+ "np_transaction_id": new_psp_reference,
+ },
+ error_codes=[],
+ )
+ mocked_report.return_value = NPResponse(result={}, error_codes=error_codes)
+
+ # when
+ payment_response = api.reregister_transaction_for_partial_return(
+ config,
+ payment_dummy,
+ np_payment_data,
+ shipping_company_code,
+ tracking_number,
+ refund_data,
+ )
+
+ # then
+ assert payment_response.status == PaymentStatus.FAILED
+ assert payment_response.errors == [f"FR#{code}" for code in error_codes]
+
+
@patch("saleor.payment.gateways.np_atobarai.api.register")
@patch("saleor.payment.gateways.np_atobarai.api.cancel")
def test_reregister_transaction_general_error(