refactor(router): add connector_transaction_id, send response body and use admin_api_auth_with_merchant_id for payments manual update flow (#5658)

This commit is contained in:
Sai Harsha Vardhan
2024-08-22 15:48:15 +05:30
committed by GitHub
parent da5102efe2
commit 5be0c2bfd2
7 changed files with 58 additions and 7 deletions

View File

@ -22,9 +22,9 @@ use crate::{
PaymentsApproveRequest, PaymentsCancelRequest, PaymentsCaptureRequest, PaymentsApproveRequest, PaymentsCancelRequest, PaymentsCaptureRequest,
PaymentsCompleteAuthorizeRequest, PaymentsExternalAuthenticationRequest, PaymentsCompleteAuthorizeRequest, PaymentsExternalAuthenticationRequest,
PaymentsExternalAuthenticationResponse, PaymentsIncrementalAuthorizationRequest, PaymentsExternalAuthenticationResponse, PaymentsIncrementalAuthorizationRequest,
PaymentsManualUpdateRequest, PaymentsRejectRequest, PaymentsRequest, PaymentsResponse, PaymentsManualUpdateRequest, PaymentsManualUpdateResponse, PaymentsRejectRequest,
PaymentsRetrieveRequest, PaymentsSessionResponse, PaymentsStartRequest, PaymentsRequest, PaymentsResponse, PaymentsRetrieveRequest, PaymentsSessionResponse,
RedirectionResponse, PaymentsStartRequest, RedirectionResponse,
}, },
}; };
impl ApiEventMetric for PaymentsRetrieveRequest { impl ApiEventMetric for PaymentsRetrieveRequest {
@ -262,6 +262,14 @@ impl ApiEventMetric for PaymentsManualUpdateRequest {
} }
} }
impl ApiEventMetric for PaymentsManualUpdateResponse {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
Some(ApiEventsType::Payment {
payment_id: self.payment_id.clone(),
})
}
}
impl ApiEventMetric for PaymentsSessionResponse { impl ApiEventMetric for PaymentsSessionResponse {
fn get_api_event_type(&self) -> Option<ApiEventsType> { fn get_api_event_type(&self) -> Option<ApiEventsType> {
Some(ApiEventsType::Payment { Some(ApiEventsType::Payment {

View File

@ -5054,6 +5054,29 @@ pub struct PaymentsManualUpdateRequest {
pub error_message: Option<String>, pub error_message: Option<String>,
/// Error reason of the connector /// Error reason of the connector
pub error_reason: Option<String>, pub error_reason: Option<String>,
/// A unique identifier for a payment provided by the connector
pub connector_transaction_id: Option<String>,
}
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]
pub struct PaymentsManualUpdateResponse {
/// The identifier for the payment
pub payment_id: String,
/// The identifier for the payment attempt
pub attempt_id: String,
/// Merchant ID
#[schema(value_type = String)]
pub merchant_id: id_type::MerchantId,
/// The status of the attempt
pub attempt_status: enums::AttemptStatus,
/// Error code of the connector
pub error_code: Option<String>,
/// Error message of the connector
pub error_message: Option<String>,
/// Error reason of the connector
pub error_reason: Option<String>,
/// A unique identifier for a payment provided by the connector
pub connector_transaction_id: Option<String>,
} }
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)] #[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]

View File

@ -436,6 +436,7 @@ pub enum PaymentAttemptUpdate {
updated_by: String, updated_by: String,
unified_code: Option<String>, unified_code: Option<String>,
unified_message: Option<String>, unified_message: Option<String>,
connector_transaction_id: Option<String>,
}, },
} }
@ -1645,6 +1646,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
updated_by, updated_by,
unified_code, unified_code,
unified_message, unified_message,
connector_transaction_id,
} => Self { } => Self {
status, status,
error_code: error_code.map(Some), error_code: error_code.map(Some),
@ -1657,7 +1659,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
amount: None, amount: None,
net_amount: None, net_amount: None,
currency: None, currency: None,
connector_transaction_id: None, connector_transaction_id,
amount_to_capture: None, amount_to_capture: None,
connector: None, connector: None,
authentication_type: None, authentication_type: None,

View File

@ -473,6 +473,7 @@ pub enum PaymentAttemptUpdate {
updated_by: String, updated_by: String,
unified_code: Option<String>, unified_code: Option<String>,
unified_message: Option<String>, unified_message: Option<String>,
connector_transaction_id: Option<String>,
}, },
} }

View File

@ -4416,7 +4416,7 @@ pub async fn get_extended_card_info(
pub async fn payments_manual_update( pub async fn payments_manual_update(
state: SessionState, state: SessionState,
req: api_models::payments::PaymentsManualUpdateRequest, req: api_models::payments::PaymentsManualUpdateRequest,
) -> RouterResponse<serde_json::Value> { ) -> RouterResponse<api_models::payments::PaymentsManualUpdateResponse> {
let api_models::payments::PaymentsManualUpdateRequest { let api_models::payments::PaymentsManualUpdateRequest {
payment_id, payment_id,
attempt_id, attempt_id,
@ -4425,6 +4425,7 @@ pub async fn payments_manual_update(
error_code, error_code,
error_message, error_message,
error_reason, error_reason,
connector_transaction_id,
} = req; } = req;
let key_manager_state = &(&state).into(); let key_manager_state = &(&state).into();
let key_store = state let key_store = state
@ -4494,6 +4495,7 @@ pub async fn payments_manual_update(
updated_by: merchant_account.storage_scheme.to_string(), updated_by: merchant_account.storage_scheme.to_string(),
unified_code: option_gsm.as_ref().and_then(|gsm| gsm.unified_code.clone()), unified_code: option_gsm.as_ref().and_then(|gsm| gsm.unified_code.clone()),
unified_message: option_gsm.and_then(|gsm| gsm.unified_message), unified_message: option_gsm.and_then(|gsm| gsm.unified_message),
connector_transaction_id,
}; };
let updated_payment_attempt = state let updated_payment_attempt = state
.store .store
@ -4525,5 +4527,16 @@ pub async fn payments_manual_update(
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound) .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
.attach_printable("Error while updating payment_intent")?; .attach_printable("Error while updating payment_intent")?;
} }
Ok(services::ApplicationResponse::StatusOk) Ok(services::ApplicationResponse::Json(
api_models::payments::PaymentsManualUpdateResponse {
payment_id: updated_payment_attempt.payment_id,
attempt_id: updated_payment_attempt.attempt_id,
merchant_id: updated_payment_attempt.merchant_id,
attempt_status: updated_payment_attempt.status,
error_code: updated_payment_attempt.error_code,
error_message: updated_payment_attempt.error_message,
error_reason: updated_payment_attempt.error_reason,
connector_transaction_id: updated_payment_attempt.connector_transaction_id,
},
))
} }

View File

@ -1486,7 +1486,7 @@ pub async fn payments_manual_update(
&req, &req,
payload, payload,
|state, _auth, req, _req_state| payments::payments_manual_update(state, req), |state, _auth, req, _req_state| payments::payments_manual_update(state, req),
&auth::AdminApiAuth, &auth::AdminApiAuthWithMerchantId::default(),
locking_action, locking_action,
)) ))
.await .await

View File

@ -1917,6 +1917,7 @@ impl DataModelExt for PaymentAttemptUpdate {
updated_by, updated_by,
unified_code, unified_code,
unified_message, unified_message,
connector_transaction_id,
} => DieselPaymentAttemptUpdate::ManualUpdate { } => DieselPaymentAttemptUpdate::ManualUpdate {
status, status,
error_code, error_code,
@ -1925,6 +1926,7 @@ impl DataModelExt for PaymentAttemptUpdate {
updated_by, updated_by,
unified_code, unified_code,
unified_message, unified_message,
connector_transaction_id,
}, },
} }
} }
@ -2267,6 +2269,7 @@ impl DataModelExt for PaymentAttemptUpdate {
updated_by, updated_by,
unified_code, unified_code,
unified_message, unified_message,
connector_transaction_id,
} => Self::ManualUpdate { } => Self::ManualUpdate {
status, status,
error_code, error_code,
@ -2275,6 +2278,7 @@ impl DataModelExt for PaymentAttemptUpdate {
updated_by, updated_by,
unified_code, unified_code,
unified_message, unified_message,
connector_transaction_id,
}, },
} }
} }