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_capturable field to manual update api (#10013)

awasthi2134cd79df7c30
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index f20afcf61e..f3a6ff88bf 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -8556,6 +8556,8 @@ pub struct PaymentsManualUpdateRequest {
pub error_reason: Option<String>,
/// A unique identifier for a payment provided by the connector
pub connector_transaction_id: Option<String>,
+ /// The amount that can be captured on the payment.
+ pub amount_capturable: Option<MinorUnit>,
}
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]
@@ -8577,6 +8579,8 @@ pub struct PaymentsManualUpdateResponse {
pub error_reason: Option<String>,
/// A unique identifier for a payment provided by the connector
pub connector_transaction_id: Option<String>,
+ /// The amount that can be captured on the payment.
+ pub amount_capturable: Option<MinorUnit>,
}
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]
diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs
index c28d0ab820..2ba97f900b 100644
--- a/crates/diesel_models/src/payment_attempt.rs
+++ b/crates/diesel_models/src/payment_attempt.rs
@@ -676,6 +676,7 @@ pub enum PaymentAttemptUpdate {
unified_code: Option<String>,
unified_message: Option<String>,
connector_transaction_id: Option<String>,
+ amount_capturable: Option<MinorUnit>,
},
PostSessionTokensUpdate {
updated_by: String,
@@ -865,6 +866,7 @@ pub enum PaymentAttemptUpdate {
unified_code: Option<String>,
unified_message: Option<String>,
connector_payment_id: Option<String>,
+ amount_capturable: Option<MinorUnit>,
},
}
@@ -1625,6 +1627,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
unified_code,
unified_message,
connector_payment_id,
+ amount_capturable,
} => {
let (connector_payment_id, connector_payment_data) = connector_payment_id
.map(ConnectorTransactionId::form_id_and_data)
@@ -1646,7 +1649,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
payment_method_id: None,
browser_info: None,
connector_metadata: None,
- amount_capturable: None,
+ amount_capturable,
amount_to_capture: None,
merchant_connector_id: None,
connector: None,
@@ -4130,6 +4133,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
unified_code,
unified_message,
connector_transaction_id,
+ amount_capturable,
} => {
let (connector_transaction_id, processor_transaction_data) =
connector_transaction_id
@@ -4171,7 +4175,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
multiple_capture_count: None,
surcharge_amount: None,
tax_amount: None,
- amount_capturable: None,
+ amount_capturable,
merchant_connector_id: None,
authentication_data: None,
encoded_data: None,
diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
index 7a2616bfcc..89bb31de56 100644
--- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
+++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
@@ -1556,6 +1556,7 @@ pub enum PaymentAttemptUpdate {
unified_code: Option<String>,
unified_message: Option<String>,
connector_transaction_id: Option<String>,
+ amount_capturable: Option<MinorUnit>,
},
PostSessionTokensUpdate {
updated_by: String,
@@ -1962,6 +1963,7 @@ impl PaymentAttemptUpdate {
unified_code,
unified_message,
connector_transaction_id,
+ amount_capturable,
} => DieselPaymentAttemptUpdate::ManualUpdate {
status,
error_code,
@@ -1971,6 +1973,7 @@ impl PaymentAttemptUpdate {
unified_code,
unified_message,
connector_transaction_id,
+ amount_capturable,
},
Self::PostSessionTokensUpdate {
updated_by,
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 4059d315a9..ba771c2e0f 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -10579,6 +10579,7 @@ pub async fn payments_manual_update(
error_message,
error_reason,
connector_transaction_id,
+ amount_capturable,
} = req;
let key_manager_state = &(&state).into();
let key_store = state
@@ -10611,6 +10612,17 @@ pub async fn payments_manual_update(
"Error while fetching the payment_attempt by payment_id, merchant_id and attempt_id",
)?;
+ if let Some(amount_capturable) = amount_capturable {
+ utils::when(
+ amount_capturable > payment_attempt.net_amount.get_total_amount(),
+ || {
+ Err(errors::ApiErrorResponse::InvalidRequestData {
+ message: "amount_capturable should be less than or equal to amount".to_string(),
+ })
+ },
+ )?;
+ }
+
let payment_intent = state
.store
.find_payment_intent_by_payment_id_merchant_id(
@@ -10651,6 +10663,7 @@ pub async fn payments_manual_update(
unified_code: option_gsm.as_ref().and_then(|gsm| gsm.unified_code.clone()),
unified_message: option_gsm.and_then(|gsm| gsm.unified_message),
connector_transaction_id,
+ amount_capturable,
};
let updated_payment_attempt = state
.store
@@ -10692,6 +10705,7 @@ pub async fn payments_manual_update(
error_message: updated_payment_attempt.error_message,
error_reason: updated_payment_attempt.error_reason,
connector_transaction_id: updated_payment_attempt.connector_transaction_id,
+ amount_capturable: Some(updated_payment_attempt.amount_capturable),
},
))
}