feat(connector): [Stripe] implement Bancontact Bank Redirect for stripe (#1169)

Co-authored-by: Jagan <jaganelavarasan@gmail.com>
This commit is contained in:
AkshayaFoiger
2023-05-16 16:19:24 +05:30
committed by GitHub
parent 3606723a9b
commit 5b22e96798
4 changed files with 62 additions and 12 deletions

View File

@ -590,18 +590,21 @@ pub enum BankRedirectData {
BancontactCard { BancontactCard {
/// The card number /// The card number
#[schema(value_type = String, example = "4242424242424242")] #[schema(value_type = String, example = "4242424242424242")]
card_number: CardNumber, card_number: Option<CardNumber>,
/// The card's expiry month /// The card's expiry month
#[schema(value_type = String, example = "24")] #[schema(value_type = String, example = "24")]
card_exp_month: Secret<String>, card_exp_month: Option<Secret<String>>,
/// The card's expiry year /// The card's expiry year
#[schema(value_type = String, example = "24")] #[schema(value_type = String, example = "24")]
card_exp_year: Secret<String>, card_exp_year: Option<Secret<String>>,
/// The card holder's name /// The card holder's name
#[schema(value_type = String, example = "John Test")] #[schema(value_type = String, example = "John Test")]
card_holder_name: Secret<String>, card_holder_name: Option<Secret<String>>,
//Required by Stripes
billing_details: Option<BankRedirectBilling>,
}, },
Blik { Blik {
// Blik Code // Blik Code
@ -698,7 +701,7 @@ pub struct BankRedirectBilling {
pub billing_name: Option<Secret<String>>, pub billing_name: Option<Secret<String>>,
/// The billing email for bank redirect /// The billing email for bank redirect
#[schema(value_type = String, example = "example@example.com")] #[schema(value_type = String, example = "example@example.com")]
pub email: Email, pub email: Option<Email>,
} }
#[derive(serde::Deserialize, serde::Serialize, Debug, Clone, ToSchema, Eq, PartialEq)] #[derive(serde::Deserialize, serde::Serialize, Debug, Clone, ToSchema, Eq, PartialEq)]

View File

@ -248,7 +248,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for AciPaymentsRequest {
billing_country: None, billing_country: None,
merchant_customer_id: None, merchant_customer_id: None,
merchant_transaction_id: None, merchant_transaction_id: None,
customer_email: Some(billing_details.email.clone()), customer_email: billing_details.email.clone(),
shopper_result_url: item.request.router_return_url.clone(), shopper_result_url: item.request.router_return_url.clone(),
})), })),

View File

@ -1116,14 +1116,35 @@ impl<'a> TryFrom<&api_models::payments::BankRedirectData> for AdyenPaymentMethod
card_exp_month, card_exp_month,
card_exp_year, card_exp_year,
card_holder_name, card_holder_name,
..
} => Ok(AdyenPaymentMethod::BancontactCard(Box::new( } => Ok(AdyenPaymentMethod::BancontactCard(Box::new(
BancontactCardData { BancontactCardData {
payment_type: PaymentType::Scheme, payment_type: PaymentType::Scheme,
brand: "bcmc".to_string(), brand: "bcmc".to_string(),
number: card_number.clone(), number: card_number
expiry_month: card_exp_month.clone(), .as_ref()
expiry_year: card_exp_year.clone(), .ok_or(errors::ConnectorError::MissingRequiredField {
holder_name: card_holder_name.clone(), field_name: "bancontact_card.card_number",
})?
.clone(),
expiry_month: card_exp_month
.as_ref()
.ok_or(errors::ConnectorError::MissingRequiredField {
field_name: "bancontact_card.card_exp_month",
})?
.clone(),
expiry_year: card_exp_year
.as_ref()
.ok_or(errors::ConnectorError::MissingRequiredField {
field_name: "bancontact_card.card_exp_year",
})?
.clone(),
holder_name: card_holder_name
.as_ref()
.ok_or(errors::ConnectorError::MissingRequiredField {
field_name: "bancontact_card.card_holder_name",
})?
.clone(),
}, },
))), ))),
api_models::payments::BankRedirectData::Blik { blik_code } => { api_models::payments::BankRedirectData::Blik { blik_code } => {

View File

@ -238,10 +238,16 @@ fn get_bank_name(
}, },
)?)?, )?)?,
})), })),
(StripePaymentMethodType::Sofort | StripePaymentMethodType::Giropay, _) => Ok(None), (
StripePaymentMethodType::Sofort
| StripePaymentMethodType::Giropay
| StripePaymentMethodType::Bancontact,
_,
) => Ok(None),
_ => Err(errors::ConnectorError::MismatchedPaymentData), _ => Err(errors::ConnectorError::MismatchedPaymentData),
} }
} }
#[derive(Debug, Eq, PartialEq, Serialize)] #[derive(Debug, Eq, PartialEq, Serialize)]
pub struct StripeBankRedirectData { pub struct StripeBankRedirectData {
#[serde(rename = "payment_method_types[]")] #[serde(rename = "payment_method_types[]")]
@ -392,6 +398,7 @@ pub enum StripePaymentMethodType {
Becs, Becs,
#[serde(rename = "bacs_debit")] #[serde(rename = "bacs_debit")]
Bacs, Bacs,
Bancontact,
#[serde(rename = "wechat_pay")] #[serde(rename = "wechat_pay")]
Wechatpay, Wechatpay,
Alipay, Alipay,
@ -627,6 +634,10 @@ fn infer_stripe_bank_redirect_issuer(
Some(storage_models::enums::PaymentMethodType::Sofort) => { Some(storage_models::enums::PaymentMethodType::Sofort) => {
Ok(StripePaymentMethodType::Sofort) Ok(StripePaymentMethodType::Sofort)
} }
Some(storage_models::enums::PaymentMethodType::BancontactCard) => {
Ok(StripePaymentMethodType::Bancontact)
}
Some(storage_models::enums::PaymentMethodType::Przelewy24) => { Some(storage_models::enums::PaymentMethodType::Przelewy24) => {
Ok(StripePaymentMethodType::Przelewy24) Ok(StripePaymentMethodType::Przelewy24)
} }
@ -732,7 +743,19 @@ impl TryFrom<&payments::BankRedirectData> for StripeBillingAddress {
payments::BankRedirectData::Przelewy24 { payments::BankRedirectData::Przelewy24 {
billing_details, .. billing_details, ..
} => Ok(Self { } => Ok(Self {
email: Some(billing_details.email.clone()), email: billing_details.email.clone(),
..Self::default()
}),
payments::BankRedirectData::BancontactCard {
billing_details, ..
} => Ok(Self {
name: billing_details
.as_ref()
.ok_or(errors::ConnectorError::MissingRequiredField {
field_name: "bancontact_card.billing_name",
})?
.billing_name
.clone(),
..Self::default() ..Self::default()
}), }),
_ => Ok(Self::default()), _ => Ok(Self::default()),
@ -876,6 +899,7 @@ fn create_stripe_payment_method(
let pm_type = infer_stripe_bank_redirect_issuer(pm_type)?; let pm_type = infer_stripe_bank_redirect_issuer(pm_type)?;
let bank_specific_data = get_bank_specific_data(bank_redirect_data); let bank_specific_data = get_bank_specific_data(bank_redirect_data);
let bank_name = get_bank_name(&pm_type, bank_redirect_data)?; let bank_name = get_bank_name(&pm_type, bank_redirect_data)?;
Ok(( Ok((
StripePaymentMethodData::BankRedirect(StripeBankRedirectData { StripePaymentMethodData::BankRedirect(StripeBankRedirectData {
payment_method_types: pm_type, payment_method_types: pm_type,
@ -1346,6 +1370,7 @@ impl ForeignFrom<(Option<StripePaymentMethodOptions>, String)> for types::Mandat
| StripePaymentMethodOptions::WechatPay {} | StripePaymentMethodOptions::WechatPay {}
| StripePaymentMethodOptions::Alipay {} | StripePaymentMethodOptions::Alipay {}
| StripePaymentMethodOptions::Sepa {} | StripePaymentMethodOptions::Sepa {}
| StripePaymentMethodOptions::Bancontact {}
| StripePaymentMethodOptions::Przelewy24 {} => None, | StripePaymentMethodOptions::Przelewy24 {} => None,
}), }),
payment_method_id: Some(payment_method_id), payment_method_id: Some(payment_method_id),
@ -1758,6 +1783,7 @@ pub enum StripePaymentMethodOptions {
Becs {}, Becs {},
#[serde(rename = "bacs_debit")] #[serde(rename = "bacs_debit")]
Bacs {}, Bacs {},
Bancontact {},
WechatPay {}, WechatPay {},
Alipay {}, Alipay {},
#[serde(rename = "p24")] #[serde(rename = "p24")]