Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
551e52f
feat: addition of billing_address_details in Payment Intent
prajjwalkumar17 Jun 24, 2024
69e23eb
feat: addition of billing_address_details in Payment Intent
prajjwalkumar17 Jun 24, 2024
73c29dd
chore: run formatter
hyperswitch-bot[bot] Jun 24, 2024
fb2371b
Merge branch 'main' into feat/business_address_in_payment_intent
prajjwalkumar17 Jun 24, 2024
e0bffab
chore: clippy corrections
prajjwalkumar17 Jun 24, 2024
60c5579
Merge branch 'feat/business_address_in_payment_intent' of https://git…
prajjwalkumar17 Jun 24, 2024
9a6f846
chore: run formatter
hyperswitch-bot[bot] Jun 24, 2024
6892f35
chore: clippy corrections
prajjwalkumar17 Jun 24, 2024
89cb79e
Merge branch 'feat/business_address_in_payment_intent' of https://git…
prajjwalkumar17 Jun 24, 2024
801c8e6
chore: using Address struct instead of BusinessDetails
prajjwalkumar17 Jun 24, 2024
19000a5
chore: run formatter
hyperswitch-bot[bot] Jun 24, 2024
144f5c6
chore: replacing null constructor with default implemetation
prajjwalkumar17 Jun 24, 2024
c6f9ad2
chore: minor code beautifications
prajjwalkumar17 Jun 25, 2024
5fb6287
chore: run formatter
hyperswitch-bot[bot] Jun 25, 2024
6974c11
chore: merge main
prajjwalkumar17 Jun 29, 2024
4e0a13e
chore: code beautification
prajjwalkumar17 Jun 30, 2024
17305b2
chore: run formatter
hyperswitch-bot[bot] Jun 30, 2024
c3fc514
chore: addressing comments
prajjwalkumar17 Jul 1, 2024
417469c
chore: run formatter
hyperswitch-bot[bot] Jul 1, 2024
af27990
chore: addition of billing address in payment_confirm and update flows
prajjwalkumar17 Jul 4, 2024
fa76433
chore: run formatter
hyperswitch-bot[bot] Jul 4, 2024
df7bff1
chore: addressal of comments
prajjwalkumar17 Jul 5, 2024
1e874d7
chore: merge conflicts
prajjwalkumar17 Jul 5, 2024
e54fe58
chore: schema changes
prajjwalkumar17 Jul 5, 2024
0c7ac06
chore: spell checks addressed of some old change
prajjwalkumar17 Jul 5, 2024
b49b186
chore: renamed the col to billing_details
prajjwalkumar17 Jul 5, 2024
b5ecb0c
chore: run formatter
hyperswitch-bot[bot] Jul 5, 2024
ba888ba
Merge branch 'main' into feat/business_address_in_payment_intent
prajjwalkumar17 Jul 5, 2024
cfcad51
chore: clippy lints fixed
prajjwalkumar17 Jul 5, 2024
38319c8
chore: run formatter
hyperswitch-bot[bot] Jul 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2933,7 +2933,9 @@ impl Address {

// used by customers also, could be moved outside
/// Address details
#[derive(Clone, Default, Debug, Eq, serde::Deserialize, serde::Serialize, PartialEq, ToSchema)]
#[derive(
Clone, Default, Debug, Eq, serde::Deserialize, serde::Serialize, Setter, PartialEq, ToSchema,
)]
#[serde(deny_unknown_fields)]
pub struct AddressDetails {
/// The address city
Expand Down
8 changes: 8 additions & 0 deletions crates/diesel_models/src/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub struct PaymentIntent {
pub request_external_three_ds_authentication: Option<bool>,
pub charges: Option<pii::SecretSerdeValue>,
pub frm_metadata: Option<pii::SecretSerdeValue>,
pub billing_address_details: Option<Encryption>,
pub customer_details: Option<Encryption>,
}

Expand Down Expand Up @@ -115,6 +116,7 @@ pub struct PaymentIntentNew {
pub request_external_three_ds_authentication: Option<bool>,
pub charges: Option<pii::SecretSerdeValue>,
pub frm_metadata: Option<pii::SecretSerdeValue>,
pub billing_address_details: Option<Encryption>,
pub customer_details: Option<Encryption>,
}

Expand Down Expand Up @@ -175,6 +177,7 @@ pub enum PaymentIntentUpdate {
request_external_three_ds_authentication: Option<bool>,
frm_metadata: Option<pii::SecretSerdeValue>,
customer_details: Option<Encryption>,
billing_address_details: Option<Encryption>,
},
PaymentAttemptAndAttemptCountUpdate {
active_attempt_id: String,
Expand Down Expand Up @@ -250,6 +253,7 @@ pub struct PaymentIntentUpdateInternal {
pub fingerprint_id: Option<String>,
pub request_external_three_ds_authentication: Option<bool>,
pub frm_metadata: Option<pii::SecretSerdeValue>,
pub billing_address_details: Option<Encryption>,
pub customer_details: Option<Encryption>,
}

Expand Down Expand Up @@ -286,6 +290,7 @@ impl PaymentIntentUpdate {
fingerprint_id,
request_external_three_ds_authentication,
frm_metadata,
billing_address_details,
customer_details,
} = self.into();
PaymentIntent {
Expand Down Expand Up @@ -324,6 +329,7 @@ impl PaymentIntentUpdate {
request_external_three_ds_authentication: request_external_three_ds_authentication
.or(source.request_external_three_ds_authentication),
frm_metadata: frm_metadata.or(source.frm_metadata),
billing_address_details: billing_address_details.or(source.billing_address_details),
customer_details: customer_details.or(source.customer_details),
..source
}
Expand Down Expand Up @@ -356,6 +362,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
request_external_three_ds_authentication,
frm_metadata,
customer_details,
billing_address_details,
} => Self {
amount: Some(amount),
currency: Some(currency),
Expand All @@ -380,6 +387,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
request_external_three_ds_authentication,
frm_metadata,
customer_details,
billing_address_details,
..Default::default()
},
PaymentIntentUpdate::MetadataUpdate {
Expand Down
1 change: 1 addition & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@ diesel::table! {
charges -> Nullable<Jsonb>,
frm_metadata -> Nullable<Jsonb>,
customer_details -> Nullable<Bytea>,
billing_address_details -> Nullable<Bytea>,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/hyperswitch_domain_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ pub struct PaymentIntent {
pub request_external_three_ds_authentication: Option<bool>,
pub charges: Option<pii::SecretSerdeValue>,
pub frm_metadata: Option<pii::SecretSerdeValue>,
pub billing_address_details: Option<Encryptable<Secret<serde_json::Value>>>,
pub customer_details: Option<Encryptable<Secret<serde_json::Value>>>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ impl behaviour::Conversion for PaymentIntent {
request_external_three_ds_authentication: self.request_external_three_ds_authentication,
charges: self.charges,
frm_metadata: self.frm_metadata,
billing_address_details: self.billing_address_details.map(Encryption::from),
customer_details: self.customer_details.map(Encryption::from),
})
}
Expand Down Expand Up @@ -587,6 +588,10 @@ impl behaviour::Conversion for PaymentIntent {
.request_external_three_ds_authentication,
charges: storage_model.charges,
frm_metadata: storage_model.frm_metadata,
billing_address_details: storage_model
.billing_address_details
.async_lift(inner_decrypt)
.await?,
customer_details: storage_model
.customer_details
.async_lift(inner_decrypt)
Expand Down Expand Up @@ -644,6 +649,7 @@ impl behaviour::Conversion for PaymentIntent {
request_external_three_ds_authentication: self.request_external_three_ds_authentication,
charges: self.charges,
frm_metadata: self.frm_metadata,
billing_address_details: self.billing_address_details.map(Encryption::from),
customer_details: self.customer_details.map(Encryption::from),
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ pub struct PaymentIntentNew {
pub session_expiry: Option<PrimitiveDateTime>,
pub request_external_three_ds_authentication: Option<bool>,
pub charges: Option<pii::SecretSerdeValue>,
pub billing_address_details: Option<Encryptable<Secret<serde_json::Value>>>,
pub customer_details: Option<Encryptable<Secret<serde_json::Value>>>,
}

Expand Down Expand Up @@ -193,6 +194,7 @@ pub enum PaymentIntentUpdate {
session_expiry: Option<PrimitiveDateTime>,
request_external_three_ds_authentication: Option<bool>,
customer_details: Option<Encryptable<Secret<serde_json::Value>>>,
billing_address_details: Option<Encryptable<Secret<serde_json::Value>>>,
},
PaymentAttemptAndAttemptCountUpdate {
active_attempt_id: String,
Expand Down Expand Up @@ -269,6 +271,7 @@ pub struct PaymentIntentUpdateInternal {
pub session_expiry: Option<PrimitiveDateTime>,
pub request_external_three_ds_authentication: Option<bool>,
pub frm_metadata: Option<pii::SecretSerdeValue>,
pub billing_address_details: Option<Encryptable<Secret<serde_json::Value>>>,
pub customer_details: Option<Encryptable<Secret<serde_json::Value>>>,
}

Expand Down Expand Up @@ -298,6 +301,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
request_external_three_ds_authentication,
frm_metadata,
customer_details,
billing_address_details,
} => Self {
amount: Some(amount),
currency: Some(currency),
Expand All @@ -322,6 +326,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
request_external_three_ds_authentication,
frm_metadata,
customer_details,
billing_address_details,
..Default::default()
},
PaymentIntentUpdate::MetadataUpdate {
Expand Down Expand Up @@ -562,6 +567,7 @@ impl From<PaymentIntentUpdate> for DieselPaymentIntentUpdate {
request_external_three_ds_authentication,
frm_metadata,
customer_details,
billing_address_details,
} => Self::Update {
amount,
currency,
Expand All @@ -585,6 +591,7 @@ impl From<PaymentIntentUpdate> for DieselPaymentIntentUpdate {
request_external_three_ds_authentication,
frm_metadata,
customer_details: customer_details.map(Encryption::from),
billing_address_details: billing_address_details.map(Encryption::from),
},
PaymentIntentUpdate::PaymentAttemptAndAttemptCountUpdate {
active_attempt_id,
Expand Down Expand Up @@ -686,6 +693,7 @@ impl From<PaymentIntentUpdateInternal> for diesel_models::PaymentIntentUpdateInt
fingerprint_id,
request_external_three_ds_authentication,
frm_metadata,
billing_address_details,
customer_details,
} = value;

Expand Down Expand Up @@ -720,6 +728,7 @@ impl From<PaymentIntentUpdateInternal> for diesel_models::PaymentIntentUpdateInt
fingerprint_id,
request_external_three_ds_authentication,
frm_metadata,
billing_address_details: billing_address_details.map(Encryption::from),
customer_details: customer_details.map(Encryption::from),
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3121,6 +3121,7 @@ mod tests {
request_external_three_ds_authentication: None,
charges: None,
frm_metadata: None,
billing_address_details: None,
customer_details: None,
};
let req_cs = Some("1".to_string());
Expand Down Expand Up @@ -3181,6 +3182,7 @@ mod tests {
request_external_three_ds_authentication: None,
charges: None,
frm_metadata: None,
billing_address_details: None,
customer_details: None,
};
let req_cs = Some("1".to_string());
Expand Down Expand Up @@ -3240,6 +3242,7 @@ mod tests {
request_external_three_ds_authentication: None,
charges: None,
frm_metadata: None,
billing_address_details: None,
customer_details: None,
};
let req_cs = Some("1".to_string());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::{
blocklist::utils as blocklist_utils,
errors::{self, CustomResult, RouterResult, StorageErrorExt},
mandate::helpers as m_helpers,
payment_methods::cards::create_encrypted_data,
payments::{
self, helpers, operations, populate_surcharge_details, CustomerDetails, PaymentAddress,
PaymentData,
Expand Down Expand Up @@ -1213,6 +1214,9 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
.in_current_span(),
);

let billing_address = payment_data.address.get_payment_billing();
let billing_address_details =
async { create_encrypted_data(key_store, billing_address).await }.await;
let m_payment_data_payment_intent = payment_data.payment_intent.clone();
let m_customer_id = customer_id.clone();
let m_shipping_address_id = shipping_address_id.clone();
Expand Down Expand Up @@ -1257,6 +1261,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
request_external_three_ds_authentication: None,
frm_metadata: m_frm_metadata,
customer_details,
billing_address_details,
},
&m_key_store,
storage_scheme,
Expand Down
15 changes: 15 additions & 0 deletions crates/router/src/core/payments/operations/payment_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,20 @@ impl PaymentCreate {
.change_context(errors::ApiErrorResponse::InternalServerError)?
.map(Secret::new);

// Derivation of directly supplied Billing Address data in our Payment Create Request
let raw_billing_address_details = request
.billing
.clone()
.and_then(|billing_details| billing_details.address.clone());

// Encrypting our Billing Address Details to be stored in Payment Intent
let billing_address_details = raw_billing_address_details
.clone()
.async_and_then(|_| async {
create_encrypted_data(key_store, raw_billing_address_details.clone()).await
})
.await;

// Derivation of directly supplied Customer data in our Payment Create Request
let raw_customer_details = if request.customer_id.is_none()
&& (request.name.is_some()
Expand Down Expand Up @@ -1114,6 +1128,7 @@ impl PaymentCreate {
.request_external_three_ds_authentication,
charges,
frm_metadata: request.frm_metadata.clone(),
billing_address_details,
customer_details,
})
}
Expand Down
10 changes: 10 additions & 0 deletions crates/router/src/core/payments/operations/payment_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{
core::{
errors::{self, CustomResult, RouterResult, StorageErrorExt},
mandate::helpers as m_helpers,
payment_methods::cards::create_encrypted_data,
payments::{self, helpers, operations, CustomerDetails, PaymentAddress, PaymentData},
utils as core_utils,
},
Expand Down Expand Up @@ -217,6 +218,13 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
)
.await?;

payment_intent.billing_address_details = billing_address
.clone()
.async_and_then(|_| async {
create_encrypted_data(key_store, billing_address.clone()).await
})
.await;

let payment_method_billing = helpers::create_or_update_address_for_payment_by_request(
db,
request
Expand Down Expand Up @@ -704,6 +712,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
let metadata = payment_data.payment_intent.metadata.clone();
let frm_metadata = payment_data.payment_intent.frm_metadata.clone();
let session_expiry = payment_data.payment_intent.session_expiry;
let billing_address_details = payment_data.payment_intent.billing_address_details.clone();
payment_data.payment_intent = state
.store
.update_payment_intent(
Expand Down Expand Up @@ -733,6 +742,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
.request_external_three_ds_authentication,
frm_metadata,
customer_details,
billing_address_details,
},
key_store,
storage_scheme,
Expand Down
5 changes: 4 additions & 1 deletion crates/router/src/services/kafka/payment_intent.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use common_utils::{id_type, types::MinorUnit};
use common_utils::{crypto::Encryptable, id_type, types::MinorUnit};
use diesel_models::enums as storage_enums;
use hyperswitch_domain_models::payments::PaymentIntent;
use masking::Secret;
use time::OffsetDateTime;

#[derive(serde::Serialize, Debug)]
Expand Down Expand Up @@ -31,6 +32,7 @@ pub struct KafkaPaymentIntent<'a> {
pub business_label: Option<&'a String>,
pub attempt_count: i16,
pub payment_confirm_source: Option<storage_enums::PaymentSource>,
pub billing_address_details: Option<Encryptable<Secret<serde_json::Value>>>,
}

impl<'a> KafkaPaymentIntent<'a> {
Expand Down Expand Up @@ -59,6 +61,7 @@ impl<'a> KafkaPaymentIntent<'a> {
business_label: intent.business_label.as_ref(),
attempt_count: intent.attempt_count,
payment_confirm_source: intent.payment_confirm_source,
billing_address_details: intent.billing_address_details.clone(),
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion crates/router/src/services/kafka/payment_intent_event.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use common_utils::{id_type, types::MinorUnit};
use common_utils::{crypto::Encryptable, id_type, types::MinorUnit};
use diesel_models::enums as storage_enums;
use hyperswitch_domain_models::payments::PaymentIntent;
use masking::Secret;
use time::OffsetDateTime;

#[serde_with::skip_serializing_none]
Expand Down Expand Up @@ -32,6 +33,7 @@ pub struct KafkaPaymentIntentEvent<'a> {
pub business_label: Option<&'a String>,
pub attempt_count: i16,
pub payment_confirm_source: Option<storage_enums::PaymentSource>,
pub billing_address_details: Option<Encryptable<Secret<serde_json::Value>>>,
}

impl<'a> KafkaPaymentIntentEvent<'a> {
Expand Down Expand Up @@ -60,6 +62,7 @@ impl<'a> KafkaPaymentIntentEvent<'a> {
business_label: intent.business_label.as_ref(),
attempt_count: intent.attempt_count,
payment_confirm_source: intent.payment_confirm_source,
billing_address_details: intent.billing_address_details.clone(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/utils/user/sample_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ pub async fn generate_sample_data(
request_external_three_ds_authentication: None,
charges: None,
frm_metadata: Default::default(),
billing_address_details: None,
customer_details: None,
};
let payment_attempt = PaymentAttemptBatchNew {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
ALTER TABLE payment_intent DROP COLUMN IF EXISTS billing_address_details;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Your SQL goes here
ALTER TABLE payment_intent ADD COLUMN IF NOT EXISTS billing_address_details BYTEA DEFAULT NULL;