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

feat(core): Add logger for sessions call failure #5036

Merged
merged 1 commit into from
Jun 19, 2024

Conversation

deepanshu-iiitu
Copy link
Contributor

@deepanshu-iiitu deepanshu-iiitu commented Jun 19, 2024

Type of Change

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

Description

Add a logger for failure of sessions call when the call fails at connector's end.

Additional Changes

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

Motivation and Context

#5037

How did you test it?

The following logs should be checked:

  1. Session call fails without calling connector:
  • Payments Create(Klarna):

Request:

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_jOiTovkpGinwxAIGAlEyC9SiVkJCfK3Tc1NNOntnkLMaeaM7U7xtde8a88LhPVlm' \
--data-raw '{
    "amount": 6500,
    "client_secret": "pay_QWcuxERT26fPFELkA1d6_secret_m9LRWGDRVRckiKvfnNUZ",
    "currency": "USD",
    "customer_id": "cdsdcwmn",
    "customer": {
        "id": "cdsdcwmn",
        "email": "user@gmail.com"
    },
    "confirm": false,
    "description": "Hello this is description",
    "setup_future_usage": "on_session",
    "capture_method": "automatic",
    "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"
        }
    },
     "shipping": {
        "address": {
            "line1": "444, Stelar Enclave",
            "line2": "California",
            "line3": "Groningen",
            "city": "Groningen",
            "state": "Groningen",
            "zip": "94105",
            "country": "US",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "446681800",
            "country_code": "+41"
        }
    },
    "order_details": [
        {
            "amount": 6500,
            "quantity": 1,
            "product_name": "Apple iphone 15"
        }
    ],
    "email": "user@gmail.com",
    "metadata": {
        "udf1": "value1",
        "login_date": "2019-09-10T10:11:12Z",
        "new_customer": "true"
    }
}'

Response:

{
    "payment_id": "pay_tVGVQM83dIDCw3ruJ2rW",
    "merchant_id": "merchant_1718782884",
    "status": "requires_payment_method",
    "amount": 6500,
    "net_amount": 6500,
    "amount_capturable": 0,
    "amount_received": null,
    "connector": null,
    "client_secret": "pay_tVGVQM83dIDCw3ruJ2rW_secret_5yzEyo6XRKmikqS1mAvM",
    "created": "2024-06-19T08:02:28.968Z",
    "currency": "USD",
    "customer_id": "cdsdcwmn",
    "customer": {
        "id": "cdsdcwmn",
        "name": null,
        "email": "user@gmail.com",
        "phone": null,
        "phone_country_code": null
    },
    "description": "Hello this is description",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": "on_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": null,
    "payment_method_data": null,
    "payment_token": null,
    "shipping": {
        "address": {
            "city": "Groningen",
            "country": "US",
            "line1": "444, Stelar Enclave",
            "line2": "California",
            "line3": "Groningen",
            "zip": "94105",
            "state": "Groningen",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "446681800",
            "country_code": "+41"
        },
        "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": [
        {
            "brand": null,
            "amount": 6500,
            "category": null,
            "quantity": 1,
            "product_id": null,
            "product_name": "Apple iphone 15",
            "product_type": null,
            "sub_category": null,
            "product_img_link": null,
            "requires_shipping": null
        }
    ],
    "email": "user@gmail.com",
    "name": null,
    "phone": null,
    "return_url": null,
    "authentication_type": null,
    "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": {
        "customer_id": "cdsdcwmn",
        "created_at": 1718784148,
        "expires": 1718787748,
        "secret": "epk_4f84615faf66473aa1a1344bb10d014a"
    },
    "manual_retry_allowed": null,
    "connector_transaction_id": null,
    "frm_message": null,
    "metadata": {
        "udf1": "value1",
        "login_date": "2019-09-10T10:11:12Z",
        "new_customer": "true"
    },
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": null,
    "payment_link": null,
    "profile_id": "pro_rDD29g488ZjT3dFTLs9s",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": null,
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-06-19T08:17:28.968Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2024-06-19T08:02:28.986Z",
    "charges": null,
    "frm_metadata": null
}
  • Session Token:

Request:

curl --location 'http://localhost:8080/payments/session_tokens' \
--header 'Content-Type: application/json' \
--header 'api-key: pk_dev_d36f99efb52a4dd891bca3d9bd9c8842' \
--data '{
    "payment_id": "pay_tVGVQM83dIDCw3ruJ2rW",
    "wallets": [],
    "client_secret": "pay_tVGVQM83dIDCw3ruJ2rW_secret_5yzEyo6XRKmikqS1mAvM"
}'

Response:

{
    "payment_id": "pay_tVGVQM83dIDCw3ruJ2rW",
    "client_secret": "pay_tVGVQM83dIDCw3ruJ2rW_secret_5yzEyo6XRKmikqS1mAvM",
    "session_token": []
}

Logs:
Screenshot 2024-06-19 at 1 33 09 PM

  1. Session Call fails at connector:
    NOTE: To generate this error enter wrong api credentials for Klarna while creating the connector
  • Payments Create (Klarna):

Request:

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_jOiTovkpGinwxAIGAlEyC9SiVkJCfK3Tc1NNOntnkLMaeaM7U7xtde8a88LhPVlm' \
--data-raw '{
    "amount": 6500,
    "client_secret": "pay_QWcuxERT26fPFELkA1d6_secret_m9LRWGDRVRckiKvfnNUZ",
    "currency": "USD",
    "customer_id": "cdsdcwmn",
    "customer": {
        "id": "cdsdcwmn",
        "email": "user@gmail.com"
    },
    "confirm": false,
    "description": "Hello this is description",
    "setup_future_usage": "on_session",
    "capture_method": "automatic",
    "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"
        }
    },
    "order_details": [
        {
            "amount": 6500,
            "quantity": 1,
            "product_name": "Apple iphone 15"
        }
    ],
    "email": "user@gmail.com",
    "metadata": {
        "udf1": "value1",
        "login_date": "2019-09-10T10:11:12Z",
        "new_customer": "true"
    }
}'

Response:

{
    "payment_id": "pay_eJNLxe3merOzC4Ne0yBk",
    "merchant_id": "merchant_1718782884",
    "status": "requires_payment_method",
    "amount": 6500,
    "net_amount": 6500,
    "amount_capturable": 0,
    "amount_received": null,
    "connector": null,
    "client_secret": "pay_eJNLxe3merOzC4Ne0yBk_secret_e8cDuFl2f0flJTbXnx9s",
    "created": "2024-06-19T08:14:18.074Z",
    "currency": "USD",
    "customer_id": "cdsdcwmn",
    "customer": {
        "id": "cdsdcwmn",
        "name": null,
        "email": "user@gmail.com",
        "phone": null,
        "phone_country_code": null
    },
    "description": "Hello this is description",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": "on_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": null,
    "payment_method_data": null,
    "payment_token": null,
    "shipping": 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": [
        {
            "brand": null,
            "amount": 6500,
            "category": null,
            "quantity": 1,
            "product_id": null,
            "product_name": "Apple iphone 15",
            "product_type": null,
            "sub_category": null,
            "product_img_link": null,
            "requires_shipping": null
        }
    ],
    "email": "user@gmail.com",
    "name": null,
    "phone": null,
    "return_url": null,
    "authentication_type": null,
    "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": {
        "customer_id": "cdsdcwmn",
        "created_at": 1718784858,
        "expires": 1718788458,
        "secret": "epk_c15cf7f5abb74cc79d7d5135d7b7bbf1"
    },
    "manual_retry_allowed": null,
    "connector_transaction_id": null,
    "frm_message": null,
    "metadata": {
        "udf1": "value1",
        "login_date": "2019-09-10T10:11:12Z",
        "new_customer": "true"
    },
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": null,
    "payment_link": null,
    "profile_id": "pro_rDD29g488ZjT3dFTLs9s",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": null,
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-06-19T08:29:18.073Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2024-06-19T08:14:18.149Z",
    "charges": null,
    "frm_metadata": null
}
  • Session Token:

Request:

curl --location 'http://localhost:8080/payments/session_tokens' \
--header 'Content-Type: application/json' \
--header 'api-key: pk_dev_d36f99efb52a4dd891bca3d9bd9c8842' \
--data '{
    "payment_id": "pay_eJNLxe3merOzC4Ne0yBk",
    "wallets": [],
    "client_secret": "pay_eJNLxe3merOzC4Ne0yBk_secret_e8cDuFl2f0flJTbXnx9s"
}'

Response:

{
    "payment_id": "pay_eJNLxe3merOzC4Ne0yBk",
    "client_secret": "pay_eJNLxe3merOzC4Ne0yBk_secret_e8cDuFl2f0flJTbXnx9s",
    "session_token": []
}

Logs:
Screenshot 2024-06-19 at 1 32 03 PM

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

@deepanshu-iiitu deepanshu-iiitu added A-core Area: Core flows C-feature Category: Feature request or enhancement labels Jun 19, 2024
@deepanshu-iiitu deepanshu-iiitu self-assigned this Jun 19, 2024
@deepanshu-iiitu deepanshu-iiitu requested review from a team as code owners June 19, 2024 08:07
@deepanshu-iiitu deepanshu-iiitu linked an issue Jun 19, 2024 that may be closed by this pull request
2 tasks
if let Err(connector_error_response) = connector_response.response {
logger::error!(
"sessions_connector_error {} {:?}",
connector_name,
Copy link
Member

Choose a reason for hiding this comment

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

this field shouldn'e be needed since we already record connector_name

connector_error
);
Err(api_error) => {
logger::error!("sessions_api_error {} {:?}", connector_name, api_error);
Copy link
Member

Choose a reason for hiding this comment

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

the connector_name field shouldn't be needed since we already recorded

@likhinbopanna likhinbopanna added this pull request to the merge queue Jun 19, 2024
Merged via the queue into main with commit 397d221 Jun 19, 2024
31 checks passed
@likhinbopanna likhinbopanna deleted the log-conn-session-error branch June 19, 2024 10:46
pixincreate added a commit that referenced this pull request Jun 20, 2024
…ress-skip

* 'main' of github.com:juspay/hyperswitch: (27 commits)
  feat(cypress): add 2 more payout connectors and bank transfer support for payout (#4993)
  chore(version): 2024.06.20.0
  Refactor(core): reverts the payment method list filtering using constraint graph (#5044)
  feat(router): add payment method type duplication check for `google_pay` (#5023)
  refactor(storage): remove `id` from payment intent, attempt and remove datamodel ext from payment intent (#4923)
  fix(events): Correct parsing of API events with user event_type for Clickhouse (#5022)
  fix(connector):  add local bank redirect type in compatibility layer, default the country to AT for Local Bank Redirect and add creds_identifier in access token  (#5038)
  refactor(connector): add amount conversion framework for noon (#4843)
  fix(logging): fix stack overflow on recording restricted keys (#4423)
  feat(core): Add logger for sessions call failure (#5036)
  chore(version): 2024.06.19.0
  fix(opensearch): handle index not present errors in search api (#4965)
  feat(multitenancy): add tenant_id as a field for data pipeline and support individual database for clickhouse  (#4867)
  refactor: add basic counter metrics for IMC (#5006)
  fix(payment_methods): populate card fields while saving card again during metadata change condition (#5019)
  feat(router): Override the `setup_future_usage` to `on_session` based on the merchant config (#5016)
  chore(docker-compose): pass correct configuration values for running SDK demo app  (#5012)
  refactor: Move trait ConnectorIntegration to crate hyperswitch_interfaces (#4946)
  chore(version): 2024.06.17.0
  chore(process_tracker): use `const` instead of `String` for `business_status` (#4849)
  ...
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-feature Category: Feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add logger for sessions call failure
4 participants