Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Chikke Srujan authored and Chikke Srujan committed Nov 12, 2024
1 parent 465aea0 commit f239f59
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 76 deletions.
7 changes: 3 additions & 4 deletions crates/hyperswitch_connectors/src/connectors/fiuu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,10 +898,9 @@ impl webhooks::IncomingWebhook for Fiuu {
Option<hyperswitch_domain_models::router_flow_types::ConnectorMandateDetails>,
errors::ConnectorError,
> {
let webhook_payment_response: transformers::FiuuWebhooksPaymentResponse = request
.body
.parse_struct("fiuu::FiuuWebhooksPaymentResponse")
.change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;
let webhook_payment_response: transformers::FiuuWebhooksPaymentResponse =
serde_urlencoded::from_bytes::<transformers::FiuuWebhooksPaymentResponse>(request.body)
.change_context(errors::ConnectorError::WebhookResourceObjectNotFound)?;
let mandate_reference = webhook_payment_response.extra_parameters.as_ref().and_then(|extra_p| {
let mandate_token: Result<ExtraParameters, _> = serde_json::from_str(extra_p);
match mandate_token {
Expand Down
138 changes: 66 additions & 72 deletions crates/router/src/core/webhooks/incoming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1790,81 +1790,75 @@ async fn update_connector_mandate_details(
.clone()
.get_required_value("merchant_connector_id")?;

if let Some(ref mandate_detail) = mandate_details {
if !mandate_detail
.0
.contains_key(&merchant_connector_account_id)
{
let updated_connector_mandate_details = insert_mandate_details(
&payment_attempt,
&webhook_mandate_details,
mandate_details,
)?;

let pm_update =
diesel_models::PaymentMethodUpdate::ConnectorMandateDetailsUpdate {
connector_mandate_details: updated_connector_mandate_details,
};
if mandate_details
.as_ref()
.map(|details: &diesel_models::PaymentsMandateReference| !details.0.contains_key(&merchant_connector_account_id))
.unwrap_or(true)
{
let updated_connector_mandate_details = insert_mandate_details(
&payment_attempt,
&webhook_mandate_details,
mandate_details,
)?;
let pm_update = diesel_models::PaymentMethodUpdate::ConnectorMandateDetailsUpdate {
connector_mandate_details: updated_connector_mandate_details,
};

state
.store
.update_payment_method(
key_manager_state,
key_store,
payment_method_info,
pm_update,
merchant_account.storage_scheme,
state
.store
.update_payment_method(
key_manager_state,
key_store,
payment_method_info,
pm_update,
merchant_account.storage_scheme,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to update payment method in db")?;
// Update the payment attempt to maintain consistency across tables.

let (mandate_metadata, connector_mandate_request_reference_id) = payment_attempt
.connector_mandate_detail
.as_ref()
.map(|details| {
(
details.mandate_metadata.clone(),
details.connector_mandate_request_reference_id.clone(),
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to update payment method in db")?;

// Update the payment attempt to maintain consistency across tables.

let (mandate_metadata, connector_mandate_request_reference_id) =
payment_attempt
.connector_mandate_detail
.as_ref()
.map(|details| {
(
details.mandate_metadata.clone(),
details.connector_mandate_request_reference_id.clone(),
)
})
.unwrap_or((None, None));

let connector_mandate_reference_id = ConnectorMandateReferenceId {
connector_mandate_id: Some(
webhook_mandate_details
.connector_mandate_id
.peek()
.to_string(),
),
payment_method_id: Some(payment_method_id.to_string()),
mandate_metadata,
connector_mandate_request_reference_id,
};

let attempt_update =
storage::PaymentAttemptUpdate::ConnectorMandateDetailUpdate {
connector_mandate_detail: Some(connector_mandate_reference_id),
updated_by: merchant_account.storage_scheme.to_string(),
};
})
.unwrap_or((None, None));

let connector_mandate_reference_id = ConnectorMandateReferenceId {
connector_mandate_id: Some(
webhook_mandate_details
.connector_mandate_id
.peek()
.to_string(),
),
payment_method_id: Some(payment_method_id.to_string()),
mandate_metadata,
connector_mandate_request_reference_id,
};

state
.store
.update_payment_attempt_with_attempt_id(
payment_attempt.clone(),
attempt_update,
merchant_account.storage_scheme,
)
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
} else {
logger::info!(
"Skipping connector mandate details update since they are already present."
);
}
let attempt_update = storage::PaymentAttemptUpdate::ConnectorMandateDetailUpdate {
connector_mandate_detail: Some(connector_mandate_reference_id),
updated_by: merchant_account.storage_scheme.to_string(),
};

state
.store
.update_payment_attempt_with_attempt_id(
payment_attempt.clone(),
attempt_update,
merchant_account.storage_scheme,
)
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
} else {
logger::info!(
"Skipping connector mandate details update since they are already present."
);
}
}
}
Expand Down

0 comments on commit f239f59

Please sign in to comment.