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(core): Add amount_captured field to manual update api (#14136)

Vani Gupta051c96914a69
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index 5681c9b526..f334eb5ad5 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -11828,6 +11828,8 @@ pub struct PaymentsManualUpdateRequest {
/// Whether to update amount_captured using amount_to_capture from the attempt.
/// When true, amount_captured will be set to amount_to_capture
pub update_amount_captured: Option<bool>,
+ /// The amount that has been captured for the payment.
+ pub amount_captured: Option<MinorUnit>,
}
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 540e378f3c..d4104cb32c 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -13828,6 +13828,7 @@ pub async fn payments_manual_update(
connector_transaction_id,
amount_capturable,
update_amount_captured,
+ amount_captured,
} = req;
let key_store = state
.store
@@ -13870,6 +13871,23 @@ pub async fn payments_manual_update(
)?;
}
+ if let Some(amount_captured) = amount_captured {
+ utils::when(update_amount_captured == Some(true), || {
+ Err(errors::ApiErrorResponse::InvalidRequestData {
+ message: "amount_captured cannot be provided when update_amount_captured is true"
+ .to_string(),
+ })
+ })?;
+ utils::when(
+ amount_captured > payment_attempt.net_amount.get_total_amount(),
+ || {
+ Err(errors::ApiErrorResponse::InvalidRequestData {
+ message: "amount_captured should be less than or equal to amount".to_string(),
+ })
+ },
+ )?;
+ }
+
let payment_intent = state
.store
.find_payment_intent_by_payment_id_processor_merchant_id(
@@ -13920,7 +13938,7 @@ pub async fn payments_manual_update(
.unwrap_or(payment_attempt.net_amount.get_total_amount());
Some(new_captured_amount)
} else {
- None
+ amount_captured
};
let option_gsm = if let Some(((code, message), connector_name)) = error_code