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: add support for card extended bin in payment attempt #3312

Merged
merged 1 commit into from
Jan 11, 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
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 @@ -2528,6 +2530,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 @@ -2538,7 +2541,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 @@ -35,6 +35,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 @@ -3287,6 +3287,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 @@ -3306,6 +3307,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 @@ -3329,6 +3331,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 @@ -3344,6 +3347,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
Loading