mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 12:06:56 +08:00
refactor(storage_models, errors): impl StorageErrorExt for error_stack::Result<T, errors::StorageError> (#886)
This commit is contained in:
@ -156,9 +156,7 @@ pub async fn create_merchant_account(
|
||||
let merchant_account = db
|
||||
.insert_merchant(merchant_account)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_duplicate_response(errors::ApiErrorResponse::DuplicateMerchantAccount)
|
||||
})?;
|
||||
.to_duplicate_response(errors::ApiErrorResponse::DuplicateMerchantAccount)?;
|
||||
|
||||
Ok(service_api::ApplicationResponse::Json(
|
||||
ForeignTryFrom::foreign_try_from(merchant_account).change_context(
|
||||
@ -176,9 +174,7 @@ pub async fn get_merchant_account(
|
||||
let merchant_account = db
|
||||
.find_merchant_account_by_merchant_id(&req.merchant_id)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
|
||||
|
||||
Ok(service_api::ApplicationResponse::Json(
|
||||
ForeignTryFrom::foreign_try_from(merchant_account).change_context(
|
||||
@ -267,9 +263,7 @@ pub async fn merchant_account_update(
|
||||
let response = db
|
||||
.update_specific_fields_in_merchant(merchant_id, updated_merchant_account)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
|
||||
|
||||
Ok(service_api::ApplicationResponse::Json(
|
||||
ForeignTryFrom::foreign_try_from(response).change_context(
|
||||
@ -287,9 +281,7 @@ pub async fn merchant_account_delete(
|
||||
let is_deleted = db
|
||||
.delete_merchant_account_by_merchant_id(&merchant_id)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
|
||||
let response = api::MerchantAccountDeleteResponse {
|
||||
merchant_id,
|
||||
deleted: is_deleted,
|
||||
@ -330,9 +322,7 @@ async fn validate_merchant_id<S: Into<String>>(
|
||||
) -> RouterResult<MerchantAccount> {
|
||||
db.find_merchant_account_by_merchant_id(&merchant_id.into())
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
|
||||
})
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
|
||||
}
|
||||
|
||||
fn get_business_details_wrapper(
|
||||
@ -364,9 +354,7 @@ pub async fn create_payment_connector(
|
||||
let merchant_account = store
|
||||
.find_merchant_account_by_merchant_id(merchant_id)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
|
||||
|
||||
let (business_country, business_label) = get_business_details_wrapper(&req, &merchant_account)?;
|
||||
|
||||
@ -431,9 +419,7 @@ pub async fn create_payment_connector(
|
||||
let mca = store
|
||||
.insert_merchant_connector_account(merchant_connector_account)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_duplicate_response(errors::ApiErrorResponse::DuplicateMerchantConnectorAccount)
|
||||
})?;
|
||||
.to_duplicate_response(errors::ApiErrorResponse::DuplicateMerchantConnectorAccount)?;
|
||||
|
||||
let mca_response = ForeignTryFrom::foreign_try_from(mca)?;
|
||||
|
||||
@ -448,9 +434,7 @@ pub async fn retrieve_payment_connector(
|
||||
let _merchant_account = store
|
||||
.find_merchant_account_by_merchant_id(&merchant_id)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
|
||||
|
||||
let mca = store
|
||||
.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
|
||||
@ -458,9 +442,7 @@ pub async fn retrieve_payment_connector(
|
||||
&merchant_connector_id,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound)?;
|
||||
|
||||
Ok(service_api::ApplicationResponse::Json(
|
||||
ForeignTryFrom::foreign_try_from(mca)?,
|
||||
@ -475,16 +457,12 @@ pub async fn list_payment_connectors(
|
||||
store
|
||||
.find_merchant_account_by_merchant_id(&merchant_id)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
err.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
|
||||
|
||||
let merchant_connector_accounts = store
|
||||
.find_merchant_connector_account_by_merchant_id_and_disabled_list(&merchant_id, true)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound)?;
|
||||
let mut response = vec![];
|
||||
|
||||
// The can be eliminated once [#79711](https://github.com/rust-lang/rust/issues/79711) is stabilized
|
||||
@ -504,9 +482,7 @@ pub async fn update_payment_connector(
|
||||
let _merchant_account = db
|
||||
.find_merchant_account_by_merchant_id(merchant_id)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
|
||||
|
||||
let mca = db
|
||||
.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
|
||||
@ -514,9 +490,7 @@ pub async fn update_payment_connector(
|
||||
merchant_connector_id,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound)?;
|
||||
|
||||
let payment_methods_enabled = req.payment_methods_enabled.map(|pm_enabled| {
|
||||
pm_enabled
|
||||
@ -568,9 +542,7 @@ pub async fn delete_payment_connector(
|
||||
let _merchant_account = db
|
||||
.find_merchant_account_by_merchant_id(&merchant_id)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
|
||||
|
||||
let is_deleted = db
|
||||
.delete_merchant_connector_account_by_merchant_id_merchant_connector_id(
|
||||
@ -578,9 +550,7 @@ pub async fn delete_payment_connector(
|
||||
&merchant_connector_id,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound)?;
|
||||
let response = api::MerchantConnectorDeleteResponse {
|
||||
merchant_id,
|
||||
merchant_connector_id,
|
||||
@ -598,9 +568,7 @@ pub async fn kv_for_merchant(
|
||||
let merchant_account = db
|
||||
.find_merchant_account_by_merchant_id(&merchant_id)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
|
||||
|
||||
let updated_merchant_account = match (enable, merchant_account.storage_scheme) {
|
||||
(true, enums::MerchantStorageScheme::RedisKv)
|
||||
@ -650,9 +618,7 @@ pub async fn check_merchant_account_kv_status(
|
||||
let merchant_account = db
|
||||
.find_merchant_account_by_merchant_id(&merchant_id)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
|
||||
|
||||
let kv_status = matches!(
|
||||
merchant_account.storage_scheme,
|
||||
|
||||
@ -179,7 +179,7 @@ pub async fn update_api_key(
|
||||
let api_key = store
|
||||
.update_api_key(key_id.to_owned(), api_key.foreign_into())
|
||||
.await
|
||||
.map_err(|err| err.to_not_found_response(errors::ApiErrorResponse::ApiKeyNotFound))?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::ApiKeyNotFound)?;
|
||||
|
||||
Ok(ApplicationResponse::Json(api_key.foreign_into()))
|
||||
}
|
||||
@ -192,7 +192,7 @@ pub async fn revoke_api_key(
|
||||
let revoked = store
|
||||
.revoke_api_key(key_id)
|
||||
.await
|
||||
.map_err(|err| err.to_not_found_response(errors::ApiErrorResponse::ApiKeyNotFound))?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::ApiKeyNotFound)?;
|
||||
|
||||
metrics::API_KEY_REVOKED.add(&metrics::CONTEXT, 1, &[]);
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ pub async fn read_config(store: &dyn StorageInterface, key: &str) -> RouterRespo
|
||||
let config = store
|
||||
.find_config_by_key_cached(key)
|
||||
.await
|
||||
.map_err(|err| err.to_not_found_response(errors::ApiErrorResponse::ConfigNotFound))?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::ConfigNotFound)?;
|
||||
Ok(ApplicationResponse::Json(config.foreign_into()))
|
||||
}
|
||||
|
||||
@ -20,6 +20,6 @@ pub async fn update_config(
|
||||
let config = store
|
||||
.update_config_cached(&config_update.key, config_update.foreign_into())
|
||||
.await
|
||||
.map_err(|err| err.to_not_found_response(errors::ApiErrorResponse::ConfigNotFound))?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::ConfigNotFound)?;
|
||||
Ok(ApplicationResponse::Json(config.foreign_into()))
|
||||
}
|
||||
|
||||
@ -75,12 +75,10 @@ pub async fn create_customer(
|
||||
if error.current_context().is_db_unique_violation() {
|
||||
db.find_customer_by_customer_id_merchant_id(customer_id, merchant_id)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
err.to_not_found_response(errors::ApiErrorResponse::InternalServerError)
|
||||
.attach_printable(format!(
|
||||
"Failed while fetching Customer, customer_id: {customer_id}",
|
||||
))
|
||||
})?
|
||||
.to_not_found_response(errors::ApiErrorResponse::InternalServerError)
|
||||
.attach_printable(format!(
|
||||
"Failed while fetching Customer, customer_id: {customer_id}",
|
||||
))?
|
||||
} else {
|
||||
Err(error
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
@ -103,7 +101,7 @@ pub async fn retrieve_customer(
|
||||
let response = db
|
||||
.find_customer_by_customer_id_merchant_id(&req.customer_id, &merchant_account.merchant_id)
|
||||
.await
|
||||
.map_err(|error| error.to_not_found_response(errors::ApiErrorResponse::CustomerNotFound))?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::CustomerNotFound)?;
|
||||
|
||||
Ok(services::ApplicationResponse::Json(response.into()))
|
||||
}
|
||||
@ -118,12 +116,12 @@ pub async fn delete_customer(
|
||||
|
||||
db.find_customer_by_customer_id_merchant_id(&req.customer_id, &merchant_account.merchant_id)
|
||||
.await
|
||||
.map_err(|err| err.to_not_found_response(errors::ApiErrorResponse::CustomerNotFound))?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::CustomerNotFound)?;
|
||||
|
||||
let customer_mandates = db
|
||||
.find_mandate_by_merchant_id_customer_id(&merchant_account.merchant_id, &req.customer_id)
|
||||
.await
|
||||
.map_err(|err| err.to_not_found_response(errors::ApiErrorResponse::MandateNotFound))?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MandateNotFound)?;
|
||||
|
||||
for mandate in customer_mandates.into_iter() {
|
||||
if mandate.mandate_status == enums::MandateStatus::Active {
|
||||
@ -154,9 +152,7 @@ pub async fn delete_customer(
|
||||
&pm.payment_method_id,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?;
|
||||
}
|
||||
}
|
||||
Err(error) => match error.current_context() {
|
||||
@ -239,7 +235,7 @@ pub async fn update_customer(
|
||||
&merchant_account.merchant_id,
|
||||
)
|
||||
.await
|
||||
.map_err(|err| err.to_not_found_response(errors::ApiErrorResponse::CustomerNotFound))?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::CustomerNotFound)?;
|
||||
|
||||
if let Some(addr) = &update_customer.address {
|
||||
let customer_address: api_models::payments::AddressDetails = addr
|
||||
@ -287,7 +283,7 @@ pub async fn update_customer(
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map_err(|error| error.to_not_found_response(errors::ApiErrorResponse::CustomerNotFound))?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::CustomerNotFound)?;
|
||||
|
||||
let mut customer_update_response: customers::CustomerResponse = response.into();
|
||||
customer_update_response.address = update_customer.address;
|
||||
|
||||
@ -17,10 +17,8 @@ pub async fn retrieve_dispute(
|
||||
.store
|
||||
.find_dispute_by_merchant_id_dispute_id(&merchant_account.merchant_id, &req.dispute_id)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::DisputeNotFound {
|
||||
dispute_id: req.dispute_id,
|
||||
})
|
||||
.to_not_found_response(errors::ApiErrorResponse::DisputeNotFound {
|
||||
dispute_id: req.dispute_id,
|
||||
})?;
|
||||
let dispute_response = api_models::disputes::DisputeResponse::foreign_from(dispute);
|
||||
Ok(services::ApplicationResponse::Json(dispute_response))
|
||||
@ -36,9 +34,7 @@ pub async fn retrieve_disputes_list(
|
||||
.store
|
||||
.find_disputes_by_merchant_id(&merchant_account.merchant_id, constraints)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::InternalServerError)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::InternalServerError)?;
|
||||
let disputes_list = disputes
|
||||
.into_iter()
|
||||
.map(api_models::disputes::DisputeResponse::foreign_from)
|
||||
|
||||
@ -1,45 +1,49 @@
|
||||
use crate::{core::errors, logger};
|
||||
|
||||
pub trait StorageErrorExt {
|
||||
pub trait StorageErrorExt<T> {
|
||||
#[track_caller]
|
||||
fn to_not_found_response(
|
||||
self,
|
||||
not_found_response: errors::ApiErrorResponse,
|
||||
) -> error_stack::Report<errors::ApiErrorResponse>;
|
||||
) -> error_stack::Result<T, errors::ApiErrorResponse>;
|
||||
|
||||
#[track_caller]
|
||||
fn to_duplicate_response(
|
||||
self,
|
||||
duplicate_response: errors::ApiErrorResponse,
|
||||
) -> error_stack::Report<errors::ApiErrorResponse>;
|
||||
) -> error_stack::Result<T, errors::ApiErrorResponse>;
|
||||
}
|
||||
|
||||
impl StorageErrorExt for error_stack::Report<errors::StorageError> {
|
||||
impl<T> StorageErrorExt<T> for error_stack::Result<T, errors::StorageError> {
|
||||
#[track_caller]
|
||||
fn to_not_found_response(
|
||||
self,
|
||||
not_found_response: errors::ApiErrorResponse,
|
||||
) -> error_stack::Report<errors::ApiErrorResponse> {
|
||||
if self.current_context().is_db_not_found() {
|
||||
return self.change_context(not_found_response);
|
||||
}
|
||||
match self.current_context() {
|
||||
errors::StorageError::CustomerRedacted => {
|
||||
self.change_context(errors::ApiErrorResponse::CustomerRedacted)
|
||||
) -> error_stack::Result<T, errors::ApiErrorResponse> {
|
||||
self.map_err(|err| {
|
||||
if err.current_context().is_db_not_found() {
|
||||
return err.change_context(not_found_response);
|
||||
};
|
||||
match err.current_context() {
|
||||
errors::StorageError::CustomerRedacted => {
|
||||
err.change_context(errors::ApiErrorResponse::CustomerRedacted)
|
||||
}
|
||||
_ => err.change_context(errors::ApiErrorResponse::InternalServerError),
|
||||
}
|
||||
_ => self.change_context(errors::ApiErrorResponse::InternalServerError),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn to_duplicate_response(
|
||||
self,
|
||||
duplicate_response: errors::ApiErrorResponse,
|
||||
) -> error_stack::Report<errors::ApiErrorResponse> {
|
||||
if self.current_context().is_db_unique_violation() {
|
||||
self.change_context(duplicate_response)
|
||||
} else {
|
||||
self.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
}
|
||||
) -> error_stack::Result<T, errors::ApiErrorResponse> {
|
||||
self.map_err(|err| {
|
||||
if err.current_context().is_db_unique_violation() {
|
||||
err.change_context(duplicate_response)
|
||||
} else {
|
||||
err.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ pub async fn get_mandate(
|
||||
.store
|
||||
.find_mandate_by_merchant_id_mandate_id(&merchant_account.merchant_id, &req.mandate_id)
|
||||
.await
|
||||
.map_err(|error| error.to_not_found_response(errors::ApiErrorResponse::MandateNotFound))?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MandateNotFound)?;
|
||||
Ok(services::ApplicationResponse::Json(
|
||||
mandates::MandateResponse::from_db_mandate(state, mandate, &merchant_account).await?,
|
||||
))
|
||||
@ -51,7 +51,7 @@ pub async fn revoke_mandate(
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map_err(|error| error.to_not_found_response(errors::ApiErrorResponse::MandateNotFound))?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MandateNotFound)?;
|
||||
|
||||
Ok(services::ApplicationResponse::Json(
|
||||
mandates::MandateRevokedResponse {
|
||||
@ -176,11 +176,7 @@ where
|
||||
.store
|
||||
.insert_mandate(new_mandate_data)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
err.to_duplicate_response(
|
||||
errors::ApiErrorResponse::DuplicateRefundRequest,
|
||||
)
|
||||
})?;
|
||||
.to_duplicate_response(errors::ApiErrorResponse::DuplicateRefundRequest)?;
|
||||
metrics::MANDATE_COUNT.add(
|
||||
&metrics::CONTEXT,
|
||||
1,
|
||||
|
||||
@ -119,9 +119,7 @@ pub async fn update_customer_payment_method(
|
||||
payment_method_id,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?;
|
||||
if pm.payment_method == enums::PaymentMethod::Card {
|
||||
delete_card_from_locker(
|
||||
state,
|
||||
@ -827,9 +825,7 @@ pub async fn list_payment_methods(
|
||||
false,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
|
||||
|
||||
logger::debug!(mca_before_filtering=?all_mcas);
|
||||
|
||||
@ -1440,9 +1436,7 @@ pub async fn list_customer_payment_method(
|
||||
&merchant_account.merchant_id,
|
||||
)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
err.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?;
|
||||
//let mca = query::find_mca_by_merchant_id(conn, &merchant_account.merchant_id)?;
|
||||
if resp.is_empty() {
|
||||
return Err(error_stack::report!(
|
||||
@ -1745,9 +1739,7 @@ pub async fn retrieve_payment_method(
|
||||
let pm = db
|
||||
.find_payment_method(&pm.payment_method_id)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?;
|
||||
let card = if pm.payment_method == enums::PaymentMethod::Card {
|
||||
let card = get_card_from_locker(
|
||||
state,
|
||||
@ -1801,9 +1793,7 @@ pub async fn delete_payment_method(
|
||||
&payment_method_id,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?;
|
||||
|
||||
if pm.payment_method == enums::PaymentMethod::Card {
|
||||
let response =
|
||||
|
||||
@ -865,19 +865,14 @@ pub async fn list_payments(
|
||||
) -> RouterResponse<api::PaymentListResponse> {
|
||||
use futures::stream::StreamExt;
|
||||
|
||||
use crate::types::transformers::ForeignFrom;
|
||||
use crate::{core::errors::utils::StorageErrorExt, types::transformers::ForeignFrom};
|
||||
|
||||
helpers::validate_payment_list_request(&constraints)?;
|
||||
let merchant_id = &merchant.merchant_id;
|
||||
let payment_intents =
|
||||
helpers::filter_by_constraints(db, &constraints, merchant_id, merchant.storage_scheme)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
errors::StorageErrorExt::to_not_found_response(
|
||||
err,
|
||||
errors::ApiErrorResponse::PaymentNotFound,
|
||||
)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
let pi = futures::stream::iter(payment_intents)
|
||||
.filter_map(|pi| async {
|
||||
|
||||
@ -53,9 +53,7 @@ pub async fn get_address_for_payment_request(
|
||||
Some(id) => Some(
|
||||
db.update_address(id.to_owned(), address.foreign_into())
|
||||
.await
|
||||
.map_err(|err| {
|
||||
err.to_not_found_response(errors::ApiErrorResponse::AddressNotFound)
|
||||
})?,
|
||||
.to_not_found_response(errors::ApiErrorResponse::AddressNotFound)?,
|
||||
),
|
||||
None => {
|
||||
// generate a new address here
|
||||
@ -84,9 +82,9 @@ pub async fn get_address_for_payment_request(
|
||||
}
|
||||
}
|
||||
None => match address_id {
|
||||
Some(id) => Some(db.find_address(id).await).transpose().map_err(|err| {
|
||||
err.to_not_found_response(errors::ApiErrorResponse::AddressNotFound)
|
||||
})?,
|
||||
Some(id) => Some(db.find_address(id).await)
|
||||
.transpose()
|
||||
.to_not_found_response(errors::ApiErrorResponse::AddressNotFound)?,
|
||||
None => None,
|
||||
},
|
||||
})
|
||||
@ -148,7 +146,7 @@ pub async fn get_token_for_recurring_mandate(
|
||||
let mandate = db
|
||||
.find_mandate_by_merchant_id_mandate_id(&merchant_account.merchant_id, mandate_id.as_str())
|
||||
.await
|
||||
.map_err(|error| error.to_not_found_response(errors::ApiErrorResponse::MandateNotFound))?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MandateNotFound)?;
|
||||
|
||||
let customer = req.customer_id.clone().get_required_value("customer_id")?;
|
||||
|
||||
@ -174,9 +172,7 @@ pub async fn get_token_for_recurring_mandate(
|
||||
let payment_method = db
|
||||
.find_payment_method(payment_method_id.as_str())
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?;
|
||||
|
||||
let token = Uuid::new_v4().to_string();
|
||||
let locker_id = merchant_account
|
||||
@ -1428,11 +1424,9 @@ pub async fn get_merchant_connector_account(
|
||||
let mca_config = db
|
||||
.find_config_by_key(format!("mcd_{merchant_id}_{creds_identifier}").as_str())
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(
|
||||
errors::ApiErrorResponse::MerchantConnectorAccountNotFound,
|
||||
)
|
||||
})?;
|
||||
.to_not_found_response(
|
||||
errors::ApiErrorResponse::MerchantConnectorAccountNotFound,
|
||||
)?;
|
||||
|
||||
let cached_mca = consts::BASE64_ENGINE
|
||||
.decode(mca_config.config.as_bytes())
|
||||
|
||||
@ -51,9 +51,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsCancelRequest>
|
||||
let payment_intent = db
|
||||
.find_payment_intent_by_payment_id_merchant_id(&payment_id, merchant_id, storage_scheme)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
let mut payment_attempt = db
|
||||
.find_payment_attempt_by_payment_id_merchant_id_attempt_id(
|
||||
@ -63,9 +61,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsCancelRequest>
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
let shipping_address = helpers::get_address_for_payment_request(
|
||||
db,
|
||||
@ -92,9 +88,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsCancelRequest>
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
let currency = payment_attempt.currency.get_required_value("currency")?;
|
||||
let amount = payment_attempt.amount.into();
|
||||
|
||||
@ -186,7 +180,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsCancelRequest> for
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|err| err.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound))?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
Ok((Box::new(self), payment_data))
|
||||
}
|
||||
|
||||
@ -54,9 +54,7 @@ impl<F: Send + Clone> GetTracker<F, payments::PaymentData<F>, api::PaymentsCaptu
|
||||
payment_intent = db
|
||||
.find_payment_intent_by_payment_id_merchant_id(&payment_id, merchant_id, storage_scheme)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
helpers::validate_status(payment_intent.status)?;
|
||||
|
||||
@ -70,9 +68,7 @@ impl<F: Send + Clone> GetTracker<F, payments::PaymentData<F>, api::PaymentsCaptu
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
payment_attempt
|
||||
.amount_to_capture
|
||||
@ -96,9 +92,7 @@ impl<F: Send + Clone> GetTracker<F, payments::PaymentData<F>, api::PaymentsCaptu
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
let shipping_address = helpers::get_address_for_payment_request(
|
||||
db,
|
||||
|
||||
@ -55,9 +55,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co
|
||||
payment_intent = db
|
||||
.find_payment_intent_by_payment_id_merchant_id(&payment_id, merchant_id, storage_scheme)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
payment_intent.setup_future_usage = request
|
||||
.setup_future_usage
|
||||
.map(ForeignInto::foreign_into)
|
||||
@ -102,9 +100,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
let token = token.or_else(|| payment_attempt.payment_token.clone());
|
||||
|
||||
@ -163,9 +159,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
connector_response.encoded_data = request.metadata.clone().and_then(|secret_metadata| {
|
||||
secret_metadata
|
||||
|
||||
@ -55,9 +55,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
|
||||
payment_intent = db
|
||||
.find_payment_intent_by_payment_id_merchant_id(&payment_id, merchant_id, storage_scheme)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
payment_intent.setup_future_usage = request
|
||||
.setup_future_usage
|
||||
@ -103,9 +101,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
let token = token.or_else(|| payment_attempt.payment_token.clone());
|
||||
|
||||
@ -166,9 +162,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
payment_intent.shipping_address_id = shipping_address.clone().map(|i| i.address_id);
|
||||
payment_intent.billing_address_id = billing_address.clone().map(|i| i.address_id);
|
||||
@ -364,9 +358,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
let (shipping_address, billing_address) = (
|
||||
payment_data.payment_intent.shipping_address_id.clone(),
|
||||
@ -397,9 +389,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
Ok((Box::new(self), payment_data))
|
||||
}
|
||||
|
||||
@ -111,10 +111,8 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
err.to_duplicate_response(errors::ApiErrorResponse::DuplicatePayment {
|
||||
payment_id: payment_id.clone(),
|
||||
})
|
||||
.to_duplicate_response(errors::ApiErrorResponse::DuplicatePayment {
|
||||
payment_id: payment_id.clone(),
|
||||
})?;
|
||||
|
||||
payment_intent = db
|
||||
@ -131,10 +129,8 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
err.to_duplicate_response(errors::ApiErrorResponse::DuplicatePayment {
|
||||
payment_id: payment_id.clone(),
|
||||
})
|
||||
.to_duplicate_response(errors::ApiErrorResponse::DuplicatePayment {
|
||||
payment_id: payment_id.clone(),
|
||||
})?;
|
||||
connector_response = db
|
||||
.insert_connector_response(
|
||||
@ -142,10 +138,8 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
err.to_duplicate_response(errors::ApiErrorResponse::DuplicatePayment {
|
||||
payment_id: payment_id.clone(),
|
||||
})
|
||||
.to_duplicate_response(errors::ApiErrorResponse::DuplicatePayment {
|
||||
payment_id: payment_id.clone(),
|
||||
})?;
|
||||
|
||||
let mandate_id = request
|
||||
@ -330,9 +324,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
let customer_id = payment_data.payment_intent.customer_id.clone();
|
||||
payment_data.payment_intent = db
|
||||
@ -348,9 +340,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
// payment_data.mandate_id = response.and_then(|router_data| router_data.request.mandate_id);
|
||||
|
||||
|
||||
@ -220,11 +220,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::VerifyRequest> for PaymentM
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
err.to_not_found_response(errors::ApiErrorResponse::VerificationFailed {
|
||||
data: None,
|
||||
})
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::VerificationFailed { data: None })?;
|
||||
|
||||
Ok((Box::new(self), payment_data))
|
||||
}
|
||||
|
||||
@ -398,9 +398,7 @@ async fn payment_response_update_tracker<F: Clone, T>(
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?,
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?,
|
||||
None => payment_data.payment_attempt,
|
||||
};
|
||||
|
||||
@ -412,9 +410,7 @@ async fn payment_response_update_tracker<F: Clone, T>(
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?,
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?,
|
||||
None => payment_data.connector_response,
|
||||
};
|
||||
|
||||
@ -443,7 +439,7 @@ async fn payment_response_update_tracker<F: Clone, T>(
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound))?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
Ok(payment_data)
|
||||
}
|
||||
|
||||
@ -57,9 +57,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsSessionRequest>
|
||||
let mut payment_intent = db
|
||||
.find_payment_intent_by_payment_id_merchant_id(&payment_id, merchant_id, storage_scheme)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
helpers::validate_payment_status_against_not_allowed_statuses(
|
||||
&payment_intent.status,
|
||||
@ -78,9 +76,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsSessionRequest>
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
let currency = payment_intent.currency.get_required_value("currency")?;
|
||||
|
||||
@ -211,9 +207,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsSessionRequest> for
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?,
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?,
|
||||
None => payment_data.payment_intent,
|
||||
};
|
||||
|
||||
|
||||
@ -54,9 +54,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsStartRequest> f
|
||||
payment_intent = db
|
||||
.find_payment_intent_by_payment_id_merchant_id(&payment_id, merchant_id, storage_scheme)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
helpers::validate_payment_status_against_not_allowed_statuses(
|
||||
&payment_intent.status,
|
||||
@ -75,9 +73,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsStartRequest> f
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
currency = payment_attempt.currency.get_required_value("currency")?;
|
||||
amount = payment_attempt.amount.into();
|
||||
|
||||
@ -360,7 +360,5 @@ pub async fn get_payment_intent_payment_attempt(
|
||||
Ok((pi, pa))
|
||||
})()
|
||||
.await
|
||||
.map_err(|error: error_stack::Report<errors::StorageError>| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
}
|
||||
|
||||
@ -54,9 +54,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
|
||||
payment_intent = db
|
||||
.find_payment_intent_by_payment_id_merchant_id(&payment_id, merchant_id, storage_scheme)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
payment_intent.setup_future_usage = request
|
||||
.setup_future_usage
|
||||
@ -90,9 +88,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
|
||||
payment_intent = db
|
||||
.find_payment_intent_by_payment_id_merchant_id(&payment_id, merchant_id, storage_scheme)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
payment_attempt = db
|
||||
.find_payment_attempt_by_payment_id_merchant_id_attempt_id(
|
||||
@ -102,9 +98,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
currency = match request.currency {
|
||||
Some(cur) => cur.foreign_into(),
|
||||
@ -405,9 +399,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
let customer_id = customer.map(|c| c.customer_id);
|
||||
|
||||
@ -452,9 +444,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
payment_data.mandate_id = payment_data.mandate_id.clone();
|
||||
|
||||
|
||||
@ -278,7 +278,7 @@ pub async fn refund_retrieve_core(
|
||||
merchant_account.storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| error.to_not_found_response(errors::ApiErrorResponse::RefundNotFound))?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::RefundNotFound)?;
|
||||
|
||||
let payment_id = refund.payment_id.as_str();
|
||||
payment_intent = db
|
||||
@ -288,7 +288,7 @@ pub async fn refund_retrieve_core(
|
||||
merchant_account.storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound))?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
payment_attempt = db
|
||||
.find_payment_attempt_by_connector_transaction_id_payment_id_merchant_id(
|
||||
@ -298,7 +298,7 @@ pub async fn refund_retrieve_core(
|
||||
merchant_account.storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound))?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
let creds_identifier = request
|
||||
.merchant_connector_details
|
||||
@ -443,7 +443,7 @@ pub async fn refund_update_core(
|
||||
merchant_account.storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| error.to_not_found_response(errors::ApiErrorResponse::RefundNotFound))?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::RefundNotFound)?;
|
||||
|
||||
let response = db
|
||||
.update_refund(
|
||||
@ -582,9 +582,7 @@ pub async fn validate_and_create_refund(
|
||||
refund = db
|
||||
.insert_refund(refund_create_req, merchant_account.storage_scheme)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_duplicate_response(errors::ApiErrorResponse::DuplicateRefundRequest)
|
||||
})?;
|
||||
.to_duplicate_response(errors::ApiErrorResponse::DuplicateRefundRequest)?;
|
||||
schedule_refund_execution(
|
||||
state,
|
||||
refund,
|
||||
@ -820,9 +818,7 @@ pub async fn trigger_refund_execute_workflow(
|
||||
let merchant_account = db
|
||||
.find_merchant_account_by_merchant_id(&refund_core.merchant_id)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
|
||||
|
||||
let refund = db
|
||||
.find_refund_by_internal_reference_id_merchant_id(
|
||||
@ -831,15 +827,13 @@ pub async fn trigger_refund_execute_workflow(
|
||||
merchant_account.storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| error.to_not_found_response(errors::ApiErrorResponse::RefundNotFound))?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::RefundNotFound)?;
|
||||
match (&refund.sent_to_gateway, &refund.refund_status) {
|
||||
(false, enums::RefundStatus::Pending) => {
|
||||
let merchant_account = db
|
||||
.find_merchant_account_by_merchant_id(&refund.merchant_id)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
|
||||
|
||||
let payment_attempt = db
|
||||
.find_payment_attempt_by_connector_transaction_id_payment_id_merchant_id(
|
||||
@ -849,9 +843,7 @@ pub async fn trigger_refund_execute_workflow(
|
||||
merchant_account.storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
let payment_intent = db
|
||||
.find_payment_intent_by_payment_id_merchant_id(
|
||||
@ -860,9 +852,7 @@ pub async fn trigger_refund_execute_workflow(
|
||||
merchant_account.storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
|
||||
|
||||
//trigger refund request to gateway
|
||||
let updated_refund = trigger_refund_to_gateway(
|
||||
|
||||
@ -42,9 +42,7 @@ impl MandateResponseExt for MandateResponse {
|
||||
let payment_method = db
|
||||
.find_payment_method(&mandate.payment_method_id)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)
|
||||
})?;
|
||||
.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?;
|
||||
|
||||
let card = if payment_method.payment_method == storage_enums::PaymentMethod::Card {
|
||||
let card = payment_methods::cards::get_card_from_locker(
|
||||
|
||||
Reference in New Issue
Block a user