Skip to content
New issue

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

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

Already on GitHub? # to your account

refactor(core): add connector mandate id in payments_response based on merchant config #5999

Merged
merged 10 commits into from
Sep 24, 2024

Conversation

Aprabhat19
Copy link
Contributor

@Aprabhat19 Aprabhat19 commented Sep 23, 2024

Type of Change

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

Description

Add connector_mandate_id as a field in payments_response based on merchant level config.

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?

  • Create a MA and an MCA
  • Hit the following curl to set the connector_mandate_details flag as true
curl --location 'http://localhost:8080/configs/' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data '{
    "key":"{{merchant_id}}_should_show_connector_mandate_id",
    "value":"true"
}'
  • Make a mandate payment
  • The connector_mandate_id would show up in the response
{
    "payment_id": "pay_EFzwx23DYvXTKTNlirna",
    "merchant_id": "merchant_1727118169",
    "status": "succeeded",
    "amount": 400,
    "net_amount": 400,
    "amount_capturable": 0,
    "amount_received": 400,
    "connector": "stripe",
    "client_secret": "pay_EFzwx23DYvXTKTNlirna_secret_hEotHr2NVtFG2Bb6N6dQ",
    "created": "2024-09-23T19:07:16.475Z",
    "currency": "USD",
    "customer_id": "CustomerX7777",
    "customer": {
        "id": "CustomerX7777",
        "name": "Joseph Doe",
        "email": "something@gmail.com",
        "phone": "999999999",
        "phone_country_code": "+65"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": "off_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "4242",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "424242",
            "card_extended_bin": null,
            "card_exp_month": "06",
            "card_exp_year": "2030",
            "card_holder_name": null,
            "payment_checks": {
                "cvc_check": "pass",
                "address_line1_check": "pass",
                "address_postal_code_check": "pass"
            },
            "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": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": null
    },
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": null
    },
    "order_details": null,
    "email": "something@gmail.com",
    "name": "Joseph Doe",
    "phone": "999999999",
    "return_url": "https://google.com/",
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": null,
    "statement_descriptor_suffix": null,
    "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": null,
    "manual_retry_allowed": false,
    "connector_transaction_id": "pi_3Q2HbRD5R7gDAGff1w8eLHrI",
    "frm_message": null,
    "metadata": {
        "brand": "waytopark",
        "order_id": 221275
    },
    "connector_metadata": {
        "apple_pay": null,
        "airwallex": null,
        "noon": {
            "order_category": "pay"
        }
    },
    "feature_metadata": null,
    "reference_id": "pi_3Q2HbRD5R7gDAGff1w8eLHrI",
    "payment_link": null,
    "profile_id": "pro_Ir6txlgPQZbNyeUB7OcT",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_ltS4Yz0TVGyJtjnmHEMv",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-09-23T19:22:16.475Z",
    "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": "pm_7eRMpm37Z2HPXo7iuzmI",
    "payment_method_status": null,
    "updated": "2024-09-23T19:07:22.808Z",
    "charges": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": "pm_1Q2HbRD5R7gDAGffn8nbrrOQ"
}
  • If the flag was false, which is the default value connector_mandate_details field would be None

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

@Aprabhat19 Aprabhat19 requested review from a team as code owners September 23, 2024 19:27
Copy link

semanticdiff-com bot commented Sep 23, 2024

Review changes with SemanticDiff.

Analyzed 8 of 8 files.

Overall, the semantic diff is 35% smaller than the GitHub diff.

Filename Status
✔️ crates/router/tests/payments.rs Analyzed
✔️ crates/router/tests/payments2.rs Analyzed
✔️ crates/router/src/core/payments/tokenization.rs 17.19% smaller
✔️ crates/router/src/core/payments/transformers.rs Analyzed
✔️ crates/router/src/core/payments/operations/payment_response.rs 70.53% smaller
✔️ crates/api_models/src/payments.rs Analyzed
✔️ api-reference-v2/openapi_spec.json Analyzed
✔️ api-reference/openapi_spec.json Analyzed

@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Sep 23, 2024
@Aprabhat19 Aprabhat19 self-assigned this Sep 23, 2024
@@ -3925,6 +3925,9 @@ pub struct PaymentsResponse {
pub merchant_order_reference_id: Option<String>,
/// order tax amount calculated by tax connectors
pub order_tax_amount: Option<MinorUnit>,

/// Identifier for the payment_method saved with the connector
Copy link
Contributor

Choose a reason for hiding this comment

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

could you verify this doc comment

Ok((pm_id, pm_status))
let cmid_config = db
.find_config_by_key_unwrap_or(
format!("{}_connector_mandate_details", merchant_account.get_id().get_string_repr().to_owned()).as_str(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:

config name doesn't convey its purpose

lsampras
lsampras previously approved these changes Sep 24, 2024
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Sep 24, 2024
Merged via the queue into main with commit af0d2a8 Sep 24, 2024
12 of 14 checks passed
@Gnanasundari24 Gnanasundari24 deleted the cmid-under-merchant-config branch September 24, 2024 12:33
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
M-api-contract-changes Metadata: This PR involves API contract changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REFACTOR] Add connector_mandate_details to the payments_response based on the merchant config
5 participants