File size: 9,199 Bytes
f7453fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
  "commit_sha": "ece0e2b94281f8fcc9460ca2ce12e7362add0a31",
  "pr_number": 10092,
  "rust_files": [
    "crates/router/src/workflows/revenue_recovery.rs"
  ],
  "diffs": [
    {
      "id": "crates/router/src/workflows/revenue_recovery.rs::function::call_decider_for_payment_processor_tokens_select_closest_time",
      "file": "crates/router/src/workflows/revenue_recovery.rs",
      "kind": "function_item",
      "status": "modified",
      "code_changed": true,
      "imports_changed": false,
      "before_code": "pub async fn call_decider_for_payment_processor_tokens_select_closest_time(\n    state: &SessionState,\n    processor_tokens: &HashMap<String, PaymentProcessorTokenWithRetryInfo>,\n    payment_intent: &PaymentIntent,\n    connector_customer_id: &str,\n) -> CustomResult<PaymentProcessorTokenResponse, errors::ProcessTrackerError> {\n    let mut tokens_with_schedule_time: Vec<ScheduledToken> = Vec::new();\n\n    // Check for successful token\n    let mut token_with_none_error_code = processor_tokens.values().find(|token| {\n        token.token_status.error_code.is_none()\n            && !token.token_status.is_hard_decline.unwrap_or(false)\n    });\n\n    match token_with_none_error_code {\n        Some(token_with_retry_info) => {\n            let token_details = &token_with_retry_info\n                .token_status\n                .payment_processor_token_details;\n\n            let utc_schedule_time = time::OffsetDateTime::now_utc() + time::Duration::minutes(1);\n            let schedule_time =\n                time::PrimitiveDateTime::new(utc_schedule_time.date(), utc_schedule_time.time());\n\n            tokens_with_schedule_time = vec![ScheduledToken {\n                token_details: token_details.clone(),\n                schedule_time,\n            }];\n\n            tracing::debug!(\n                \"Found payment processor token with no error code, scheduling it for {schedule_time}\",\n            );\n        }\n\n        None => {\n            for token_with_retry_info in processor_tokens.values() {\n                process_token_for_retry(state, token_with_retry_info, payment_intent)\n                    .await?\n                    .map(|token_with_schedule_time| {\n                        tokens_with_schedule_time.push(token_with_schedule_time)\n                    });\n            }\n        }\n    }\n\n    let best_token = tokens_with_schedule_time\n        .iter()\n        .min_by_key(|token| token.schedule_time)\n        .cloned();\n\n    let mut payment_processor_token_response;\n    match best_token {\n        None => {\n            // No tokens available for scheduling, unlock the connector customer status\n\n            // Check if all tokens are hard declined\n            let hard_decline_status = processor_tokens\n                .values()\n                .all(|token| token.token_status.is_hard_decline.unwrap_or(false));\n\n            RedisTokenManager::unlock_connector_customer_status(state, connector_customer_id)\n                .await\n                .change_context(errors::ProcessTrackerError::EApiErrorResponse)?;\n\n            tracing::debug!(\"No payment processor tokens available for scheduling\");\n\n            if hard_decline_status {\n                payment_processor_token_response = PaymentProcessorTokenResponse::HardDecline;\n            } else {\n                payment_processor_token_response = PaymentProcessorTokenResponse::None;\n            }\n        }\n\n        Some(token) => {\n            tracing::debug!(\"Found payment processor token with least schedule time\");\n\n            RedisTokenManager::update_payment_processor_tokens_schedule_time_to_none(\n                state,\n                connector_customer_id,\n            )\n            .await\n            .change_context(errors::ProcessTrackerError::EApiErrorResponse)?;\n\n            RedisTokenManager::update_payment_processor_token_schedule_time(\n                state,\n                connector_customer_id,\n                &token.token_details.payment_processor_token,\n                Some(token.schedule_time),\n            )\n            .await\n            .change_context(errors::ProcessTrackerError::EApiErrorResponse)?;\n\n            payment_processor_token_response = PaymentProcessorTokenResponse::ScheduledTime {\n                scheduled_time: token.schedule_time,\n            };\n        }\n    }\n    Ok(payment_processor_token_response)\n}",
      "after_code": "pub async fn call_decider_for_payment_processor_tokens_select_closest_time(\n    state: &SessionState,\n    processor_tokens: &HashMap<String, PaymentProcessorTokenWithRetryInfo>,\n    payment_intent: &PaymentIntent,\n    connector_customer_id: &str,\n) -> CustomResult<PaymentProcessorTokenResponse, errors::ProcessTrackerError> {\n    let mut tokens_with_schedule_time: Vec<ScheduledToken> = Vec::new();\n\n    // Check for successful token\n    let mut token_with_none_error_code = processor_tokens.values().find(|token| {\n        token.token_status.error_code.is_none()\n            && !token.token_status.is_hard_decline.unwrap_or(false)\n    });\n\n    match token_with_none_error_code {\n        Some(token_with_retry_info) => {\n            let token_details = &token_with_retry_info\n                .token_status\n                .payment_processor_token_details;\n\n            let utc_schedule_time = time::OffsetDateTime::now_utc() + time::Duration::minutes(1);\n            let schedule_time =\n                time::PrimitiveDateTime::new(utc_schedule_time.date(), utc_schedule_time.time());\n\n            tokens_with_schedule_time = vec![ScheduledToken {\n                token_details: token_details.clone(),\n                schedule_time,\n            }];\n\n            tracing::debug!(\n                \"Found payment processor token with no error code, scheduling it for {schedule_time}\",\n            );\n        }\n\n        None => {\n            for token_with_retry_info in processor_tokens.values() {\n                process_token_for_retry(state, token_with_retry_info, payment_intent)\n                    .await?\n                    .map(|token_with_schedule_time| {\n                        tokens_with_schedule_time.push(token_with_schedule_time)\n                    });\n            }\n        }\n    }\n\n    let best_token = tokens_with_schedule_time\n        .iter()\n        .min_by_key(|token| token.schedule_time)\n        .cloned();\n\n    let mut payment_processor_token_response;\n    match best_token {\n        None => {\n            // No tokens available for scheduling, unlock the connector customer status\n\n            // Check if all tokens are hard declined\n            let hard_decline_status = processor_tokens\n                .values()\n                .all(|token| token.token_status.is_hard_decline.unwrap_or(false))\n                && !processor_tokens.is_empty();\n        \n\n            RedisTokenManager::unlock_connector_customer_status(state, connector_customer_id)\n                .await\n                .change_context(errors::ProcessTrackerError::EApiErrorResponse)?;\n\n            tracing::debug!(\"No payment processor tokens available for scheduling\");\n\n            if hard_decline_status {\n                payment_processor_token_response = PaymentProcessorTokenResponse::HardDecline;\n            } else {\n                payment_processor_token_response = PaymentProcessorTokenResponse::None;\n            }\n        }\n\n        Some(token) => {\n            tracing::debug!(\"Found payment processor token with least schedule time\");\n\n            RedisTokenManager::update_payment_processor_tokens_schedule_time_to_none(\n                state,\n                connector_customer_id,\n            )\n            .await\n            .change_context(errors::ProcessTrackerError::EApiErrorResponse)?;\n\n            RedisTokenManager::update_payment_processor_token_schedule_time(\n                state,\n                connector_customer_id,\n                &token.token_details.payment_processor_token,\n                Some(token.schedule_time),\n            )\n            .await\n            .change_context(errors::ProcessTrackerError::EApiErrorResponse)?;\n\n            payment_processor_token_response = PaymentProcessorTokenResponse::ScheduledTime {\n                scheduled_time: token.schedule_time,\n            };\n        }\n    }\n    Ok(payment_processor_token_response)\n}",
      "diff_span": {
        "before": "            let hard_decline_status = processor_tokens\n                .values()\n                .all(|token| token.token_status.is_hard_decline.unwrap_or(false));\n\n            RedisTokenManager::unlock_connector_customer_status(state, connector_customer_id)",
        "after": "            let hard_decline_status = processor_tokens\n                .values()\n                .all(|token| token.token_status.is_hard_decline.unwrap_or(false))\n                && !processor_tokens.is_empty();\n        \n\n            RedisTokenManager::unlock_connector_customer_status(state, connector_customer_id)"
      },
      "commit_sha": "ece0e2b94281f8fcc9460ca2ce12e7362add0a31"
    }
  ]
}