Skip to content

Commit

Permalink
core-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
awasthi21 committed Oct 29, 2024
1 parent 6feba97 commit b21ccbe
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 60 deletions.
28 changes: 14 additions & 14 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1346,20 +1346,20 @@ impl ConnectorMandateReferenceId {
self.connector_mandate_request_reference_id.clone()
}

pub fn set_connector_mandate_id(&mut self, value: Option<String>) {
self.connector_mandate_id = value;
}

pub fn set_payment_method_id(&mut self, value: Option<String>) {
self.payment_method_id = value;
}

pub fn set_mandate_metadata(&mut self, value: Option<serde_json::Value>) {
self.mandate_metadata = value;
}

pub fn set_connector_mandate_request_reference_id(&mut self, value: Option<String>) {
self.connector_mandate_request_reference_id = value;
pub fn update(
&mut self,
connector_mandate_id: Option<String>,
payment_method_id: Option<String>,
update_history: Option<Vec<UpdateHistory>>,
mandate_metadata: Option<serde_json::Value>,
connector_mandate_request_reference_id: Option<String>,
) {
self.connector_mandate_id = connector_mandate_id.or(self.connector_mandate_id.clone());
self.payment_method_id = payment_method_id.or(self.payment_method_id.clone());
self.update_history = update_history.or(self.update_history.clone());
self.mandate_metadata = mandate_metadata.or(self.mandate_metadata.clone());
self.connector_mandate_request_reference_id = connector_mandate_request_reference_id
.or(self.connector_mandate_request_reference_id.clone());
}
}
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Eq, PartialEq)]
Expand Down
1 change: 0 additions & 1 deletion crates/router/src/core/mandate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,5 +455,4 @@ pub trait MandateBehaviour {
&self,
) -> Option<&hyperswitch_domain_models::mandates::MandateData>;
fn get_customer_acceptance(&self) -> Option<payments::CustomerAcceptance>;
// fn get_connector_mandate_request_reference_id(&self) -> Option<String>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
connector_id.get_payment_method_id(),
None,
None,
None
connector_id.get_connector_mandate_request_reference_id(),
)
))
}
Expand Down
64 changes: 31 additions & 33 deletions crates/router/src/core/payments/operations/payment_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ impl<F: Send + Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsAuthor
.ok();
}
};
let connector_mandate_request_reference_id = payment_data
let connector_mandate_reference_id = payment_data
.payment_attempt
.connector_mandate_detail
.as_ref()
.and_then(|detail| detail.get_connector_mandate_request_reference_id());
.map(|detail| ConnectorMandateReferenceId::foreign_from(detail.clone()));
let save_payment_call_future = Box::pin(tokenization::save_payment_method(
state,
connector_name.clone(),
Expand All @@ -197,7 +197,7 @@ impl<F: Send + Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsAuthor
billing_name.clone(),
payment_method_billing_address,
business_profile,
connector_mandate_request_reference_id.clone(),
connector_mandate_reference_id.clone(),
));

let is_connector_mandate = resp.request.customer_acceptance.is_some()
Expand Down Expand Up @@ -312,7 +312,7 @@ impl<F: Send + Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsAuthor
billing_name,
payment_method_billing_address.as_ref(),
&business_profile,
connector_mandate_request_reference_id,
connector_mandate_reference_id,
))
.await;

Expand Down Expand Up @@ -599,15 +599,6 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsSyncData> for
})
.unwrap_or((None, None, None));

let original_connector_mandate_request_reference_id = payment_data
.payment_attempt
.connector_mandate_detail
.as_ref()
.and_then(|detail| detail.get_connector_mandate_request_reference_id());
// Reassign `connector_mandate_request_reference_id` to use fallback if necessary
let connector_mandate_request_reference_id = connector_mandate_request_reference_id
.or(original_connector_mandate_request_reference_id.clone());

update_connector_mandate_details_for_the_flow(
connector_mandate_id,
mandate_metadata,
Expand Down Expand Up @@ -1083,11 +1074,12 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::SetupMandateRequestDa
field_name: "connector_name",
}
})?;
let connector_mandate_request_reference_id = payment_data
let connector_mandate_reference_id = payment_data
.payment_attempt
.connector_mandate_detail
.as_ref()
.and_then(|detail| detail.get_connector_mandate_request_reference_id());
.map(|detail| ConnectorMandateReferenceId::foreign_from(detail.clone()));

let merchant_connector_id = payment_data.payment_attempt.merchant_connector_id.clone();
let tokenization::SavePaymentMethodDataResponse {
payment_method_id,
Expand All @@ -1104,7 +1096,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::SetupMandateRequestDa
billing_name,
payment_method_billing_address,
business_profile,
connector_mandate_request_reference_id,
connector_mandate_reference_id,
))
.await?;

Expand Down Expand Up @@ -1202,16 +1194,6 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::CompleteAuthorizeData
}
})
.unwrap_or((None, None, None));
let original_connector_mandate_request_reference_id = payment_data
.payment_attempt
.connector_mandate_detail
.as_ref()
.and_then(|detail| detail.get_connector_mandate_request_reference_id());

// Reassign `connector_mandate_request_reference_id` to use fallback if necessary
let connector_mandate_request_reference_id = connector_mandate_request_reference_id
.or(original_connector_mandate_request_reference_id.clone());

update_connector_mandate_details_for_the_flow(
connector_mandate_id,
mandate_metadata,
Expand Down Expand Up @@ -2329,14 +2311,30 @@ fn update_connector_mandate_details_for_the_flow<F: Clone>(
connector_mandate_request_reference_id: Option<String>,
payment_data: &mut PaymentData<F>,
) -> RouterResult<()> {
let mut original_connector_mandate_reference_id = payment_data
.payment_attempt
.connector_mandate_detail
.as_ref()
.map(|detail| ConnectorMandateReferenceId::foreign_from(detail.clone()));
let connector_mandate_reference_id = if connector_mandate_id.is_some() {
Some(ConnectorMandateReferenceId::new(
connector_mandate_id.clone(),
None,
None,
mandate_metadata,
connector_mandate_request_reference_id,
))
if let Some(ref mut record) = original_connector_mandate_reference_id {
record.update(
connector_mandate_id,
None,
None,
mandate_metadata,
connector_mandate_request_reference_id,
);
Some(record.clone())
} else {
Some(ConnectorMandateReferenceId::new(
connector_mandate_id,
None,
None,
mandate_metadata,
connector_mandate_request_reference_id,
))
}
} else {
None
};
Expand Down
30 changes: 19 additions & 11 deletions crates/router/src/core/payments/tokenization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub async fn save_payment_method<FData>(
billing_name: Option<Secret<String>>,
payment_method_billing_address: Option<&api::Address>,
business_profile: &domain::Profile,
original_connector_mandate_request_reference_id: Option<String>,
mut original_connector_mandate_reference_id: Option<ConnectorMandateReferenceId>,
) -> RouterResult<SavePaymentMethodDataResponse>
where
FData: mandate::MandateBehaviour + Clone,
Expand Down Expand Up @@ -173,9 +173,6 @@ where
}
_ => (None, None, None),
};
// Reassign `connector_mandate_request_reference_id` to use fallback if necessary
let connector_mandate_request_reference_id = connector_mandate_request_reference_id
.or(original_connector_mandate_request_reference_id.clone());

let pm_id = if customer_acceptance.is_some() {
let payment_method_create_request =
Expand Down Expand Up @@ -695,13 +692,24 @@ where
};
// check if there needs to be a config if yes then remove it to a different place
let connector_mandate_reference_id = if connector_mandate_id.is_some() {
Some(ConnectorMandateReferenceId::new(
connector_mandate_id.clone(),
None,
None,
mandate_metadata.clone(),
connector_mandate_request_reference_id.clone(),
))
if let Some(ref mut record) = original_connector_mandate_reference_id {
record.update(
connector_mandate_id,
None,
None,
mandate_metadata,
connector_mandate_request_reference_id,
);
Some(record.clone())
} else {
Some(ConnectorMandateReferenceId::new(
connector_mandate_id,
None,
None,
mandate_metadata,
connector_mandate_request_reference_id,
))
}
} else {
None
};
Expand Down

0 comments on commit b21ccbe

Please sign in to comment.