Skip to content

Commit

Permalink
refactor(router): use the saved billing details in the recurring paym…
Browse files Browse the repository at this point in the history
…ents (#5631)
  • Loading branch information
ShankarSinghC authored Aug 14, 2024
1 parent 56791c2 commit 5fa7b14
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
24 changes: 24 additions & 0 deletions crates/hyperswitch_domain_models/src/payment_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl PaymentAddress {
}

/// Unify the billing details from `payment_method_data.[payment_method_data].billing details`.
/// Here the fields passed in payment_method_data_billing takes precedence
pub fn unify_with_payment_method_data_billing(
self,
payment_method_data_billing: Option<Address>,
Expand All @@ -72,6 +73,29 @@ impl PaymentAddress {
}
}

/// Unify the billing details from `payment_method_data.[payment_method_data].billing details`.
/// Here the `self` takes precedence
pub fn unify_with_payment_data_billing(
self,
other_payment_method_billing: Option<Address>,
) -> Self {
let unified_payment_method_billing = self
.get_payment_method_billing()
.map(|payment_method_billing| {
payment_method_billing
.clone()
.unify_address(other_payment_method_billing.as_ref())
})
.or(other_payment_method_billing);

Self {
shipping: self.shipping,
billing: self.billing,
unified_payment_method_billing,
payment_method_billing: self.payment_method_billing,
}
}

pub fn get_request_payment_method_billing(&self) -> Option<&Address> {
self.payment_method_billing.as_ref()
}
Expand Down
24 changes: 22 additions & 2 deletions crates/router/src/core/payments/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub async fn construct_payment_router_data<'a, F, T>(
payment_data: PaymentData<F>,
connector_id: &str,
merchant_account: &domain::MerchantAccount,
_key_store: &domain::MerchantKeyStore,
key_store: &domain::MerchantKeyStore,
customer: &'a Option<domain::Customer>,
merchant_connector_account: &helpers::MerchantConnectorAccountType,
merchant_recipient_data: Option<types::MerchantRecipientData>,
Expand Down Expand Up @@ -135,6 +135,26 @@ where
Some(merchant_connector_account),
);

let unified_address =
if let Some(payment_method_info) = payment_data.payment_method_info.clone() {
let payment_method_billing =
crate::core::payment_methods::cards::decrypt_generic_data::<Address>(
state,
payment_method_info.payment_method_billing_address,
key_store,
)
.await
.attach_printable("unable to decrypt payment method billing address details")?;
payment_data
.address
.clone()
.unify_with_payment_data_billing(payment_method_billing)
} else {
payment_data.address
};

crate::logger::debug!("unified address details {:?}", unified_address);

router_data = types::RouterData {
flow: PhantomData,
merchant_id: merchant_account.get_id().clone(),
Expand All @@ -147,7 +167,7 @@ where
connector_auth_type: auth_type,
description: payment_data.payment_intent.description.clone(),
return_url: payment_data.payment_intent.return_url.clone(),
address: payment_data.address.clone(),
address: unified_address,
auth_type: payment_data
.payment_attempt
.authentication_type
Expand Down

0 comments on commit 5fa7b14

Please sign in to comment.