Skip to content

Commit

Permalink
feat(payment_methods_v2): implement a barebones version of list custo…
Browse files Browse the repository at this point in the history
…mer payment methods v2 (#6649)
  • Loading branch information
SanchithHegde authored Dec 2, 2024
1 parent 982b26a commit 797a0db
Show file tree
Hide file tree
Showing 15 changed files with 173 additions and 187 deletions.
8 changes: 4 additions & 4 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -7153,6 +7153,7 @@
"customer_id",
"payment_method_type",
"recurring_enabled",
"created",
"requires_cvv",
"is_default"
],
Expand Down Expand Up @@ -7210,9 +7211,8 @@
"created": {
"type": "string",
"format": "date-time",
"description": "A timestamp (ISO 8601 code) that determines when the customer was created",
"example": "2023-01-18T11:04:09.922Z",
"nullable": true
"description": "A timestamp (ISO 8601 code) that determines when the payment method was created",
"example": "2023-01-18T11:04:09.922Z"
},
"surcharge_details": {
"allOf": [
Expand Down Expand Up @@ -13542,7 +13542,7 @@
"created": {
"type": "string",
"format": "date-time",
"description": "A timestamp (ISO 8601 code) that determines when the customer was created",
"description": "A timestamp (ISO 8601 code) that determines when the payment method was created",
"example": "2023-01-18T11:04:09.922Z",
"nullable": true
},
Expand Down
4 changes: 2 additions & 2 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -9739,7 +9739,7 @@
"created": {
"type": "string",
"format": "date-time",
"description": "A timestamp (ISO 8601 code) that determines when the customer was created",
"description": "A timestamp (ISO 8601 code) that determines when the payment method was created",
"example": "2023-01-18T11:04:09.922Z",
"nullable": true
},
Expand Down Expand Up @@ -16326,7 +16326,7 @@
"created": {
"type": "string",
"format": "date-time",
"description": "A timestamp (ISO 8601 code) that determines when the customer was created",
"description": "A timestamp (ISO 8601 code) that determines when the payment method was created",
"example": "2023-01-18T11:04:09.922Z",
"nullable": true
},
Expand Down
14 changes: 7 additions & 7 deletions crates/api_models/src/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ pub struct PaymentMethodResponse {
#[schema(value_type = Option<Object>, example = json!({ "city": "NY", "unit": "245" }))]
pub metadata: Option<pii::SecretSerdeValue>,

/// A timestamp (ISO 8601 code) that determines when the customer was created
/// A timestamp (ISO 8601 code) that determines when the payment method was created
#[schema(value_type = Option<PrimitiveDateTime>, example = "2023-01-18T11:04:09.922Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub created: Option<time::PrimitiveDateTime>,
Expand Down Expand Up @@ -801,7 +801,7 @@ pub struct PaymentMethodResponse {
#[schema(example = true)]
pub recurring_enabled: bool,

/// A timestamp (ISO 8601 code) that determines when the customer was created
/// A timestamp (ISO 8601 code) that determines when the payment method was created
#[schema(value_type = Option<PrimitiveDateTime>, example = "2023-01-18T11:04:09.922Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub created: Option<time::PrimitiveDateTime>,
Expand Down Expand Up @@ -1802,10 +1802,10 @@ pub struct CustomerPaymentMethod {
#[schema(example = json!({"mask": "0000"}))]
pub bank: Option<MaskedBankDetails>,

/// A timestamp (ISO 8601 code) that determines when the customer was created
#[schema(value_type = Option<PrimitiveDateTime>,example = "2023-01-18T11:04:09.922Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub created: Option<time::PrimitiveDateTime>,
/// A timestamp (ISO 8601 code) that determines when the payment method was created
#[schema(value_type = PrimitiveDateTime, example = "2023-01-18T11:04:09.922Z")]
#[serde(with = "common_utils::custom_serde::iso8601")]
pub created: time::PrimitiveDateTime,

/// Surcharge details for this saved card
pub surcharge_details: Option<SurchargeDetailsResponse>,
Expand Down Expand Up @@ -1890,7 +1890,7 @@ pub struct CustomerPaymentMethod {
#[schema(value_type = Option<Object>,example = json!({ "city": "NY", "unit": "245" }))]
pub metadata: Option<pii::SecretSerdeValue>,

/// A timestamp (ISO 8601 code) that determines when the customer was created
/// A timestamp (ISO 8601 code) that determines when the payment method was created
#[schema(value_type = Option<PrimitiveDateTime>,example = "2023-01-18T11:04:09.922Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub created: Option<time::PrimitiveDateTime>,
Expand Down
4 changes: 2 additions & 2 deletions crates/common_utils/src/id_type/global_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub(crate) enum GlobalIdError {
impl GlobalId {
/// Create a new global id from entity and cell information
/// The entity prefix is used to identify the entity, `cus` for customers, `pay`` for payments etc.
pub fn generate(cell_id: CellId, entity: GlobalEntity) -> Self {
pub fn generate(cell_id: &CellId, entity: GlobalEntity) -> Self {
let prefix = format!("{}_{}", cell_id.get_string_repr(), entity.prefix());
let id = generate_time_ordered_id(&prefix);
let alphanumeric_id = AlphaNumericId::new_unchecked(id);
Expand Down Expand Up @@ -201,7 +201,7 @@ mod global_id_tests {
let cell_id_string = "12345";
let entity = GlobalEntity::Customer;
let cell_id = CellId::from_str(cell_id_string).unwrap();
let global_id = GlobalId::generate(cell_id, entity);
let global_id = GlobalId::generate(&cell_id, entity);

/// Generate a regex for globalid
/// Eg - 12abc_cus_abcdefghijklmnopqrstuvwxyz1234567890
Expand Down
4 changes: 2 additions & 2 deletions crates/common_utils/src/id_type/global_id/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl GlobalPaymentId {
}

/// Generate a new GlobalPaymentId from a cell id
pub fn generate(cell_id: crate::id_type::CellId) -> Self {
pub fn generate(cell_id: &crate::id_type::CellId) -> Self {
let global_id = super::GlobalId::generate(cell_id, super::GlobalEntity::Payment);
Self(global_id)
}
Expand Down Expand Up @@ -57,7 +57,7 @@ crate::impl_to_sql_from_sql_global_id_type!(GlobalAttemptId);
impl GlobalAttemptId {
/// Generate a new GlobalAttemptId from a cell id
pub fn generate(cell_id: &super::CellId) -> Self {
let global_id = super::GlobalId::generate(cell_id.clone(), super::GlobalEntity::Attempt);
let global_id = super::GlobalId::generate(cell_id, super::GlobalEntity::Attempt);
Self(global_id)
}

Expand Down
5 changes: 1 addition & 4 deletions crates/common_utils/src/id_type/global_id/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ pub enum GlobalPaymentMethodIdError {

impl GlobalPaymentMethodId {
/// Create a new GlobalPaymentMethodId from cell id information
pub fn generate(cell_id: &str) -> error_stack::Result<Self, GlobalPaymentMethodIdError> {
let cell_id = CellId::from_str(cell_id)
.change_context(GlobalPaymentMethodIdError::ConstructionError)
.attach_printable("Failed to construct CellId from str")?;
pub fn generate(cell_id: &CellId) -> error_stack::Result<Self, GlobalPaymentMethodIdError> {
let global_id = GlobalId::generate(cell_id, GlobalEntity::PaymentMethod);
Ok(Self(global_id))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/common_utils/src/id_type/global_id/refunds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl GlobalRefundId {
}

/// Generate a new GlobalRefundId from a cell id
pub fn generate(cell_id: crate::id_type::CellId) -> Self {
pub fn generate(cell_id: &crate::id_type::CellId) -> Self {
let global_id = super::GlobalId::generate(cell_id, super::GlobalEntity::Refund);
Self(global_id)
}
Expand Down
7 changes: 3 additions & 4 deletions crates/hyperswitch_domain_models/src/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use masking::{PeekInterface, Secret};
use time::PrimitiveDateTime;

#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
use crate::type_encryption::EncryptedJsonType;
use crate::type_encryption::OptionalEncryptableJsonType;
use crate::type_encryption::{crypto_operation, AsyncLift, CryptoOperation};

#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
Expand Down Expand Up @@ -80,9 +80,8 @@ pub struct PaymentMethod {
pub last_modified: PrimitiveDateTime,
pub payment_method_type: Option<storage_enums::PaymentMethod>,
pub payment_method_subtype: Option<storage_enums::PaymentMethodType>,
pub payment_method_data: Option<
Encryptable<Secret<EncryptedJsonType<api_models::payment_methods::PaymentMethodsData>>>,
>,
pub payment_method_data:
OptionalEncryptableJsonType<api_models::payment_methods::PaymentMethodsData>,
pub locker_id: Option<VaultId>,
pub last_used_at: PrimitiveDateTime,
pub connector_mandate_details: Option<diesel_models::PaymentsMandateReference>,
Expand Down
Loading

0 comments on commit 797a0db

Please sign in to comment.