refac: customer address db alter for gdpr compliance (#105)

This commit is contained in:
Manoj Ghorela
2022-12-12 00:19:33 +05:30
committed by GitHub
parent 585858ed6e
commit affa9fc35a
18 changed files with 76 additions and 60 deletions

View File

@ -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

View File

@ -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?;

View File

@ -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?;

View File

@ -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

View File

@ -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?;

View File

@ -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?;

View File

@ -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?;