Skip to content

Commit

Permalink
feat: add support for card extended bin in payment attempt (#3312)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chethan-rao authored Jan 11, 2024
1 parent 6fb3b00 commit cc3eefd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
9 changes: 6 additions & 3 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,7 @@ pub struct AdditionalCardInfo {
pub bank_code: Option<String>,
pub last4: Option<String>,
pub card_isin: Option<String>,
pub card_extended_bin: Option<String>,
pub card_exp_month: Option<Secret<String>>,
pub card_exp_year: Option<Secret<String>>,
pub card_holder_name: Option<Secret<String>>,
Expand Down Expand Up @@ -1665,6 +1666,7 @@ pub struct CardResponse {
pub card_issuer: Option<String>,
pub card_issuing_country: Option<String>,
pub card_isin: Option<String>,
pub card_extended_bin: Option<String>,
pub card_exp_month: Option<Secret<String>>,
pub card_exp_year: Option<Secret<String>>,
pub card_holder_name: Option<Secret<String>>,
Expand Down Expand Up @@ -1707,7 +1709,7 @@ pub enum VoucherData {
#[serde(rename_all = "snake_case")]
pub enum PaymentMethodDataResponse {
#[serde(rename = "card")]
Card(CardResponse),
Card(Box<CardResponse>),
BankTransfer,
Wallet,
PayLater,
Expand Down Expand Up @@ -2037,7 +2039,7 @@ pub struct PaymentsResponse {
#[schema(example = 100)]
pub amount: i64,

/// The payment net amount. net_amount = amount + surcharge_details.surcharge_amount + surcharge_details.tax_amount,
/// The payment net amount. net_amount = amount + surcharge_details.surcharge_amount + surcharge_details.tax_amount,
/// If no surcharge_details, net_amount = amount
#[schema(example = 110)]
pub net_amount: i64,
Expand Down Expand Up @@ -2531,6 +2533,7 @@ impl From<AdditionalCardInfo> for CardResponse {
card_issuer: card.card_issuer,
card_issuing_country: card.card_issuing_country,
card_isin: card.card_isin,
card_extended_bin: card.card_extended_bin,
card_exp_month: card.card_exp_month,
card_exp_year: card.card_exp_year,
card_holder_name: card.card_holder_name,
Expand All @@ -2541,7 +2544,7 @@ impl From<AdditionalCardInfo> for CardResponse {
impl From<AdditionalPaymentData> for PaymentMethodDataResponse {
fn from(payment_method_data: AdditionalPaymentData) -> Self {
match payment_method_data {
AdditionalPaymentData::Card(card) => Self::Card(CardResponse::from(*card)),
AdditionalPaymentData::Card(card) => Self::Card(Box::new(CardResponse::from(*card))),
AdditionalPaymentData::PayLater {} => Self::PayLater,
AdditionalPaymentData::Wallet {} => Self::Wallet,
AdditionalPaymentData::BankRedirect { .. } => Self::BankRedirect,
Expand Down
3 changes: 3 additions & 0 deletions crates/cards/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ impl CardNumber {
.rev()
.collect::<String>()
}
pub fn get_card_extended_bin(self) -> String {
self.0.peek().chars().take(8).collect::<String>()
}
}

impl FromStr for CardNumber {
Expand Down
4 changes: 4 additions & 0 deletions crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3290,6 +3290,7 @@ pub async fn get_additional_payment_data(
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 last4 = Some(card_data.card_number.clone().get_last4());
if card_data.card_issuer.is_some()
&& card_data.card_network.is_some()
Expand All @@ -3309,6 +3310,7 @@ pub async fn get_additional_payment_data(
card_holder_name: card_data.card_holder_name.clone(),
last4: last4.clone(),
card_isin: card_isin.clone(),
card_extended_bin: card_extended_bin.clone(),
},
))
} else {
Expand All @@ -3332,6 +3334,7 @@ pub async fn get_additional_payment_data(
card_issuing_country: card_info.card_issuing_country,
last4: last4.clone(),
card_isin: card_isin.clone(),
card_extended_bin: card_extended_bin.clone(),
card_exp_month: Some(card_data.card_exp_month.clone()),
card_exp_year: Some(card_data.card_exp_year.clone()),
card_holder_name: card_data.card_holder_name.clone(),
Expand All @@ -3347,6 +3350,7 @@ pub async fn get_additional_payment_data(
card_issuing_country: None,
last4,
card_isin,
card_extended_bin,
card_exp_month: Some(card_data.card_exp_month.clone()),
card_exp_year: Some(card_data.card_exp_year.clone()),
card_holder_name: card_data.card_holder_name.clone(),
Expand Down

0 comments on commit cc3eefd

Please sign in to comment.