Skip to content

Conversation

dgeee13
Copy link
Contributor

@dgeee13 dgeee13 commented Jan 28, 2025

…ated errors

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

Some connectors like Novalnet do not have a separate list of refund errors, they only have a single list for all the possible connector error codes.
In such cases, the error codes and messages are stored under "Authorize" flow in GSM table.

During refund related error when we fetch GSM in code, we will have to fetch the GSM using Authorize flow in case GSM is not found using "refund_flow".
[ Enhancement for this PR ]

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

How did you test it?

Steps:

  1. Make a card payment for 1000 MYR, and capture.
  2. Update DB to alter the captured amount to a greater amount say 3000 MYR.
  3. Make refunds call with 3000 MYR, connector will throw error since the real captured amount is lesser than this new amount.

1) Make card payment via Fiuu

cURL

curl --location --request POST 'http://localhost:8080/payments' \ --header 'Content-Type: application/json' \ --header 'Accept: application/json' \ --header 'api-key: dev_k6hN6WS14LcwHh4Q7bKCcTDRBwPRUnfQpraO5c7dW6oWiAFOmK8pdWfHlmg6adrt' \ --data-raw '{ "amount":1000, "currency": "MYR", "confirm": true, "payment_link" : false, "capture_method": "automatic", "capture_on": "2022-09-10T10:11:12Z", "amount_to_capture": 1000, "customer_id": "exampel3rewfdsvc2", "phone": "999999999", "phone_country_code": "+1", "description": "Its my first payment request", "authentication_type": "three_ds", "return_url": "https://google.com", "payment_method": "card", "payment_method_type": "credit", "payment_method_data": { "card": { "card_number": "5105105105105100", "card_exp_month": "12", "card_exp_year": "2030", "card_holder_name": "Max Mustermann", "card_cvc": "444" } }, "browser_info": { "user_agent": "Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/70.0.3538.110 Safari\/537.36", "accept_header": "text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/webp,image\/apng,\/;q=0.8", "language": "nl-NL", "color_depth": 24, "ip_address": "103.77.139.95", "screen_height": 723, "screen_width": 1536, "time_zone": 0, "java_enabled": true, "java_script_enabled": true }, "statement_descriptor_name": "joseph", "statement_descriptor_suffix": "JS", "metadata": { "udf1": "value1", "new_customer": "true", "login_date": "2019-09-10T10:11:12Z" } }'

Response
Screenshot 2024-12-24 at 16 54 21

2)Update DB with following commands to make captured amount greater than the real captured amount

UPDATE payment_intent
SET amount = 3000
WHERE payment_id='pay_FBXuXJ8A2WdhcwYueQCY';
UPDATE payment_intent
SET amount_captured = 3000
WHERE payment_id='pay_FBXuXJ8A2WdhcwYueQCY';

UPDATE payment_attempt
SET amount = 3000
WHERE payment_id='pay_FBXuXJ8A2WdhcwYueQCY';
UPDATE payment_attempt
SET amount_to_capture = 3000
WHERE payment_id='pay_FBXuXJ8A2WdhcwYueQCY';

3)Update gateway_status_map (with "Authorize flow") and unified_translations table

INSERT INTO unified_translations (unified_code, unified_message, locale, translation)
VALUES ('UE_1000', 'Issue with payment method details', 'zh-Hant', '支付方式資訊有問題');

INSERT INTO unified_translations (unified_code, unified_message, locale, translation)
VALUES ('UE_2000', 'Issue with Configurations', 'zh-Hant', '配置有問題');

INSERT INTO unified_translations (unified_code, unified_message, locale, translation)
VALUES ('UE_3000', 'Technical issue with PSP', 'zh-Hant', '支付服務提供商 (PSP) 出現技術問題');

INSERT INTO unified_translations (unified_code, unified_message, locale, translation)
VALUES ('UE_4000', 'Issue in the integration', 'zh-Hant', '整合過程中出現問題');

INSERT INTO unified_translations (unified_code, unified_message, locale, translation)
VALUES ('UE_9000', 'Something went wrong', 'zh-Hant', '授權被拒絕');

INSERT INTO
    gateway_status_map (
        connector,
        flow,
        sub_flow,
        code,
        message,
        status,
        decision,
        step_up_possible,
        unified_code,
        unified_message
    )
VALUES (
        'fiuu',
        'Authorize',
        'sub_flow',
        'PR011',
        'Exceed refund amount for this transaction.',
        'Failure',
        'do_default',
        false,
        'UE_1000',
        'Issue with payment method details'
    );

4)a) Make refunds call with locale "zh-Hant"

cURL

curl --location --request POST 'http://localhost:8080/refunds' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_k6hN6WS14LcwHh4Q7bKCcTDRBwPRUnfQpraO5c7dW6oWiAFOmK8pdWfHlmg6adrt' \
--data-raw '{
    "payment_id": "pay_FBXuXJ8A2WdhcwYueQCY",
    "amount": 3000,
    "reason": "Customer returned product",
    "refund_type": "instant",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'

Response
Screenshot 2024-12-24 at 16 55 49

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@dgeee13 dgeee13 requested review from a team as code owners January 28, 2025 09:23
Copy link

semanticdiff-com bot commented Jan 28, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/consts.rs  0% smaller
  crates/router/src/core/refunds.rs  0% smaller

@dgeee13 dgeee13 changed the title (feat:core) Add Authorize flow as fallback flow while fetching GSM for refund rel… (feat:core) Add Authorize flow as fallback flow while fetching GSM for refund errors Jan 28, 2025
@dgeee13 dgeee13 self-assigned this Jan 28, 2025
@dgeee13 dgeee13 changed the title (feat:core) Add Authorize flow as fallback flow while fetching GSM for refund errors feat:(core) Add Authorize flow as fallback flow while fetching GSM for refund errors Jan 28, 2025
@dgeee13 dgeee13 changed the title feat:(core) Add Authorize flow as fallback flow while fetching GSM for refund errors feat(core): Add Authorize flow as fallback flow while fetching GSM for refund errors Jan 28, 2025
Comment on lines +303 to +314
let option_gsm = if option_gsm.is_none() {
helpers::get_gsm_record(
state,
Some(err.code.clone()),
Some(err.message.clone()),
connector.connector_name.to_string(),
consts::AUTHORIZE_FLOW_STR.to_string(),
)
.await
} else {
option_gsm
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
let option_gsm = if option_gsm.is_none() {
helpers::get_gsm_record(
state,
Some(err.code.clone()),
Some(err.message.clone()),
connector.connector_name.to_string(),
consts::AUTHORIZE_FLOW_STR.to_string(),
)
.await
} else {
option_gsm
};
let option_gsm = option_gsm.or_else(|| {
helpers::get_gsm_record(
state,
Some(err.code.clone()),
Some(err.message.clone()),
connector.connector_name.to_string(),
consts::AUTHORIZE_FLOW_STR.to_string(),
)
.await
});

@likhinbopanna likhinbopanna added this pull request to the merge queue Feb 5, 2025
Merged via the queue into main with commit 7ea630d Feb 5, 2025
37 of 45 checks passed
@likhinbopanna likhinbopanna deleted the fallback branch February 5, 2025 15:29
Narayanbhat166 pushed a commit that referenced this pull request Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants