Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat(revenue_recovery): add customer_present and setup_future_usage to recovery api (#15119)

balakrishna146c8c7551c3
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.json
index 31ed9c1fed..0744f0a87f 100644
--- a/api-reference/v2/openapi_spec_v2.json
+++ b/api-reference/v2/openapi_spec_v2.json
@@ -31729,6 +31729,24 @@
],
"nullable": true
},
+ "customer_present": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/PresenceOfCustomerDuringPayment"
+ }
+ ],
+ "default": "absent",
+ "nullable": true
+ },
+ "setup_future_usage": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/FutureUsage"
+ }
+ ],
+ "default": "off_session",
+ "nullable": true
+ },
"billing": {
"allOf": [
{
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index 6425c7e8d1..a0be3a35a2 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -15019,6 +15019,14 @@ pub struct RecoveryPaymentsCreate {
#[schema(value_type = Option<MitCategory>, example = "recurring")]
pub mit_category: Option<api_enums::MitCategory>,
+ /// Set to `present` if the customer was present during the transaction. Defaults to `absent`.
+ #[schema(example = "absent", default = "absent", value_type = Option<PresenceOfCustomerDuringPayment>)]
+ pub customer_present: Option<common_enums::PresenceOfCustomerDuringPayment>,
+
+ /// Indicates how the payment method is intended to be used in the future. Defaults to `off_session`.
+ #[schema(value_type = Option<FutureUsage>, default = "off_session", example = "off_session")]
+ pub setup_future_usage: Option<api_enums::FutureUsage>,
+
/// The billing details of the transaction.
pub billing: Option<Address>,
diff --git a/crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rs b/crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rs
index 93f40c35fd..15cf096126 100644
--- a/crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rs
@@ -1098,6 +1098,7 @@ impl TryFrom<ChargebeeInvoiceBody> for revenue_recovery::RevenueRecoveryInvoiceD
// TODO! This field should be handled for billing connnector integrations
enable_partial_authorization: None,
customer_present: common_enums::PresenceOfCustomerDuringPayment::Absent,
+ setup_future_usage: common_enums::FutureUsage::OffSession,
// Chargebee invoices come from subscriptions, so recovery retries are sent as recurring merchant initiated transactions
mit_category: Some(common_enums::MitCategory::Recurring),
})
diff --git a/crates/hyperswitch_connectors/src/connectors/stripebilling/transformers.rs b/crates/hyperswitch_connectors/src/connectors/stripebilling/transformers.rs
index 72a8d3a647..a9f15ab219 100644
--- a/crates/hyperswitch_connectors/src/connectors/stripebilling/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/stripebilling/transformers.rs
@@ -430,6 +430,7 @@ impl TryFrom<StripebillingInvoiceBody> for revenue_recovery::RevenueRecoveryInvo
// TODO! This field should be handled for billing connnector integrations
enable_partial_authorization: None,
customer_present: common_enums::PresenceOfCustomerDuringPayment::Absent,
+ setup_future_usage: common_enums::FutureUsage::OffSession,
// Not set since Stripe Billing recovers only through Stripe, which doesn't use the mit category
mit_category: None,
})
diff --git a/crates/hyperswitch_domain_models/src/revenue_recovery.rs b/crates/hyperswitch_domain_models/src/revenue_recovery.rs
index c3652647fd..9136f8722c 100644
--- a/crates/hyperswitch_domain_models/src/revenue_recovery.rs
+++ b/crates/hyperswitch_domain_models/src/revenue_recovery.rs
@@ -94,6 +94,8 @@ pub struct RevenueRecoveryInvoiceData {
/// Whether the customer was present during the payment. Billing connectors only report
/// merchant initiated transactions, so they always set this to absent.
pub customer_present: common_enums::PresenceOfCustomerDuringPayment,
+ /// How the payment method is intended to be used in the future.
+ pub setup_future_usage: common_enums::FutureUsage,
/// Category of the merchant initiated transactions made to recover this invoice.
pub mit_category: Option<common_enums::MitCategory>,
}
@@ -169,7 +171,7 @@ impl From<&RevenueRecoveryInvoiceData> for api_payments::PaymentsCreateIntentReq
customer_present: Some(data.customer_present),
description: None,
return_url: None,
- setup_future_usage: Some(common_enums::FutureUsage::OffSession),
+ setup_future_usage: Some(data.setup_future_usage),
apply_mit_exemption: None,
statement_descriptor: None,
order_details: None,
@@ -208,6 +210,7 @@ impl From<&BillingConnectorInvoiceSyncResponse> for RevenueRecoveryInvoiceData {
metadata: None,
enable_partial_authorization: None,
customer_present: common_enums::PresenceOfCustomerDuringPayment::Absent,
+ setup_future_usage: common_enums::FutureUsage::OffSession,
mit_category: None,
}
}
diff --git a/crates/router/src/core/revenue_recovery/transformers.rs b/crates/router/src/core/revenue_recovery/transformers.rs
index 7542248340..d27469dbcd 100644
--- a/crates/router/src/core/revenue_recovery/transformers.rs
+++ b/crates/router/src/core/revenue_recovery/transformers.rs
@@ -59,8 +59,13 @@ impl ForeignFrom<api_models::payments::RecoveryPaymentsCreate>
billing_started_at: Some(data.billing_started_at),
metadata: data.metadata,
enable_partial_authorization: data.enable_partial_authorization,
- // Recovery retries are merchant initiated, so the customer is never present
- customer_present: common_enums::PresenceOfCustomerDuringPayment::Absent,
+ // Defaults to absent since recovery retries are merchant initiated
+ customer_present: data
+ .customer_present
+ .unwrap_or(common_enums::PresenceOfCustomerDuringPayment::Absent),
+ setup_future_usage: data
+ .setup_future_usage
+ .unwrap_or(common_enums::FutureUsage::OffSession),
// Defaults to recurring since recovery retries are merchant initiated transactions on a saved card for a recurring invoice
mit_category: Some(
data.mit_category