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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
docs(revenue-recovery): add revenue recovery api to docs (#13730)
CHALLA NISHANTH BABU42bbdc2c61a2
diff --git a/api-reference/docs.json b/api-reference/docs.jsonindex df914a65ab..41383a86cf 100644--- a/api-reference/docs.json+++ b/api-reference/docs.json@@ -502,6 +502,7 @@{"group": "Revenue Recovery","pages": [+ "v2/revenue-recovery/revenue-recovery--create","v2/revenue-recovery/revenue-recovery--retrieve"]}diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.jsonindex 5b515b2548..58459976b9 100644--- a/api-reference/v2/openapi_spec_v2.json+++ b/api-reference/v2/openapi_spec_v2.json@@ -4866,6 +4866,91 @@]}},+ "/v2/payments/recovery": {+ "post": {+ "tags": [+ "Revenue Recovery"+ ],+ "summary": "Revenue Recovery - Create",+ "description": "Record a payment attempt made outside of Hyperswitch against a billing connector invoice,\nand take the requested recovery action on it, such as scheduling a retry for a failed payment\nor cancelling the invoice.",+ "operationId": "Create a Revenue Recovery Payment",+ "requestBody": {+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/RecoveryPaymentsCreate"+ },+ "examples": {+ "Record a failed payment attempt and schedule a retry": {+ "value": {+ "action": "schedule_failed_payment",+ "amount_details": {+ "currency": "USD",+ "order_amount": 6540+ },+ "billing_merchant_connector_id": "mca_billing_1234567890",+ "connector_customer_id": "cust_12345",+ "connector_transaction_id": "993672945374576J",+ "error": {+ "code": "card_declined",+ "message": "The card was declined."+ },+ "merchant_reference_id": "invoice_mbabizu24mvu3mela5njyh",+ "payment_merchant_connector_id": "mca_payment_1234567890",+ "payment_method_data": {+ "payment_method_metadata": {+ "card_network": "Visa",+ "card_type": "credit",+ "last4": "4242"+ },+ "primary_processor_payment_method_token": "token_1234"+ },+ "payment_method_sub_type": "credit",+ "payment_method_type": "card",+ "transaction_created_at": "2022-09-10T10:11:12Z",+ "transaction_status": "failure"+ }+ }+ }+ }+ },+ "required": true+ },+ "responses": {+ "200": {+ "description": "Revenue Recovery Payment Recorded Successfully",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/RecoveryPaymentsResponse"+ }+ }+ }+ },+ "400": {+ "description": "Missing mandatory fields",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/GenericErrorResponseOpenApi"+ }+ }+ }+ },+ "404": {+ "description": "Resource missing"+ },+ "500": {+ "description": "Internal server error"+ }+ },+ "security": [+ {+ "api_key": []+ }+ ]+ }+ },"/v2/proxy": {"post": {"tags": [@@ -5483,6 +5568,97 @@"failed"]},+ "AdditionalCardInfo": {+ "type": "object",+ "properties": {+ "card_issuer": {+ "type": "string",+ "description": "The name of issuer of the card",+ "nullable": true+ },+ "card_network": {+ "allOf": [+ {+ "$ref": "#/components/schemas/CardNetwork"+ }+ ],+ "nullable": true+ },+ "card_type": {+ "type": "string",+ "description": "Card type, can be either `credit` or `debit`",+ "nullable": true+ },+ "card_issuing_country": {+ "type": "string",+ "nullable": true+ },+ "card_issuing_country_code": {+ "type": "string",+ "nullable": true+ },+ "bank_code": {+ "type": "string",+ "nullable": true+ },+ "last4": {+ "type": "string",+ "description": "Last 4 digits of the card number",+ "nullable": true+ },+ "card_isin": {+ "type": "string",+ "description": "The ISIN of the card",+ "nullable": true+ },+ "card_extended_bin": {+ "type": "string",+ "description": "Extended bin of card, contains the first 8 digits of card number",+ "nullable": true+ },+ "card_exp_month": {+ "type": "string",+ "example": "01",+ "nullable": true+ },+ "card_exp_year": {+ "type": "string",+ "example": "2026",+ "nullable": true+ },+ "card_holder_name": {+ "type": "string",+ "example": "John Doe",+ "nullable": true+ },+ "payment_checks": {+ "description": "Additional payment checks done on the cvv and billing address by the processors.\nThis is a free form field and the structure varies from processor to processor",+ "nullable": true+ },+ "authentication_data": {+ "description": "Details about the threeds environment.\nThis is a free form field and the structure varies from processor to processor",+ "nullable": true+ },+ "is_regulated": {+ "type": "boolean",+ "description": "Indicates if the card issuer is regulated under government-imposed interchange fee caps.\nIn the United States, this includes debit cards that fall under the Durbin Amendment,\nwhich imposes capped interchange fees.",+ "nullable": true+ },+ "signature_network": {+ "allOf": [+ {+ "$ref": "#/components/schemas/CardNetwork"+ }+ ],+ "nullable": true+ },+ "auth_code": {+ "type": "string",+ "description": "Unique authorisation code generated for the payment.",+ "nullable": true+ }+ }+ },"AdditionalMerchantData": {"oneOf": [{@@ -13459,6 +13635,23 @@}}},+ "CustomRecoveryPaymentMethodData": {+ "type": "object",+ "required": [+ "primary_processor_payment_method_token",+ "payment_method_metadata"+ ],+ "properties": {+ "primary_processor_payment_method_token": {+ "type": "string",+ "description": "Primary payment method token at payment processor end.",+ "example": "token_1234"+ },+ "payment_method_metadata": {+ "$ref": "#/components/schemas/AdditionalCardInfo"+ }+ }+ },"CustomTerms": {"type": "object","description": "Custom T&C message for a specific payment method type",@@ -30290,6 +30483,159 @@}}},+ "RecoveryAction": {+ "type": "string",+ "description": "type of action that needs to taken after consuming recovery payload",+ "enum": [+ "cancel_invoice",+ "schedule_failed_payment",+ "success_payment_external",+ "pending_payment",+ "no_action",+ "invalid_action"+ ]+ },+ "RecoveryPaymentsCreate": {+ "type": "object",+ "required": [+ "amount_details",+ "billing_merchant_connector_id",+ "payment_merchant_connector_id",+ "transaction_status",+ "payment_method_sub_type",+ "connector_customer_id",+ "payment_method_data",+ "action"+ ],+ "properties": {+ "amount_details": {+ "$ref": "#/components/schemas/AmountDetails"+ },+ "merchant_reference_id": {+ "type": "string",+ "description": "The invoice identifier from the merchant's billing system that this payment attempt is\nbeing recorded against. This ensures idempotency when the same invoice is reported\nmore than once.",+ "example": "invoice_mbabizu24mvu3mela5njyh",+ "nullable": true,+ "maxLength": 30,+ "minLength": 30+ },+ "error": {+ "allOf": [+ {+ "$ref": "#/components/schemas/ErrorDetails"+ }+ ],+ "nullable": true+ },+ "billing_merchant_connector_id": {+ "type": "string",+ "description": "Billing connector id to update the invoices.",+ "example": "mca_1234567890"+ },+ "payment_merchant_connector_id": {+ "type": "string",+ "description": "Payments connector id to update the invoices.",+ "example": "mca_1234567890"+ },+ "transaction_status": {+ "$ref": "#/components/schemas/AttemptStatus"+ },+ "billing": {+ "allOf": [+ {+ "$ref": "#/components/schemas/Address"+ }+ ],+ "nullable": true+ },+ "payment_method_sub_type": {+ "$ref": "#/components/schemas/PaymentMethodType"+ },+ "transaction_created_at": {+ "type": "string",+ "format": "date-time",+ "description": "The time at which payment attempt was created.",+ "example": "2022-09-10T10:11:12Z",+ "nullable": true+ },+ "payment_method_type": {+ "allOf": [+ {+ "$ref": "#/components/schemas/PaymentMethod"+ }+ ],+ "nullable": true+ },+ "connector_customer_id": {+ "type": "string",+ "description": "customer id at payment connector for which mandate is attached.",+ "example": "cust_12345"+ },+ "billing_started_at": {+ "type": "string",+ "format": "date-time",+ "description": "Invoice billing started at billing connector end.",+ "example": "2022-09-10T10:11:12Z",+ "nullable": true+ },+ "connector_transaction_id": {+ "type": "string",+ "description": "A unique identifier for a payment provided by the payment connector",+ "example": "993672945374576J",+ "nullable": true+ },+ "payment_method_data": {+ "$ref": "#/components/schemas/CustomRecoveryPaymentMethodData"+ },+ "action": {+ "$ref": "#/components/schemas/RecoveryAction"+ },+ "enable_partial_authorization": {+ "type": "boolean",+ "description": "Allow partial authorization for this payment",+ "default": false,+ "nullable": true+ },+ "metadata": {+ "type": "object",+ "description": "You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.",+ "nullable": true+ }+ },+ "additionalProperties": false+ },+ "RecoveryPaymentsResponse": {+ "type": "object",+ "required": [+ "id",+ "intent_status"+ ],+ "properties": {+ "id": {+ "type": "string",+ "description": "Unique identifier for the payment.",+ "example": "pay_mbabizu24mvu3mela5njyhpit4",+ "maxLength": 30,+ "minLength": 30+ },+ "intent_status": {+ "allOf": [+ {+ "$ref": "#/components/schemas/IntentStatus"+ }+ ],+ "default": "requires_confirmation"+ },+ "merchant_reference_id": {+ "type": "string",+ "description": "Unique identifier for the payment. This ensures idempotency for multiple payments\nthat have been done by a single merchant.",+ "example": "pay_mbabizu24mvu3mela5njyhpit4",+ "nullable": true,+ "maxLength": 30,+ "minLength": 30+ }+ }+ },"RecurringDetails": {"oneOf": [{diff --git a/api-reference/v2/revenue-recovery/revenue-recovery--create.mdx b/api-reference/v2/revenue-recovery/revenue-recovery--create.mdxnew file mode 100644index 0000000000..c9a9c6cb84--- /dev/null+++ b/api-reference/v2/revenue-recovery/revenue-recovery--create.mdx@@ -0,0 +1,3 @@+---+openapi: post /v2/payments/recovery+---diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex 25d9849e4a..946a0a5f10 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -4159,6 +4159,7 @@ pub struct AdditionalCardInfo {pub card_issuer: Option<String>,/// Card network of the card+ #[schema(value_type = Option<CardNetwork>, example = "Visa")]pub card_network: Option<api_enums::CardNetwork>,/// Card type, can be either `credit` or `debit`@@ -4177,10 +4178,13 @@ pub struct AdditionalCardInfo {/// Extended bin of card, contains the first 8 digits of card numberpub card_extended_bin: Option<String>,+ #[schema(value_type = Option<String>, example = "01")]pub card_exp_month: Option<Secret<String>>,+ #[schema(value_type = Option<String>, example = "2026")]pub card_exp_year: Option<Secret<String>>,+ #[schema(value_type = Option<String>, example = "John Doe")]pub card_holder_name: Option<Secret<String>>,/// Additional payment checks done on the cvv and billing address by the processors.@@ -4198,6 +4202,7 @@ pub struct AdditionalCardInfo {/// The global signature network under which the card is issued./// This represents the primary global card brand, even if the transaction uses a local network+ #[schema(value_type = Option<CardNetwork>, example = "Visa")]pub signature_network: Option<api_enums::CardNetwork>,/// Unique authorisation code generated for the payment.pub auth_code: Option<String>,@@ -6361,8 +6366,8 @@ pub struct CustomRecoveryPaymentMethodData {#[schema(value_type = String, example = "token_1234")]pub primary_processor_payment_method_token: Secret<String>,- /// AdditionalCardInfo for the primary token.- pub additional_payment_method_info: AdditionalCardInfo,+ /// Card details associated with the primary payment method token.+ pub payment_method_metadata: AdditionalCardInfo,}#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, ToSchema)]@@ -14048,13 +14053,14 @@ pub struct RecoveryPaymentsCreate {/// The amount details for the paymentpub amount_details: AmountDetails,- /// Unique identifier for the payment. This ensures idempotency for multiple payments- /// that have been done by a single merchant.+ /// The invoice identifier from the merchant's billing system that this payment attempt is+ /// being recorded against. This ensures idempotency when the same invoice is reported+ /// more than once.#[schema(value_type = Option<String>,min_length = 30,max_length = 30,- example = "pay_mbabizu24mvu3mela5njyhpit4"+ example = "invoice_mbabizu24mvu3mela5njyh")]pub merchant_reference_id: id_type::PaymentReferenceId,@@ -14069,8 +14075,9 @@ pub struct RecoveryPaymentsCreate {#[schema(value_type = String, example = "mca_1234567890")]pub payment_merchant_connector_id: id_type::MerchantConnectorAccountId,+ /// The status of the transaction at the payment connector.#[schema(value_type = AttemptStatus, example = "charged")]- pub attempt_status: enums::AttemptStatus,+ pub transaction_status: enums::AttemptStatus,/// The billing details of the payment attempt.pub billing: Option<Address>,@@ -14105,6 +14112,7 @@ pub struct RecoveryPaymentsCreate {pub payment_method_data: CustomRecoveryPaymentMethodData,/// Type of action that needs to be taken after consuming the recovery payload. For example: scheduling a failed payment or stopping the invoice.+ #[schema(value_type = RecoveryAction, example = "schedule_failed_payment")]pub action: common_payments_types::RecoveryAction,/// Allow partial authorization for this paymentdiff --git a/crates/common_types/src/payments.rs b/crates/common_types/src/payments.rsindex 444a12ac31..045ca3b28b 100644--- a/crates/common_types/src/payments.rs+++ b/crates/common_types/src/payments.rs@@ -958,7 +958,7 @@ impl ApplePayPredecryptData {}/// type of action that needs to taken after consuming recovery payload-#[derive(Debug, Clone, Serialize, Deserialize)]+#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]#[serde(rename_all = "snake_case")]pub enum RecoveryAction {/// Stops the process tracker and update the payment intent.diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rsindex 0b1bd82b12..90df76d52f 100644--- a/crates/openapi/src/openapi_v2.rs+++ b/crates/openapi/src/openapi_v2.rs@@ -178,6 +178,7 @@ Never share your secret api keys. Keep them guarded and secure.// Routes for Revenue Recovery flow under Process Trackerroutes::revenue_recovery::revenue_recovery_pt_retrieve_api,+ routes::revenue_recovery::revenue_recovery_payments_create,// Routes for proxyroutes::proxy::proxy_core,@@ -985,6 +986,11 @@ Never share your secret api keys. Keep them guarded and secure.api_models::payment_methods::PaymentMethodSessionResponse,api_models::payment_methods::AuthenticationDetails,api_models::process_tracker::revenue_recovery::RevenueRecoveryResponse,+ api_models::payments::RecoveryPaymentsCreate,+ api_models::payments::RecoveryPaymentsResponse,+ api_models::payments::CustomRecoveryPaymentMethodData,+ api_models::payments::AdditionalCardInfo,+ common_types::payments::RecoveryAction,api_models::enums::RevenueRecoveryAlgorithmType,api_models::enums::ProcessTrackerStatus,api_models::proxy::ProxyRequest,diff --git a/crates/openapi/src/routes/revenue_recovery.rs b/crates/openapi/src/routes/revenue_recovery.rsindex 0f22b340bd..617e13b296 100644--- a/crates/openapi/src/routes/revenue_recovery.rs+++ b/crates/openapi/src/routes/revenue_recovery.rs@@ -20,3 +20,61 @@security(("jwt_key" = [])))]pub async fn revenue_recovery_pt_retrieve_api() {}++#[cfg(feature = "v2")]+/// Revenue Recovery - Create+///+/// Record a payment attempt made outside of Hyperswitch against a billing connector invoice,+/// and take the requested recovery action on it, such as scheduling a retry for a failed payment+/// or cancelling the invoice.+#[utoipa::path(+ post,+ path = "/v2/payments/recovery",+ request_body(+ content = RecoveryPaymentsCreate,+ examples(+ (+ "Record a failed payment attempt and schedule a retry" = (+ value = json!({+ "amount_details": {+ "order_amount": 6540,+ "currency": "USD"+ },+ "merchant_reference_id": "invoice_mbabizu24mvu3mela5njyh",+ "billing_merchant_connector_id": "mca_billing_1234567890",+ "payment_merchant_connector_id": "mca_payment_1234567890",+ "transaction_status": "failure",+ "payment_method_type": "card",+ "payment_method_sub_type": "credit",+ "connector_customer_id": "cust_12345",+ "connector_transaction_id": "993672945374576J",+ "transaction_created_at": "2022-09-10T10:11:12Z",+ "error": {+ "code": "card_declined",+ "message": "The card was declined."+ },+ "payment_method_data": {+ "primary_processor_payment_method_token": "token_1234",+ "payment_method_metadata": {+ "card_network": "Visa",+ "card_type": "credit",+ "last4": "4242"+ }+ },+ "action": "schedule_failed_payment"+ })+ )+ ),+ ),+ ),+ responses(+ (status = 200, description = "Revenue Recovery Payment Recorded Successfully", body = RecoveryPaymentsResponse),+ (status = 400, description = "Missing mandatory fields", body = GenericErrorResponseOpenApi),+ (status = 404, description = "Resource missing"),+ (status = 500, description = "Internal server error"),+ ),+ tag = "Revenue Recovery",+ operation_id = "Create a Revenue Recovery Payment",+ security(("api_key" = []))+)]+pub async fn revenue_recovery_payments_create() {}diff --git a/crates/router/src/core/revenue_recovery/transformers.rs b/crates/router/src/core/revenue_recovery/transformers.rsindex 605d09d2f4..34ebd1095c 100644--- a/crates/router/src/core/revenue_recovery/transformers.rs+++ b/crates/router/src/core/revenue_recovery/transformers.rs@@ -86,7 +86,7 @@ impl ForeignFrom<&api_models::payments::RecoveryPaymentsCreate>.get_string_repr().to_string(),transaction_created_at: data.transaction_created_at.to_owned(),- status: data.attempt_status,+ status: data.transaction_status,payment_method_type: data.payment_method_type,payment_method_sub_type: data.payment_method_sub_type,network_advice_code: data@@ -105,10 +105,7 @@ impl ForeignFrom<&api_models::payments::RecoveryPaymentsCreate>retry_count: None,invoice_next_billing_time: None,invoice_billing_started_at_time: data.billing_started_at,- card_info: data- .payment_method_data- .additional_payment_method_info- .clone(),+ card_info: data.payment_method_data.payment_method_metadata.clone(),charge_id: None,}}