refactor: Refactored Response types for subscription APIs (#9788)

This commit is contained in:
Sarthak Soni
2025-10-13 15:53:18 +05:30
committed by GitHub
parent f616ffcdd1
commit 435bc11776
4 changed files with 34 additions and 17 deletions

View File

@ -212,6 +212,7 @@ impl ApiEventMetric for GetPlansResponse {}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct ConfirmSubscriptionPaymentDetails {
pub shipping: Option<Address>,
pub billing: Option<Address>,
pub payment_method: api_enums::PaymentMethod,
pub payment_method_type: Option<api_enums::PaymentMethodType>,
pub payment_method_data: PaymentMethodDataRequest,
@ -305,6 +306,8 @@ pub struct PaymentResponseData {
pub error_message: Option<String>,
pub payment_method_type: Option<api_enums::PaymentMethodType>,
pub client_secret: Option<Secret<String>>,
pub billing: Option<Address>,
pub shipping: Option<Address>,
pub payment_type: Option<api_enums::PaymentType>,
}
@ -346,16 +349,13 @@ impl ConfirmSubscriptionRequest {
))
}
pub fn get_billing_address(&self) -> Result<Address, error_stack::Report<ValidationError>> {
pub fn get_billing_address(&self) -> Option<Address> {
self.payment_details
.payment_method_data
.billing
.clone()
.ok_or(error_stack::report!(
ValidationError::MissingRequiredField {
field_name: "billing".to_string()
}
))
.as_ref()
.or(self.payment_details.billing.as_ref())
.cloned()
}
}
@ -394,6 +394,16 @@ pub struct CreateAndConfirmSubscriptionRequest {
pub merchant_reference_id: Option<String>,
}
impl CreateAndConfirmSubscriptionRequest {
pub fn get_billing_address(&self) -> Option<Address> {
self.payment_details
.payment_method_data
.as_ref()
.and_then(|data| data.billing.clone())
.or(self.billing.clone())
}
}
impl ApiEventMetric for CreateAndConfirmSubscriptionRequest {}
#[derive(Debug, Clone, serde::Serialize, ToSchema)]