feat(storage_impl): split payment intent interface implementation (#1946)

This commit is contained in:
Sampras Lopes
2023-08-21 19:23:03 +05:30
committed by GitHub
parent a0d66d5424
commit 88d65a62fc
43 changed files with 2280 additions and 690 deletions

View File

@ -0,0 +1,32 @@
#[derive(Debug, thiserror::Error)]
pub enum StorageError {
// TODO: deprecate this error type to use a domain error instead
#[error("DatabaseError: {0:?}")]
DatabaseError(String),
#[error("ValueNotFound: {0}")]
ValueNotFound(String),
#[error("DuplicateValue: {entity} already exists {key:?}")]
DuplicateValue {
entity: &'static str,
key: Option<String>,
},
#[error("Timed out while trying to connect to the database")]
DatabaseConnectionError,
#[error("KV error")]
KVError,
#[error("Serialization failure")]
SerializationFailed,
#[error("MockDb error")]
MockDbError,
#[error("Customer with this id is Redacted")]
CustomerRedacted,
#[error("Deserialization failure")]
DeserializationFailed,
#[error("Error while encrypting data")]
EncryptionError,
#[error("Error while decrypting data from database")]
DecryptionError,
// TODO: deprecate this error type to use a domain error instead
#[error("RedisError: {0:?}")]
RedisError(String),
}

View File

@ -0,0 +1,25 @@
pub mod errors;
pub mod mandates;
pub mod payments;
// TODO: This decision about using KV mode or not,
// should be taken at a top level rather than pushing it down to individual functions via an enum.
#[derive(
Clone,
Copy,
Debug,
Default,
Eq,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum MerchantStorageScheme {
#[default]
PostgresOnly,
RedisKv,
}

View File

@ -0,0 +1,19 @@
use common_enums::Currency;
use common_utils::pii;
use time::PrimitiveDateTime;
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum MandateDataType {
SingleUse(MandateAmountData),
MultiUse(Option<MandateAmountData>),
}
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
pub struct MandateAmountData {
pub amount: i64,
pub currency: Currency,
pub start_date: Option<PrimitiveDateTime>,
pub end_date: Option<PrimitiveDateTime>,
pub metadata: Option<pii::SecretSerdeValue>,
}

View File

@ -0,0 +1,2 @@
pub mod payment_attempt;
pub mod payment_intent;

View File

@ -0,0 +1,276 @@
use common_enums as storage_enums;
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
use super::payment_intent::PaymentIntent;
use crate::{errors, mandates::MandateDataType, MerchantStorageScheme};
#[async_trait::async_trait]
pub trait PaymentAttemptInterface {
async fn insert_payment_attempt(
&self,
payment_attempt: PaymentAttemptNew,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError>;
async fn update_payment_attempt_with_attempt_id(
&self,
this: PaymentAttempt,
payment_attempt: PaymentAttemptUpdate,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError>;
async fn find_payment_attempt_by_connector_transaction_id_payment_id_merchant_id(
&self,
connector_transaction_id: &str,
payment_id: &str,
merchant_id: &str,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError>;
async fn find_payment_attempt_last_successful_attempt_by_payment_id_merchant_id(
&self,
payment_id: &str,
merchant_id: &str,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError>;
async fn find_payment_attempt_by_merchant_id_connector_txn_id(
&self,
merchant_id: &str,
connector_txn_id: &str,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError>;
async fn find_payment_attempt_by_payment_id_merchant_id_attempt_id(
&self,
payment_id: &str,
merchant_id: &str,
attempt_id: &str,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError>;
async fn find_payment_attempt_by_attempt_id_merchant_id(
&self,
attempt_id: &str,
merchant_id: &str,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError>;
async fn find_payment_attempt_by_preprocessing_id_merchant_id(
&self,
preprocessing_id: &str,
merchant_id: &str,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError>;
async fn find_attempts_by_merchant_id_payment_id(
&self,
merchant_id: &str,
payment_id: &str,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<Vec<PaymentAttempt>, errors::StorageError>;
async fn get_filters_for_payments(
&self,
pi: &[PaymentIntent],
merchant_id: &str,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentListFilters, errors::StorageError>;
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct PaymentAttempt {
pub id: i32,
pub payment_id: String,
pub merchant_id: String,
pub attempt_id: String,
pub status: storage_enums::AttemptStatus,
pub amount: i64,
pub currency: Option<storage_enums::Currency>,
pub save_to_locker: Option<bool>,
pub connector: Option<String>,
pub error_message: Option<String>,
pub offer_amount: Option<i64>,
pub surcharge_amount: Option<i64>,
pub tax_amount: Option<i64>,
pub payment_method_id: Option<String>,
pub payment_method: Option<storage_enums::PaymentMethod>,
pub connector_transaction_id: Option<String>,
pub capture_method: Option<storage_enums::CaptureMethod>,
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub capture_on: Option<PrimitiveDateTime>,
pub confirm: bool,
pub authentication_type: Option<storage_enums::AuthenticationType>,
#[serde(with = "common_utils::custom_serde::iso8601")]
pub created_at: PrimitiveDateTime,
#[serde(with = "common_utils::custom_serde::iso8601")]
pub modified_at: PrimitiveDateTime,
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub last_synced: Option<PrimitiveDateTime>,
pub cancellation_reason: Option<String>,
pub amount_to_capture: Option<i64>,
pub mandate_id: Option<String>,
pub browser_info: Option<serde_json::Value>,
pub error_code: Option<String>,
pub payment_token: Option<String>,
pub connector_metadata: Option<serde_json::Value>,
pub payment_experience: Option<storage_enums::PaymentExperience>,
pub payment_method_type: Option<storage_enums::PaymentMethodType>,
pub payment_method_data: Option<serde_json::Value>,
pub business_sub_label: Option<String>,
pub straight_through_algorithm: Option<serde_json::Value>,
pub preprocessing_step_id: Option<String>,
// providing a location to store mandate details intermediately for transaction
pub mandate_details: Option<MandateDataType>,
pub error_reason: Option<String>,
pub multiple_capture_count: Option<i16>,
// reference to the payment at connector side
pub connector_response_reference_id: Option<String>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct PaymentListFilters {
pub connector: Vec<String>,
pub currency: Vec<storage_enums::Currency>,
pub status: Vec<storage_enums::IntentStatus>,
pub payment_method: Vec<storage_enums::PaymentMethod>,
}
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct PaymentAttemptNew {
pub payment_id: String,
pub merchant_id: String,
pub attempt_id: String,
pub status: storage_enums::AttemptStatus,
pub amount: i64,
pub currency: Option<storage_enums::Currency>,
// pub auto_capture: Option<bool>,
pub save_to_locker: Option<bool>,
pub connector: Option<String>,
pub error_message: Option<String>,
pub offer_amount: Option<i64>,
pub surcharge_amount: Option<i64>,
pub tax_amount: Option<i64>,
pub payment_method_id: Option<String>,
pub payment_method: Option<storage_enums::PaymentMethod>,
pub capture_method: Option<storage_enums::CaptureMethod>,
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub capture_on: Option<PrimitiveDateTime>,
pub confirm: bool,
pub authentication_type: Option<storage_enums::AuthenticationType>,
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub created_at: Option<PrimitiveDateTime>,
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub modified_at: Option<PrimitiveDateTime>,
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub last_synced: Option<PrimitiveDateTime>,
pub cancellation_reason: Option<String>,
pub amount_to_capture: Option<i64>,
pub mandate_id: Option<String>,
pub browser_info: Option<serde_json::Value>,
pub payment_token: Option<String>,
pub error_code: Option<String>,
pub connector_metadata: Option<serde_json::Value>,
pub payment_experience: Option<storage_enums::PaymentExperience>,
pub payment_method_type: Option<storage_enums::PaymentMethodType>,
pub payment_method_data: Option<serde_json::Value>,
pub business_sub_label: Option<String>,
pub straight_through_algorithm: Option<serde_json::Value>,
pub preprocessing_step_id: Option<String>,
pub mandate_details: Option<MandateDataType>,
pub error_reason: Option<String>,
pub connector_response_reference_id: Option<String>,
pub multiple_capture_count: Option<i16>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PaymentAttemptUpdate {
Update {
amount: i64,
currency: storage_enums::Currency,
status: storage_enums::AttemptStatus,
authentication_type: Option<storage_enums::AuthenticationType>,
payment_method: Option<storage_enums::PaymentMethod>,
payment_token: Option<String>,
payment_method_data: Option<serde_json::Value>,
payment_method_type: Option<storage_enums::PaymentMethodType>,
payment_experience: Option<storage_enums::PaymentExperience>,
business_sub_label: Option<String>,
amount_to_capture: Option<i64>,
capture_method: Option<storage_enums::CaptureMethod>,
},
UpdateTrackers {
payment_token: Option<String>,
connector: Option<String>,
straight_through_algorithm: Option<serde_json::Value>,
},
AuthenticationTypeUpdate {
authentication_type: storage_enums::AuthenticationType,
},
ConfirmUpdate {
amount: i64,
currency: storage_enums::Currency,
status: storage_enums::AttemptStatus,
authentication_type: Option<storage_enums::AuthenticationType>,
payment_method: Option<storage_enums::PaymentMethod>,
browser_info: Option<serde_json::Value>,
connector: Option<String>,
payment_token: Option<String>,
payment_method_data: Option<serde_json::Value>,
payment_method_type: Option<storage_enums::PaymentMethodType>,
payment_experience: Option<storage_enums::PaymentExperience>,
business_sub_label: Option<String>,
straight_through_algorithm: Option<serde_json::Value>,
},
VoidUpdate {
status: storage_enums::AttemptStatus,
cancellation_reason: Option<String>,
},
ResponseUpdate {
status: storage_enums::AttemptStatus,
connector: Option<String>,
connector_transaction_id: Option<String>,
authentication_type: Option<storage_enums::AuthenticationType>,
payment_method_id: Option<Option<String>>,
mandate_id: Option<String>,
connector_metadata: Option<serde_json::Value>,
payment_token: Option<String>,
error_code: Option<Option<String>>,
error_message: Option<Option<String>>,
error_reason: Option<Option<String>>,
connector_response_reference_id: Option<String>,
},
UnresolvedResponseUpdate {
status: storage_enums::AttemptStatus,
connector: Option<String>,
connector_transaction_id: Option<String>,
payment_method_id: Option<Option<String>>,
error_code: Option<Option<String>>,
error_message: Option<Option<String>>,
error_reason: Option<Option<String>>,
connector_response_reference_id: Option<String>,
},
StatusUpdate {
status: storage_enums::AttemptStatus,
},
ErrorUpdate {
connector: Option<String>,
status: storage_enums::AttemptStatus,
error_code: Option<Option<String>>,
error_message: Option<Option<String>>,
error_reason: Option<Option<String>>,
},
MultipleCaptureUpdate {
status: Option<storage_enums::AttemptStatus>,
multiple_capture_count: Option<i16>,
},
PreprocessingUpdate {
status: storage_enums::AttemptStatus,
payment_method_id: Option<Option<String>>,
connector_metadata: Option<serde_json::Value>,
preprocessing_step_id: Option<String>,
connector_transaction_id: Option<String>,
connector_response_reference_id: Option<String>,
},
}

View File

@ -0,0 +1,424 @@
use common_enums as storage_enums;
use common_utils::pii;
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
use crate::{errors, MerchantStorageScheme};
#[async_trait::async_trait]
pub trait PaymentIntentInterface {
async fn update_payment_intent(
&self,
this: PaymentIntent,
payment_intent: PaymentIntentUpdate,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentIntent, errors::StorageError>;
async fn insert_payment_intent(
&self,
new: PaymentIntentNew,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentIntent, errors::StorageError>;
async fn find_payment_intent_by_payment_id_merchant_id(
&self,
payment_id: &str,
merchant_id: &str,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentIntent, errors::StorageError>;
#[cfg(feature = "olap")]
async fn filter_payment_intent_by_constraints(
&self,
merchant_id: &str,
filters: &PaymentIntentFetchConstraints,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<Vec<PaymentIntent>, errors::StorageError>;
#[cfg(feature = "olap")]
async fn filter_payment_intents_by_time_range_constraints(
&self,
merchant_id: &str,
time_range: &api_models::payments::TimeRange,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<Vec<PaymentIntent>, errors::StorageError>;
#[cfg(feature = "olap")]
async fn get_filtered_payment_intents_attempt(
&self,
merchant_id: &str,
constraints: &PaymentIntentFetchConstraints,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<
Vec<(PaymentIntent, super::payment_attempt::PaymentAttempt)>,
errors::StorageError,
>;
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct PaymentIntent {
pub id: i32,
pub payment_id: String,
pub merchant_id: String,
pub status: storage_enums::IntentStatus,
pub amount: i64,
pub currency: Option<storage_enums::Currency>,
pub amount_captured: Option<i64>,
pub customer_id: Option<String>,
pub description: Option<String>,
pub return_url: Option<String>,
pub metadata: Option<pii::SecretSerdeValue>,
pub connector_id: Option<String>,
pub shipping_address_id: Option<String>,
pub billing_address_id: Option<String>,
pub statement_descriptor_name: Option<String>,
pub statement_descriptor_suffix: Option<String>,
#[serde(with = "common_utils::custom_serde::iso8601")]
pub created_at: PrimitiveDateTime,
#[serde(with = "common_utils::custom_serde::iso8601")]
pub modified_at: PrimitiveDateTime,
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub last_synced: Option<PrimitiveDateTime>,
pub setup_future_usage: Option<storage_enums::FutureUsage>,
pub off_session: Option<bool>,
pub client_secret: Option<String>,
pub active_attempt_id: String,
pub business_country: storage_enums::CountryAlpha2,
pub business_label: String,
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
pub allowed_payment_method_types: Option<serde_json::Value>,
pub connector_metadata: Option<serde_json::Value>,
pub feature_metadata: Option<serde_json::Value>,
pub attempt_count: i16,
}
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct PaymentIntentNew {
pub payment_id: String,
pub merchant_id: String,
pub status: storage_enums::IntentStatus,
pub amount: i64,
pub currency: Option<storage_enums::Currency>,
pub amount_captured: Option<i64>,
pub customer_id: Option<String>,
pub description: Option<String>,
pub return_url: Option<String>,
pub metadata: Option<pii::SecretSerdeValue>,
pub connector_id: Option<String>,
pub shipping_address_id: Option<String>,
pub billing_address_id: Option<String>,
pub statement_descriptor_name: Option<String>,
pub statement_descriptor_suffix: Option<String>,
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub created_at: Option<PrimitiveDateTime>,
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub modified_at: Option<PrimitiveDateTime>,
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub last_synced: Option<PrimitiveDateTime>,
pub setup_future_usage: Option<storage_enums::FutureUsage>,
pub off_session: Option<bool>,
pub client_secret: Option<String>,
pub active_attempt_id: String,
pub business_country: storage_enums::CountryAlpha2,
pub business_label: String,
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
pub allowed_payment_method_types: Option<serde_json::Value>,
pub connector_metadata: Option<serde_json::Value>,
pub feature_metadata: Option<serde_json::Value>,
pub attempt_count: i16,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PaymentIntentUpdate {
ResponseUpdate {
status: storage_enums::IntentStatus,
amount_captured: Option<i64>,
return_url: Option<String>,
},
MetadataUpdate {
metadata: pii::SecretSerdeValue,
},
ReturnUrlUpdate {
return_url: Option<String>,
status: Option<storage_enums::IntentStatus>,
customer_id: Option<String>,
shipping_address_id: Option<String>,
billing_address_id: Option<String>,
},
MerchantStatusUpdate {
status: storage_enums::IntentStatus,
shipping_address_id: Option<String>,
billing_address_id: Option<String>,
},
PGStatusUpdate {
status: storage_enums::IntentStatus,
},
Update {
amount: i64,
currency: storage_enums::Currency,
setup_future_usage: Option<storage_enums::FutureUsage>,
status: storage_enums::IntentStatus,
customer_id: Option<String>,
shipping_address_id: Option<String>,
billing_address_id: Option<String>,
return_url: Option<String>,
business_country: Option<storage_enums::CountryAlpha2>,
business_label: Option<String>,
description: Option<String>,
statement_descriptor_name: Option<String>,
statement_descriptor_suffix: Option<String>,
order_details: Option<Vec<pii::SecretSerdeValue>>,
metadata: Option<pii::SecretSerdeValue>,
},
PaymentAttemptAndAttemptCountUpdate {
active_attempt_id: String,
attempt_count: i16,
},
StatusAndAttemptUpdate {
status: storage_enums::IntentStatus,
active_attempt_id: String,
attempt_count: i16,
},
}
#[derive(Clone, Debug, Default)]
pub struct PaymentIntentUpdateInternal {
pub amount: Option<i64>,
pub currency: Option<storage_enums::Currency>,
pub status: Option<storage_enums::IntentStatus>,
pub amount_captured: Option<i64>,
pub customer_id: Option<String>,
pub return_url: Option<String>,
pub setup_future_usage: Option<storage_enums::FutureUsage>,
pub off_session: Option<bool>,
pub metadata: Option<pii::SecretSerdeValue>,
pub billing_address_id: Option<String>,
pub shipping_address_id: Option<String>,
pub modified_at: Option<PrimitiveDateTime>,
pub active_attempt_id: Option<String>,
pub business_country: Option<storage_enums::CountryAlpha2>,
pub business_label: Option<String>,
pub description: Option<String>,
pub statement_descriptor_name: Option<String>,
pub statement_descriptor_suffix: Option<String>,
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
pub attempt_count: Option<i16>,
}
impl PaymentIntentUpdate {
pub fn apply_changeset(self, source: PaymentIntent) -> PaymentIntent {
let internal_update: PaymentIntentUpdateInternal = self.into();
PaymentIntent {
amount: internal_update.amount.unwrap_or(source.amount),
currency: internal_update.currency.or(source.currency),
status: internal_update.status.unwrap_or(source.status),
amount_captured: internal_update.amount_captured.or(source.amount_captured),
customer_id: internal_update.customer_id.or(source.customer_id),
return_url: internal_update.return_url.or(source.return_url),
setup_future_usage: internal_update
.setup_future_usage
.or(source.setup_future_usage),
off_session: internal_update.off_session.or(source.off_session),
metadata: internal_update.metadata.or(source.metadata),
billing_address_id: internal_update
.billing_address_id
.or(source.billing_address_id),
shipping_address_id: internal_update
.shipping_address_id
.or(source.shipping_address_id),
modified_at: common_utils::date_time::now(),
order_details: internal_update.order_details.or(source.order_details),
..source
}
}
}
impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
fn from(payment_intent_update: PaymentIntentUpdate) -> Self {
match payment_intent_update {
PaymentIntentUpdate::Update {
amount,
currency,
setup_future_usage,
status,
customer_id,
shipping_address_id,
billing_address_id,
return_url,
business_country,
business_label,
description,
statement_descriptor_name,
statement_descriptor_suffix,
order_details,
metadata,
} => Self {
amount: Some(amount),
currency: Some(currency),
status: Some(status),
setup_future_usage,
customer_id,
shipping_address_id,
billing_address_id,
modified_at: Some(common_utils::date_time::now()),
return_url,
business_country,
business_label,
description,
statement_descriptor_name,
statement_descriptor_suffix,
order_details,
metadata,
..Default::default()
},
PaymentIntentUpdate::MetadataUpdate { metadata } => Self {
metadata: Some(metadata),
modified_at: Some(common_utils::date_time::now()),
..Default::default()
},
PaymentIntentUpdate::ReturnUrlUpdate {
return_url,
status,
customer_id,
shipping_address_id,
billing_address_id,
} => Self {
return_url,
status,
customer_id,
shipping_address_id,
billing_address_id,
modified_at: Some(common_utils::date_time::now()),
..Default::default()
},
PaymentIntentUpdate::PGStatusUpdate { status } => Self {
status: Some(status),
modified_at: Some(common_utils::date_time::now()),
..Default::default()
},
PaymentIntentUpdate::MerchantStatusUpdate {
status,
shipping_address_id,
billing_address_id,
} => Self {
status: Some(status),
shipping_address_id,
billing_address_id,
modified_at: Some(common_utils::date_time::now()),
..Default::default()
},
PaymentIntentUpdate::ResponseUpdate {
// amount,
// currency,
status,
amount_captured,
// customer_id,
return_url,
} => Self {
// amount,
// currency: Some(currency),
status: Some(status),
amount_captured,
// customer_id,
return_url,
modified_at: Some(common_utils::date_time::now()),
..Default::default()
},
PaymentIntentUpdate::PaymentAttemptAndAttemptCountUpdate {
active_attempt_id,
attempt_count,
} => Self {
active_attempt_id: Some(active_attempt_id),
attempt_count: Some(attempt_count),
..Default::default()
},
PaymentIntentUpdate::StatusAndAttemptUpdate {
status,
active_attempt_id,
attempt_count,
} => Self {
status: Some(status),
active_attempt_id: Some(active_attempt_id),
attempt_count: Some(attempt_count),
..Default::default()
},
}
}
}
pub enum PaymentIntentFetchConstraints {
Single {
payment_intent_id: String,
},
List {
offset: Option<u32>,
starting_at: Option<PrimitiveDateTime>,
ending_at: Option<PrimitiveDateTime>,
connector: Option<Vec<api_models::enums::Connector>>,
currency: Option<Vec<storage_enums::Currency>>,
status: Option<Vec<storage_enums::IntentStatus>>,
payment_methods: Option<Vec<storage_enums::PaymentMethod>>,
customer_id: Option<String>,
starting_after_id: Option<String>,
ending_before_id: Option<String>,
limit: Option<u32>,
},
}
impl From<api_models::payments::PaymentListConstraints> for PaymentIntentFetchConstraints {
fn from(value: api_models::payments::PaymentListConstraints) -> Self {
Self::List {
offset: None,
starting_at: value.created_gte.or(value.created_gt).or(value.created),
ending_at: value.created_lte.or(value.created_lt).or(value.created),
connector: None,
currency: None,
status: None,
payment_methods: None,
customer_id: value.customer_id,
starting_after_id: value.starting_after,
ending_before_id: value.ending_before,
limit: None,
}
}
}
impl From<api_models::payments::TimeRange> for PaymentIntentFetchConstraints {
fn from(value: api_models::payments::TimeRange) -> Self {
Self::List {
offset: None,
starting_at: Some(value.start_time),
ending_at: value.end_time,
connector: None,
currency: None,
status: None,
payment_methods: None,
customer_id: None,
starting_after_id: None,
ending_before_id: None,
limit: None,
}
}
}
impl From<api_models::payments::PaymentListFilterConstraints> for PaymentIntentFetchConstraints {
fn from(value: api_models::payments::PaymentListFilterConstraints) -> Self {
if let Some(payment_intent_id) = value.payment_id {
Self::Single { payment_intent_id }
} else {
Self::List {
offset: value.offset,
starting_at: value.time_range.map(|t| t.start_time),
ending_at: value.time_range.and_then(|t| t.end_time),
connector: value.connector,
currency: value.currency,
status: value.status,
payment_methods: value.payment_methods,
customer_id: None,
starting_after_id: None,
ending_before_id: None,
limit: None,
}
}
}
}