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(payments): Add audit events for PaymentUpdate update #6426

Merged
merged 6 commits into from
Nov 8, 2024

Conversation

Rutam21
Copy link
Contributor

@Rutam21 Rutam21 commented Oct 24, 2024

Type of Change

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

Description

This PR adds an Audit event for the PaymentUpdate operation.

Additional Changes

  • This PR modifies the files below

  • crates/router/src/core/payments/operations/payment_update.rs

  • crates/router/src/events/audit_events.rs

Motivation and Context

This PR fixes #4682

How did you test it

  • Hit the Payments - Create endpoint.
    Make a payment with "confirm": false
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_LZcIA7XeMpnK5satp4CDvjcnHCaeKTBcosyuBBJaknZu1odhFo96cwS0nSdfzuJF' \
--data-raw '{
    "amount": 6540,
    "currency": "USD",
    "confirm": false,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "amount_to_capture": 6540,
    "customer_id": "StripeCustomer",
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+65",
    "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",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    },
    "profile_id": "pro_v5sFoHe80OeiUlIonocM"
}'
  • Now hit the Payments - Update endpoint.
{
  "amount": 20000,
  "currency": "SGD",
  "confirm": false,
  "capture_method": "automatic",
  "capture_on": "2022-09-10T10:11:12Z",
  "amount_to_capture": 20000,
  "email": "[email protected]",
  "name": "joseph Doe",
  "phone": "8888888888",
  "phone_country_code": "+65",
  "description": "Its my first payment request",
  "authentication_type": "no_three_ds",
  "payment_method": "card",
  "return_url": "https://google.com",
  "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"
        }
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US"
        }
    },
  "statement_descriptor_name": "joseph",
  "statement_descriptor_suffix": "JS",
  "metadata": {
    "udf1": "value1",
    "new_customer": "true",
    "login_date": "2019-09-10T10:11:12Z"
  }
}

Audit log will get generated and can be viewed in hyperswitch-audit-events topic in kafka with PaymentUpdate event-type.
Amount parameter can be verified in the event.
Screenshot 2024-11-07 at 12 42 34 PM
Screenshot 2024-11-07 at 12 42 42 PM

Now payment can be completed by hitting the Payments - Confirm endpoint.

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code

@Rutam21 Rutam21 requested review from a team as code owners October 24, 2024 11:03
Copy link

semanticdiff-com bot commented Oct 24, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/payments/operations/payment_update.rs  0% smaller
  crates/router/src/events/audit_events.rs  0% smaller

@Rutam21
Copy link
Contributor Author

Rutam21 commented Oct 24, 2024

Please review and suggest changes, if any.

cc: @Isampras @ShivanshMathurJuspay @ivor11

@gorakhnathy7 gorakhnathy7 added the hacktoberfest Issues that are up for grabs for Hacktoberfest participants label Oct 25, 2024
@gorakhnathy7 gorakhnathy7 requested a review from lsampras October 25, 2024 05:07
@lsampras
Copy link
Contributor

Hey @Rutam21 ,
Can you share the event json or a screenshot of the event,
Can refer to pr #4166 for reference.

@Rutam21
Copy link
Contributor Author

Rutam21 commented Oct 28, 2024

@lsampras I checked #4166, can you please point me out how I can get a event screenhsot or event json for this update? It seems like you were using something similar to Postman to hit the API endpoint. If you could please let me know the steps, I would follow along and update.

@maverox
Copy link
Contributor

maverox commented Oct 28, 2024

@lsampras I checked #4166, can you please point me out how I can get a event screenhsot or event json for this update? It seems like you were using something similar to Postman to hit the API endpoint. If you could please let me know the steps, I would follow along and update.

For the UI in this screenshot, you can find the docs to set up Kafka, kafka-ui (the interface in the screenshot) and ClickHouse using Docker Compose here: https://github.com/juspay/hyperswitch/tree/main/crates/analytics/docs

and then try generating said events and monitor logs in kafka-ui.

Also the docs are self-explanatory but still if in any doubt ping us in this slack channel

@gorakhnathy7
Copy link
Collaborator

Hey @Rutam21 Any updates.

@Rutam21
Copy link
Contributor Author

Rutam21 commented Oct 31, 2024

@maverox I tried updating the respective toml files and then starting the app using docker-compose. But this errors out while starting the hyperswitch-server-1. Please let me know if there are some additional settings that I am missing here. Thanks.

Screenshot 2024-10-31 050533

cc: @gorakhnathy7

@maverox
Copy link
Contributor

maverox commented Oct 31, 2024

@maverox I tried updating the respective toml files and then starting the app using docker-compose. But this errors out while starting the hyperswitch-server-1. Please let me know if there are some additional settings that I am missing here. Thanks.

Screenshot 2024-10-31 050533

cc: @gorakhnathy7

hey bro this happens with me as well when i am running the server locally (not containerized)
basically if you do

cargo r

so if your server is running and all these other containers are running as well there shouldn't be any problem try
going to any of the analytics services
kafka-ui or clickhouse playground

make some payments using the api or dashboard and check for new logs there.

@gorakhnathy7 gorakhnathy7 added the hacktoberfest-accepted Pull requests accepted as Hacktoberfest contributions label Oct 31, 2024
tsdk02
tsdk02 previously approved these changes Nov 4, 2024
@tsdk02 tsdk02 self-requested a review November 4, 2024 07:50
@tsdk02 tsdk02 self-requested a review November 4, 2024 07:52
@gorakhnathy7 gorakhnathy7 requested review from Chethan-rao and removed request for lsampras November 5, 2024 06:13
@Rutam21
Copy link
Contributor Author

Rutam21 commented Nov 5, 2024

@tsdk02 I will push another commit to add the amount parameter. Thanks for the suggestion.

@tsdk02
Copy link
Contributor

tsdk02 commented Nov 6, 2024

Hey @Rutam21, a gentle reminder to add the suggested changes to this PR, so it can be merged.

@Rutam21
Copy link
Contributor Author

Rutam21 commented Nov 6, 2024

@tsdk02 I have added the amount parameter to the audit event. Let me know if this looks good. Thanks.

@Rutam21
Copy link
Contributor Author

Rutam21 commented Nov 7, 2024

@tsdk02 Please review and suggest changes, if any. Thanks.

@Rutam21 Rutam21 requested a review from tsdk02 November 7, 2024 10:12
tsdk02
tsdk02 previously approved these changes Nov 7, 2024
Chethan-rao
Chethan-rao previously approved these changes Nov 8, 2024
@Rutam21 Rutam21 dismissed stale reviews from Chethan-rao and tsdk02 via 1e8a326 November 8, 2024 11:06
@Rutam21
Copy link
Contributor Author

Rutam21 commented Nov 8, 2024

The merge conflict is resolved and the branch is updated.

Please review, approve and add to the merge queue. Thanks.

cc: @Chethan-rao @tsdk02 @likhinbopanna

@Rutam21 Rutam21 requested review from tsdk02 and Chethan-rao November 8, 2024 11:09
@likhinbopanna likhinbopanna added this pull request to the merge queue Nov 8, 2024
Merged via the queue into juspay:main with commit 1be2654 Nov 8, 2024
16 of 17 checks passed
@Rutam21 Rutam21 deleted the FEAT-4682 branch November 8, 2024 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Issues that are up for grabs for Hacktoberfest participants hacktoberfest-accepted Pull requests accepted as Hacktoberfest contributions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add audit events for PaymentUpdate update
7 participants