feat(recovery): add support for custom billing api for v2 (#8838)

Co-authored-by: Chikke Srujan <chikke.srujan@Chikke-Srujan-V9P7D4K9V0.local>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
chikke srujan
2025-08-08 02:38:34 -07:00
committed by GitHub
parent b0b71935ca
commit 9e8df84590
15 changed files with 622 additions and 178 deletions

View File

@ -4,6 +4,7 @@ use common_utils::events::{ApiEventMetric, ApiEventsType};
use super::{
PaymentAttemptListRequest, PaymentAttemptListResponse, PaymentStartRedirectionRequest,
PaymentsCreateIntentRequest, PaymentsGetIntentRequest, PaymentsIntentResponse, PaymentsRequest,
RecoveryPaymentsCreate, RecoveryPaymentsResponse,
};
#[cfg(feature = "v2")]
use crate::payment_methods::{
@ -416,6 +417,20 @@ impl ApiEventMetric for PaymentListResponse {
}
}
#[cfg(feature = "v2")]
impl ApiEventMetric for RecoveryPaymentsCreate {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
None
}
}
#[cfg(feature = "v2")]
impl ApiEventMetric for RecoveryPaymentsResponse {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
None
}
}
#[cfg(feature = "v1")]
impl ApiEventMetric for PaymentListResponseV2 {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
@ -496,7 +511,6 @@ impl ApiEventMetric for payments::PaymentMethodListResponseForPayments {
None
}
}
#[cfg(feature = "v2")]
impl ApiEventMetric for PaymentMethodListResponseForSession {}

View File

@ -1696,6 +1696,32 @@ pub struct PaymentAttemptRecordResponse {
pub created_at: PrimitiveDateTime,
}
#[cfg(feature = "v2")]
#[derive(Debug, serde::Serialize, Clone, ToSchema)]
pub struct RecoveryPaymentsResponse {
/// Unique identifier for the payment.
#[schema(
min_length = 30,
max_length = 30,
example = "pay_mbabizu24mvu3mela5njyhpit4",
value_type = String,
)]
pub id: id_type::GlobalPaymentId,
#[schema(value_type = IntentStatus, example = "failed", default = "requires_confirmation")]
pub intent_status: api_enums::IntentStatus,
/// Unique identifier for the payment. This ensures idempotency for multiple payments
/// that have been done by a single merchant.
#[schema(
value_type = Option<String>,
min_length = 30,
max_length = 30,
example = "pay_mbabizu24mvu3mela5njyhpit4"
)]
pub merchant_reference_id: Option<id_type::PaymentReferenceId>,
}
#[cfg(feature = "v2")]
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq, ToSchema)]
pub struct PaymentAttemptFeatureMetadata {
@ -4318,6 +4344,12 @@ pub struct PaymentMethodDataResponseWithBilling {
pub billing: Option<Address>,
}
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, ToSchema, serde::Serialize)]
pub struct CustomRecoveryPaymentMethodData {
#[serde(flatten)]
pub units: HashMap<String, AdditionalCardInfo>,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, ToSchema)]
#[cfg(feature = "v1")]
pub enum PaymentIdType {
@ -9100,6 +9132,78 @@ pub struct PaymentsAttemptRecordRequest {
pub card_issuer: Option<String>,
}
// Serialize is required because the api event requires Serialize to be implemented
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
#[cfg(feature = "v2")]
pub struct RecoveryPaymentsCreate {
/// The amount details for the payment
pub amount_details: AmountDetails,
/// Unique identifier for the payment. This ensures idempotency for multiple payments
/// that have been done by a single merchant.
#[schema(
value_type = Option<String>,
min_length = 30,
max_length = 30,
example = "pay_mbabizu24mvu3mela5njyhpit4"
)]
pub merchant_reference_id: id_type::PaymentReferenceId,
/// Error details for the payment if any
pub error: Option<ErrorDetails>,
/// Billing connector id to update the invoices.
#[schema(value_type = String, example = "mca_1234567890")]
pub billing_merchant_connector_id: id_type::MerchantConnectorAccountId,
/// Payments connector id to update the invoices.
#[schema(value_type = String, example = "mca_1234567890")]
pub payment_merchant_connector_id: id_type::MerchantConnectorAccountId,
#[schema(value_type = AttemptStatus, example = "charged")]
pub attempt_status: enums::AttemptStatus,
/// The billing details of the payment attempt.
pub billing: Option<Address>,
/// The payment method subtype to be used for the payment. This should match with the `payment_method_data` provided
#[schema(value_type = PaymentMethodType, example = "apple_pay")]
pub payment_method_sub_type: api_enums::PaymentMethodType,
/// primary payment method token at payment processor end.
#[schema(value_type = String, example = "token_1234")]
pub primary_processor_payment_method_token: Secret<String>,
/// The time at which payment attempt was created.
#[schema(example = "2022-09-10T10:11:12Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub transaction_created_at: Option<PrimitiveDateTime>,
/// Payment method type for the payment attempt
#[schema(value_type = Option<PaymentMethod>, example = "wallet")]
pub payment_method_type: common_enums::PaymentMethod,
/// customer id at payment connector for which mandate is attached.
#[schema(value_type = String, example = "cust_12345")]
pub connector_customer_id: Secret<String>,
/// Invoice billing started at billing connector end.
#[schema(example = "2022-09-10T10:11:12Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub billing_started_at: Option<PrimitiveDateTime>,
/// A unique identifier for a payment provided by the payment connector
#[schema(value_type = Option<String>, example = "993672945374576J")]
pub connector_transaction_id: Option<Secret<String>>,
/// payment method token units at payment processor end.
pub payment_method_units: CustomRecoveryPaymentMethodData,
/// Type of action that needs to be taken after consuming the recovery payload. For example: scheduling a failed payment or stopping the invoice.
pub action: common_payments_types::RecoveryAction,
}
/// Error details for the payment
#[cfg(feature = "v2")]
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]