feat(confirm): reduce the database calls to 2 stages in case of non-retry (#2113)

This commit is contained in:
Nishant Joshi
2023-09-11 12:10:48 +05:30
committed by GitHub
parent 76e9159344
commit 28b102de24
2 changed files with 108 additions and 40 deletions

View File

@ -2772,7 +2772,7 @@ impl AttemptType {
}
}
pub async fn get_connector_response(
pub async fn get_or_insert_connector_response(
&self,
payment_attempt: &PaymentAttempt,
db: &dyn StorageInterface,
@ -2799,6 +2799,30 @@ impl AttemptType {
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound),
}
}
pub async fn get_connector_response(
&self,
db: &dyn StorageInterface,
payment_id: &str,
merchant_id: &str,
attempt_id: &str,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> RouterResult<storage::ConnectorResponse> {
match self {
Self::New => Err(errors::ApiErrorResponse::InternalServerError)
.into_report()
.attach_printable("Precondition failed, the attempt type should not be `New`"),
Self::SameOld => db
.find_connector_response_by_payment_id_merchant_id_attempt_id(
payment_id,
merchant_id,
attempt_id,
storage_scheme,
)
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound),
}
}
}
#[inline(always)]