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(payment_methods): refactor customer payment methods list v2 code to follow better code practices #6433

Merged
merged 25 commits into from
Nov 8, 2024

Conversation

SanchithHegde
Copy link
Member

Type of Change

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

Description

This PR includes refactors around the customer payment methods list v2 code to follow some of the practices we've started enforcing in the recent few months. Additionally, I've picked up some minor refactors along the way.

This PR contains the following changes:

  • Adds a should_collect_cvv_during_payment column to the business profile v2 table to replace the {merchant_id}_requires_cvv config we used to read previously (and still do in v1) from the configs table.
  • Renames the business_profile field to profile in the SavedPMLPaymentsInfo struct. (This follows the changes done in refactor: Rename business profile to profiles in api, diesel, domain, interface and error types #5877.)
  • Renames the requires_cvv field to collect_cvv_during_payment in SavedPMLPaymentsInfo struct, to follow the new column added in the business profile v2 table.
  • Passes profile to the form_payments_info() method instead of fetching it within the method. Eventually, we'd want to obtain the profile from the authentication layer instead, which would be passed forward.
  • Moves the PaymentsMandateReference from the router crate to the diesel_models crate, and updates the connector_mandate_details field in the payment methods table to use PaymentsMandateReference instead of serde_json::Value in v2 code. (This should help reduce / prevent invalid data being stored in this column of the database.)
  • Refactors the get_mca_status() function to avoid a possible database call (to fetch merchant connector accounts associated with a merchant / profile) happening within an iterator.
  • Drops the metadata column from the payment methods table and API models in v2 code, since it isn't being actively used in v1 code anyway. Neither do any of our hosted environments have any useful data stored in that column.

The other minor refactors I took up along the way include:

  • Improves the doc comment for the is_network_tokenization_enabled field in profile API models.
  • Update the ExtendedCardInfoUpdate, ConnectorAgnosticMitUpdate and NetworkTokenizationUpdate enum variants of the ProfileUpdate domain model enum to have required fields instead of optional ones. (This is because these variants either enable something or not, and we always have the value to be updated in all cases.)
  • Uses serialize_and_set_key_with_expiry() when storing payment method token in Redis instead of explicit JSON serialization happening in business logic.
  • Replace usages of create_payment_method() (which only seemed to be updating the metadata field, and was thus confusing) with a correct apply_changeset() implementation. This change only affects MockDb implementation.

The PR can be reviewed one commit at a time, if that helps ease reviews.

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables
  • This PR adds a new column in the business profile v2 database table and corresponding field in the business profile v2 API models.
  • This PR drops the metadata column from the payment methods v2 database table and corresponding payment methods v2 API models.

Motivation and Context

This PR contains only a subset of the changes / improvements that can help us in arriving at the final implementation of the customer payment methods list v2 API. There are still a few more refactors pending, which would be taken up in subsequent PRs.

How did you test it?

Haven't been able to test these changes, there are still a couple of panics remaining in the customer payment methods list v2 code.

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

…ng_payment` in `SavedPMLPaymentsInfo` and populate it from profile
…Value` for `connector_mandate_details` field
…when storing payment method token in Redis
…` with a correct `apply_changeset()` implementation
… not actively being used in v1

There does not seem to be any useful information in this column in any of our hosted environments either.
@SanchithHegde SanchithHegde added S-waiting-on-review Status: This PR has been implemented and needs to be reviewed M-database-changes Metadata: This PR involves database schema changes A-payment-methods Area: Payment Methods C-refactor Category: Refactor M-api-contract-changes Metadata: This PR involves API contract changes api-v2 labels Oct 24, 2024
@SanchithHegde SanchithHegde added this to the October 2024 Release milestone Oct 24, 2024
@SanchithHegde SanchithHegde self-assigned this Oct 24, 2024
Copy link

semanticdiff-com bot commented Oct 24, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  crates/hyperswitch_connectors/src/connectors/deutschebank/transformers.rs  97% smaller
  crates/router/src/core/payments.rs  94% smaller
  api-reference/openapi_spec.json  48% smaller
  crates/api_models/src/admin.rs  46% smaller
  crates/router/src/db/payment_method.rs  38% smaller
  api-reference-v2/openapi_spec.json  34% smaller
  crates/router/src/types/payment_methods.rs  25% smaller
  crates/router/src/core/payment_methods.rs  16% smaller
  crates/diesel_models/src/payment_method.rs  13% smaller
  crates/router/src/core/payment_methods/cards.rs  9% smaller
  crates/hyperswitch_domain_models/src/business_profile.rs  7% smaller
  crates/router/src/core/payments/tokenization.rs  1% smaller
  Cargo.lock Unsupported file format
  crates/api_models/src/payment_methods.rs  0% smaller
  crates/api_models/src/payments.rs  0% smaller
  crates/diesel_models/src/business_profile.rs  0% smaller
  crates/diesel_models/src/payment_attempt.rs  0% smaller
  crates/diesel_models/src/schema_v2.rs  0% smaller
  crates/hyperswitch_domain_models/src/merchant_connector_account.rs  0% smaller
  crates/hyperswitch_domain_models/src/payment_methods.rs  0% smaller
  crates/hyperswitch_domain_models/src/router_data.rs  0% smaller
  crates/hyperswitch_domain_models/src/router_response_types.rs  0% smaller
  crates/router/src/core/admin.rs  0% smaller
  crates/router/src/core/payment_methods/transformers.rs  0% smaller
  crates/router/src/core/payments/operations/payment_response.rs  0% smaller
  crates/router/src/routes/payment_methods.rs  0% smaller
  crates/router/src/services/authentication.rs  0% smaller
  crates/router/src/types/api/admin.rs  0% smaller
  crates/router/src/types/storage/payment_method.rs  0% smaller
  v2_migrations/2024-08-23-112510_payment_methods_v2_db_changes/down.sql Unsupported file format
  v2_migrations/2024-08-23-112510_payment_methods_v2_db_changes/up.sql Unsupported file format
  v2_migrations/2024-08-28-081721_add_v2_columns/down.sql Unsupported file format
  v2_migrations/2024-08-28-081721_add_v2_columns/up.sql Unsupported file format

@SanchithHegde SanchithHegde marked this pull request as ready for review October 25, 2024 06:00
@SanchithHegde SanchithHegde requested review from a team as code owners October 25, 2024 06:00
@SanchithHegde SanchithHegde requested a review from a team as a code owner November 4, 2024 17:44
crates/diesel_models/src/payment_method.rs Show resolved Hide resolved
crates/diesel_models/src/payment_method.rs Outdated Show resolved Hide resolved
@SanchithHegde SanchithHegde requested a review from a team as a code owner November 5, 2024 11:30
jarnura
jarnura previously approved these changes Nov 6, 2024
ThisIsMani
ThisIsMani previously approved these changes Nov 6, 2024
Sarthak1799
Sarthak1799 previously approved these changes Nov 6, 2024
@likhinbopanna likhinbopanna added this pull request to the merge queue Nov 8, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 8, 2024
@likhinbopanna likhinbopanna added this pull request to the merge queue Nov 8, 2024
Merged via the queue into main with commit 0389ae7 Nov 8, 2024
16 of 17 checks passed
@likhinbopanna likhinbopanna deleted the customer-payment-method-list-v2 branch November 8, 2024 14:57
@SanchithHegde SanchithHegde removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Nov 8, 2024
bsayak03 pushed a commit that referenced this pull request Nov 26, 2024
bsayak03 pushed a commit that referenced this pull request Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-payment-methods Area: Payment Methods api-v2 C-refactor Category: Refactor M-api-contract-changes Metadata: This PR involves API contract changes M-database-changes Metadata: This PR involves database schema changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants