Skip to content

Commit

Permalink
diesel: Added api_version + resolved comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarthak1799 committed Sep 2, 2024
1 parent f4a6e33 commit a156223
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 13 deletions.
6 changes: 6 additions & 0 deletions crates/diesel_models/src/payment_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub struct PaymentMethod {
pub client_secret: Option<String>,
pub payment_method_billing_address: Option<Encryption>,
pub updated_by: Option<String>,
pub version: common_enums::ApiVersion,
}

#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
Expand Down Expand Up @@ -85,6 +86,7 @@ pub struct PaymentMethod {
pub updated_by: Option<String>,
pub locker_fingerprint_id: Option<String>,
pub id: String,
pub version: common_enums::ApiVersion,
}

impl PaymentMethod {
Expand Down Expand Up @@ -141,6 +143,7 @@ pub struct PaymentMethodNew {
pub client_secret: Option<String>,
pub payment_method_billing_address: Option<Encryption>,
pub updated_by: Option<String>,
pub version: common_enums::ApiVersion,
}

#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
Expand Down Expand Up @@ -168,6 +171,7 @@ pub struct PaymentMethodNew {
pub updated_by: Option<String>,
pub locker_fingerprint_id: Option<String>,
pub id: String,
pub version: common_enums::ApiVersion,
}

impl PaymentMethodNew {
Expand Down Expand Up @@ -708,6 +712,7 @@ impl From<&PaymentMethodNew> for PaymentMethod {
payment_method_billing_address: payment_method_new
.payment_method_billing_address
.clone(),
version: payment_method_new.version,
}
}
}
Expand Down Expand Up @@ -737,6 +742,7 @@ impl From<&PaymentMethodNew> for PaymentMethod {
.clone(),
id: payment_method_new.id.clone(),
locker_fingerprint_id: payment_method_new.locker_fingerprint_id.clone(),
version: payment_method_new.version,
}
}
}
1 change: 1 addition & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@ diesel::table! {
payment_method_billing_address -> Nullable<Bytea>,
#[max_length = 64]
updated_by -> Nullable<Varchar>,
version -> ApiVersion,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/diesel_models/src/schema_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@ diesel::table! {
locker_fingerprint_id -> Nullable<Varchar>,
#[max_length = 64]
id -> Varchar,
version -> ApiVersion,
}
}

Expand Down
8 changes: 8 additions & 0 deletions crates/hyperswitch_domain_models/src/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub struct PaymentMethod {
pub client_secret: Option<String>,
pub payment_method_billing_address: OptionalEncryptableValue,
pub updated_by: Option<String>,
pub version: common_enums::ApiVersion,
}

#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
Expand All @@ -74,6 +75,7 @@ pub struct PaymentMethod {
pub updated_by: Option<String>,
pub locker_fingerprint_id: Option<String>,
pub id: String,
pub version: common_enums::ApiVersion,
}

impl PaymentMethod {
Expand Down Expand Up @@ -133,6 +135,7 @@ impl super::behaviour::Conversion for PaymentMethod {
.payment_method_billing_address
.map(|val| val.into()),
updated_by: self.updated_by,
version: self.version,
})
}

Expand Down Expand Up @@ -203,6 +206,7 @@ impl super::behaviour::Conversion for PaymentMethod {
})
.await?,
updated_by: item.updated_by,
version: item.version,
})
}
.await
Expand Down Expand Up @@ -245,6 +249,7 @@ impl super::behaviour::Conversion for PaymentMethod {
.payment_method_billing_address
.map(|val| val.into()),
updated_by: self.updated_by,
version: self.version,
})
}
}
Expand Down Expand Up @@ -277,6 +282,7 @@ impl super::behaviour::Conversion for PaymentMethod {
.map(|val| val.into()),
updated_by: self.updated_by,
locker_fingerprint_id: self.locker_fingerprint_id,
version: self.version,
})
}

Expand Down Expand Up @@ -336,6 +342,7 @@ impl super::behaviour::Conversion for PaymentMethod {
.await?,
updated_by: item.updated_by,
locker_fingerprint_id: item.locker_fingerprint_id,
version: item.version,
})
}
.await
Expand Down Expand Up @@ -367,6 +374,7 @@ impl super::behaviour::Conversion for PaymentMethod {
.map(|val| val.into()),
updated_by: self.updated_by,
locker_fingerprint_id: self.locker_fingerprint_id,
version: self.version,
})
}
}
2 changes: 2 additions & 0 deletions crates/router/src/core/payment_methods/cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ pub async fn create_payment_method(
last_used_at: current_time,
payment_method_billing_address,
updated_by: None,
version: enums::ApiVersion::V1,
},
storage_scheme,
)
Expand Down Expand Up @@ -748,6 +749,7 @@ pub async fn skip_locker_call_and_migrate_payment_method(
last_used_at: current_time,
payment_method_billing_address: payment_method_billing_address.map(Into::into),
updated_by: None,
version: enums::ApiVersion::V1,
},
merchant_account.storage_scheme,
)
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/core/pm_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ async fn store_bank_details_in_payment_methods(
client_secret: None,
payment_method_billing_address: None,
updated_by: None,
version: enums::ApiVersion::V1,
};

#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
Expand All @@ -543,6 +544,7 @@ async fn store_bank_details_in_payment_methods(
payment_method_billing_address: None,
updated_by: None,
locker_fingerprint_id: None,
version: enums::ApiVersion::V2,
};

new_entries.push(pm_new);
Expand Down
12 changes: 6 additions & 6 deletions crates/router/src/db/customers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ mod storage {
MerchantStorageScheme::RedisKv => {
let key = PartitionKey::MerchantIdCustomerId {
merchant_id,
customer_id: customer_id.get_string_repr(),
customer_id,
};
let field = format!("cust_{}", customer_id.get_string_repr());
Box::pin(db_utils::try_redis_get_else_try_database_get(
Expand Down Expand Up @@ -267,9 +267,9 @@ mod storage {
let maybe_customer = match storage_scheme {
MerchantStorageScheme::PostgresOnly => database_call().await,
MerchantStorageScheme::RedisKv => {
let key = PartitionKey::MerchantIdCustomerId {
let key = PartitionKey::MerchantIdMerchantReferenceId {
merchant_id,
customer_id: merchant_reference_id.get_string_repr(),
merchant_reference_id: merchant_reference_id.get_string_repr(),
};
let field = format!("cust_{}", merchant_reference_id.get_string_repr());
Box::pin(db_utils::try_redis_get_else_try_database_get(
Expand Down Expand Up @@ -339,7 +339,7 @@ mod storage {
};
let key = PartitionKey::MerchantIdCustomerId {
merchant_id: &merchant_id,
customer_id: customer_id.get_string_repr(),
customer_id: &customer_id,
};
let field = format!("cust_{}", customer_id.get_string_repr());
let storage_scheme = decide_storage_scheme::<_, diesel_models::Customer>(
Expand Down Expand Up @@ -487,7 +487,7 @@ mod storage {
MerchantStorageScheme::RedisKv => {
let key = PartitionKey::MerchantIdCustomerId {
merchant_id,
customer_id: customer_id.get_string_repr(),
customer_id,
};
let field = format!("cust_{}", customer_id.get_string_repr());
Box::pin(db_utils::try_redis_get_else_try_database_get(
Expand Down Expand Up @@ -670,7 +670,7 @@ mod storage {
MerchantStorageScheme::RedisKv => {
let key = PartitionKey::MerchantIdCustomerId {
merchant_id: &merchant_id,
customer_id: customer_id.get_string_repr(),
customer_id: &customer_id,
};
let field = format!("cust_{}", customer_id.get_string_repr());

Expand Down
8 changes: 4 additions & 4 deletions crates/router/src/db/payment_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ mod storage {

let key = PartitionKey::MerchantIdCustomerId {
merchant_id: &merchant_id,
customer_id: customer_id.get_string_repr(),
customer_id: &customer_id,
};
let key_str = key.to_string();
let field = format!("payment_method_id_{}", payment_method_new.get_id());
Expand Down Expand Up @@ -494,7 +494,7 @@ mod storage {
let customer_id = payment_method.customer_id.clone();
let key = PartitionKey::MerchantIdCustomerId {
merchant_id: &merchant_id,
customer_id: customer_id.get_string_repr(),
customer_id: &customer_id,
};
let field = format!("payment_method_id_{}", payment_method.get_id());
let storage_scheme = decide_storage_scheme::<_, storage_types::PaymentMethod>(
Expand Down Expand Up @@ -580,7 +580,7 @@ mod storage {
let customer_id = payment_method.customer_id.clone();
let key = PartitionKey::MerchantIdCustomerId {
merchant_id: &merchant_id,
customer_id: customer_id.get_string_repr(),
customer_id: &customer_id,
};
let field = format!("payment_method_id_{}", payment_method.get_id());
let storage_scheme = decide_storage_scheme::<_, storage_types::PaymentMethod>(
Expand Down Expand Up @@ -718,7 +718,7 @@ mod storage {
MerchantStorageScheme::RedisKv => {
let key = PartitionKey::MerchantIdCustomerId {
merchant_id,
customer_id: customer_id.get_string_repr(),
customer_id,
};

let pattern = "payment_method_id_*";
Expand Down
7 changes: 4 additions & 3 deletions crates/storage_impl/src/redis/kv_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub enum PartitionKey<'a> {
},
MerchantIdCustomerId {
merchant_id: &'a common_utils::id_type::MerchantId,
customer_id: &'a str,
customer_id: &'a common_utils::id_type::CustomerId,
},
#[cfg(all(feature = "v2", feature = "customer_v2"))]
MerchantIdMerchantReferenceId {
Expand Down Expand Up @@ -72,8 +72,9 @@ impl<'a> std::fmt::Display for PartitionKey<'a> {
merchant_id,
customer_id,
} => f.write_str(&format!(
"mid_{}_cust_{customer_id}",
merchant_id.get_string_repr()
"mid_{}_cust_{}",
merchant_id.get_string_repr(),
customer_id.get_string_repr()
)),
#[cfg(all(feature = "v2", feature = "customer_v2"))]
PartitionKey::MerchantIdMerchantReferenceId {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
ALTER TABLE payment_methods DROP COLUMN IF EXISTS version;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Your SQL goes here
ALTER TABLE payment_methods
ADD COLUMN IF NOT EXISTS version "ApiVersion" NOT NULL DEFAULT 'v1';

0 comments on commit a156223

Please sign in to comment.