Skip to content

Commit

Permalink
extended card bin config
Browse files Browse the repository at this point in the history
  • Loading branch information
Aprabhat19 committed Apr 23, 2024
1 parent 776c1a7 commit e08a339
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
3 changes: 2 additions & 1 deletion crates/router/src/core/fraud_check.rs
Expand Up @@ -230,10 +230,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
18 changes: 17 additions & 1 deletion crates/router/src/core/payments/helpers.rs
Expand Up @@ -3619,11 +3619,27 @@ 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(profile_id, 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 card_extended_bin =
// if let Some(config) = enable_extended_bin.map(|config| config.config == "true") {
// Some(card_data.card_number.clone().get_card_extended_bin())
// } else {
// 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
Expand Up @@ -414,13 +414,23 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
.map(|pmd| pmd.payment_method_data.clone());

let store = state.clone().store;
let profile_id = payment_intent
.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 @@ -987,12 +997,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
5 changes: 4 additions & 1 deletion crates/router/src/core/payments/operations/payment_create.rs
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.clone(),
)
.await?;

Expand Down Expand Up @@ -767,6 +768,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 @@ -783,6 +785,7 @@ impl PaymentCreate {
helpers::get_additional_payment_data(
&payment_method_data.payment_method_data,
&*state.store,
&profile_id,
)
.await
})
Expand Down
10 changes: 9 additions & 1 deletion crates/router/src/core/payments/operations/payment_update.rs
Expand Up @@ -592,12 +592,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

0 comments on commit e08a339

Please sign in to comment.