Skip to content

Commit

Permalink
fix(payouts): persist status updates in payouts table (#4280)
Browse files Browse the repository at this point in the history
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
kashif-m and hyperswitch-bot[bot] authored Apr 4, 2024
1 parent 622aac3 commit 02ffe7e
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 61 deletions.
2 changes: 0 additions & 2 deletions crates/api_models/src/payouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,6 @@ pub struct PayoutAttemptResponse {
pub connector_transaction_id: Option<String>,
/// If the payout was cancelled the reason provided here
pub cancellation_reason: Option<String>,
/// Provide a reference to a stored payout method
pub payout_token: Option<String>,
/// error code unified across the connectors is received here if there was an error while calling connector
pub unified_code: Option<String>,
/// error message unified across the connectors is received here if there was an error while calling connector
Expand Down
16 changes: 13 additions & 3 deletions crates/data_models/src/payouts/payouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ pub trait PayoutsInterface {
_merchant_id: &str,
_filters: &PayoutFetchConstraints,
_storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<Vec<(Payouts, PayoutAttempt)>, errors::StorageError>;
) -> error_stack::Result<
Vec<(Payouts, PayoutAttempt, diesel_models::Customer)>,
errors::StorageError,
>;

#[cfg(feature = "olap")]
async fn filter_payouts_by_time_range_constraints(
Expand Down Expand Up @@ -155,14 +158,17 @@ pub enum PayoutsUpdate {
status: Option<storage_enums::PayoutStatus>,
},
PayoutMethodIdUpdate {
payout_method_id: Option<String>,
payout_method_id: String,
},
RecurringUpdate {
recurring: bool,
},
AttemptCountUpdate {
attempt_count: i16,
},
StatusUpdate {
status: storage_enums::PayoutStatus,
},
}

#[derive(Clone, Debug, Default)]
Expand Down Expand Up @@ -212,7 +218,7 @@ impl From<PayoutsUpdate> for PayoutsUpdateInternal {
..Default::default()
},
PayoutsUpdate::PayoutMethodIdUpdate { payout_method_id } => Self {
payout_method_id,
payout_method_id: Some(payout_method_id),
..Default::default()
},
PayoutsUpdate::RecurringUpdate { recurring } => Self {
Expand All @@ -223,6 +229,10 @@ impl From<PayoutsUpdate> for PayoutsUpdateInternal {
attempt_count: Some(attempt_count),
..Default::default()
},
PayoutsUpdate::StatusUpdate { status } => Self {
status: Some(status),
..Default::default()
},
}
}
}
11 changes: 9 additions & 2 deletions crates/diesel_models/src/payouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,17 @@ pub enum PayoutsUpdate {
status: Option<storage_enums::PayoutStatus>,
},
PayoutMethodIdUpdate {
payout_method_id: Option<String>,
payout_method_id: String,
},
RecurringUpdate {
recurring: bool,
},
AttemptCountUpdate {
attempt_count: i16,
},
StatusUpdate {
status: storage_enums::PayoutStatus,
},
}

#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
Expand Down Expand Up @@ -168,7 +171,7 @@ impl From<PayoutsUpdate> for PayoutsUpdateInternal {
..Default::default()
},
PayoutsUpdate::PayoutMethodIdUpdate { payout_method_id } => Self {
payout_method_id,
payout_method_id: Some(payout_method_id),
..Default::default()
},
PayoutsUpdate::RecurringUpdate { recurring } => Self {
Expand All @@ -179,6 +182,10 @@ impl From<PayoutsUpdate> for PayoutsUpdateInternal {
attempt_count: Some(attempt_count),
..Default::default()
},
PayoutsUpdate::StatusUpdate { status } => Self {
status: Some(status),
..Default::default()
},
}
}
}
Expand Down
39 changes: 25 additions & 14 deletions crates/router/src/core/payments/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,44 +883,55 @@ impl ForeignFrom<(storage::PaymentIntent, storage::PaymentAttempt)> for api::Pay
}

#[cfg(feature = "payouts")]
impl ForeignFrom<(storage::Payouts, storage::PayoutAttempt)> for api::PayoutCreateResponse {
fn foreign_from(item: (storage::Payouts, storage::PayoutAttempt)) -> Self {
let payout = item.0;
let payout_attempt = item.1;
impl ForeignFrom<(storage::Payouts, storage::PayoutAttempt, domain::Customer)>
for api::PayoutCreateResponse
{
fn foreign_from(item: (storage::Payouts, storage::PayoutAttempt, domain::Customer)) -> Self {
let (payout, payout_attempt, customer) = item;
let attempt = PayoutAttemptResponse {
attempt_id: payout_attempt.payout_attempt_id,
status: payout_attempt.status,
amount: payout.amount,
currency: Some(payout.destination_currency),
connector: payout_attempt.connector.clone(),
error_code: payout_attempt.error_code,
error_message: payout_attempt.error_message,
error_code: payout_attempt.error_code.clone(),
error_message: payout_attempt.error_message.clone(),
payment_method: Some(payout.payout_type),
payout_method_type: None,
connector_transaction_id: Some(payout_attempt.connector_payout_id),
cancellation_reason: None,
payout_token: payout_attempt.payout_token,
unified_code: None,
unified_message: None,
};
let attempts = vec![attempt];
Self {
payout_id: payout.payout_id,
merchant_id: payout.merchant_id,
status: payout.status,
amount: payout.amount,
created: Some(payout.created_at),
currency: payout.destination_currency,
description: payout.description,
metadata: payout.metadata,
customer_id: payout.customer_id,
connector: payout_attempt.connector,
payout_type: payout.payout_type,
business_label: payout_attempt.business_label,
customer_id: customer.customer_id,
auto_fulfill: payout.auto_fulfill,
email: customer.email,
name: customer.name,
phone: customer.phone,
phone_country_code: customer.phone_country_code,
return_url: payout.return_url,
business_country: payout_attempt.business_country,
business_label: payout_attempt.business_label,
description: payout.description,
entity_type: payout.entity_type,
recurring: payout.recurring,
metadata: payout.metadata,
status: payout_attempt.status,
error_message: payout_attempt.error_message,
error_code: payout_attempt.error_code,
profile_id: payout.profile_id,
created: Some(payout.created_at),
attempts: Some(attempts),
..Default::default()
billing: None,
client_secret: None,
}
}
}
Expand Down
Loading

0 comments on commit 02ffe7e

Please sign in to comment.