Skip to content

Commit

Permalink
refactor(router): add revenue_recovery_metadata to payment intent in …
Browse files Browse the repository at this point in the history
…diesel and api model for v2 flow (#7176)

Co-authored-by: Nishanth Challa <[email protected]>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 14, 2025
1 parent fbbbe3e commit 2ee22cd
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 3 deletions.
75 changes: 75 additions & 0 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -5793,6 +5793,23 @@
}
}
},
"BillingConnectorPaymentDetails": {
"type": "object",
"required": [
"payment_processor_token",
"connector_customer_id"
],
"properties": {
"payment_processor_token": {
"type": "string",
"description": "Payment Processor Token to process the Revenue Recovery Payment"
},
"connector_customer_id": {
"type": "string",
"description": "Billing Connector's Customer Id"
}
}
},
"BlikBankRedirectAdditionalData": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -9025,6 +9042,14 @@
}
],
"nullable": true
},
"payment_revenue_recovery_metadata": {
"allOf": [
{
"$ref": "#/components/schemas/PaymentRevenueRecoveryMetadata"
}
],
"nullable": true
}
}
},
Expand Down Expand Up @@ -13167,6 +13192,13 @@
"bank_acquirer"
]
},
"PaymentConnectorTransmission": {
"type": "string",
"enum": [
"ConnectorCallFailed",
"ConnectorCallSucceeded"
]
},
"PaymentCreatePaymentLinkConfig": {
"allOf": [
{
Expand Down Expand Up @@ -14926,6 +14958,49 @@
}
}
},
"PaymentRevenueRecoveryMetadata": {
"type": "object",
"required": [
"total_retry_count",
"payment_connector_transmission",
"billing_connector_id",
"active_attempt_payment_connector_id",
"billing_connector_payment_details",
"payment_method_type",
"payment_method_subtype"
],
"properties": {
"total_retry_count": {
"type": "integer",
"format": "int32",
"description": "Total number of billing connector + recovery retries for a payment intent.",
"example": "1",
"minimum": 0
},
"payment_connector_transmission": {
"$ref": "#/components/schemas/PaymentConnectorTransmission"
},
"billing_connector_id": {
"type": "string",
"description": "Billing Connector Id to update the invoices",
"example": "mca_1234567890"
},
"active_attempt_payment_connector_id": {
"type": "string",
"description": "Payment Connector Id to retry the payments",
"example": "mca_1234567890"
},
"billing_connector_payment_details": {
"$ref": "#/components/schemas/BillingConnectorPaymentDetails"
},
"payment_method_type": {
"$ref": "#/components/schemas/PaymentMethod"
},
"payment_method_subtype": {
"$ref": "#/components/schemas/PaymentMethodType"
}
}
},
"PaymentType": {
"type": "string",
"description": "The type of the payment that differentiates between normal and various types of mandate payments. Use 'setup_mandate' in case of zero auth flow.",
Expand Down
53 changes: 52 additions & 1 deletion crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::{
};
pub mod additional_info;
use cards::CardNumber;
#[cfg(feature = "v2")]
use common_enums::enums::PaymentConnectorTransmission;
use common_enums::ProductType;
#[cfg(feature = "v2")]
use common_utils::id_type::GlobalPaymentId;
Expand Down Expand Up @@ -7111,12 +7113,28 @@ pub struct PaymentsStartRequest {
}

/// additional data that might be required by hyperswitch
#[cfg(feature = "v2")]
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)]
pub struct FeatureMetadata {
/// Redirection response coming in request as metadata field only for redirection scenarios
#[schema(value_type = Option<RedirectResponse>)]
pub redirect_response: Option<RedirectResponse>,
/// Additional tags to be used for global search
#[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>,
/// revenue recovery data for payment intent
pub payment_revenue_recovery_metadata: Option<PaymentRevenueRecoveryMetadata>,
}

/// additional data that might be required by hyperswitch
#[cfg(feature = "v1")]
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)]
pub struct FeatureMetadata {
/// Redirection response coming in request as metadata field only for redirection scenarios
#[schema(value_type = Option<RedirectResponse>)]
pub redirect_response: Option<RedirectResponse>,
// TODO: Convert this to hashedstrings to avoid PII sensitive data
/// Additional tags to be used for global search
#[schema(value_type = Option<Vec<String>>)]
pub search_tags: Option<Vec<HashedString<WithType>>>,
Expand Down Expand Up @@ -7977,3 +7995,36 @@ mod billing_from_payment_method_data {
assert!(billing_details.is_none());
}
}

#[cfg(feature = "v2")]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct PaymentRevenueRecoveryMetadata {
/// Total number of billing connector + recovery retries for a payment intent.
#[schema(value_type = u16,example = "1")]
pub total_retry_count: u16,
/// Flag for the payment connector's call
pub payment_connector_transmission: PaymentConnectorTransmission,
/// Billing Connector Id to update the invoices
#[schema(value_type = String, example = "mca_1234567890")]
pub billing_connector_id: id_type::MerchantConnectorAccountId,
/// Payment Connector Id to retry the payments
#[schema(value_type = String, example = "mca_1234567890")]
pub active_attempt_payment_connector_id: id_type::MerchantConnectorAccountId,
/// Billing Connector Payment Details
#[schema(value_type = BillingConnectorPaymentDetails)]
pub billing_connector_payment_details: BillingConnectorPaymentDetails,
/// Payment Method Type
#[schema(example = "pay_later", value_type = PaymentMethod)]
pub payment_method_type: common_enums::PaymentMethod,
/// PaymentMethod Subtype
#[schema(example = "klarna", value_type = PaymentMethodType)]
pub payment_method_subtype: common_enums::PaymentMethodType,
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[cfg(feature = "v2")]
pub struct BillingConnectorPaymentDetails {
/// Payment Processor Token to process the Revenue Recovery Payment
pub payment_processor_token: String,
/// Billing Connector's Customer Id
pub connector_customer_id: String,
}
9 changes: 9 additions & 0 deletions crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3768,3 +3768,12 @@ pub enum AdyenSplitType {
/// The value-added tax charged on the payment, booked to your platforms liable balance account.
Vat,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
#[serde(rename = "snake_case")]
pub enum PaymentConnectorTransmission {
/// Failed to call the payment connector
ConnectorCallFailed,
/// Payment Connector call succeeded
ConnectorCallSucceeded,
}
48 changes: 46 additions & 2 deletions crates/diesel_models/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#[cfg(feature = "v2")]
use common_enums::{enums::PaymentConnectorTransmission, PaymentMethod, PaymentMethodType};
use common_utils::{hashing::HashedString, pii, types::MinorUnit};
use diesel::{
sql_types::{Json, Jsonb},
AsExpression, FromSqlRow,
};
use masking::{Secret, WithType};
use serde::{Deserialize, Serialize};
use serde::{self, Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, FromSqlRow, AsExpression)]
#[diesel(sql_type = Jsonb)]
pub struct OrderDetailsWithAmount {
Expand Down Expand Up @@ -40,12 +42,26 @@ impl masking::SerializableSecret for OrderDetailsWithAmount {}

common_utils::impl_to_sql_from_sql_json!(OrderDetailsWithAmount);

#[cfg(feature = "v2")]
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, FromSqlRow, AsExpression)]
#[diesel(sql_type = Json)]
pub struct FeatureMetadata {
/// Redirection response coming in request as metadata field only for redirection scenarios
pub redirect_response: Option<RedirectResponse>,
/// Additional tags to be used for global search
pub search_tags: Option<Vec<HashedString<WithType>>>,
/// Recurring payment details required for apple pay Merchant Token
pub apple_pay_recurring_details: Option<ApplePayRecurringDetails>,
/// revenue recovery data for payment intent
pub payment_revenue_recovery_metadata: Option<PaymentRevenueRecoveryMetadata>,
}

#[cfg(feature = "v1")]
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, FromSqlRow, AsExpression)]
#[diesel(sql_type = Json)]
pub struct FeatureMetadata {
/// Redirection response coming in request as metadata field only for redirection scenarios
pub redirect_response: Option<RedirectResponse>,
// TODO: Convert this to hashedstrings to avoid PII sensitive data
/// Additional tags to be used for global search
pub search_tags: Option<Vec<HashedString<WithType>>>,
/// Recurring payment details required for apple pay Merchant Token
Expand Down Expand Up @@ -106,3 +122,31 @@ 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)]
pub struct PaymentRevenueRecoveryMetadata {
/// Total number of billing connector + recovery retries for a payment intent.
pub total_retry_count: u16,
/// Flag for the payment connector's call
pub payment_connector_transmission: PaymentConnectorTransmission,
/// 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 Payment Details
pub billing_connector_payment_details: BillingConnectorPaymentDetails,
///Payment Method Type
pub payment_method_type: PaymentMethod,
/// PaymentMethod Subtype
pub payment_method_subtype: PaymentMethodType,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
#[cfg(feature = "v2")]
pub struct BillingConnectorPaymentDetails {
/// Payment Processor Token to process the Revenue Recovery Payment
pub payment_processor_token: String,
/// Billing Connector's Customer Id
pub connector_customer_id: String,
}
Loading

0 comments on commit 2ee22cd

Please sign in to comment.