Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(relay): populate connector metadata in the refunds flow #7045

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ShankarSinghC
Copy link
Contributor

Type of Change

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

Description

Some connector requires connector metadata in the refund flow.
Example adyen requires endpoint_prefix. Hence this change is to populate the connector metadata in the relay refunds flow.

Additional Changes

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

Motivation and Context

Some connector like adyen requires the connector metadata in order to perform the refund.

How did you test it?

-> Create a adyen merchant connector account with endpoint_prefix in the metadata
-> Create a payment

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-tenant-id: hyperswitch' \
--header 'api-key: ' \
--data-raw '{
    "amount": 100,
    "amount_to_capture": 100,
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "customer_id": "cu_1737027612",
    "return_url": "http://127.0.0.1:4040",
    "customer_acceptance": {
        "acceptance_type": "offline",
        "accepted_at": "1963-05-03T04:07:52.723Z",
        "online": {
            "ip_address": "in sit",
            "user_agent": "amet irure esse"
        }
    },
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "card_number": "4111111111111111",
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holder_name": "joseph Doe",
            "card_cvc": "737"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "PiX",
            "last_name": "ss"
        },
        "email": "[email protected]"
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "PiX"
        }
    },
    "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,
        "screen_height": 723,
        "screen_width": 1536,
        "time_zone": 0,
        "java_enabled": true,
        "java_script_enabled": true,
        "ip_address": "125.0.0.1"
    },
    "routing": {
        "type": "single",
        "data": {
            "connector": "cybersource",
            "merchant_connector_id": "mca_8W0CQfwE89J1BJBbpcnt"
        }
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'
{
    "payment_id": "pay_8jnUUY21QbQQUYZw3oXp",
    "merchant_id": "merchant_1737026210",
    "status": "succeeded",
    "amount": 100,
    "net_amount": 100,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 100,
    "connector": "adyen",
    "client_secret": "pay_8jnUUY21QbQQUYZw3oXp_secret_gCitDmBCSL1rf57aWz2x",
    "created": "2025-01-16T11:17:06.935Z",
    "currency": "USD",
    "customer_id": "cu_1737026227",
    "customer": {
        "id": "cu_1737026227",
        "name": "John Doe",
        "email": "[email protected]",
        "phone": "999999999",
        "phone_country_code": "+1"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "1111",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "411111",
            "card_extended_bin": null,
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holder_name": "joseph Doe",
            "payment_checks": null,
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": null,
    "shipping": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "PiX",
            "last_name": null
        },
        "phone": null,
        "email": null
    },
    "billing": {
        "address": {
            "city": "San",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "PiX",
            "last_name": "ss"
        },
        "phone": null,
        "email": "[email protected]"
    },
    "order_details": null,
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "http://127.0.0.1:4040/",
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": null,
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "cu_1737026227",
        "created_at": 1737026226,
        "expires": 1737029826,
        "secret": "epk_60cc9662baa0498baf38418e6012aec4"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "JTP7LKV93245FNV5",
    "frm_message": null,
    "metadata": {
        "udf1": "value1",
        "login_date": "2019-09-10T10:11:12Z",
        "new_customer": "true"
    },
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pay_8jnUUY21QbQQUYZw3oXp_1",
    "payment_link": null,
    "profile_id": "pro_G34dqlGIBvt43dRfzHqg",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_ElpENwTfGeuTBYpCz0mq",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2025-01-16T11:32:06.935Z",
    "fingerprint": null,
    "browser_info": {
        "language": "nl-NL",
        "time_zone": 0,
        "ip_address": "125.0.0.1",
        "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",
        "color_depth": 24,
        "java_enabled": true,
        "screen_width": 1536,
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "screen_height": 723,
        "java_script_enabled": true
    },
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2025-01-16T11:17:08.458Z",
    "split_payments": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": null
}

-> With the above connector reference id perform the relay refund

curl --location 'http://localhost:8080/relay' \
--header 'Content-Type: application/json' \
--header 'x-profile-id: pro_G34dqlGIBvt43dRfzHqg' \
--header 'api-key:' \
--data '{
    "connector_id": "mca_ElpENwTfGeuTBYpCz0mq",
    "connector_resource_id": "JTP7LKV93245FNV5",
    "data": {
        "refund": {
            "amount": 1,
            "currency": "USD"
        }
    },
    "type": "refund"
}'
{
    "id": "relay_IzveULiShYKchIM8AL8Q",
    "status": "pending",
    "connector_resource_id": "JTP7LKV93245FNV5",
    "error": null,
    "connector_reference_id": "STZLZN7FSHSXRCV5",
    "connector_id": "mca_ElpENwTfGeuTBYpCz0mq",
    "profile_id": "pro_G34dqlGIBvt43dRfzHqg",
    "type": "refund",
    "data": {
        "refund": {
            "amount": 1,
            "currency": "USD",
            "reason": null
        }
    }
}

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

@ShankarSinghC ShankarSinghC added the C-bug Category: Bug label Jan 16, 2025
@ShankarSinghC ShankarSinghC self-assigned this Jan 16, 2025
@ShankarSinghC ShankarSinghC requested a review from a team as a code owner January 16, 2025 11:41
Copy link

semanticdiff-com bot commented Jan 16, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/relay/utils.rs  0% smaller

@ShankarSinghC ShankarSinghC force-pushed the relay/populate-connector-metadata branch from 4a202d3 to 7ea8642 Compare January 16, 2025 13:14
@ShankarSinghC ShankarSinghC force-pushed the relay/populate-connector-metadata branch from 7ea8642 to e1aed78 Compare January 16, 2025 13:15
@ShankarSinghC ShankarSinghC linked an issue Jan 16, 2025 that may be closed by this pull request
@ShankarSinghC ShankarSinghC added the A-core Area: Core flows label Jan 16, 2025
@ShankarSinghC ShankarSinghC changed the title fix(router): populate connector metadata in the relay refunds flow fix(relay): populate connector metadata in the refunds flow Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows C-bug Category: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

populate connector metadata in the relay refunds flow
3 participants