mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 17:19:15 +08:00
chore: Resolved comments
This commit is contained in:
@ -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 {}
|
||||
|
||||
Reference in New Issue
Block a user