feat(connector): (checkout.com) add support for multiple captures PSync (#2043)

This commit is contained in:
Hrithikesh
2023-09-08 12:47:43 +05:30
committed by GitHub
parent 7777c5ca84
commit 517c5c4165
12 changed files with 259 additions and 47 deletions

View File

@ -21,7 +21,10 @@ use crate::{
consts,
core::errors::{self, CustomResult},
pii::PeekInterface,
types::{self, api, transformers::ForeignTryFrom, PaymentsCancelData, ResponseId},
types::{
self, api, storage::enums as storage_enums, transformers::ForeignTryFrom,
PaymentsCancelData, ResponseId,
},
utils::{OptionExt, ValueExt},
};
@ -1332,6 +1335,41 @@ mod error_code_error_message_tests {
}
}
pub trait MultipleCaptureSyncResponse {
fn get_connector_capture_id(&self) -> String;
fn get_capture_attempt_status(&self) -> storage_enums::AttemptStatus;
fn is_capture_response(&self) -> bool;
fn get_connector_reference_id(&self) -> Option<String> {
None
}
}
pub fn construct_captures_response_hashmap<T>(
capture_sync_response_list: Vec<T>,
) -> HashMap<String, types::CaptureSyncResponse>
where
T: MultipleCaptureSyncResponse,
{
let mut hashmap = HashMap::new();
capture_sync_response_list
.into_iter()
.for_each(|capture_sync_response| {
let connector_capture_id = capture_sync_response.get_connector_capture_id();
if capture_sync_response.is_capture_response() {
hashmap.insert(
connector_capture_id.clone(),
types::CaptureSyncResponse::Success {
resource_id: ResponseId::ConnectorTransactionId(connector_capture_id),
status: capture_sync_response.get_capture_attempt_status(),
connector_response_reference_id: capture_sync_response
.get_connector_reference_id(),
},
);
}
});
hashmap
}
pub fn validate_currency(
request_currency: types::storage::enums::Currency,
merchant_config_currency: Option<types::storage::enums::Currency>,