mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 05:17:02 +08:00
feat(payouts): implement KVRouterStore (#3889)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Kashif <mohammed.kashif@juspay.in>
This commit is contained in:
@ -30,33 +30,8 @@ pub struct Payouts {
|
||||
#[serde(with = "common_utils::custom_serde::iso8601")]
|
||||
pub last_modified_at: PrimitiveDateTime,
|
||||
pub attempt_count: i16,
|
||||
}
|
||||
|
||||
impl Default for Payouts {
|
||||
fn default() -> Self {
|
||||
let now = common_utils::date_time::now();
|
||||
|
||||
Self {
|
||||
payout_id: String::default(),
|
||||
merchant_id: String::default(),
|
||||
customer_id: String::default(),
|
||||
address_id: String::default(),
|
||||
payout_type: storage_enums::PayoutType::default(),
|
||||
payout_method_id: Option::default(),
|
||||
amount: i64::default(),
|
||||
destination_currency: storage_enums::Currency::default(),
|
||||
source_currency: storage_enums::Currency::default(),
|
||||
description: Option::default(),
|
||||
recurring: bool::default(),
|
||||
auto_fulfill: bool::default(),
|
||||
return_url: None,
|
||||
entity_type: storage_enums::PayoutEntityType::default(),
|
||||
metadata: Option::default(),
|
||||
created_at: now,
|
||||
last_modified_at: now,
|
||||
attempt_count: i16::default(),
|
||||
}
|
||||
}
|
||||
pub profile_id: String,
|
||||
pub status: storage_enums::PayoutStatus,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
@ -92,10 +67,12 @@ pub struct PayoutsNew {
|
||||
pub created_at: Option<PrimitiveDateTime>,
|
||||
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
|
||||
pub last_modified_at: Option<PrimitiveDateTime>,
|
||||
pub profile_id: String,
|
||||
pub status: storage_enums::PayoutStatus,
|
||||
pub attempt_count: i16,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum PayoutsUpdate {
|
||||
Update {
|
||||
amount: i64,
|
||||
@ -107,22 +84,21 @@ pub enum PayoutsUpdate {
|
||||
return_url: Option<String>,
|
||||
entity_type: storage_enums::PayoutEntityType,
|
||||
metadata: Option<pii::SecretSerdeValue>,
|
||||
last_modified_at: Option<PrimitiveDateTime>,
|
||||
profile_id: Option<String>,
|
||||
status: Option<storage_enums::PayoutStatus>,
|
||||
},
|
||||
PayoutMethodIdUpdate {
|
||||
payout_method_id: Option<String>,
|
||||
last_modified_at: Option<PrimitiveDateTime>,
|
||||
},
|
||||
RecurringUpdate {
|
||||
recurring: bool,
|
||||
last_modified_at: Option<PrimitiveDateTime>,
|
||||
},
|
||||
AttemptCountUpdate {
|
||||
attempt_count: i16,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)]
|
||||
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
|
||||
#[diesel(table_name = payouts)]
|
||||
pub struct PayoutsUpdateInternal {
|
||||
pub amount: Option<i64>,
|
||||
@ -134,11 +110,34 @@ pub struct PayoutsUpdateInternal {
|
||||
pub return_url: Option<String>,
|
||||
pub entity_type: Option<storage_enums::PayoutEntityType>,
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
pub last_modified_at: Option<PrimitiveDateTime>,
|
||||
pub payout_method_id: Option<String>,
|
||||
pub profile_id: Option<String>,
|
||||
pub status: Option<storage_enums::PayoutStatus>,
|
||||
pub last_modified_at: PrimitiveDateTime,
|
||||
pub attempt_count: Option<i16>,
|
||||
}
|
||||
|
||||
impl Default for PayoutsUpdateInternal {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
amount: None,
|
||||
destination_currency: None,
|
||||
source_currency: None,
|
||||
description: None,
|
||||
recurring: None,
|
||||
auto_fulfill: None,
|
||||
return_url: None,
|
||||
entity_type: None,
|
||||
metadata: None,
|
||||
payout_method_id: None,
|
||||
profile_id: None,
|
||||
status: None,
|
||||
last_modified_at: common_utils::date_time::now(),
|
||||
attempt_count: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PayoutsUpdate> for PayoutsUpdateInternal {
|
||||
fn from(payout_update: PayoutsUpdate) -> Self {
|
||||
match payout_update {
|
||||
@ -152,7 +151,8 @@ impl From<PayoutsUpdate> for PayoutsUpdateInternal {
|
||||
return_url,
|
||||
entity_type,
|
||||
metadata,
|
||||
last_modified_at,
|
||||
profile_id,
|
||||
status,
|
||||
} => Self {
|
||||
amount: Some(amount),
|
||||
destination_currency: Some(destination_currency),
|
||||
@ -163,22 +163,15 @@ impl From<PayoutsUpdate> for PayoutsUpdateInternal {
|
||||
return_url,
|
||||
entity_type: Some(entity_type),
|
||||
metadata,
|
||||
last_modified_at,
|
||||
profile_id,
|
||||
status,
|
||||
..Default::default()
|
||||
},
|
||||
PayoutsUpdate::PayoutMethodIdUpdate {
|
||||
last_modified_at,
|
||||
payout_method_id,
|
||||
} => Self {
|
||||
last_modified_at,
|
||||
PayoutsUpdate::PayoutMethodIdUpdate { payout_method_id } => Self {
|
||||
payout_method_id,
|
||||
..Default::default()
|
||||
},
|
||||
PayoutsUpdate::RecurringUpdate {
|
||||
last_modified_at,
|
||||
recurring,
|
||||
} => Self {
|
||||
last_modified_at,
|
||||
PayoutsUpdate::RecurringUpdate { recurring } => Self {
|
||||
recurring: Some(recurring),
|
||||
..Default::default()
|
||||
},
|
||||
@ -189,3 +182,41 @@ impl From<PayoutsUpdate> for PayoutsUpdateInternal {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PayoutsUpdate {
|
||||
pub fn apply_changeset(self, source: Payouts) -> Payouts {
|
||||
let PayoutsUpdateInternal {
|
||||
amount,
|
||||
destination_currency,
|
||||
source_currency,
|
||||
description,
|
||||
recurring,
|
||||
auto_fulfill,
|
||||
return_url,
|
||||
entity_type,
|
||||
metadata,
|
||||
payout_method_id,
|
||||
profile_id,
|
||||
status,
|
||||
last_modified_at,
|
||||
attempt_count,
|
||||
} = self.into();
|
||||
Payouts {
|
||||
amount: amount.unwrap_or(source.amount),
|
||||
destination_currency: destination_currency.unwrap_or(source.destination_currency),
|
||||
source_currency: source_currency.unwrap_or(source.source_currency),
|
||||
description: description.or(source.description),
|
||||
recurring: recurring.unwrap_or(source.recurring),
|
||||
auto_fulfill: auto_fulfill.unwrap_or(source.auto_fulfill),
|
||||
return_url: return_url.or(source.return_url),
|
||||
entity_type: entity_type.unwrap_or(source.entity_type),
|
||||
metadata: metadata.or(source.metadata),
|
||||
payout_method_id: payout_method_id.or(source.payout_method_id),
|
||||
profile_id: profile_id.unwrap_or(source.profile_id),
|
||||
status: status.unwrap_or(source.status),
|
||||
last_modified_at,
|
||||
attempt_count: attempt_count.unwrap_or(source.attempt_count),
|
||||
..source
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user