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

refactor(dynamic_routing): perform db operations for dynamic_routing_stats table only when payments are in terminal state #6900

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

prajjwalkumar17
Copy link
Contributor

@prajjwalkumar17 prajjwalkumar17 commented Dec 19, 2024

Type of Change

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

Description

Previously due to the DB insertion code being in post_update_tracker was being called several times as our payment's status keeps on changing, due to this our DB broke as we had a unique constraint on attempt_id in the dynamic_routing_stats table.
To fix this we have added a check that only the payments that are in terminal state will be pushed, which ensures that the insert in db will be called only once for one attempt_id.

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?

  1. Toggle Success Based routing for the merchant.
curl --location --request POST 'http://localhost:8080/account/xxxxxx/business_profile/xxxxxxx/dynamic_routing/success_based/toggle?enable=metrics' \
--header 'api-key: xxxxxxx'
  1. Create a payment that goes in processing state or any non terminal state. (VOLTE)
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: xxxxxxxx' \
--data-raw '{
    "amount": 8000,
    "currency": "EUR",
    "confirm": true,
      "capture_method": "automatic",
      "capture_on": "2022-09-10T10:11:12Z",
      "amount_to_capture": 8000,
    "customer_id": "StripeCustomer",
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+1",
    "description": "Its my first payment request",
      "authentication_type": "no_three_ds",
    "return_url": "https://www.google.com/",
    "payment_method": "bank_redirect",
    "payment_method_type": "open_banking_uk",
    "payment_method_data": {
        "bank_redirect": {
            "open_banking_uk": {
            }
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "DE",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        }
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "DE",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        }
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    },
    "profile_id": "xxxxx"
}

'
  1. Hit the 3ds link and cancel the payment
  2. Check dynamic_routing_stats table for the entry of attempt, it should be there.

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

@prajjwalkumar17 prajjwalkumar17 added A-core Area: Core flows C-refactor Category: Refactor labels Dec 19, 2024
@prajjwalkumar17 prajjwalkumar17 added this to the December 2024 Release milestone Dec 19, 2024
@prajjwalkumar17 prajjwalkumar17 self-assigned this Dec 19, 2024
@prajjwalkumar17 prajjwalkumar17 requested review from a team as code owners December 19, 2024 14:48
Copy link

semanticdiff-com bot commented Dec 19, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/payments/operations/payment_response.rs  80% smaller
  crates/common_enums/src/enums.rs  0% smaller

@prajjwalkumar17 prajjwalkumar17 changed the title refactor(dynamic_routing): perform db operations only when payments are in terminal state refactor(dynamic_routing): perform db operations for dynamic_routing_stats table only when payments are in terminal state Dec 23, 2024
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-refactor Category: Refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactor(dynamic_routing): perform db operations only when payments are in terminal state
4 participants