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_v2): rename payment_method and payment_method_type fields and use concrete type for payment_method_data #6555

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

Conversation

SanchithHegde
Copy link
Member

Type of Change

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

Description

This PR involves the following changes in payment methods v2 code:

  • Renames the payment_method field to payment_method_type, and payment_method_type to payment_method_subtype. This change affect the database columns itself, the diesel models, the domain models and the API models.
  • Updates the payment_method_data field in the domain model to have the concrete type wrapped by EncryptedJsonType, instead of the existing serde_json::Value type.
    • The EncryptedJsonType was also introduced in this PR. It adds support to use a concrete type in domain models, while handling the JSON serialization and deserialization before encryption and after decryption of data, respectively.

In addition, this PR removes the PaymentMethodList struct from the API models, which isn't being used anywhere.

By the way, I'm open to better name suggestions for the newly introduced things!

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables
  • This PR renames database columns in payment methods v2 code.
  • This PR renames fields in payment methods v2 API models.
  • This PR removes an unused type from the API models crate.

Motivation and Context

How did you test it?

This PR mostly affects the payment methods v2 code, with focus on the customer payment methods list v2 code. I haven't been able to test these changes, there are still a couple of panics remaining in the customer payment methods list v2 code.

Ideally, nothing in the payment methods v1 code should be affected and existing Postman and Cypress tests should pass.

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

…nceRecord` for v2 and rename `payment_method_type` field to `payment_method_subtype`
…ethod_type_v2` and `payment_method_type` to `payment_method_subtype` respectively
… `payment_method_type` and `payment_method_type` to `payment_method_subtype` respectively
…d_type` and `payment_method_type` to `payment_method_subtype` respectively
…ld in `PaymentMethod` to use `EncryptedJsonType`
@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 Nov 13, 2024
@SanchithHegde SanchithHegde added this to the November 2024 Release milestone Nov 13, 2024
@SanchithHegde SanchithHegde self-assigned this Nov 13, 2024
@SanchithHegde SanchithHegde requested review from a team as code owners November 13, 2024 11:07
Copy link

semanticdiff-com bot commented Nov 13, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/payment_methods/surcharge_decision_configs.rs  96% smaller
  crates/router/src/core/locker_migration.rs  85% smaller
  crates/router/src/core/payments/operations/payment_confirm.rs  82% smaller
  crates/router/src/types/transformers.rs  79% smaller
  crates/router/src/core/customers.rs  61% smaller
  crates/router/src/core/pm_auth.rs  61% smaller
  crates/router/src/core/payments/tokenization.rs  58% smaller
  crates/router/src/core/payment_methods/transformers.rs  39% smaller
  crates/router/src/types/api/mandates.rs  31% smaller
  crates/router/src/core/payments/helpers.rs  28% smaller
  crates/openapi/src/openapi.rs  26% smaller
  api-reference/openapi_spec.json  13% smaller
  api-reference-v2/openapi_spec.json  13% smaller
  crates/openapi/src/openapi_v2.rs  7% smaller
  crates/hyperswitch_domain_models/src/payment_methods.rs  5% smaller
  crates/router/src/types/domain/types.rs  4% smaller
  crates/router/src/core/payment_methods/cards.rs  3% smaller
  crates/hyperswitch_domain_models/src/type_encryption.rs  1% smaller
  crates/api_models/src/events.rs  0% smaller
  crates/api_models/src/events/payment.rs  0% smaller
  crates/api_models/src/payment_methods.rs  0% smaller
  crates/api_models/src/payments.rs  0% smaller
  crates/diesel_models/src/payment_method.rs  0% smaller
  crates/diesel_models/src/schema_v2.rs  0% smaller
  crates/openapi/Cargo.toml Unsupported file format
  crates/router/src/core/payment_methods.rs  0% smaller
  crates/router/src/core/payments.rs  0% smaller
  crates/router/src/routes/payment_methods.rs  0% smaller
  crates/router/src/types/api/payment_methods.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

@SanchithHegde SanchithHegde changed the title refactor(payment_methods_v2): rename payment_method and payment_method_type fields and use conrete type for payment_method_data refactor(payment_methods_v2): rename payment_method and payment_method_type fields and use concrete type for payment_method_data Nov 13, 2024
crates/api_models/src/payment_methods.rs Show resolved Hide resolved
crates/api_models/src/payment_methods.rs Show resolved Hide resolved
crates/router/src/core/customers.rs Show resolved Hide resolved

#[async_trait]
impl<
T: std::fmt::Debug + Clone + serde::Serialize + serde::de::DeserializeOwned + Send,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are case T required Debug? is that necessary.

jarnura
jarnura previously approved these changes Nov 14, 2024
fn get_api_event_type(&self) -> Option<ApiEventsType> {
Some(ApiEventsType::PaymentMethod {
payment_method_id: self.payment_method_id.clone(),
payment_method: self.payment_method_type,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we not changing the field name her?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since renaming the field affects the analytics pipeline, we'd have to include ClickHouse migrations as well.
For now, I'm not including v2 changes in the analytics pipeline.

CC: @ShivanshMathurJuspay @tsdk02

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we renaming payment_method to payment_method_type ?

crates/api_models/src/payment_methods.rs Outdated Show resolved Hide resolved
jarnura
jarnura previously approved these changes Nov 14, 2024
@SanchithHegde SanchithHegde removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Nov 18, 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.

6 participants