chore: Resolved comments

This commit is contained in:
Sarthak Soni
2025-10-27 15:32:22 +05:30
parent e9c618d06b
commit a3d4c4951f
2 changed files with 55 additions and 0 deletions

View File

@ -1,7 +1,9 @@
use common_enums::connector_enums::InvoiceStatus;
use common_types::payments::CustomerAcceptance;
use common_utils::{
errors::ValidationError,
events::ApiEventMetric,
fp_utils,
id_type::{
CustomerId, InvoiceId, MerchantConnectorAccountId, MerchantId, PaymentId, ProfileId,
SubscriptionId,
@ -238,6 +240,22 @@ pub struct ConfirmSubscriptionPaymentDetails {
pub payment_token: Option<String>,
}
impl ConfirmSubscriptionPaymentDetails {
pub fn validate(&self) -> Result<(), error_stack::Report<ValidationError>> {
fp_utils::when(
self.payment_method_data.is_none() && self.payment_token.is_none(),
|| {
Err(ValidationError::MissingRequiredField {
field_name: String::from(
"either of payment_method_data or payment_token must be present",
),
}
.into())
},
)
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct CreateSubscriptionPaymentDetails {
/// The url to which user must be redirected to after completion of the purchase
@ -265,6 +283,22 @@ pub struct PaymentDetails {
pub payment_token: Option<String>,
}
impl PaymentDetails {
pub fn validate(&self) -> Result<(), error_stack::Report<ValidationError>> {
fp_utils::when(
self.payment_method_data.is_none() && self.payment_token.is_none(),
|| {
Err(ValidationError::MissingRequiredField {
field_name: String::from(
"either of payment_method_data or payment_token must be present",
),
}
.into())
},
)
}
}
// Creating new type for PaymentRequest API call as usage of api_models::PaymentsRequest will result in invalid payment request during serialization
// Eg: Amount will be serialized as { amount: {Value: 100 }}
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
@ -376,6 +410,11 @@ impl ConfirmSubscriptionRequest {
.and_then(|data| data.billing.clone())
.or(self.payment_details.billing.clone())
}
// Perform validation on ConfirmSubscriptionRequest fields
pub fn validate(&self) -> Result<(), error_stack::Report<ValidationError>> {
self.payment_details.validate()
}
}
impl ApiEventMetric for ConfirmSubscriptionRequest {}
@ -415,6 +454,10 @@ impl CreateAndConfirmSubscriptionRequest {
.and_then(|data| data.billing.clone())
.or(self.billing.clone())
}
pub fn validate(&self) -> Result<(), error_stack::Report<ValidationError>> {
self.payment_details.validate()
}
}
impl ApiEventMetric for CreateAndConfirmSubscriptionRequest {}