Skip to content

Commit

Permalink
refactor(dynamic_fields): populate billing.email with customer emai…
Browse files Browse the repository at this point in the history
…l if not present (#5962)
  • Loading branch information
Narayanbhat166 authored Sep 19, 2024
1 parent 156a161 commit f4fa4cd
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion crates/router/src/types/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1459,10 +1459,38 @@ impl
.change_context(errors::ApiErrorResponse::InvalidDataValue {
field_name: "customer_details",
})?;

let mut billing_address = billing.map(api_types::Address::from);

// This change is to fix a merchant integration
// If billing.email is not passed by the merchant, and if the customer email is present, then use the `customer.email` as the billing email
if let Some(billing_address) = &mut billing_address {
billing_address.email = billing_address.email.clone().or_else(|| {
customer
.and_then(|cust| {
cust.email
.as_ref()
.map(|email| pii::Email::from(email.clone()))
})
.or(customer_details_from_pi.clone().and_then(|cd| cd.email))
});
} else {
billing_address = Some(payments::Address {
email: customer
.and_then(|cust| {
cust.email
.as_ref()
.map(|email| pii::Email::from(email.clone()))
})
.or(customer_details_from_pi.clone().and_then(|cd| cd.email)),
..Default::default()
});
}

Ok(Self {
currency: payment_attempt.map(|pa| pa.currency.unwrap_or_default()),
shipping: shipping.map(api_types::Address::from),
billing: billing.map(api_types::Address::from),
billing: billing_address,
amount: payment_attempt.map(|pa| api_types::Amount::from(pa.amount)),
email: customer
.and_then(|cust| cust.email.as_ref().map(|em| pii::Email::from(em.clone())))
Expand Down

0 comments on commit f4fa4cd

Please sign in to comment.