mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 12:15:40 +08:00
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:
committed by
GitHub
parent
da5102efe2
commit
5be0c2bfd2
@ -22,9 +22,9 @@ use crate::{
|
||||
PaymentsApproveRequest, PaymentsCancelRequest, PaymentsCaptureRequest,
|
||||
PaymentsCompleteAuthorizeRequest, PaymentsExternalAuthenticationRequest,
|
||||
PaymentsExternalAuthenticationResponse, PaymentsIncrementalAuthorizationRequest,
|
||||
PaymentsManualUpdateRequest, PaymentsRejectRequest, PaymentsRequest, PaymentsResponse,
|
||||
PaymentsRetrieveRequest, PaymentsSessionResponse, PaymentsStartRequest,
|
||||
RedirectionResponse,
|
||||
PaymentsManualUpdateRequest, PaymentsManualUpdateResponse, PaymentsRejectRequest,
|
||||
PaymentsRequest, PaymentsResponse, PaymentsRetrieveRequest, PaymentsSessionResponse,
|
||||
PaymentsStartRequest, RedirectionResponse,
|
||||
},
|
||||
};
|
||||
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 {
|
||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||
Some(ApiEventsType::Payment {
|
||||
|
||||
@ -5054,6 +5054,29 @@ pub struct PaymentsManualUpdateRequest {
|
||||
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)]
|
||||
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)]
|
||||
|
||||
@ -436,6 +436,7 @@ pub enum PaymentAttemptUpdate {
|
||||
updated_by: String,
|
||||
unified_code: Option<String>,
|
||||
unified_message: Option<String>,
|
||||
connector_transaction_id: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
@ -1645,6 +1646,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
|
||||
updated_by,
|
||||
unified_code,
|
||||
unified_message,
|
||||
connector_transaction_id,
|
||||
} => Self {
|
||||
status,
|
||||
error_code: error_code.map(Some),
|
||||
@ -1657,7 +1659,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
|
||||
amount: None,
|
||||
net_amount: None,
|
||||
currency: None,
|
||||
connector_transaction_id: None,
|
||||
connector_transaction_id,
|
||||
amount_to_capture: None,
|
||||
connector: None,
|
||||
authentication_type: None,
|
||||
|
||||
@ -473,6 +473,7 @@ pub enum PaymentAttemptUpdate {
|
||||
updated_by: String,
|
||||
unified_code: Option<String>,
|
||||
unified_message: Option<String>,
|
||||
connector_transaction_id: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -4416,7 +4416,7 @@ pub async fn get_extended_card_info(
|
||||
pub async fn payments_manual_update(
|
||||
state: SessionState,
|
||||
req: api_models::payments::PaymentsManualUpdateRequest,
|
||||
) -> RouterResponse<serde_json::Value> {
|
||||
) -> RouterResponse<api_models::payments::PaymentsManualUpdateResponse> {
|
||||
let api_models::payments::PaymentsManualUpdateRequest {
|
||||
payment_id,
|
||||
attempt_id,
|
||||
@ -4425,6 +4425,7 @@ pub async fn payments_manual_update(
|
||||
error_code,
|
||||
error_message,
|
||||
error_reason,
|
||||
connector_transaction_id,
|
||||
} = req;
|
||||
let key_manager_state = &(&state).into();
|
||||
let key_store = state
|
||||
@ -4494,6 +4495,7 @@ pub async fn payments_manual_update(
|
||||
updated_by: merchant_account.storage_scheme.to_string(),
|
||||
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,
|
||||
};
|
||||
let updated_payment_attempt = state
|
||||
.store
|
||||
@ -4525,5 +4527,16 @@ pub async fn payments_manual_update(
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
.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,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
@ -1486,7 +1486,7 @@ pub async fn payments_manual_update(
|
||||
&req,
|
||||
payload,
|
||||
|state, _auth, req, _req_state| payments::payments_manual_update(state, req),
|
||||
&auth::AdminApiAuth,
|
||||
&auth::AdminApiAuthWithMerchantId::default(),
|
||||
locking_action,
|
||||
))
|
||||
.await
|
||||
|
||||
@ -1917,6 +1917,7 @@ impl DataModelExt for PaymentAttemptUpdate {
|
||||
updated_by,
|
||||
unified_code,
|
||||
unified_message,
|
||||
connector_transaction_id,
|
||||
} => DieselPaymentAttemptUpdate::ManualUpdate {
|
||||
status,
|
||||
error_code,
|
||||
@ -1925,6 +1926,7 @@ impl DataModelExt for PaymentAttemptUpdate {
|
||||
updated_by,
|
||||
unified_code,
|
||||
unified_message,
|
||||
connector_transaction_id,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -2267,6 +2269,7 @@ impl DataModelExt for PaymentAttemptUpdate {
|
||||
updated_by,
|
||||
unified_code,
|
||||
unified_message,
|
||||
connector_transaction_id,
|
||||
} => Self::ManualUpdate {
|
||||
status,
|
||||
error_code,
|
||||
@ -2275,6 +2278,7 @@ impl DataModelExt for PaymentAttemptUpdate {
|
||||
updated_by,
|
||||
unified_code,
|
||||
unified_message,
|
||||
connector_transaction_id,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user