fix(customer): populate email from customer table if not present in request (#692)

This commit is contained in:
Nishant Joshi
2023-02-28 22:54:27 +05:30
committed by GitHub
parent f12abbcef4
commit cf71d7aa3b
2 changed files with 14 additions and 3 deletions

View File

@ -584,16 +584,23 @@ pub(crate) async fn call_payment_method(
}
}
pub async fn get_customer_from_details(
pub async fn get_customer_from_details<F: Clone>(
db: &dyn StorageInterface,
customer_id: Option<String>,
merchant_id: &str,
payment_data: &mut PaymentData<F>,
) -> CustomResult<Option<storage::Customer>, errors::StorageError> {
match customer_id {
None => Ok(None),
Some(c_id) => {
db.find_customer_optional_by_customer_id_merchant_id(&c_id, merchant_id)
.await
let customer = db
.find_customer_optional_by_customer_id_merchant_id(&c_id, merchant_id)
.await?;
payment_data.email = payment_data
.email
.clone()
.or(customer.as_ref().and_then(|inner| inner.email.clone()));
Ok(customer)
}
}
}
@ -663,6 +670,7 @@ pub async fn create_customer_if_not_exist<'a, F: Clone, R>(
let customer = customer?;
payment_data.payment_intent.customer_id = Some(customer.customer_id.clone());
payment_data.email = payment_data.email.clone().or(customer.email.clone());
Some(customer)
}

View File

@ -183,6 +183,7 @@ where
db,
payment_data.payment_intent.customer_id.clone(),
merchant_id,
payment_data,
)
.await?,
))
@ -238,6 +239,7 @@ where
db,
payment_data.payment_intent.customer_id.clone(),
merchant_id,
payment_data,
)
.await?,
))
@ -292,6 +294,7 @@ where
db,
payment_data.payment_intent.customer_id.clone(),
merchant_id,
payment_data,
)
.await?,
))