mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +08:00
refactor(storage_impl): split payment attempt models to domain + diesel (#2010)
Signed-off-by: chikke srujan <121822803+srujanchikke@users.noreply.github.com> Co-authored-by: Mani Chandra <84711804+ThisIsMani@users.noreply.github.com> Co-authored-by: Arjun Karthik <m.arjunkarthik@gmail.com> Co-authored-by: Sai Harsha Vardhan <56996463+sai-harsha-vardhan@users.noreply.github.com> Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com> Co-authored-by: chikke srujan <121822803+srujanchikke@users.noreply.github.com> Co-authored-by: Prasunna Soppa <prasunna.soppa@juspay.in> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: DEEPANSHU BANSAL <41580413+deepanshu-iiitu@users.noreply.github.com> Co-authored-by: Arvind Patel <52006565+arvindpatel24@users.noreply.github.com> Co-authored-by: Jagan Elavarasan <jaganelavarasan@gmail.com> Co-authored-by: arvindpatel24 <arvind.patel@juspay.in> Co-authored-by: anji-reddy-j <125157119+anji-reddy-j@users.noreply.github.com> Co-authored-by: Hrithikesh <61539176+hrithikesh026@users.noreply.github.com> Co-authored-by: Apoorv Dixit <64925866+apoorvdixit88@users.noreply.github.com> Co-authored-by: Pa1NarK <69745008+pixincreate@users.noreply.github.com>
This commit is contained in:
@ -1,5 +1,12 @@
|
||||
use api_models::payments::{
|
||||
AcceptanceType as ApiAcceptanceType, CustomerAcceptance as ApiCustomerAcceptance,
|
||||
MandateAmountData as ApiMandateAmountData, MandateData as ApiMandateData, MandateType,
|
||||
OnlineMandate as ApiOnlineMandate,
|
||||
};
|
||||
use common_enums::Currency;
|
||||
use common_utils::pii;
|
||||
use common_utils::{date_time, errors::ParsingError, pii};
|
||||
use error_stack::{IntoReport, ResultExt};
|
||||
use masking::{PeekInterface, Secret};
|
||||
use time::PrimitiveDateTime;
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
@ -17,3 +24,135 @@ pub struct MandateAmountData {
|
||||
pub end_date: Option<PrimitiveDateTime>,
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
}
|
||||
|
||||
// The fields on this struct are optional, as we want to allow the merchant to provide partial
|
||||
// information about creating mandates
|
||||
#[derive(Default, Eq, PartialEq, Debug, Clone)]
|
||||
pub struct MandateData {
|
||||
/// A concent from the customer to store the payment method
|
||||
pub customer_acceptance: Option<CustomerAcceptance>,
|
||||
/// A way to select the type of mandate used
|
||||
pub mandate_type: Option<MandateDataType>,
|
||||
}
|
||||
|
||||
#[derive(Default, Eq, PartialEq, Debug, Clone)]
|
||||
pub struct CustomerAcceptance {
|
||||
/// Type of acceptance provided by the
|
||||
pub acceptance_type: AcceptanceType,
|
||||
/// Specifying when the customer acceptance was provided
|
||||
pub accepted_at: Option<PrimitiveDateTime>,
|
||||
/// Information required for online mandate generation
|
||||
pub online: Option<OnlineMandate>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, Eq, Clone)]
|
||||
pub enum AcceptanceType {
|
||||
Online,
|
||||
#[default]
|
||||
Offline,
|
||||
}
|
||||
|
||||
#[derive(Default, Eq, PartialEq, Debug, Clone)]
|
||||
pub struct OnlineMandate {
|
||||
/// Ip address of the customer machine from which the mandate was created
|
||||
pub ip_address: Option<Secret<String, pii::IpAddress>>,
|
||||
/// The user-agent of the customer's browser
|
||||
pub user_agent: String,
|
||||
}
|
||||
|
||||
impl From<MandateType> for MandateDataType {
|
||||
fn from(mandate_type: MandateType) -> Self {
|
||||
match mandate_type {
|
||||
MandateType::SingleUse(mandate_amount_data) => {
|
||||
Self::SingleUse(mandate_amount_data.into())
|
||||
}
|
||||
MandateType::MultiUse(mandate_amount_data) => {
|
||||
Self::MultiUse(mandate_amount_data.map(|d| d.into()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ApiMandateAmountData> for MandateAmountData {
|
||||
fn from(value: ApiMandateAmountData) -> Self {
|
||||
Self {
|
||||
amount: value.amount,
|
||||
currency: value.currency,
|
||||
start_date: value.start_date,
|
||||
end_date: value.end_date,
|
||||
metadata: value.metadata,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ApiMandateData> for MandateData {
|
||||
fn from(value: ApiMandateData) -> Self {
|
||||
Self {
|
||||
customer_acceptance: value.customer_acceptance.map(|d| d.into()),
|
||||
mandate_type: value.mandate_type.map(|d| d.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ApiCustomerAcceptance> for CustomerAcceptance {
|
||||
fn from(value: ApiCustomerAcceptance) -> Self {
|
||||
Self {
|
||||
acceptance_type: value.acceptance_type.into(),
|
||||
accepted_at: value.accepted_at,
|
||||
online: value.online.map(|d| d.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ApiAcceptanceType> for AcceptanceType {
|
||||
fn from(value: ApiAcceptanceType) -> Self {
|
||||
match value {
|
||||
ApiAcceptanceType::Online => Self::Online,
|
||||
ApiAcceptanceType::Offline => Self::Offline,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ApiOnlineMandate> for OnlineMandate {
|
||||
fn from(value: ApiOnlineMandate) -> Self {
|
||||
Self {
|
||||
ip_address: value.ip_address,
|
||||
user_agent: value.user_agent,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CustomerAcceptance {
|
||||
pub fn get_ip_address(&self) -> Option<String> {
|
||||
self.online
|
||||
.as_ref()
|
||||
.and_then(|data| data.ip_address.as_ref().map(|ip| ip.peek().to_owned()))
|
||||
}
|
||||
|
||||
pub fn get_user_agent(&self) -> Option<String> {
|
||||
self.online.as_ref().map(|data| data.user_agent.clone())
|
||||
}
|
||||
|
||||
pub fn get_accepted_at(&self) -> PrimitiveDateTime {
|
||||
self.accepted_at
|
||||
.unwrap_or_else(common_utils::date_time::now)
|
||||
}
|
||||
}
|
||||
|
||||
impl MandateAmountData {
|
||||
pub fn get_end_date(
|
||||
&self,
|
||||
format: date_time::DateFormat,
|
||||
) -> error_stack::Result<Option<String>, ParsingError> {
|
||||
self.end_date
|
||||
.map(|date| {
|
||||
date_time::format_date(date, format)
|
||||
.into_report()
|
||||
.change_context(ParsingError::DateTimeParsingError)
|
||||
})
|
||||
.transpose()
|
||||
}
|
||||
pub fn get_metadata(&self) -> Option<pii::SecretSerdeValue> {
|
||||
self.metadata.clone()
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
use api_models::enums::Connector;
|
||||
use common_enums as storage_enums;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use time::PrimitiveDateTime;
|
||||
@ -77,6 +78,15 @@ pub trait PaymentAttemptInterface {
|
||||
merchant_id: &str,
|
||||
storage_scheme: MerchantStorageScheme,
|
||||
) -> error_stack::Result<PaymentListFilters, errors::StorageError>;
|
||||
|
||||
async fn get_total_count_of_filtered_payment_attempts(
|
||||
&self,
|
||||
merchant_id: &str,
|
||||
active_attempt_ids: &[String],
|
||||
connector: Option<Vec<Connector>>,
|
||||
payment_methods: Option<Vec<storage_enums::PaymentMethod>>,
|
||||
storage_scheme: MerchantStorageScheme,
|
||||
) -> error_stack::Result<i64, errors::StorageError>;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
@ -129,7 +139,7 @@ pub struct PaymentAttempt {
|
||||
pub connector_response_reference_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct PaymentListFilters {
|
||||
pub connector: Vec<String>,
|
||||
pub currency: Vec<storage_enums::Currency>,
|
||||
@ -222,6 +232,13 @@ pub enum PaymentAttemptUpdate {
|
||||
payment_experience: Option<storage_enums::PaymentExperience>,
|
||||
business_sub_label: Option<String>,
|
||||
straight_through_algorithm: Option<serde_json::Value>,
|
||||
error_code: Option<Option<String>>,
|
||||
error_message: Option<Option<String>>,
|
||||
},
|
||||
RejectUpdate {
|
||||
status: storage_enums::AttemptStatus,
|
||||
error_code: Option<Option<String>>,
|
||||
error_message: Option<Option<String>>,
|
||||
},
|
||||
VoidUpdate {
|
||||
status: storage_enums::AttemptStatus,
|
||||
@ -261,9 +278,8 @@ pub enum PaymentAttemptUpdate {
|
||||
error_message: Option<Option<String>>,
|
||||
error_reason: Option<Option<String>>,
|
||||
},
|
||||
MultipleCaptureUpdate {
|
||||
status: Option<storage_enums::AttemptStatus>,
|
||||
multiple_capture_count: Option<i16>,
|
||||
MultipleCaptureCountUpdate {
|
||||
multiple_capture_count: i16,
|
||||
},
|
||||
PreprocessingUpdate {
|
||||
status: storage_enums::AttemptStatus,
|
||||
|
||||
Reference in New Issue
Block a user