mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 12:06:56 +08:00
refactor(payouts): update helper functions for deciding whether or not to consume flows based on current status (#5248)
This commit is contained in:
@ -368,8 +368,6 @@ pub async fn payouts_confirm_core(
|
|||||||
let payout_attempt = payout_data.payout_attempt.to_owned();
|
let payout_attempt = payout_data.payout_attempt.to_owned();
|
||||||
let status = payout_attempt.status;
|
let status = payout_attempt.status;
|
||||||
|
|
||||||
helpers::update_payouts_and_payout_attempt(&mut payout_data, &merchant_account, &req, &state)
|
|
||||||
.await?;
|
|
||||||
helpers::validate_payout_status_against_not_allowed_statuses(
|
helpers::validate_payout_status_against_not_allowed_statuses(
|
||||||
&status,
|
&status,
|
||||||
&[
|
&[
|
||||||
@ -384,10 +382,11 @@ pub async fn payouts_confirm_core(
|
|||||||
"confirm",
|
"confirm",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Update payout link's status
|
helpers::update_payouts_and_payout_attempt(&mut payout_data, &merchant_account, &req, &state)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let db = &*state.store;
|
let db = &*state.store;
|
||||||
|
|
||||||
// payout_data.payout_link
|
|
||||||
payout_data.payout_link = payout_data
|
payout_data.payout_link = payout_data
|
||||||
.payout_link
|
.payout_link
|
||||||
.clone()
|
.clone()
|
||||||
@ -467,15 +466,17 @@ pub async fn payouts_update_core(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
payouts_core(
|
if let Some(true) = payout_data.payouts.confirm {
|
||||||
&state,
|
payouts_core(
|
||||||
&merchant_account,
|
&state,
|
||||||
&key_store,
|
&merchant_account,
|
||||||
&mut payout_data,
|
&key_store,
|
||||||
req.routing.clone(),
|
&mut payout_data,
|
||||||
req.connector.clone(),
|
req.routing.clone(),
|
||||||
)
|
req.connector.clone(),
|
||||||
.await?;
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
response_handler(&merchant_account, &payout_data).await
|
response_handler(&merchant_account, &payout_data).await
|
||||||
}
|
}
|
||||||
@ -2052,6 +2053,18 @@ pub async fn payout_create_db_entries(
|
|||||||
format!("payout_{payout_id}_secret").as_str(),
|
format!("payout_{payout_id}_secret").as_str(),
|
||||||
);
|
);
|
||||||
let amount = MinorUnit::from(req.amount.unwrap_or(api::Amount::Zero));
|
let amount = MinorUnit::from(req.amount.unwrap_or(api::Amount::Zero));
|
||||||
|
let status = if req.payout_method_data.is_some()
|
||||||
|
|| req.payout_token.is_some()
|
||||||
|
|| stored_payout_method_data.is_some()
|
||||||
|
{
|
||||||
|
match req.confirm {
|
||||||
|
Some(true) => storage_enums::PayoutStatus::RequiresCreation,
|
||||||
|
_ => storage_enums::PayoutStatus::RequiresConfirmation,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
storage_enums::PayoutStatus::RequiresPayoutMethodData
|
||||||
|
};
|
||||||
|
|
||||||
let payouts_req = storage::PayoutsNew {
|
let payouts_req = storage::PayoutsNew {
|
||||||
payout_id: payout_id.to_string(),
|
payout_id: payout_id.to_string(),
|
||||||
merchant_id: merchant_id.to_string(),
|
merchant_id: merchant_id.to_string(),
|
||||||
@ -2076,6 +2089,7 @@ pub async fn payout_create_db_entries(
|
|||||||
.map(|link_data| link_data.link_id.clone()),
|
.map(|link_data| link_data.link_id.clone()),
|
||||||
client_secret: Some(client_secret),
|
client_secret: Some(client_secret),
|
||||||
priority: req.priority,
|
priority: req.priority,
|
||||||
|
status,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let payouts = db
|
let payouts = db
|
||||||
@ -2086,17 +2100,6 @@ pub async fn payout_create_db_entries(
|
|||||||
})
|
})
|
||||||
.attach_printable("Error inserting payouts in db")?;
|
.attach_printable("Error inserting payouts in db")?;
|
||||||
// Make payout_attempt entry
|
// Make payout_attempt entry
|
||||||
let status = if req.payout_method_data.is_some()
|
|
||||||
|| req.payout_token.is_some()
|
|
||||||
|| stored_payout_method_data.is_some()
|
|
||||||
{
|
|
||||||
match req.confirm {
|
|
||||||
Some(true) => storage_enums::PayoutStatus::RequiresCreation,
|
|
||||||
_ => storage_enums::PayoutStatus::RequiresConfirmation,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
storage_enums::PayoutStatus::RequiresPayoutMethodData
|
|
||||||
};
|
|
||||||
let payout_attempt_id = utils::get_payment_attempt_id(payout_id, 1);
|
let payout_attempt_id = utils::get_payment_attempt_id(payout_id, 1);
|
||||||
|
|
||||||
let payout_attempt_req = storage::PayoutAttemptNew {
|
let payout_attempt_req = storage::PayoutAttemptNew {
|
||||||
|
|||||||
@ -887,9 +887,12 @@ pub async fn get_gsm_record(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_payout_initiated(status: api_enums::PayoutStatus) -> bool {
|
pub fn is_payout_initiated(status: api_enums::PayoutStatus) -> bool {
|
||||||
matches!(
|
!matches!(
|
||||||
status,
|
status,
|
||||||
api_enums::PayoutStatus::Pending | api_enums::PayoutStatus::RequiresFulfillment
|
api_enums::PayoutStatus::RequiresCreation
|
||||||
|
| api_enums::PayoutStatus::RequiresConfirmation
|
||||||
|
| api_enums::PayoutStatus::RequiresPayoutMethodData
|
||||||
|
| api_enums::PayoutStatus::RequiresVendorAccountCreation
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -910,10 +913,13 @@ pub(crate) fn validate_payout_status_against_not_allowed_statuses(
|
|||||||
pub fn is_payout_terminal_state(status: api_enums::PayoutStatus) -> bool {
|
pub fn is_payout_terminal_state(status: api_enums::PayoutStatus) -> bool {
|
||||||
!matches!(
|
!matches!(
|
||||||
status,
|
status,
|
||||||
api_enums::PayoutStatus::Pending
|
api_enums::PayoutStatus::RequiresCreation
|
||||||
| api_enums::PayoutStatus::RequiresCreation
|
| api_enums::PayoutStatus::RequiresConfirmation
|
||||||
| api_enums::PayoutStatus::RequiresFulfillment
|
|
||||||
| api_enums::PayoutStatus::RequiresPayoutMethodData
|
| api_enums::PayoutStatus::RequiresPayoutMethodData
|
||||||
|
| api_enums::PayoutStatus::RequiresVendorAccountCreation
|
||||||
|
// Initiated by the underlying connector
|
||||||
|
| api_enums::PayoutStatus::Pending
|
||||||
|
| api_enums::PayoutStatus::RequiresFulfillment
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -930,7 +936,9 @@ pub fn is_eligible_for_local_payout_cancellation(status: api_enums::PayoutStatus
|
|||||||
matches!(
|
matches!(
|
||||||
status,
|
status,
|
||||||
api_enums::PayoutStatus::RequiresCreation
|
api_enums::PayoutStatus::RequiresCreation
|
||||||
| api_enums::PayoutStatus::RequiresPayoutMethodData,
|
| api_enums::PayoutStatus::RequiresConfirmation
|
||||||
|
| api_enums::PayoutStatus::RequiresPayoutMethodData
|
||||||
|
| api_enums::PayoutStatus::RequiresVendorAccountCreation
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user