Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add profile level config to toggle extended card bin #4445

Merged
merged 7 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion crates/router/src/core/fraud_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,11 @@ where
})
.collect::<Vec<_>>()
.concat();

let additional_payment_data = match &payment_data.payment_method_data {
Some(pmd) => {
let additional_payment_data =
get_additional_payment_data(pmd, db).await;
get_additional_payment_data(pmd, db, &profile_id).await;
Some(additional_payment_data)
}
None => payment_data
Expand Down
14 changes: 13 additions & 1 deletion crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3649,11 +3649,23 @@ mod test {
pub async fn get_additional_payment_data(
pm_data: &api_models::payments::PaymentMethodData,
db: &dyn StorageInterface,
profile_id: &str,
) -> api_models::payments::AdditionalPaymentData {
match pm_data {
api_models::payments::PaymentMethodData::Card(card_data) => {
let card_isin = Some(card_data.card_number.clone().get_card_isin());
let card_extended_bin = Some(card_data.card_number.clone().get_card_extended_bin());
let enable_extended_bin =db
.find_config_by_key_unwrap_or(
format!("{}_enable_extended_card_bin", profile_id).as_str(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create a helper function to construct this key. Not a blocker.

Some("false".to_string()))
.await.map_err(|err| services::logger::error!(message="Failed to fetch the config", extended_card_bin_error=?err)).ok();

let card_extended_bin = match enable_extended_bin {
Some(config) if config.config == "true" => {
Some(card_data.card_number.clone().get_card_extended_bin())
}
_ => None,
};
let last4 = Some(card_data.card_number.clone().get_last4());
if card_data.card_issuer.is_some()
&& card_data.card_network.is_some()
Expand Down
23 changes: 20 additions & 3 deletions crates/router/src/core/payments/operations/payment_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,23 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
.and_then(|pmd| pmd.payment_method_data.clone());

let store = state.clone().store;
let profile_id = payment_intent
Aprabhat19 marked this conversation as resolved.
Show resolved Hide resolved
.profile_id
.clone()
.get_required_value("profile_id")
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("'profile_id' not set in payment intent")?;

let additional_pm_data_fut = tokio::spawn(
async move {
Ok(n_request_payment_method_data
.async_map(|payment_method_data| async move {
helpers::get_additional_payment_data(&payment_method_data, store.as_ref())
.await
helpers::get_additional_payment_data(
&payment_method_data,
store.as_ref(),
profile_id.as_ref(),
)
.await
})
.await)
}
Expand Down Expand Up @@ -1059,12 +1069,19 @@ impl<F: Clone, Ctx: PaymentMethodRetrieve>
.clone();
let payment_token = payment_data.token.clone();
let payment_method_type = payment_data.payment_attempt.payment_method_type;
let profile_id = payment_data
.payment_intent
.profile_id
.as_ref()
.get_required_value("profile_id")
.change_context(errors::ApiErrorResponse::InternalServerError)?;
let payment_experience = payment_data.payment_attempt.payment_experience;
let additional_pm_data = payment_data
.payment_method_data
.as_ref()
.async_map(|payment_method_data| async {
helpers::get_additional_payment_data(payment_method_data, &*state.store).await
helpers::get_additional_payment_data(payment_method_data, &*state.store, profile_id)
.await
})
.await
.as_ref()
Expand Down
11 changes: 9 additions & 2 deletions crates/router/src/core/payments/operations/payment_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
.as_ref()
.map(|address| address.address_id.clone()),
attempt_id,
profile_id,
profile_id.clone(),
session_expiry,
)
.await?;
Expand All @@ -277,6 +277,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
.map(|address| address.address_id.clone()),
&payment_method_info,
merchant_key_store,
profile_id,
)
.await?;

Expand Down Expand Up @@ -771,6 +772,7 @@ impl PaymentCreate {
payment_method_billing_address_id: Option<String>,
payment_method_info: &Option<PaymentMethod>,
key_store: &domain::MerchantKeyStore,
profile_id: String,
) -> RouterResult<(
storage::PaymentAttemptNew,
Option<api_models::payments::AdditionalPaymentData>,
Expand All @@ -794,7 +796,12 @@ impl PaymentCreate {
payment_method_data_request.payment_method_data.as_ref()
})
.async_map(|payment_method_data| async {
helpers::get_additional_payment_data(payment_method_data, &*state.store).await
helpers::get_additional_payment_data(
payment_method_data,
&*state.store,
&profile_id,
)
.await
})
.await;

Expand Down
10 changes: 9 additions & 1 deletion crates/router/src/core/payments/operations/payment_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,20 @@ impl<F: Clone, Ctx: PaymentMethodRetrieve>
storage_enums::AttemptStatus::ConfirmationAwaited
}
};
let profile_id = payment_data
.payment_intent
.profile_id
.as_ref()
.get_required_value("profile_id")
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("'profile_id' not set in payment intent")?;

let additional_pm_data = payment_data
.payment_method_data
.as_ref()
.async_map(|payment_method_data| async {
helpers::get_additional_payment_data(payment_method_data, &*state.store).await
helpers::get_additional_payment_data(payment_method_data, &*state.store, profile_id)
.await
})
.await
.as_ref()
Expand Down
Loading