mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 05:17:02 +08:00
refac: customer address db alter for gdpr compliance (#105)
This commit is contained in:
@ -36,6 +36,8 @@ pub async fn get_address_for_payment_request(
|
||||
db: &dyn StorageInterface,
|
||||
req_address: Option<&api::Address>,
|
||||
address_id: Option<&str>,
|
||||
merchant_id: &str,
|
||||
customer_id: &Option<String>,
|
||||
) -> CustomResult<Option<storage::Address>, errors::ApiErrorResponse> {
|
||||
// TODO: Refactor this function for more readability (TryFrom)
|
||||
Ok(match req_address {
|
||||
@ -50,6 +52,10 @@ pub async fn get_address_for_payment_request(
|
||||
),
|
||||
None => {
|
||||
// generate a new address here
|
||||
let customer_id = customer_id
|
||||
.as_deref()
|
||||
.get_required_value("customer_id")
|
||||
.change_context(errors::ApiErrorResponse::CustomerNotFound)?;
|
||||
Some(
|
||||
db.insert_address(storage::AddressNew {
|
||||
city: address.address.as_ref().and_then(|a| a.city.clone()),
|
||||
@ -66,6 +72,8 @@ pub async fn get_address_for_payment_request(
|
||||
.phone
|
||||
.as_ref()
|
||||
.and_then(|a| a.country_code.clone()),
|
||||
customer_id: customer_id.to_string(),
|
||||
merchant_id: merchant_id.to_string(),
|
||||
..storage::AddressNew::default()
|
||||
})
|
||||
.await
|
||||
|
||||
@ -101,6 +101,8 @@ impl<F: Send + Clone> GetTracker<F, payments::PaymentData<F>, api::PaymentsCaptu
|
||||
db,
|
||||
None,
|
||||
payment_intent.shipping_address_id.as_deref(),
|
||||
merchant_id,
|
||||
&payment_intent.customer_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@ -108,6 +110,8 @@ impl<F: Send + Clone> GetTracker<F, payments::PaymentData<F>, api::PaymentsCaptu
|
||||
db,
|
||||
None,
|
||||
payment_intent.billing_address_id.as_deref(),
|
||||
merchant_id,
|
||||
&payment_intent.customer_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
@ -109,12 +109,16 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
|
||||
db,
|
||||
request.shipping.as_ref(),
|
||||
payment_intent.shipping_address_id.as_deref(),
|
||||
merchant_id,
|
||||
&payment_intent.customer_id,
|
||||
)
|
||||
.await?;
|
||||
let billing_address = helpers::get_address_for_payment_request(
|
||||
db,
|
||||
request.billing.as_ref(),
|
||||
payment_intent.billing_address_id.as_deref(),
|
||||
merchant_id,
|
||||
&payment_intent.customer_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
@ -61,11 +61,23 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
|
||||
helpers::get_token_pm_type_mandate_details(state, request, mandate_type, merchant_id)
|
||||
.await?;
|
||||
|
||||
let shipping_address =
|
||||
helpers::get_address_for_payment_request(db, request.shipping.as_ref(), None).await?;
|
||||
let shipping_address = helpers::get_address_for_payment_request(
|
||||
db,
|
||||
request.shipping.as_ref(),
|
||||
None,
|
||||
merchant_id,
|
||||
&request.customer_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let billing_address =
|
||||
helpers::get_address_for_payment_request(db, request.billing.as_ref(), None).await?;
|
||||
let billing_address = helpers::get_address_for_payment_request(
|
||||
db,
|
||||
request.billing.as_ref(),
|
||||
None,
|
||||
merchant_id,
|
||||
&request.customer_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let browser_info = request
|
||||
.browser_info
|
||||
|
||||
@ -82,6 +82,8 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsSessionRequest>
|
||||
db,
|
||||
None,
|
||||
payment_intent.shipping_address_id.as_deref(),
|
||||
merchant_id,
|
||||
&payment_intent.customer_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@ -89,6 +91,8 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsSessionRequest>
|
||||
db,
|
||||
None,
|
||||
payment_intent.billing_address_id.as_deref(),
|
||||
merchant_id,
|
||||
&payment_intent.customer_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
@ -72,12 +72,16 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsStartRequest> f
|
||||
db,
|
||||
None,
|
||||
payment_intent.shipping_address_id.as_deref(),
|
||||
merchant_id,
|
||||
&payment_intent.customer_id,
|
||||
)
|
||||
.await?;
|
||||
let billing_address = helpers::get_address_for_payment_request(
|
||||
db,
|
||||
None,
|
||||
payment_intent.billing_address_id.as_deref(),
|
||||
merchant_id,
|
||||
&payment_intent.customer_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
@ -96,12 +96,16 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
|
||||
db,
|
||||
request.shipping.as_ref(),
|
||||
payment_intent.shipping_address_id.as_deref(),
|
||||
merchant_id,
|
||||
&payment_intent.customer_id,
|
||||
)
|
||||
.await?;
|
||||
let billing_address = helpers::get_address_for_payment_request(
|
||||
db,
|
||||
request.billing.as_ref(),
|
||||
payment_intent.billing_address_id.as_deref(),
|
||||
merchant_id,
|
||||
&payment_intent.customer_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user