juspay / hyperswitch

An open source payments switch written in Rust to make payments fast, reliable and affordable
https://hyperswitch.io/
Apache License 2.0
12.34k stars 1.34k forks source link

[FEATURE] Extend the BatchSampleDataInterface Trait for Disputes #6111

Closed apoorvdixit88 closed 2 weeks ago

apoorvdixit88 commented 1 month ago

Feature Description

The issue is sub part of issue: #5991

We currently have a feature for generating sample data, which includes batch insertion of payments and refunds. The feature inserts payments and refunds in batches using the BatchSampleDataInterface trait. We need to extend this functionality to support batch insertion and deletion of disputes as well.

Steps to Implement Batch Support for Disputes

Extend the BatchSampleDataInterface Trait We need to extend the existing BatchSampleDataInterface to include methods for batch insertion and deletion of disputes. These methods will be similar to the ones already implemented for PaymentIntent, PaymentAttempt, and Refund.

New Methods for Disputes: insert_disputes_batch_for_sample_data: This method will handle batch insertion of disputes. delete_disputes_for_sample_data: This method will handle (batch) deletion of disputes.

Possible Implementation

Add Functions for Dispute Insert and Delete in BatchSampleDataInterface

Complete these interface functions for Store, Mock Db and Kafka like we did for other functions.

Write Batch Insert and Delete Queries for Disputes

To test we can hard code some dummy dispute and try inserting using the function we made in core. We can check Db and see the logs for the query that is getting printed.

Steps for Testing Dispute Batch Insertion and Deletion

}'

The JWT token we can get from signup and then skipping the 2FA:

curl --location 'http://localhost:8080/user/signup' \ --header 'Content-Type: application/json' \ --data-raw '{ "email": "JohnTest@test.com", "password": "Test@321" }'

This will give an intermediate token in response, we need to use this token to skip 2FA

curl --location 'http://localhost:8080/user/2fa/terminate?skip_two_factor_auth=true' \ --header 'Authorization: Bearer Intermediatetoken'

This will give us JWT Token that we can use to hit the sample_data api
Curl to delete sample data (The core function for sample dispute delete can be used to our advantage):

curl --location --request DELETE 'http://localhost:8080/user/sample_data' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer JWT' \ --data '{

}'


- We can check Database Logs and Printed Queries whether the appropriate queries are getting printed
- We can also manually check DB 

Note: Omit the Code for Testing part in the PR raised, have only Insert and Delete logic related to the DB, include the relevant logs and screenshots after test.
The Sample disputes generation part, we will be handling in the separate PR. (#6117 )

### Have you spent some time checking if this feature request has been raised before?

- [X] I checked and didn't find a similar issue

### Have you read the Contributing Guidelines?

- [X] I have read the [Contributing Guidelines](https://github.com/juspay/hyperswitch/blob/main/docs/CONTRIBUTING.md)

### Are you willing to submit a PR?

None
qstommyshu commented 1 month ago

Hi @apoorvdixit88 , I can help on this.

qstommyshu commented 1 month ago

Hi @apoorvdixit88 ,

Just wondering which commit should I use as my branch base? I can successfully run hyperswitch using docker compose up -d (I suppose this is production environment?). However, I tried to run the development environment on tagged revision v1.111.3 following this guide but failed. I think I need some guide on setting up the dev environment.

Here is a screen shot of what I encountered: I'm on branch tagged v1.111.3

image

Please let me know how to set up the development environment. Thanks!

apoorvdixit88 commented 4 weeks ago

Hey @qstommyshu I will suggest to Set up Rust and other dependencies natively it will be better for local development. You can use docker to run all other services, but for hyperswitch server local dev will be better.

In the screen shot all the services are running, please clone the repo and make a new branch and you can start the development. You can run the hyperswitch server locally.

Please let me know if you encounter any challenges. Thanks

qstommyshu commented 3 weeks ago

Hi @apoorvdixit88 , I've finished working on this issue. Here is the result:

Before sending a POST request to /sample_data: table payment_intent starts with 18 non-generated records:

image

and table dispute does not have any records:

image

After sending a POST request to /sample_data:

image

table payment_intent now has 118 records:

image

table dispute has 100 records with prefixed test_ dispute_id, payment_id, attempt_id, connector_dispute_id

image

We can also tell disputes are generated from diesel logs, for example, the highlighted area is a generated dispute as we can see keywords PreArbitration and DisputeOpened.

image

Then, we send a DELETE request to /sample_data:

image

We are now left with the original 18 records in the payment_intent table and 0 records for the dispute table:

image image

For now, the /sample_data generates as many disputes as payment intents. I will address the dispute number requirement and randomness requirement in #6117.

Should I submit a PR for this issue or you want me to submit a PR that combines this issue and #6117?

apoorvdixit88 commented 3 weeks ago

Hey @qstommyshu you can raise PR for this issue first.

qstommyshu commented 3 weeks ago

Hi @apoorvdixit88, PR raised, here is the link: https://github.com/juspay/hyperswitch/pull/6293

Please take a look when you are available :)

apoorvdixit88 commented 3 weeks ago

Hey @qstommyshu, the PR looks great. Added few comments, please address.

qstommyshu commented 3 weeks ago

Hi @apoorvdixit88 ,

Thanks for the quick reply. I've addressed all your comments. Please take a look when you are available.

It seems I also accidentally added resolve #5991 to the latest commit, this might close #5991 after the PR is merged. Do you know how can I fix it?

image
apoorvdixit88 commented 3 weeks ago

Hi @apoorvdixit88 ,

Thanks for the quick reply. I've addressed all your comments. Please take a look when you are available.

It seems I also accidentally added resolve #5991 to the latest commit, this might close #5991 after the PR is merged. Do you know how can I fix it? image

For other issue which you mentioned we can do Force Push that removes the issue from commit message. We can Squash commits. But we can simply open issue again after it gets closed. So let it be.

gorakhnathy7 commented 1 week ago

Hey @qstommyshu Thanks for participating! Kindly fill this form once all of your PRs are merged.