Skip to content

Commit

Permalink
feat(core): billing_details inclusion in Payment Intent (#5090)
Browse files Browse the repository at this point in the history
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
prajjwalkumar17 and hyperswitch-bot[bot] authored Jul 5, 2024
1 parent c642d9d commit ec01788
Show file tree
Hide file tree
Showing 42 changed files with 212 additions and 144 deletions.
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 @@ -60,6 +60,7 @@ pub struct PaymentIntent {
pub charges: Option<pii::SecretSerdeValue>,
pub frm_metadata: Option<pii::SecretSerdeValue>,
pub customer_details: Option<Encryption>,
pub billing_details: Option<Encryption>,
pub merchant_order_reference_id: Option<String>,
}

Expand Down Expand Up @@ -117,6 +118,7 @@ pub struct PaymentIntentNew {
pub charges: Option<pii::SecretSerdeValue>,
pub frm_metadata: Option<pii::SecretSerdeValue>,
pub customer_details: Option<Encryption>,
pub billing_details: Option<Encryption>,
pub merchant_order_reference_id: Option<String>,
}

Expand Down Expand Up @@ -177,6 +179,7 @@ pub enum PaymentIntentUpdate {
request_external_three_ds_authentication: Option<bool>,
frm_metadata: Option<pii::SecretSerdeValue>,
customer_details: Option<Encryption>,
billing_details: Option<Encryption>,
merchant_order_reference_id: Option<String>,
},
PaymentAttemptAndAttemptCountUpdate {
Expand Down Expand Up @@ -254,6 +257,7 @@ pub struct PaymentIntentUpdateInternal {
pub request_external_three_ds_authentication: Option<bool>,
pub frm_metadata: Option<pii::SecretSerdeValue>,
pub customer_details: Option<Encryption>,
pub billing_details: Option<Encryption>,
pub merchant_order_reference_id: Option<String>,
}

Expand Down Expand Up @@ -291,6 +295,7 @@ impl PaymentIntentUpdate {
request_external_three_ds_authentication,
frm_metadata,
customer_details,
billing_details,
merchant_order_reference_id,
} = self.into();
PaymentIntent {
Expand Down Expand Up @@ -330,6 +335,7 @@ impl PaymentIntentUpdate {
.or(source.request_external_three_ds_authentication),
frm_metadata: frm_metadata.or(source.frm_metadata),
customer_details: customer_details.or(source.customer_details),
billing_details: billing_details.or(source.billing_details),
merchant_order_reference_id: merchant_order_reference_id
.or(source.merchant_order_reference_id),
..source
Expand Down Expand Up @@ -363,6 +369,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
request_external_three_ds_authentication,
frm_metadata,
customer_details,
billing_details,
merchant_order_reference_id,
} => Self {
amount: Some(amount),
Expand All @@ -388,6 +395,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
request_external_three_ds_authentication,
frm_metadata,
customer_details,
billing_details,
merchant_order_reference_id,
..Default::default()
},
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 @@ -890,6 +890,7 @@ diesel::table! {
charges -> Nullable<Jsonb>,
frm_metadata -> Nullable<Jsonb>,
customer_details -> Nullable<Bytea>,
billing_details -> Nullable<Bytea>,
#[max_length = 255]
merchant_order_reference_id -> Nullable<Varchar>,
}
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 @@ -63,5 +63,6 @@ pub struct PaymentIntent {
pub charges: Option<pii::SecretSerdeValue>,
pub frm_metadata: Option<pii::SecretSerdeValue>,
pub customer_details: Option<Encryptable<Secret<serde_json::Value>>>,
pub billing_details: Option<Encryptable<Secret<serde_json::Value>>>,
pub merchant_order_reference_id: Option<String>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ impl behaviour::Conversion for PaymentIntent {
charges: self.charges,
frm_metadata: self.frm_metadata,
customer_details: self.customer_details.map(Encryption::from),
billing_details: self.billing_details.map(Encryption::from),
merchant_order_reference_id: self.merchant_order_reference_id,
})
}
Expand Down Expand Up @@ -592,6 +593,10 @@ impl behaviour::Conversion for PaymentIntent {
.customer_details
.async_lift(inner_decrypt)
.await?,
billing_details: storage_model
.billing_details
.async_lift(inner_decrypt)
.await?,
merchant_order_reference_id: storage_model.merchant_order_reference_id,
})
}
Expand Down Expand Up @@ -647,6 +652,7 @@ impl behaviour::Conversion for PaymentIntent {
charges: self.charges,
frm_metadata: self.frm_metadata,
customer_details: self.customer_details.map(Encryption::from),
billing_details: self.billing_details.map(Encryption::from),
merchant_order_reference_id: self.merchant_order_reference_id,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ pub struct PaymentIntentNew {
pub request_external_three_ds_authentication: Option<bool>,
pub charges: Option<pii::SecretSerdeValue>,
pub customer_details: Option<Encryptable<Secret<serde_json::Value>>>,
pub billing_details: Option<Encryptable<Secret<serde_json::Value>>>,
}

#[derive(Debug, Clone, Serialize)]
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_details: Option<Encryptable<Secret<serde_json::Value>>>,
merchant_order_reference_id: Option<String>,
},
PaymentAttemptAndAttemptCountUpdate {
Expand Down Expand Up @@ -271,6 +273,7 @@ pub struct PaymentIntentUpdateInternal {
pub request_external_three_ds_authentication: Option<bool>,
pub frm_metadata: Option<pii::SecretSerdeValue>,
pub customer_details: Option<Encryptable<Secret<serde_json::Value>>>,
pub billing_details: Option<Encryptable<Secret<serde_json::Value>>>,
pub merchant_order_reference_id: Option<String>,
}

Expand Down Expand Up @@ -300,6 +303,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
request_external_three_ds_authentication,
frm_metadata,
customer_details,
billing_details,
merchant_order_reference_id,
} => Self {
amount: Some(amount),
Expand All @@ -325,6 +329,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
request_external_three_ds_authentication,
frm_metadata,
customer_details,
billing_details,
merchant_order_reference_id,
..Default::default()
},
Expand Down Expand Up @@ -566,6 +571,7 @@ impl From<PaymentIntentUpdate> for DieselPaymentIntentUpdate {
request_external_three_ds_authentication,
frm_metadata,
customer_details,
billing_details,
merchant_order_reference_id,
} => Self::Update {
amount,
Expand All @@ -590,6 +596,7 @@ impl From<PaymentIntentUpdate> for DieselPaymentIntentUpdate {
request_external_three_ds_authentication,
frm_metadata,
customer_details: customer_details.map(Encryption::from),
billing_details: billing_details.map(Encryption::from),
merchant_order_reference_id,
},
PaymentIntentUpdate::PaymentAttemptAndAttemptCountUpdate {
Expand Down Expand Up @@ -693,6 +700,7 @@ impl From<PaymentIntentUpdateInternal> for diesel_models::PaymentIntentUpdateInt
request_external_three_ds_authentication,
frm_metadata,
customer_details,
billing_details,
merchant_order_reference_id,
} = value;

Expand Down Expand Up @@ -728,6 +736,7 @@ impl From<PaymentIntentUpdateInternal> for diesel_models::PaymentIntentUpdateInt
request_external_three_ds_authentication,
frm_metadata,
customer_details: customer_details.map(Encryption::from),
billing_details: billing_details.map(Encryption::from),
merchant_order_reference_id,
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/rapyd/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl TryFrom<&RapydRouterData<&types::PaymentsAuthorizeRouterData>> for RapydPay
}
_ => None,
}
.get_required_value("payment_method not implemnted")
.get_required_value("payment_method not implemented")
.change_context(errors::ConnectorError::NotImplemented(
"payment_method".to_owned(),
))?;
Expand Down
26 changes: 13 additions & 13 deletions crates/router/src/connector/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
billing_address
.clone()
.address
.and_then(|billing_address_details| billing_address_details.first_name.clone())
.and_then(|billing_details| billing_details.first_name.clone())
})
.ok_or_else(missing_field_err(
"payment_method_data.billing.address.first_name",
Expand All @@ -364,7 +364,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
billing_address
.clone()
.address
.and_then(|billing_address_details| billing_address_details.last_name.clone())
.and_then(|billing_details| billing_details.last_name.clone())
})
.ok_or_else(missing_field_err(
"payment_method_data.billing.address.last_name",
Expand All @@ -378,7 +378,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
billing_address
.clone()
.address
.and_then(|billing_address_details| billing_address_details.line1.clone())
.and_then(|billing_details| billing_details.line1.clone())
})
.ok_or_else(missing_field_err(
"payment_method_data.billing.address.line1",
Expand All @@ -391,7 +391,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
billing_address
.clone()
.address
.and_then(|billing_address_details| billing_address_details.city)
.and_then(|billing_details| billing_details.city)
})
.ok_or_else(missing_field_err(
"payment_method_data.billing.address.city",
Expand Down Expand Up @@ -421,7 +421,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
billing_address
.clone()
.address
.and_then(|billing_address_details| billing_address_details.line1)
.and_then(|billing_details| billing_details.line1)
})
}

Expand All @@ -432,7 +432,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
billing_address
.clone()
.address
.and_then(|billing_address_details| billing_address_details.line2)
.and_then(|billing_details| billing_details.line2)
})
}

Expand All @@ -443,7 +443,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
billing_address
.clone()
.address
.and_then(|billing_address_details| billing_address_details.city)
.and_then(|billing_details| billing_details.city)
})
}

Expand All @@ -454,7 +454,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
billing_address
.clone()
.address
.and_then(|billing_address_details| billing_address_details.country)
.and_then(|billing_details| billing_details.country)
})
}

Expand All @@ -465,7 +465,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
billing_address
.clone()
.address
.and_then(|billing_address_details| billing_address_details.zip)
.and_then(|billing_details| billing_details.zip)
})
}

Expand All @@ -476,7 +476,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
billing_address
.clone()
.address
.and_then(|billing_address_details| billing_address_details.state)
.and_then(|billing_details| billing_details.state)
})
}

Expand All @@ -487,7 +487,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
billing_address
.clone()
.address
.and_then(|billing_address_details| billing_address_details.first_name)
.and_then(|billing_details| billing_details.first_name)
})
}

Expand All @@ -498,7 +498,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
billing_address
.clone()
.address
.and_then(|billing_address_details| billing_address_details.last_name)
.and_then(|billing_details| billing_details.last_name)
})
}

Expand Down Expand Up @@ -615,7 +615,7 @@ impl AddressData for api::Address {
fn get_optional_country(&self) -> Option<enums::CountryAlpha2> {
self.address
.as_ref()
.and_then(|billing_address_details| billing_address_details.country)
.and_then(|billing_details| billing_details.country)
}

fn get_optional_full_name(&self) -> Option<Secret<String>> {
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 @@ -3151,6 +3151,7 @@ mod tests {
charges: None,
frm_metadata: None,
customer_details: None,
billing_details: None,
merchant_order_reference_id: None,
};
let req_cs = Some("1".to_string());
Expand Down Expand Up @@ -3212,6 +3213,7 @@ mod tests {
charges: None,
frm_metadata: None,
customer_details: None,
billing_details: None,
merchant_order_reference_id: None,
};
let req_cs = Some("1".to_string());
Expand Down Expand Up @@ -3272,6 +3274,7 @@ mod tests {
charges: None,
frm_metadata: None,
customer_details: None,
billing_details: None,
merchant_order_reference_id: None,
};
let req_cs = Some("1".to_string());
Expand Down
6 changes: 6 additions & 0 deletions crates/router/src/core/payments/operations/payment_confirm.rs
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 @@ -1218,6 +1219,10 @@ 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_details = billing_address
.async_and_then(|_| 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 @@ -1263,6 +1268,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
frm_metadata: m_frm_metadata,
customer_details,
merchant_order_reference_id: None,
billing_details,
},
&m_key_store,
storage_scheme,
Expand Down
11 changes: 11 additions & 0 deletions crates/router/src/core/payments/operations/payment_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,16 @@ impl PaymentCreate {
.change_context(errors::ApiErrorResponse::InternalServerError)?
.map(Secret::new);

// Derivation of directly supplied Billing Address data in our Payment Create Request
// Encrypting our Billing Address Details to be stored in Payment Intent
let billing_details = request
.billing
.clone()
.async_and_then(|_| async {
create_encrypted_data(key_store, request.billing.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 @@ -1116,6 +1126,7 @@ impl PaymentCreate {
.request_external_three_ds_authentication,
charges,
frm_metadata: request.frm_metadata.clone(),
billing_details,
customer_details,
merchant_order_reference_id: request.merchant_order_reference_id.clone(),
})
Expand Down
Loading

0 comments on commit ec01788

Please sign in to comment.