feat(connector): [Stripe] Add support for Blik (#1565)

This commit is contained in:
Sangamesh Kulkarni
2023-07-20 22:46:05 +05:30
committed by GitHub
parent 0c3cf05ffc
commit 0589c572c4
2 changed files with 36 additions and 8 deletions

View File

@ -271,7 +271,8 @@ fn get_bank_name(
(
StripePaymentMethodType::Sofort
| StripePaymentMethodType::Giropay
| StripePaymentMethodType::Bancontact,
| StripePaymentMethodType::Bancontact
| StripePaymentMethodType::Blik,
_,
) => Ok(None),
_ => Err(errors::ConnectorError::MismatchedPaymentData),
@ -287,6 +288,8 @@ pub struct StripeBankRedirectData {
pub bank_name: Option<StripeBankName>,
#[serde(flatten)]
pub bank_specific_data: Option<BankSpecificData>,
#[serde(rename = "payment_method_options[blik][code]")]
pub code: Option<String>,
}
#[derive(Debug, Eq, PartialEq, Serialize)]
@ -513,6 +516,7 @@ pub enum StripePaymentMethodType {
Przelewy24,
CustomerBalance,
Multibanco,
Blik,
}
impl TryFrom<enums::PaymentMethodType> for StripePaymentMethodType {
@ -535,6 +539,7 @@ impl TryFrom<enums::PaymentMethodType> for StripePaymentMethodType {
enums::PaymentMethodType::Bacs => Ok(Self::Bacs),
enums::PaymentMethodType::BancontactCard => Ok(Self::Bancontact),
enums::PaymentMethodType::WeChatPay => Ok(Self::Wechatpay),
enums::PaymentMethodType::Blik => Ok(Self::Blik),
enums::PaymentMethodType::AliPay => Ok(Self::Alipay),
enums::PaymentMethodType::Przelewy24 => Ok(Self::Przelewy24),
_ => Err(errors::ConnectorError::NotImplemented(
@ -802,6 +807,7 @@ fn infer_stripe_bank_redirect_issuer(
Ok(StripePaymentMethodType::Przelewy24)
}
Some(diesel_models::enums::PaymentMethodType::Eps) => Ok(StripePaymentMethodType::Eps),
Some(diesel_models::enums::PaymentMethodType::Blik) => Ok(StripePaymentMethodType::Blik),
None => Err(errors::ConnectorError::MissingRequiredField {
field_name: "payment_method_type",
}),
@ -1084,12 +1090,17 @@ fn create_stripe_payment_method(
let pm_type = infer_stripe_bank_redirect_issuer(pm_type)?;
let bank_specific_data = get_bank_specific_data(bank_redirect_data);
let bank_name = get_bank_name(&pm_type, bank_redirect_data)?;
let blik_code = match bank_redirect_data {
payments::BankRedirectData::Blik { blik_code } => Some(blik_code.to_owned()),
_ => None,
};
Ok((
StripePaymentMethodData::BankRedirect(StripeBankRedirectData {
payment_method_data_type: pm_type,
bank_name,
bank_specific_data,
code: blik_code,
}),
pm_type,
billing_address,
@ -1832,6 +1843,7 @@ impl ForeignFrom<(Option<StripePaymentMethodOptions>, String)> for types::Mandat
| StripePaymentMethodOptions::Bancontact {}
| StripePaymentMethodOptions::Przelewy24 {}
| StripePaymentMethodOptions::CustomerBalance {}
| StripePaymentMethodOptions::Blik {}
| StripePaymentMethodOptions::Multibanco {} => None,
}),
payment_method_id: Some(payment_method_id),
@ -2068,6 +2080,7 @@ pub enum StripeNextActionResponse {
VerifyWithMicrodeposits(StripeVerifyWithMicroDepositsResponse),
WechatPayDisplayQrCode(StripeRedirectToQr),
DisplayBankTransferInstructions(StripeBankTransferDetails),
NoNextActionBody,
}
impl StripeNextActionResponse {
@ -2081,6 +2094,7 @@ impl StripeNextActionResponse {
Some(verify_with_microdeposits.hosted_verification_url.to_owned())
}
Self::DisplayBankTransferInstructions(_) => None,
Self::NoNextActionBody => None,
}
}
}
@ -2101,7 +2115,17 @@ impl<'de> Deserialize<'de> for StripeNextActionResponse {
#[serde(flatten, with = "StripeNextActionResponse")]
inner: StripeNextActionResponse,
}
Wrapper::deserialize(deserializer).map(|w| w.inner)
// There is some exception in the stripe next action, it usually sends :
// "next_action": {
// "redirect_to_url": { "return_url": "...", "url": "..." },
// "type": "redirect_to_url"
// },
// But there is a case where it only sends the type and not other field named as it's type
let stripe_next_action_response =
Wrapper::deserialize(deserializer).map_or(Self::NoNextActionBody, |w| w.inner);
Ok(stripe_next_action_response)
}
}
@ -2366,6 +2390,7 @@ pub enum StripePaymentMethodOptions {
Przelewy24 {},
CustomerBalance {},
Multibanco {},
Blik {},
}
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
@ -2798,6 +2823,7 @@ impl
payment_method_data_type: pm_type,
bank_name: None,
bank_specific_data: None,
code: None,
}))
}
api::PaymentMethodData::Wallet(wallet_data) => match wallet_data {

View File

@ -361,12 +361,14 @@ where
image_data_url: qr_code_data.image_data_url,
}
}))
.or(Some(api_models::payments::NextActionData::RedirectToUrl {
redirect_to_url: helpers::create_startpay_url(
server,
&payment_attempt,
&payment_intent,
),
.or(redirection_data.map(|_| {
api_models::payments::NextActionData::RedirectToUrl {
redirect_to_url: helpers::create_startpay_url(
server,
&payment_attempt,
&payment_intent,
),
}
}));
};