mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 05:17:02 +08:00
feat(router): add payments manual-update api (#5045)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
2e1167acbc
commit
ed021c1d99
@ -4134,3 +4134,115 @@ pub async fn get_extended_card_info(
|
||||
payments_api::ExtendedCardInfoResponse { payload },
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(feature = "olap")]
|
||||
pub async fn payments_manual_update(
|
||||
state: SessionState,
|
||||
req: api_models::payments::PaymentsManualUpdateRequest,
|
||||
) -> RouterResponse<serde_json::Value> {
|
||||
let api_models::payments::PaymentsManualUpdateRequest {
|
||||
payment_id,
|
||||
attempt_id,
|
||||
merchant_id,
|
||||
attempt_status,
|
||||
error_code,
|
||||
error_message,
|
||||
error_reason,
|
||||
} = req;
|
||||
let key_store = state
|
||||
.store
|
||||
.get_merchant_key_store_by_merchant_id(
|
||||
&merchant_id,
|
||||
&state.store.get_master_key().to_vec().into(),
|
||||
)
|
||||
.await
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
|
||||
.attach_printable("Error while fetching the key store by merchant_id")?;
|
||||
let merchant_account = state
|
||||
.store
|
||||
.find_merchant_account_by_merchant_id(&merchant_id, &key_store)
|
||||
.await
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
|
||||
.attach_printable("Error while fetching the merchant_account by merchant_id")?;
|
||||
let payment_attempt = state
|
||||
.store
|
||||
.find_payment_attempt_by_payment_id_merchant_id_attempt_id(
|
||||
&payment_id,
|
||||
&merchant_id,
|
||||
&attempt_id.clone(),
|
||||
merchant_account.storage_scheme,
|
||||
)
|
||||
.await
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
.attach_printable(
|
||||
"Error while fetching the payment_attempt by payment_id, merchant_id and attempt_id",
|
||||
)?;
|
||||
let payment_intent = state
|
||||
.store
|
||||
.find_payment_intent_by_payment_id_merchant_id(
|
||||
&payment_id,
|
||||
&merchant_account.merchant_id,
|
||||
&key_store,
|
||||
merchant_account.storage_scheme,
|
||||
)
|
||||
.await
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
.attach_printable("Error while fetching the payment_intent by payment_id, merchant_id")?;
|
||||
let option_gsm = if let Some(((code, message), connector_name)) = error_code
|
||||
.as_ref()
|
||||
.zip(error_message.as_ref())
|
||||
.zip(payment_attempt.connector.as_ref())
|
||||
{
|
||||
helpers::get_gsm_record(
|
||||
&state,
|
||||
Some(code.to_string()),
|
||||
Some(message.to_string()),
|
||||
connector_name.to_string(),
|
||||
// We need to get the unified_code and unified_message of the Authorize flow
|
||||
"Authorize".to_string(),
|
||||
)
|
||||
.await
|
||||
} else {
|
||||
None
|
||||
};
|
||||
// Update the payment_attempt
|
||||
let attempt_update = storage::PaymentAttemptUpdate::ManualUpdate {
|
||||
status: attempt_status,
|
||||
error_code,
|
||||
error_message,
|
||||
error_reason,
|
||||
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),
|
||||
};
|
||||
let updated_payment_attempt = state
|
||||
.store
|
||||
.update_payment_attempt_with_attempt_id(
|
||||
payment_attempt.clone(),
|
||||
attempt_update,
|
||||
merchant_account.storage_scheme,
|
||||
)
|
||||
.await
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
.attach_printable("Error while updating the payment_attempt")?;
|
||||
// If the payment_attempt is active attempt for an intent, update the intent status
|
||||
if payment_intent.active_attempt.get_id() == payment_attempt.attempt_id {
|
||||
let intent_status = enums::IntentStatus::foreign_from(updated_payment_attempt.status);
|
||||
let payment_intent_update = storage::PaymentIntentUpdate::ManualUpdate {
|
||||
status: Some(intent_status),
|
||||
updated_by: merchant_account.storage_scheme.to_string(),
|
||||
};
|
||||
state
|
||||
.store
|
||||
.update_payment_intent(
|
||||
payment_intent,
|
||||
payment_intent_update,
|
||||
&key_store,
|
||||
merchant_account.storage_scheme,
|
||||
)
|
||||
.await
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
.attach_printable("Error while updating payment_intent")?;
|
||||
}
|
||||
Ok(services::ApplicationResponse::StatusOk)
|
||||
}
|
||||
|
||||
@ -460,6 +460,10 @@ impl Payments {
|
||||
)
|
||||
.service(web::resource("/filter").route(web::post().to(get_filters_for_payments)))
|
||||
.service(web::resource("/v2/filter").route(web::get().to(get_payment_filters)))
|
||||
.service(
|
||||
web::resource("/{payment_id}/manual-update")
|
||||
.route(web::put().to(payments_manual_update)),
|
||||
)
|
||||
}
|
||||
#[cfg(feature = "oltp")]
|
||||
{
|
||||
|
||||
@ -124,7 +124,8 @@ impl From<Flow> for ApiIdentifier {
|
||||
| Flow::PaymentsExternalAuthentication
|
||||
| Flow::PaymentsAuthorize
|
||||
| Flow::GetExtendedCardInfo
|
||||
| Flow::PaymentsCompleteAuthorize => Self::Payments,
|
||||
| Flow::PaymentsCompleteAuthorize
|
||||
| Flow::PaymentsManualUpdate => Self::Payments,
|
||||
|
||||
Flow::PayoutsCreate
|
||||
| Flow::PayoutsRetrieve
|
||||
|
||||
@ -1394,6 +1394,35 @@ pub async fn post_3ds_payments_authorize(
|
||||
.await
|
||||
}
|
||||
|
||||
#[cfg(feature = "olap")]
|
||||
pub async fn payments_manual_update(
|
||||
state: web::Data<app::AppState>,
|
||||
req: actix_web::HttpRequest,
|
||||
json_payload: web::Json<payment_types::PaymentsManualUpdateRequest>,
|
||||
path: web::Path<String>,
|
||||
) -> impl Responder {
|
||||
let flow = Flow::PaymentsManualUpdate;
|
||||
let mut payload = json_payload.into_inner();
|
||||
let payment_id = path.into_inner();
|
||||
|
||||
let locking_action = payload.get_locking_input(flow.clone());
|
||||
|
||||
tracing::Span::current().record("payment_id", &payment_id);
|
||||
|
||||
payload.payment_id = payment_id;
|
||||
|
||||
Box::pin(api::server_wrap(
|
||||
flow,
|
||||
state,
|
||||
&req,
|
||||
payload,
|
||||
|state, _auth, req, _req_state| payments::payments_manual_update(state, req),
|
||||
&auth::AdminApiAuth,
|
||||
locking_action,
|
||||
))
|
||||
.await
|
||||
}
|
||||
|
||||
/// Retrieve endpoint for merchant to fetch the encrypted customer payment method data
|
||||
#[instrument(skip_all, fields(flow = ?Flow::GetExtendedCardInfo, payment_id))]
|
||||
pub async fn retrieve_extended_card_info(
|
||||
@ -1654,3 +1683,19 @@ impl GetLockingInput for payment_types::PaymentsExternalAuthenticationRequest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GetLockingInput for payment_types::PaymentsManualUpdateRequest {
|
||||
fn get_locking_input<F>(&self, flow: F) -> api_locking::LockAction
|
||||
where
|
||||
F: types::FlowMetric,
|
||||
lock_utils::ApiIdentifier: From<F>,
|
||||
{
|
||||
api_locking::LockAction::Hold {
|
||||
input: api_locking::LockingInput {
|
||||
unique_locking_key: self.payment_id.to_owned(),
|
||||
api_identifier: lock_utils::ApiIdentifier::from(flow),
|
||||
override_lock_retries: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,11 +8,11 @@ pub use api_models::payments::{
|
||||
PaymentRetrieveBody, PaymentRetrieveBodyWithCredentials, PaymentsApproveRequest,
|
||||
PaymentsCancelRequest, PaymentsCaptureRequest, PaymentsCompleteAuthorizeRequest,
|
||||
PaymentsExternalAuthenticationRequest, PaymentsIncrementalAuthorizationRequest,
|
||||
PaymentsRedirectRequest, PaymentsRedirectionResponse, PaymentsRejectRequest, PaymentsRequest,
|
||||
PaymentsResponse, PaymentsResponseForm, PaymentsRetrieveRequest, PaymentsSessionRequest,
|
||||
PaymentsSessionResponse, PaymentsStartRequest, PgRedirectResponse, PhoneDetails,
|
||||
RedirectionResponse, SessionToken, TimeRange, UrlDetails, VerifyRequest, VerifyResponse,
|
||||
WalletData,
|
||||
PaymentsManualUpdateRequest, PaymentsRedirectRequest, PaymentsRedirectionResponse,
|
||||
PaymentsRejectRequest, PaymentsRequest, PaymentsResponse, PaymentsResponseForm,
|
||||
PaymentsRetrieveRequest, PaymentsSessionRequest, PaymentsSessionResponse, PaymentsStartRequest,
|
||||
PgRedirectResponse, PhoneDetails, RedirectionResponse, SessionToken, TimeRange, UrlDetails,
|
||||
VerifyRequest, VerifyResponse, WalletData,
|
||||
};
|
||||
use error_stack::ResultExt;
|
||||
pub use hyperswitch_domain_models::router_flow_types::payments::{
|
||||
|
||||
Reference in New Issue
Block a user