Skip to content

Commit

Permalink
add revenue_rcovery_metadata to payment intent in diesel and api model
Browse files Browse the repository at this point in the history
  • Loading branch information
Nishanth Challa authored and Nishanth Challa committed Feb 3, 2025
1 parent b5b5003 commit c088d28
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 5 deletions.
35 changes: 33 additions & 2 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};
pub mod additional_info;
use cards::CardNumber;
use common_enums::ProductType;
use common_enums::{PaymentMethodType, ProductType,PaymentMethod};
#[cfg(feature = "v2")]
use common_utils::id_type::GlobalPaymentId;
use common_utils::{
Expand Down Expand Up @@ -6650,7 +6650,10 @@ pub struct FeatureMetadata {
#[schema(value_type = Option<Vec<String>>)]
pub search_tags: Option<Vec<HashedString<WithType>>>,
/// Recurring payment details required for apple pay Merchant Token
pub apple_pay_recurring_details: Option<ApplePayRecurringDetails>,
pub apple_pay_recurring_details: Option<ApplePayRecurringDetails>,
/// revenue recovery data for payment intent
#[cfg(feature= "v2" )]
pub revenue_recovery_metadata: Option<RevenueRecoveryMetadata>,
}

#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)]
Expand Down Expand Up @@ -7506,3 +7509,31 @@ mod billing_from_payment_method_data {
assert!(billing_details.is_none());
}
}

#[cfg(feature="v2")]
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, ToSchema)]
pub struct RevenueRecoveryMetadata {
///Total number of billing connector + recovery retries for a payment intent.
#[schema(value_type = i32,example = "1")]
pub retry_count : i32,
//if the payment_connector has been called or not
pub payment_connector_transmission : bool,
// Billing Connector Id to update the invoices
pub billing_connector_id : id_type::MerchantConnectorAccountId,
// Payment Connector Id to retry the payments
pub active_attempt_payment_connector_id : id_type::MerchantConnectorAccountId,
// Billing Connector Mit Token Details
pub billing_connector_mit_token_details : BillingConnectorMitTokenDetails,
//Payment Method Type
pub payment_method_type : PaymentMethod,
//PaymentMethod Subtype
pub payment_method_subtype : PaymentMethodType
}
#[derive(Debug, Clone, Eq, PartialEq,Serialize, Deserialize, ToSchema)]
#[cfg(feature="v2")]
pub struct BillingConnectorMitTokenDetails{
//Payment Processor Token To process the retry payment
pub payment_processor_token : String,
//Connector Customer Id to process the retry payment
pub connector_customer_id : String,
}
41 changes: 41 additions & 0 deletions crates/diesel_models/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use diesel::{
};
use masking::{Secret, WithType};
use serde::{Deserialize, Serialize};
use common_enums::{
PaymentMethod,
PaymentMethodType
};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, FromSqlRow, AsExpression)]
#[diesel(sql_type = Jsonb)]
pub struct OrderDetailsWithAmount {
Expand Down Expand Up @@ -50,6 +54,8 @@ pub struct FeatureMetadata {
pub search_tags: Option<Vec<HashedString<WithType>>>,
/// Recurring payment details required for apple pay Merchant Token
pub apple_pay_recurring_details: Option<ApplePayRecurringDetails>,
#[cfg(feature = "v2")]
pub revenue_recovery_metadata: Option<RevenueRecoveryMetadata>,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, FromSqlRow, AsExpression)]
Expand Down Expand Up @@ -106,3 +112,38 @@ pub struct RedirectResponse {
}
impl masking::SerializableSecret for RedirectResponse {}
common_utils::impl_to_sql_from_sql_json!(RedirectResponse);

#[cfg(feature="v2")]
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, FromSqlRow, AsExpression)]
#[diesel(sql_type = Json)]
pub struct RevenueRecoveryMetadata {
///Total number of billing connector + recovery retries for a payment intent.
pub retry_count : i32,
//if the payment_connector has been called or not
pub payment_connector_transmission : bool,
// Billing Connector Id to update the invoices
pub billing_connector_id : common_utils::id_type::MerchantConnectorAccountId,
// Payment Connector Id to retry the payments
pub active_attempt_payment_connector_id : common_utils::id_type::MerchantConnectorAccountId,
// Billing Connector Mit Token Details
pub billing_connector_mit_token_details : BillingConnectorMitTokenDetails,
//Payment Method Type
pub payment_method_type : PaymentMethod,
//PaymentMethod Subtype
pub payment_method_subtype : PaymentMethodType
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, FromSqlRow, AsExpression)]
#[diesel(sql_type = Json)]
#[cfg(feature="v2")]
pub struct BillingConnectorMitTokenDetails{
//Payment Processor Token To process the retry payment
pub payment_processor_token : String,
//Connector Customer Id to process the retry payment
pub connector_customer_id : String,
}

#[cfg(feature="v2")]
common_utils::impl_to_sql_from_sql_json!(RevenueRecoveryMetadata);
#[cfg(feature="v2")]
common_utils::impl_to_sql_from_sql_json!(BillingConnectorMitTokenDetails);
76 changes: 73 additions & 3 deletions crates/hyperswitch_domain_models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,27 @@ use api_models::payments::{
FeatureMetadata as ApiFeatureMetadata, OrderDetailsWithAmount as ApiOrderDetailsWithAmount,
RecurringPaymentIntervalUnit as ApiRecurringPaymentIntervalUnit,
RedirectResponse as ApiRedirectResponse,

};

#[cfg(feature = "v2")]
use api_models::payments::{
RevenueRecoveryMetadata as ApiRevenueRecoveryMetadata,
BillingConnectorMitTokenDetails as ApiBillingConnectorMitTokenDetails,
};

use diesel_models::types::{
ApplePayRecurringDetails, ApplePayRegularBillingDetails, FeatureMetadata,
OrderDetailsWithAmount, RecurringPaymentIntervalUnit, RedirectResponse,
};

#[cfg(feature = "v2")]
use diesel_models::types::{
BillingConnectorMitTokenDetails,
RevenueRecoveryMetadata,
};


#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)]
pub enum RemoteStorageObject<T: ForeignIDRef> {
ForeignID(String),
Expand Down Expand Up @@ -84,27 +99,38 @@ impl ApiModelToDieselModelConvertor<ApiFeatureMetadata> for FeatureMetadata {
redirect_response,
search_tags,
apple_pay_recurring_details,

#[cfg(feature = "v2")]
revenue_recovery_metadata,
} = from;

Self {
redirect_response: redirect_response.map(RedirectResponse::convert_from),
search_tags,
apple_pay_recurring_details: apple_pay_recurring_details
.map(ApplePayRecurringDetails::convert_from),
}
apple_pay_recurring_details: apple_pay_recurring_details.map(ApplePayRecurringDetails::convert_from),

#[cfg(feature = "v2")]
revenue_recovery_metadata: revenue_recovery_metadata.map(RevenueRecoveryMetadata::convert_from),
}
}

fn convert_back(self) -> ApiFeatureMetadata {
let Self {
redirect_response,
search_tags,
apple_pay_recurring_details,

#[cfg(feature = "v2")]
revenue_recovery_metadata,
} = self;
ApiFeatureMetadata {
redirect_response: redirect_response
.map(|redirect_response| redirect_response.convert_back()),
search_tags,
apple_pay_recurring_details: apple_pay_recurring_details
.map(|value| value.convert_back()),
#[cfg(feature = "v2")]
revenue_recovery_metadata: revenue_recovery_metadata.map(|value| value.convert_back()),
}
}
}
Expand Down Expand Up @@ -204,6 +230,50 @@ impl ApiModelToDieselModelConvertor<ApiApplePayRecurringDetails> for ApplePayRec
}
}

#[cfg(feature = "v2")]
impl ApiModelToDieselModelConvertor<ApiRevenueRecoveryMetadata> for RevenueRecoveryMetadata {
fn convert_from(from: ApiRevenueRecoveryMetadata) -> Self {
Self {
retry_count: from.retry_count,
payment_connector_transmission: from.payment_connector_transmission,
billing_connector_id: from.billing_connector_id,
active_attempt_payment_connector_id: from.active_attempt_payment_connector_id,
billing_connector_mit_token_details: BillingConnectorMitTokenDetails::convert_from(from.billing_connector_mit_token_details),
payment_method_type: from.payment_method_type,
payment_method_subtype: from.payment_method_subtype,
}
}

fn convert_back(self) -> ApiRevenueRecoveryMetadata {
ApiRevenueRecoveryMetadata {
retry_count: self.retry_count,
payment_connector_transmission: self.payment_connector_transmission,
billing_connector_id: self.billing_connector_id,
active_attempt_payment_connector_id: self.active_attempt_payment_connector_id,
billing_connector_mit_token_details: self.billing_connector_mit_token_details.convert_back(),
payment_method_type: self.payment_method_type,
payment_method_subtype: self.payment_method_subtype,
}
}
}

#[cfg(feature = "v2")]
impl ApiModelToDieselModelConvertor<ApiBillingConnectorMitTokenDetails> for BillingConnectorMitTokenDetails {
fn convert_from(from: ApiBillingConnectorMitTokenDetails) -> Self {
Self {
payment_processor_token: from.payment_processor_token,
connector_customer_id: from.connector_customer_id,
}
}

fn convert_back(self) -> ApiBillingConnectorMitTokenDetails {
ApiBillingConnectorMitTokenDetails {
payment_processor_token: self.payment_processor_token,
connector_customer_id: self.connector_customer_id,
}
}
}

impl ApiModelToDieselModelConvertor<ApiOrderDetailsWithAmount> for OrderDetailsWithAmount {
fn convert_from(from: ApiOrderDetailsWithAmount) -> Self {
let ApiOrderDetailsWithAmount {
Expand Down

0 comments on commit c088d28

Please sign in to comment.