Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(payouts): Implement Smart Retries for Payout #3580

Merged
merged 40 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
42fbf3d
refactor(payouts): replace payout routing types with existing types
kashif-m Jan 29, 2024
528168d
feat(payouts): extend routing capabilities to payout operations
kashif-m Feb 1, 2024
02735c7
fix: cargo hack
kashif-m Feb 2, 2024
9e42268
feat(payouts): provision for toggling routing rules for payout operat…
kashif-m Feb 2, 2024
6c616bd
refactor(payouts): update connector_data formation for fulfill, cance…
kashif-m Feb 5, 2024
7ac92b4
refactor(payouts): clippy and fmt
kashif-m Feb 5, 2024
9d05fd6
refactor(payouts): persist routing info in payout_attempt
kashif-m Feb 5, 2024
43335ec
feat: implement smart retries for payout
Sakilmostak Feb 7, 2024
f57f5c0
fix(payouts): cargo hack
kashif-m Feb 7, 2024
f1f657e
refactor: payout_attempt updation and error handling
Sakilmostak Feb 7, 2024
4d145bf
refactor(payouts): cargo hack again
kashif-m Feb 7, 2024
d64b65c
Merge remote-tracking branch 'origin/main' into payout_routing
kashif-m Feb 8, 2024
dea2d6c
fix(payouts): cargo clippy
kashif-m Feb 8, 2024
a64eaff
Merge branch 'main' into payout_retries
Sakilmostak Feb 8, 2024
3fa57a6
refactor: update main
Sakilmostak Feb 8, 2024
eacb5c1
feat: add retry to payout update call
Sakilmostak Feb 11, 2024
e614ac2
refactor: comments
Sakilmostak Feb 12, 2024
2870ce7
Merge branch 'payout_routing' into payout_retries
Sakilmostak Feb 12, 2024
504722d
refactor: merge main
Sakilmostak Feb 12, 2024
1c2ff2f
refactor: query
Sakilmostak Feb 13, 2024
d74434d
refactor: comments
Sakilmostak Feb 14, 2024
126a54b
Merge branch 'main' into payout_retries
Sakilmostak Feb 14, 2024
0a31336
Merge remote-tracking branch 'origin/main' into payout_routing
kashif-m Feb 14, 2024
11eb077
refactor: comments
Sakilmostak Feb 15, 2024
bc23048
Merge remote-tracking branch 'origin/main' into backup-po-routing
kashif-m Feb 15, 2024
9e716a3
refactor(payouts): separate endpoints for routing config creation and…
kashif-m Feb 15, 2024
7de6abd
refactor(payouts): cargo hack
kashif-m Feb 16, 2024
b1ff72c
fix(payouts): update down db query
kashif-m Feb 16, 2024
f26df3d
Merge remote-tracking branch 'origin/main' into payout_routing
kashif-m Feb 20, 2024
fdca6cd
refactor: resolve comments
Sakilmostak Feb 20, 2024
58ee7a5
Merge branch 'main' into payout_retries
Sakilmostak Feb 20, 2024
1a794c5
Merge branch 'payout_routing' into payout_retries
Sakilmostak Feb 20, 2024
0c743e1
refactor: resolve merging payout_routing
Sakilmostak Feb 20, 2024
bd77685
refactor: update payout_attempt by payout_attempt_id in update
Sakilmostak Feb 21, 2024
4bef663
Merge branch 'main' into payout_retries
Sakilmostak Feb 26, 2024
e9f5f08
refactor: merge main
Sakilmostak Feb 27, 2024
657e325
refactor: cargo format
Sakilmostak Feb 27, 2024
17d5c93
Merge branch 'main' into payout_retries
Sakilmostak Feb 27, 2024
f50c8f8
refactor: merge main
Sakilmostak Feb 27, 2024
b462aa4
refactor: remove redundancy
Sakilmostak Feb 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/diesel_models/src/payouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct Payouts {
pub created_at: PrimitiveDateTime,
#[serde(with = "common_utils::custom_serde::iso8601")]
pub last_modified_at: PrimitiveDateTime,
pub attempt_count: i16,
}

impl Default for Payouts {
Expand All @@ -53,6 +54,7 @@ impl Default for Payouts {
metadata: Option::default(),
created_at: now,
last_modified_at: now,
attempt_count: i16::default(),
}
}
}
Expand Down Expand Up @@ -90,6 +92,7 @@ pub struct PayoutsNew {
pub created_at: Option<PrimitiveDateTime>,
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub last_modified_at: Option<PrimitiveDateTime>,
pub attempt_count: i16,
}

#[derive(Debug)]
Expand All @@ -105,6 +108,7 @@ pub enum PayoutsUpdate {
entity_type: storage_enums::PayoutEntityType,
metadata: Option<pii::SecretSerdeValue>,
last_modified_at: Option<PrimitiveDateTime>,
attempt_count: i16,
},
PayoutMethodIdUpdate {
payout_method_id: Option<String>,
Expand All @@ -130,6 +134,7 @@ pub struct PayoutsUpdateInternal {
pub metadata: Option<pii::SecretSerdeValue>,
pub last_modified_at: Option<PrimitiveDateTime>,
pub payout_method_id: Option<String>,
pub attempt_count: Option<i16>,
}

impl From<PayoutsUpdate> for PayoutsUpdateInternal {
Expand All @@ -146,6 +151,7 @@ impl From<PayoutsUpdate> for PayoutsUpdateInternal {
entity_type,
metadata,
last_modified_at,
attempt_count,
} => Self {
amount: Some(amount),
destination_currency: Some(destination_currency),
Expand All @@ -157,6 +163,7 @@ impl From<PayoutsUpdate> for PayoutsUpdateInternal {
entity_type: Some(entity_type),
metadata,
last_modified_at,
attempt_count: Some(attempt_count),
..Default::default()
},
PayoutsUpdate::PayoutMethodIdUpdate {
Expand Down
35 changes: 35 additions & 0 deletions crates/diesel_models/src/query/payout_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ impl PayoutAttempt {
.await
}

pub async fn find_by_merchant_id_payout_attempt_id(
conn: &PgPooledConn,
merchant_id: &str,
payout_attempt_id: &str,
) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::merchant_id
.eq(merchant_id.to_owned())
.and(dsl::payout_attempt_id.eq(payout_attempt_id.to_owned())),
)
.await
}

pub async fn update_by_merchant_id_payout_id(
conn: &PgPooledConn,
merchant_id: &str,
Expand All @@ -54,4 +68,25 @@ impl PayoutAttempt {
report!(errors::DatabaseError::NotFound).attach_printable("Error while updating payout")
})
}

pub async fn update_by_merchant_id_payout_attempt_id(
conn: &PgPooledConn,
merchant_id: &str,
payout_attempt_id: &str,
payout: PayoutAttemptUpdate,
) -> StorageResult<Self> {
generics::generic_update_with_results::<<Self as HasTable>::Table, _, _, _>(
conn,
dsl::merchant_id
.eq(merchant_id.to_owned())
.and(dsl::payout_attempt_id.eq(payout_attempt_id.to_owned())),
PayoutAttemptUpdateInternal::from(payout),
)
.await?
.first()
.cloned()
.ok_or_else(|| {
report!(errors::DatabaseError::NotFound).attach_printable("Error while updating payout")
})
}
}
1 change: 1 addition & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ diesel::table! {
metadata -> Nullable<Jsonb>,
created_at -> Timestamp,
last_modified_at -> Timestamp,
attempt_count -> Int2,
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "README.md"
license.workspace = true

[features]
default = ["kv_store", "stripe", "oltp", "olap", "backwards_compatibility", "accounts_cache", "dummy_connector", "payouts", "business_profile_routing", "connector_choice_mca_id", "profile_specific_fallback_routing", "retry", "frm"]
default = ["kv_store", "stripe", "oltp", "olap", "backwards_compatibility", "accounts_cache", "dummy_connector", "payouts", "payout_retry", "business_profile_routing", "connector_choice_mca_id", "profile_specific_fallback_routing", "retry", "frm"]
aws_s3 = ["external_services/aws_s3"]
kms = ["external_services/kms"]
hashicorp-vault = ["external_services/hashicorp-vault"]
Expand All @@ -31,6 +31,7 @@ connector_choice_mca_id = ["api_models/connector_choice_mca_id", "euclid/connect
external_access_dc = ["dummy_connector"]
detailed_errors = ["api_models/detailed_errors", "error-stack/serde"]
payouts = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
payouts = []
payouts = ["payout_retry"]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since, payout_retry is dependent on payout, payout is put under payout_retry

payout_retry = []
recon = ["email", "api_models/recon"]
retry = []

Expand Down
2 changes: 0 additions & 2 deletions crates/router/src/core/payments/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,6 @@ pub async fn perform_eligibility_analysis_with_fallback<F: Clone>(
profile_id.clone(),
)
.await?;

let fallback_selection = perform_fallback_routing(
state,
key_store,
Expand All @@ -784,7 +783,6 @@ pub async fn perform_eligibility_analysis_with_fallback<F: Clone>(
profile_id,
)
.await;

final_selection.append(
&mut fallback_selection
.unwrap_or_default()
Expand Down
Loading