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

10.3 KB
Raw Blame
#[cfg(feature = "v2")]
/// Revenue Recovery - Retrieve
///
/// Retrieve the Revenue Recovery Payment Info
#[utoipa::path(
    get,
    path = "/v2/process-trackers/revenue-recovery-workflow/{revenue_recovery_id}",
    params(
        ("recovery_recovery_id" = String, Path, description = "The payment intent id"),
    ),
    responses(
        (status = 200, description = "Revenue Recovery Info Retrieved Successfully", body = RevenueRecoveryResponse),
        (status = 500, description = "Internal server error"),
        (status = 404, description = "Resource missing"),
        (status = 422, description = "Unprocessable request"),
        (status = 403, description = "Forbidden"),
    ),
   tag = "Revenue Recovery",
   operation_id = "Retrieve Revenue Recovery Info",
   security(("jwt_key" = []))
)]
pub async fn revenue_recovery_pt_retrieve_api() {}

#[cfg(feature = "v2")]
/// Revenue Recovery - Create
///
/// Record a transaction made outside of Hyperswitch against an invoice.
#[utoipa::path(
    post,
    path = "/v2/recovery",
    params(
        (
            "X-Profile-Id" = String, Header,
            description = "Unique identifier of the business profile under which the invoice is processed. Any billing and payment merchant connector accounts in the request must belong to this profile.",
            example = "pro_abcdefghijklmnop"
        ),
    ),
    request_body(
        content = RecoveryPaymentsCreate,
        examples(
            (
                "Fully Managed Recovery" = (
                    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",
                        "billing_started_at": "2022-09-10T10:11:12Z",
                        "billing": {
                            "address": {
                                "line1": "1467 Harrison Street",
                                "city": "San Francisco",
                                "state": "California",
                                "zip": "94122",
                                "country": "US",
                                "first_name": "John",
                                "last_name": "Doe"
                            },
                            "email": "[email protected]"
                        },
                        "error": {
                            "code": "card_declined",
                            "message": "The card was declined.",
                            "reason": "Insufficient funds",
                            "network_advice_code": "01",
                            "network_decline_code": "51",
                            "network_error_message": "Retry after some time"
                        },
                        "payment_method_data": {
                            "primary_processor_payment_method_token": "token_1234",
                            "payment_method_metadata": {
                                "card_network": "Visa",
                                "card_type": "credit",
                                "last4": "4242",
                                "card_isin": "424242",
                                "card_extended_bin": "42424242",
                                "card_exp_month": "01",
                                "card_exp_year": "2026"
                            }
                        },
                    })
                )
            ),
            (
                "Schedule Only Recovery" = (
                    value = json!({
                        "amount_details": {
                            "order_amount": 6540,
                            "currency": "USD"
                        },
                        "merchant_reference_id": "invoice_mbabizu24mvu3mela5njyh",
                        "connector": "stripe",
                        "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",
                        "billing_started_at": "2022-09-10T10:11:12Z",
                        "billing": {
                            "address": {
                                "line1": "1467 Harrison Street",
                                "city": "San Francisco",
                                "state": "California",
                                "zip": "94122",
                                "country": "US",
                                "first_name": "John",
                                "last_name": "Doe"
                            },
                            "phone": {
                                "number": "9123456789",
                                "country_code": "+1"
                            },
                            "email": "[email protected]"
                        },
                        "error": {
                            "code": "card_declined",
                            "message": "The card was declined.",
                            "reason": "Insufficient funds",
                            "network_advice_code": "01",
                            "network_decline_code": "51",
                            "network_error_message": "Retry after some time"
                        },
                        "payment_method_data": {
                            "primary_processor_payment_method_token": "token_1234",
                            "payment_method_metadata": {
                                "card_network": "Visa",
                                "card_type": "credit",
                                "last4": "4242",
                                "card_isin": "424242",
                                "card_extended_bin": "42424242",
                                "card_exp_month": "01",
                                "card_exp_year": "2026"
                            }
                        },
                    })
                )
            ),
        ),
    ),
    responses(
        (
            status = 200,
            description = "The transaction is recorded (Fully Managed Recovery), or accepted to be recorded right after the answer (Schedule Only Recovery)",
            body = RecoveryPaymentsCreateResponse,
            examples(
                (
                    "Fully Managed Recovery" = (
                        summary = "Fully Managed Recovery",
                        value = json!({
                            "id": "12_pay_01a3868d94a471219b5c4bc71638e2zc",
                            "intent_status": "failed",
                            "merchant_reference_id": "invoice_mbabizu24mvu3mela5njyh"
                        })
                    )
                ),
                (
                    "Schedule Only Recovery" = (
                        summary = "Schedule Only Recovery",
                        value = json!({
                            "merchant_reference_id": "invoice_mbabizu24mvu3mela5njyh",
                            "connector_transaction_id": "993672945374576J"
                        })
                    )
                ),
            )
        ),
        (status = 400, description = "Missing or invalid mandatory fields, or, under Fully Managed Recovery, the invoice takes no more transactions", 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() {}

#[cfg(feature = "v2")]
/// Revenue Recovery - Cancel
///
/// Cancel the revenue recovery workflow of an invoice that is still in recovery: its scheduled
/// retries are stopped and no further recovery attempts are made. A `failed` payment moves to
/// `cancelled`, and a partially captured payment moves to `cancelled_post_capture`. The request
/// is refused with `400` when the payment is in any other state, when a retry is in progress,
/// or when recovery already reached a terminal status. The invoice is looked up by its merchant
/// reference id within the business profile given in the `X-Profile-Id` header.
#[utoipa::path(
    post,
    path = "/v2/recovery/{merchant_reference_id}/cancel",
    params(
        ("merchant_reference_id" = String, Path, description = "Merchant reference id of the invoice whose revenue recovery workflow should be cancelled"),
        (
            "X-Profile-Id" = String, Header,
            description = "Unique identifier of the business profile under which the invoice is processed.",
            example = "pro_abcdefghijklmnop"
        ),
    ),
    responses(
        (
            status = 200,
            description = "Revenue Recovery workflow cancelled successfully",
            body = RecoveryPaymentsResponse,
            example = json!({
                "id": "12_pay_01a3868d94a471219b5c4bc71638e2zc",
                "intent_status": "cancelled",
                "merchant_reference_id": "invoice_mbabizu24mvu3mela5njyh"
            })
        ),
        (status = 400, description = "The invoice cannot be cancelled: its payment is not failed or partially captured, a retry is in progress, or recovery already reached a terminal status", body = GenericErrorResponseOpenApi),
        (status = 404, description = "Invoice not found"),
        (status = 500, description = "Internal server error"),
    ),
    tag = "Revenue Recovery",
    operation_id = "Cancel a Revenue Recovery Workflow",
    security(("api_key" = []))
)]
pub async fn revenue_recovery_cancel() {}