mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 21:07:58 +08:00
fix(payouts): update payout's state in app after DB operations (#4341)
This commit is contained in:
@ -166,7 +166,7 @@ pub async fn make_connector_decision(
|
|||||||
|
|
||||||
#[cfg(feature = "payout_retry")]
|
#[cfg(feature = "payout_retry")]
|
||||||
{
|
{
|
||||||
use crate::core::payouts::retry::{self, GsmValidation};
|
use crate::core::payouts::retry::GsmValidation;
|
||||||
let config_bool = retry::config_should_call_gsm_payout(
|
let config_bool = retry::config_should_call_gsm_payout(
|
||||||
&*state.store,
|
&*state.store,
|
||||||
&merchant_account.merchant_id,
|
&merchant_account.merchant_id,
|
||||||
@ -206,7 +206,7 @@ pub async fn make_connector_decision(
|
|||||||
|
|
||||||
#[cfg(feature = "payout_retry")]
|
#[cfg(feature = "payout_retry")]
|
||||||
{
|
{
|
||||||
use crate::core::payouts::retry::{self, GsmValidation};
|
use crate::core::payouts::retry::GsmValidation;
|
||||||
let config_multiple_connector_bool = retry::config_should_call_gsm_payout(
|
let config_multiple_connector_bool = retry::config_should_call_gsm_payout(
|
||||||
&*state.store,
|
&*state.store,
|
||||||
&merchant_account.merchant_id,
|
&merchant_account.merchant_id,
|
||||||
@ -413,12 +413,12 @@ pub async fn payouts_update_core(
|
|||||||
helpers::make_payout_method_data(
|
helpers::make_payout_method_data(
|
||||||
&state,
|
&state,
|
||||||
req.payout_method_data.as_ref(),
|
req.payout_method_data.as_ref(),
|
||||||
payout_data.payout_attempt.payout_token.as_deref(),
|
payout_data.payout_attempt.payout_token.clone().as_deref(),
|
||||||
&payout_data.payout_attempt.customer_id,
|
&payout_data.payout_attempt.customer_id.clone(),
|
||||||
&payout_data.payout_attempt.merchant_id,
|
&payout_data.payout_attempt.merchant_id.clone(),
|
||||||
Some(&payouts.payout_type),
|
Some(&payouts.payout_type),
|
||||||
&key_store,
|
&key_store,
|
||||||
Some(&payout_data),
|
Some(&mut payout_data),
|
||||||
merchant_account.storage_scheme,
|
merchant_account.storage_scheme,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
@ -640,9 +640,9 @@ pub async fn payouts_fulfill_core(
|
|||||||
payout_attempt.payout_token.as_deref(),
|
payout_attempt.payout_token.as_deref(),
|
||||||
&payout_attempt.customer_id,
|
&payout_attempt.customer_id,
|
||||||
&payout_attempt.merchant_id,
|
&payout_attempt.merchant_id,
|
||||||
Some(&payout_data.payouts.payout_type),
|
Some(&payout_data.payouts.payout_type.clone()),
|
||||||
&key_store,
|
&key_store,
|
||||||
Some(&payout_data),
|
Some(&mut payout_data),
|
||||||
merchant_account.storage_scheme,
|
merchant_account.storage_scheme,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
@ -873,15 +873,16 @@ pub async fn call_connector_payout(
|
|||||||
routing_info: payout_data.payout_attempt.routing_info.clone(),
|
routing_info: payout_data.payout_attempt.routing_info.clone(),
|
||||||
};
|
};
|
||||||
let db = &*state.store;
|
let db = &*state.store;
|
||||||
db.update_payout_attempt(
|
payout_data.payout_attempt = db
|
||||||
&payout_data.payout_attempt,
|
.update_payout_attempt(
|
||||||
updated_payout_attempt,
|
&payout_data.payout_attempt,
|
||||||
payouts,
|
updated_payout_attempt,
|
||||||
merchant_account.storage_scheme,
|
payouts,
|
||||||
)
|
merchant_account.storage_scheme,
|
||||||
.await
|
)
|
||||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
.await
|
||||||
.attach_printable("Error updating routing info in payout_attempt")?;
|
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||||
|
.attach_printable("Error updating routing info in payout_attempt")?;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fetch / store payout_method_data
|
// Fetch / store payout_method_data
|
||||||
@ -1469,15 +1470,14 @@ pub async fn fulfill_payout(
|
|||||||
|
|
||||||
// 4. Process data returned by the connector
|
// 4. Process data returned by the connector
|
||||||
let db = &*state.store;
|
let db = &*state.store;
|
||||||
let payout_attempt = &payout_data.payout_attempt;
|
|
||||||
match router_data_resp.response {
|
match router_data_resp.response {
|
||||||
Ok(payout_response_data) => {
|
Ok(payout_response_data) => {
|
||||||
let status = payout_response_data
|
let status = payout_response_data
|
||||||
.status
|
.status
|
||||||
.unwrap_or(payout_attempt.status.to_owned());
|
.unwrap_or(payout_data.payout_attempt.status.to_owned());
|
||||||
payout_data.payouts.status = status;
|
payout_data.payouts.status = status;
|
||||||
if payout_data.payouts.recurring
|
if payout_data.payouts.recurring
|
||||||
&& payout_data.payouts.payout_method_id.is_none()
|
&& payout_data.payouts.payout_method_id.clone().is_none()
|
||||||
&& !helpers::is_payout_err_state(status)
|
&& !helpers::is_payout_err_state(status)
|
||||||
{
|
{
|
||||||
helpers::save_payout_data_to_locker(
|
helpers::save_payout_data_to_locker(
|
||||||
@ -1493,7 +1493,7 @@ pub async fn fulfill_payout(
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
let updated_payout_attempt = storage::PayoutAttemptUpdate::StatusUpdate {
|
let updated_payout_attempt = storage::PayoutAttemptUpdate::StatusUpdate {
|
||||||
connector_payout_id: payout_attempt.connector_payout_id.to_owned(),
|
connector_payout_id: payout_data.payout_attempt.connector_payout_id.to_owned(),
|
||||||
status,
|
status,
|
||||||
error_code: None,
|
error_code: None,
|
||||||
error_message: None,
|
error_message: None,
|
||||||
@ -1501,7 +1501,7 @@ pub async fn fulfill_payout(
|
|||||||
};
|
};
|
||||||
payout_data.payout_attempt = db
|
payout_data.payout_attempt = db
|
||||||
.update_payout_attempt(
|
.update_payout_attempt(
|
||||||
payout_attempt,
|
&payout_data.payout_attempt,
|
||||||
updated_payout_attempt,
|
updated_payout_attempt,
|
||||||
&payout_data.payouts,
|
&payout_data.payouts,
|
||||||
merchant_account.storage_scheme,
|
merchant_account.storage_scheme,
|
||||||
|
|||||||
@ -50,7 +50,7 @@ pub async fn make_payout_method_data<'a>(
|
|||||||
merchant_id: &str,
|
merchant_id: &str,
|
||||||
payout_type: Option<&api_enums::PayoutType>,
|
payout_type: Option<&api_enums::PayoutType>,
|
||||||
merchant_key_store: &domain::MerchantKeyStore,
|
merchant_key_store: &domain::MerchantKeyStore,
|
||||||
payout_data: Option<&PayoutData>,
|
payout_data: Option<&mut PayoutData>,
|
||||||
storage_scheme: storage::enums::MerchantStorageScheme,
|
storage_scheme: storage::enums::MerchantStorageScheme,
|
||||||
) -> RouterResult<Option<api::PayoutMethodData>> {
|
) -> RouterResult<Option<api::PayoutMethodData>> {
|
||||||
let db = &*state.store;
|
let db = &*state.store;
|
||||||
@ -168,15 +168,16 @@ pub async fn make_payout_method_data<'a>(
|
|||||||
let updated_payout_attempt = storage::PayoutAttemptUpdate::PayoutTokenUpdate {
|
let updated_payout_attempt = storage::PayoutAttemptUpdate::PayoutTokenUpdate {
|
||||||
payout_token: lookup_key,
|
payout_token: lookup_key,
|
||||||
};
|
};
|
||||||
db.update_payout_attempt(
|
payout_data.payout_attempt = db
|
||||||
&payout_data.payout_attempt,
|
.update_payout_attempt(
|
||||||
updated_payout_attempt,
|
&payout_data.payout_attempt,
|
||||||
&payout_data.payouts,
|
updated_payout_attempt,
|
||||||
storage_scheme,
|
&payout_data.payouts,
|
||||||
)
|
storage_scheme,
|
||||||
.await
|
)
|
||||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
.await
|
||||||
.attach_printable("Error updating token in payout attempt")?;
|
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||||
|
.attach_printable("Error updating token in payout attempt")?;
|
||||||
}
|
}
|
||||||
Ok(Some(payout_method.clone()))
|
Ok(Some(payout_method.clone()))
|
||||||
}
|
}
|
||||||
@ -188,7 +189,7 @@ pub async fn make_payout_method_data<'a>(
|
|||||||
|
|
||||||
pub async fn save_payout_data_to_locker(
|
pub async fn save_payout_data_to_locker(
|
||||||
state: &AppState,
|
state: &AppState,
|
||||||
payout_data: &PayoutData,
|
payout_data: &mut PayoutData,
|
||||||
payout_method_data: &api::PayoutMethodData,
|
payout_method_data: &api::PayoutMethodData,
|
||||||
merchant_account: &domain::MerchantAccount,
|
merchant_account: &domain::MerchantAccount,
|
||||||
key_store: &domain::MerchantKeyStore,
|
key_store: &domain::MerchantKeyStore,
|
||||||
@ -556,15 +557,16 @@ pub async fn save_payout_data_to_locker(
|
|||||||
let updated_payout = storage::PayoutsUpdate::PayoutMethodIdUpdate {
|
let updated_payout = storage::PayoutsUpdate::PayoutMethodIdUpdate {
|
||||||
payout_method_id: stored_resp.card_reference.to_owned(),
|
payout_method_id: stored_resp.card_reference.to_owned(),
|
||||||
};
|
};
|
||||||
db.update_payout(
|
payout_data.payouts = db
|
||||||
&payout_data.payouts,
|
.update_payout(
|
||||||
updated_payout,
|
&payout_data.payouts,
|
||||||
payout_attempt,
|
updated_payout,
|
||||||
merchant_account.storage_scheme,
|
payout_attempt,
|
||||||
)
|
merchant_account.storage_scheme,
|
||||||
.await
|
)
|
||||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
.await
|
||||||
.attach_printable("Error updating payouts in saved payout method")?;
|
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||||
|
.attach_printable("Error updating payouts in saved payout method")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user