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(opensearch): Updated status filter field name to match index and added time-range based search #5468

Merged
merged 8 commits into from
Aug 1, 2024

Conversation

tsdk02
Copy link
Contributor

@tsdk02 tsdk02 commented Jul 29, 2024

Type of Change

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

Description

Task 1

The status field is different in different indexes:

  • status in Payment Attempts and Payment Intents
  • refund_status in Refunds
  • dispute_status in Disputes

The correct mapping of status for each index is done, to get the search-results

Task 2

Added Time Range based search for the OpenSearch query

Additional Changes

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

Motivation and Context

Giving a better search experience for the merchants through the dashboard global-search

How did you test it?

Tested through Postman curls:

Task 1

  • Make a payment
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_8z4jfpKL8jjyFFbnQ29mzfnGQYbtwi7CAE52JjUFpzro8ZC5iSK5NyFZkr4paZ6o' \
--data-raw '{
  "amount": 6540,
  "currency": "INR",
  "confirm": true,
  "capture_method": "automatic",
  "capture_on": "2022-09-10T10:11:12Z",
  "amount_to_capture": 6540,
  "customer_id": "StripeCustomer",
  "email": "test@test6.com",
  "name": "John Doe",
  "phone": "999999999",
  "phone_country_code": "+1",
  "description": "Its my first payment request",
  "authentication_type": "no_three_ds",
  "return_url": "https://google.com",
  "payment_method": "card",
  "payment_method_type": "credit",
  "payment_method_data": {
    "card": {
      "card_number": "4242424242424242",
      "card_exp_month": "10",
      "card_exp_year": "25",
      "card_holder_name": "joseph Doe",
      "card_cvc": "123"
    }
  },
  "billing": {
    "address": {
      "line1": "1467",
      "line2": "Harrison Street",
      "line3": "Harrison Street",
      "city": "San Fransico",
      "state": "California",
      "zip": "94122",
      "country": "US",
      "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": "US",
      "first_name": "joseph",
      "last_name": "Doe"
    },
    "phone": {
      "number": "8056594427",
      "country_code": "+91"
    }
  },
  "statement_descriptor_name": "joseph",
  "statement_descriptor_suffix": "JS",
  "feature_metadata": {
    "search_tags": ["cc", "dd"]
  },
  "metadata": {
    "data2": "camel",
    "new_customer": "true",
    "login_date": "2019-09-10T10:11:12Z"
  }
}'
  • Hit the search API with status as success
    This will return the results of Refunds as internally, the status field gets converted into refund_status and success is the Successful operation in Refunds
curl --location 'http://localhost:8080/analytics/v1/search' \
--header 'Accept: */*' \
--header 'Accept-Language: en-US,en;q=0.9' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/json' \
--header 'Origin: http://localhost:9000' \
--header 'Referer: http://localhost:9000/' \
--header 'Sec-Fetch-Dest: empty' \
--header 'Sec-Fetch-Mode: cors' \
--header 'Sec-Fetch-Site: same-site' \
--header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36' \
--header 'api-key: hyperswitch' \
--header 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiYjc2ZDVmZjMtNGI1ZS00OTMyLTk1ZDItNmE3MTEyZWZiNTNlIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzIxODE1MjkwIiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTcyMjY3NTU3MSwib3JnX2lkIjoib3JnX3VFNk1LbExxalU5MWlGUEVGck1rIn0.inysDehseXLwSvbWbDEVbL2q3oUJMm2h8okCDss1kGY' \
--header 'sec-ch-ua: "Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"' \
--header 'sec-ch-ua-mobile: ?0' \
--header 'sec-ch-ua-platform: "macOS"' \
--data '{
    "query": "inr",
    "filters": {
        "status": [
            "success"
        ]
    }
}'
image

Task 2

  • Make a payment
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_8z4jfpKL8jjyFFbnQ29mzfnGQYbtwi7CAE52JjUFpzro8ZC5iSK5NyFZkr4paZ6o' \
--data-raw '{
  "amount": 6540,
  "currency": "INR",
  "confirm": true,
  "capture_method": "automatic",
  "capture_on": "2022-09-10T10:11:12Z",
  "amount_to_capture": 6540,
  "customer_id": "StripeCustomer",
  "email": "test@test6.com",
  "name": "John Doe",
  "phone": "999999999",
  "phone_country_code": "+1",
  "description": "Its my first payment request",
  "authentication_type": "no_three_ds",
  "return_url": "https://google.com",
  "payment_method": "card",
  "payment_method_type": "credit",
  "payment_method_data": {
    "card": {
      "card_number": "4242424242424242",
      "card_exp_month": "10",
      "card_exp_year": "25",
      "card_holder_name": "joseph Doe",
      "card_cvc": "123"
    }
  },
  "billing": {
    "address": {
      "line1": "1467",
      "line2": "Harrison Street",
      "line3": "Harrison Street",
      "city": "San Fransico",
      "state": "California",
      "zip": "94122",
      "country": "US",
      "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": "US",
      "first_name": "joseph",
      "last_name": "Doe"
    },
    "phone": {
      "number": "8056594427",
      "country_code": "+91"
    }
  },
  "statement_descriptor_name": "joseph",
  "statement_descriptor_suffix": "JS",
  "feature_metadata": {
    "search_tags": ["cc", "dd"]
  },
  "metadata": {
    "data2": "camel",
    "new_customer": "true",
    "login_date": "2019-09-10T10:11:12Z"
  }
}'
  • Hit the Search API:
    Able to search based on the timeRange included in the request body
curl --location 'http://localhost:8080/analytics/v1/search' \
--header 'Accept: */*' \
--header 'Accept-Language: en-US,en;q=0.9' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/json' \
--header 'Origin: http://localhost:9000' \
--header 'Referer: http://localhost:9000/' \
--header 'Sec-Fetch-Dest: empty' \
--header 'Sec-Fetch-Mode: cors' \
--header 'Sec-Fetch-Site: same-site' \
--header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36' \
--header 'api-key: hyperswitch' \
--header 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiYjc2ZDVmZjMtNGI1ZS00OTMyLTk1ZDItNmE3MTEyZWZiNTNlIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzIxODE1MjkwIiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTcyMjQxNTgyOSwib3JnX2lkIjoib3JnX3VFNk1LbExxalU5MWlGUEVGck1rIn0.GUmj5mbLgnYVanig6kwrU_gvLARQU4E68s438dvrhdc' \
--header 'sec-ch-ua: "Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"' \
--header 'sec-ch-ua-mobile: ?0' \
--header 'sec-ch-ua-platform: "macOS"' \
--data-raw '{
    "query": "inr",
    "filters": {
        "customer_email": [
            "test@test6.com"
        ],
        "status": [
            "succeeded"
        ]
    },
    "timeRange": {
        "startTime": "2024-07-29T00:30:00Z",
        "endTime": "2024-07-31T18:45:00Z"
    }
}'
image

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

@tsdk02 tsdk02 self-assigned this Jul 29, 2024
@tsdk02 tsdk02 requested a review from a team as a code owner July 29, 2024 10:11
@tsdk02 tsdk02 linked an issue Jul 29, 2024 that may be closed by this pull request
@tsdk02 tsdk02 changed the title feat(opensearch): Updated status filter field name and values to match index and fetch results feat(opensearch): Updated status filter field name and values to match index and add time-range based search Jul 30, 2024
@ShivanshMathurJuspay ShivanshMathurJuspay linked an issue Jul 31, 2024 that may be closed by this pull request
2 tasks
@tsdk02 tsdk02 changed the title feat(opensearch): Updated status filter field name and values to match index and add time-range based search feat(opensearch): Updated status filter field name and values to match index and added time-range based search Aug 1, 2024
@tsdk02 tsdk02 changed the title feat(opensearch): Updated status filter field name and values to match index and added time-range based search feat(opensearch): Updated status filter field name to match index and added time-range based search Aug 1, 2024
@likhinbopanna likhinbopanna added this pull request to the merge queue Aug 1, 2024
Merged via the queue into main with commit 625f5ae Aug 1, 2024
66 checks passed
@likhinbopanna likhinbopanna deleted the opensearch-index-specific-filters branch August 1, 2024 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants