Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(router): [mollie] add support for klarna payment method (#11112)
AkshayaFoiger235cda082294
diff --git a/config/config.example.toml b/config/config.example.tomlindex 4c9838eca3..4547837b7a 100644--- a/config/config.example.toml+++ b/config/config.example.toml@@ -898,6 +898,7 @@ debit = {country = "AR,BD,BO,BR,CM,CL,CN,CO,CR,DO,EC,SV,EG,GH,GT,HN,IN,ID,CI,JP,eps = { country = "AT", currency = "EUR" }ideal = { country = "NL", currency = "EUR" }przelewy24 = { country = "PL", currency = "PLN,EUR" }+klarna = { country = "DE,AT,NL,BE,FR,GB,IT,ES,PT,SE,DK,FI,NO,CH,IR,CZ,PL,GR,SK", currency = "EUR,GBP,DKK,SEK,NOK,CHF,PLN,CZK" }[pm_filters.amazonpay]amazon_pay = { country = "US", currency = "USD" }diff --git a/config/deployments/integration_test.toml b/config/deployments/integration_test.tomlindex 76b89a0b84..e6d90c156a 100644--- a/config/deployments/integration_test.toml+++ b/config/deployments/integration_test.toml@@ -731,6 +731,7 @@ sepa = { country = "ES,SK,AT,NL,DE,BE,FR,FI,PT,IE,EE,LT,LV,IT,GB", currency = "Eeps = { country = "AT", currency = "EUR" }ideal = { country = "NL", currency = "EUR" }przelewy24 = { country = "PL", currency = "PLN,EUR" }+klarna = { country = "DE,AT,NL,BE,FR,GB,IT,ES,PT,SE,DK,FI,NO,CH,IR,CZ,PL,GR,SK", currency = "EUR,GBP,DKK,SEK,NOK,CHF,PLN,CZK" }[debit_routing_config]supported_currencies = "USD"diff --git a/config/deployments/production.toml b/config/deployments/production.tomlindex 4a98af1491..67035a1edc 100644--- a/config/deployments/production.toml+++ b/config/deployments/production.toml@@ -749,6 +749,7 @@ sepa = { country = "ES,SK,AT,NL,DE,BE,FR,FI,PT,IE,EE,LT,LV,IT,GB", currency = "Eeps = { country = "AT", currency = "EUR" }ideal = { country = "NL", currency = "EUR" }przelewy24 = { country = "PL", currency = "PLN,EUR" }+klarna = { country = "DE,AT,NL,BE,FR,GB,IT,ES,PT,SE,DK,FI,NO,CH,IR,CZ,PL,GR,SK", currency = "EUR,GBP,DKK,SEK,NOK,CHF,PLN,CZK" }[pm_filters.rapyd]apple_pay = { country = "BR, CA, CL, CO, DO, SV, MX, PE, PT, US, AT, BE, BG, HR, CY, CZ, DO, DK, EE, FI, FR, GE, DE, GR, GL, HU, IS, IE, IL, IT, LV, LI, LT, LU, MT, MD, MC, ME, NL, NO, PL, RO, SM, SK, SI, ZA, ES, SE, CH, GB, VA, AU, HK, JP, MY, NZ, SG, KR, TW, VN", currency = "AMD, AUD, BGN, BRL, BYN, CAD, CHF, CLP, CNY, COP, CRC, CZK, DKK, DOP, EUR, GBP, GEL, GTQ, HUF, ISK, JPY, KRW, MDL, MXN, MYR, NOK, PAB, PEN, PLN, PYG, RON, RSD, SEK, SGD, TWD, UAH, USD, UYU, VND, ZAR" }diff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.tomlindex 51913d85b4..7a063d3547 100644--- a/config/deployments/sandbox.toml+++ b/config/deployments/sandbox.toml@@ -754,6 +754,7 @@ sepa = { country = "ES,SK,AT,NL,DE,BE,FR,FI,PT,IE,EE,LT,LV,IT,GB", currency = "Eeps = { country = "AT", currency = "EUR" }ideal = { country = "NL", currency = "EUR" }przelewy24 = { country = "PL", currency = "PLN,EUR" }+klarna = { country = "DE,AT,NL,BE,FR,GB,IT,ES,PT,SE,DK,FI,NO,CH,IR,CZ,PL,GR,SK", currency = "EUR,GBP,DKK,SEK,NOK,CHF,PLN,CZK" }[pm_filters.amazonpay]amazon_pay = { country = "US", currency = "USD" }diff --git a/config/development.toml b/config/development.tomlindex b292d9e300..75f5aac40a 100644--- a/config/development.toml+++ b/config/development.toml@@ -837,6 +837,7 @@ interac = { currency = "CAD"}eps = { country = "AT", currency = "EUR" }ideal = { country = "NL", currency = "EUR" }przelewy24 = { country = "PL", currency = "PLN,EUR" }+klarna = { country = "DE,AT,NL,BE,FR,GB,IT,ES,PT,SE,DK,FI,NO,CH,IR,CZ,PL,GR,SK", currency = "EUR,GBP,DKK,SEK,NOK,CHF,PLN,CZK" }[pm_filters.redsys]credit = { currency = "AUD,BGN,CAD,CHF,COP,CZK,DKK,EUR,GBP,HRK,HUF,ILS,INR,JPY,MYR,NOK,NZD,PEN,PLN,RUB,SAR,SEK,SGD,THB,USD,ZAR", country="ES" }diff --git a/config/docker_compose.toml b/config/docker_compose.tomlindex 0e8d094ee7..6850466a84 100644--- a/config/docker_compose.toml+++ b/config/docker_compose.toml@@ -873,6 +873,7 @@ sepa = { country = "ES,SK,AT,NL,DE,BE,FR,FI,PT,IE,EE,LT,LV,IT,GB", currency = "Eeps = { country = "AT", currency = "EUR" }ideal = { country = "NL", currency = "EUR" }przelewy24 = { country = "PL", currency = "PLN,EUR" }+klarna = { country = "DE,AT,NL,BE,FR,GB,IT,ES,PT,SE,DK,FI,NO,CH,IR,CZ,PL,GR,SK", currency = "EUR,GBP,DKK,SEK,NOK,CHF,PLN,CZK" }[pm_filters.amazonpay]amazon_pay = { country = "US", currency = "USD" }diff --git a/crates/connector_configs/toml/development.toml b/crates/connector_configs/toml/development.tomlindex aba8a1363c..d251609003 100644--- a/crates/connector_configs/toml/development.toml+++ b/crates/connector_configs/toml/development.toml@@ -2908,6 +2908,8 @@ key1 = "Razorpay Secret"payment_method_type = "bancontact_card"[[mollie.wallet]]payment_method_type = "paypal"+[[mollie.pay_later]]+ payment_method_type = "klarna"[mollie.connector_auth.BodyKey]api_key="API Key"key1="Profile Token"diff --git a/crates/connector_configs/toml/production.toml b/crates/connector_configs/toml/production.tomlindex 339b1ec70b..330da3843d 100644--- a/crates/connector_configs/toml/production.toml+++ b/crates/connector_configs/toml/production.toml@@ -2525,6 +2525,8 @@ payment_method_type = "sofort"payment_method_type = "eps"[[mollie.wallet]]payment_method_type = "paypal"+[[mollie.pay_later]]+ payment_method_type = "klarna"[mollie.connector_auth.BodyKey]api_key = "API Key"key1 = "Profile Token"diff --git a/crates/connector_configs/toml/sandbox.toml b/crates/connector_configs/toml/sandbox.tomlindex a189add606..cf6f1cc568 100644--- a/crates/connector_configs/toml/sandbox.toml+++ b/crates/connector_configs/toml/sandbox.toml@@ -2885,6 +2885,8 @@ payment_method_type = "przelewy24"payment_method_type = "bancontact_card"[[mollie.wallet]]payment_method_type = "paypal"+[[mollie.pay_later]]+ payment_method_type = "klarna"[mollie.connector_auth.BodyKey]api_key = "API Key"key1 = "Profile Token"diff --git a/crates/hyperswitch_connectors/src/connectors/mollie.rs b/crates/hyperswitch_connectors/src/connectors/mollie.rsindex f82e55d545..03630fa8cb 100644--- a/crates/hyperswitch_connectors/src/connectors/mollie.rs+++ b/crates/hyperswitch_connectors/src/connectors/mollie.rs@@ -1027,6 +1027,16 @@ lazy_static! {specific_features: None,},);+ mollie_supported_payment_methods.add(+ enums::PaymentMethod::PayLater,+ enums::PaymentMethodType::Klarna,+ PaymentMethodDetails{+ mandates: common_enums::FeatureStatus::NotSupported,+ refunds: common_enums::FeatureStatus::Supported,+ supported_capture_methods: supported_capture_methods.clone(),+ specific_features: None,+ },+ );mollie_supported_payment_methods};diff --git a/crates/hyperswitch_connectors/src/connectors/mollie/transformers.rs b/crates/hyperswitch_connectors/src/connectors/mollie/transformers.rsindex 56756845ed..5391003cda 100644--- a/crates/hyperswitch_connectors/src/connectors/mollie/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/mollie/transformers.rs@@ -3,7 +3,9 @@ use common_enums::enums;use common_utils::{pii::Email, request::Method, types::StringMajorUnit};use error_stack::ResultExt;use hyperswitch_domain_models::{- payment_method_data::{BankDebitData, BankRedirectData, PaymentMethodData, WalletData},+ payment_method_data::{+ BankDebitData, BankRedirectData, PayLaterData, PaymentMethodData, WalletData,+ },router_data::{ConnectorAuthType, ErrorResponse, PaymentMethodToken, RouterData},router_request_types::ResponseId,router_response_types::{@@ -21,8 +23,9 @@ use crate::{types::{RefundsResponseRouterData, ResponseRouterData},unimplemented_payment_method,utils::{- get_unimplemented_payment_method_error_message, AddressDetailsData, BrowserInformationData,- CardData as CardDataUtil, CustomerData, PaymentMethodTokenizationRequestData,+ convert_amount, get_unimplemented_payment_method_error_message, AddressData,+ AddressDetailsData, BrowserInformationData, CardData as CardDataUtil, CustomerData,+ OrderDetailsWithAmountData, PaymentMethodTokenizationRequestData,PaymentsAuthorizeRequestData, PaymentsSetupMandateRequestData,RouterData as OtherRouterData,},@@ -82,6 +85,7 @@ pub enum MolliePaymentMethodData {Bancontact,CreditCard(Box<CreditCardMethodData>),DirectDebit(Box<DirectDebitMethodData>),+ Klarna(Box<KlarnaMethodData>),#[serde(untagged)]MandatePayment(Box<MandatePaymentMethodData>),}@@ -105,6 +109,83 @@ pub struct PaypalMethodData {shipping_address: Option<Address>,}+#[derive(Debug, Serialize)]+#[serde(rename_all = "camelCase")]+pub struct KlarnaMethodData {+ billing_address: Address,+ lines: Vec<MollieLinesItems>,+}++#[derive(Debug, Serialize)]+#[serde(rename_all = "camelCase")]+pub struct MollieLinesItems {+ description: String,+ quantity: i32,+ quantity_unit: Option<String>,+ unit_price: OrderItemUnitPrice,+ total_amount: OrderItemUnitPrice,+ discount_amount: Option<OrderItemUnitPrice>,+ sku: Option<String>,+ image_url: Option<String>,+}++impl TryFrom<(types::OrderDetailsWithAmount, enums::Currency)> for MollieLinesItems {+ type Error = Error;+ fn try_from(+ (order_details, currency): (types::OrderDetailsWithAmount, enums::Currency),+ ) -> Result<Self, Self::Error> {+ let description = order_details.get_order_description()?;+ let quantity = i32::from(order_details.get_order_quantity());+ let quantity_unit = order_details.get_optional_order_quantity_unit();+ let sku = order_details.get_optional_sku();+ let image_url = order_details.get_optional_product_img_link();+ let mollie_converter = super::Mollie::new().amount_converter;+ let unit_price_value = convert_amount(+ mollie_converter,+ order_details.get_order_unit_price(),+ currency,+ )?;++ let discount_amount_value = order_details+ .get_optional_unit_discount_amount()+ .map(|unit_discount_amount| {+ convert_amount(mollie_converter, unit_discount_amount, currency)+ })+ .transpose()?;++ let total_amount_value = convert_amount(+ mollie_converter,+ order_details.get_order_total_amount()?,+ currency,+ )?;++ Ok(Self {+ description,+ quantity,+ quantity_unit,+ unit_price: OrderItemUnitPrice {+ currency,+ value: unit_price_value,+ },+ total_amount: OrderItemUnitPrice {+ currency,+ value: total_amount_value,+ },+ discount_amount: discount_amount_value+ .map(|value| OrderItemUnitPrice { currency, value }),+ sku,+ image_url,+ })+ }+}++#[derive(Debug, Serialize)]+#[serde(rename_all = "camelCase")]+pub struct OrderItemUnitPrice {+ currency: enums::Currency,+ value: StringMajorUnit,+}+#[derive(Debug, Serialize)]#[serde(rename_all = "camelCase")]pub struct Przelewy24MethodData {@@ -149,6 +230,32 @@ pub struct Address {pub city: String,pub region: Option<Secret<String>>,pub country: api_models::enums::CountryAlpha2,+ pub given_name: Option<Secret<String>>,+ pub family_name: Option<Secret<String>>,+ pub email: Option<Email>,+}++impl Address {+ fn validate_and_build_klarna_billing_address(+ address_details: hyperswitch_domain_models::address::Address,+ ) -> Result<Self, Error> {+ let address = address_details.address.clone().ok_or(+ errors::ConnectorError::MissingRequiredField {+ field_name: "Billing Address details for Klarna",+ },+ )?;++ Ok(Self {+ street_and_number: address.get_combined_address_line()?,+ postal_code: address.get_zip()?.to_owned(),+ city: address.get_city()?.to_owned(),+ region: address.get_optional_state(),+ country: address.get_country()?.to_owned(),+ given_name: Some(address.get_first_name()?.clone()),+ family_name: Some(address.get_last_name()?.clone()),+ email: Some(address_details.get_email()?.clone()),+ })+ }}#[derive(Debug, Serialize, Deserialize)]@@ -245,11 +352,11 @@ impl TryFrom<&MollieRouterData<&types::SetupMandateRouterData>> for MolliePaymen| PaymentMethodData::NetworkTokenDetailsForNetworkTransactionId(_)| PaymentMethodData::CardWithLimitedDetails(_)| PaymentMethodData::CardRedirect(_)- | PaymentMethodData::PayLater(_)| PaymentMethodData::BankTransfer(_)| PaymentMethodData::Crypto(_)| PaymentMethodData::Reward| PaymentMethodData::RealTimePayment(_)+ | PaymentMethodData::PayLater(_)| PaymentMethodData::Upi(_)| PaymentMethodData::Voucher(_)| PaymentMethodData::GiftCard(_)@@ -348,6 +455,9 @@ impl TryFrom<&MollieRouterData<&types::PaymentsAuthorizeRouterData>> for MollieP},)))}+ PaymentMethodData::PayLater(ref paylater_data) => {+ MolliePaymentMethodData::try_from((item.router_data, paylater_data))+ }PaymentMethodData::BankRedirect(ref redirect_data) => {MolliePaymentMethodData::try_from((item.router_data, redirect_data))}@@ -384,6 +494,36 @@ impl TryFrom<&MollieRouterData<&types::PaymentsAuthorizeRouterData>> for MollieP}}+impl TryFrom<(&types::PaymentsAuthorizeRouterData, &PayLaterData)> for MolliePaymentMethodData {+ type Error = Error;+ fn try_from(+ (item, value): (&types::PaymentsAuthorizeRouterData, &PayLaterData),+ ) -> Result<Self, Self::Error> {+ match value {+ PayLaterData::KlarnaRedirect {} => {+ let billing_address = Address::validate_and_build_klarna_billing_address(+ item.get_billing()?.clone(),+ )?;++ let lines = item+ .request+ .get_order_details()?+ .into_iter()+ .map(|order_detail| {+ MollieLinesItems::try_from((order_detail, item.request.currency))+ })+ .collect::<Result<Vec<MollieLinesItems>, Error>>()?;++ Ok(Self::Klarna(Box::new(KlarnaMethodData {+ billing_address,+ lines,+ })))+ }+ _ => Err(errors::ConnectorError::NotImplemented("Payment method".to_string()).into()),+ }+ }+}+impl TryFrom<(&types::PaymentsAuthorizeRouterData, &BankRedirectData)> for MolliePaymentMethodData {type Error = Error;fn try_from(@@ -534,12 +674,17 @@ fn get_address_details(let city = address.get_city()?.to_owned();let region = None;let country = address.get_country()?.to_owned();+ let given_name = address.get_optional_first_name();+ let family_name = address.get_optional_last_name();Some(Address {street_and_number,postal_code,city,region,country,+ given_name,+ family_name,+ email: None,})}None => None,diff --git a/crates/hyperswitch_connectors/src/utils.rs b/crates/hyperswitch_connectors/src/utils.rsindex efbfdc572d..d3abcffba7 100644--- a/crates/hyperswitch_connectors/src/utils.rs+++ b/crates/hyperswitch_connectors/src/utils.rs@@ -3183,6 +3183,47 @@ impl CryptoData for payment_method_data::CryptoData {}}+pub trait OrderDetailsWithAmountData {+ fn get_order_description(&self) -> Result<String, Error>;+ fn get_order_quantity(&self) -> u16;+ fn get_optional_order_quantity_unit(&self) -> Option<String>;+ fn get_order_total_amount(&self) -> Result<MinorUnit, Error>;+ fn get_optional_unit_discount_amount(&self) -> Option<MinorUnit>;+ fn get_optional_sku(&self) -> Option<String>;+ fn get_optional_product_img_link(&self) -> Option<String>;+ fn get_order_unit_price(&self) -> MinorUnit;+}++impl OrderDetailsWithAmountData for OrderDetailsWithAmount {+ fn get_order_description(&self) -> Result<String, Error> {+ self.description+ .clone()+ .ok_or_else(missing_field_err("order_details.description"))+ }+ fn get_order_quantity(&self) -> u16 {+ self.quantity+ }+ fn get_optional_order_quantity_unit(&self) -> Option<String> {+ self.unit_of_measure.clone()+ }+ fn get_order_unit_price(&self) -> MinorUnit {+ self.amount+ }+ fn get_order_total_amount(&self) -> Result<MinorUnit, Error> {+ self.total_amount+ .ok_or_else(missing_field_err("order_details.total_amount"))+ }+ fn get_optional_unit_discount_amount(&self) -> Option<MinorUnit> {+ self.unit_discount_amount+ }+ fn get_optional_sku(&self) -> Option<String> {+ self.sku.clone()+ }+ fn get_optional_product_img_link(&self) -> Option<String> {+ self.product_img_link.clone()+ }+}+#[macro_export]macro_rules! capture_method_not_supported {($connector:expr, $capture_method:expr) => {diff --git a/crates/payment_methods/src/configs/payment_connector_required_fields.rs b/crates/payment_methods/src/configs/payment_connector_required_fields.rsindex 5089eb724e..43eb46154d 100644--- a/crates/payment_methods/src/configs/payment_connector_required_fields.rs+++ b/crates/payment_methods/src/configs/payment_connector_required_fields.rs@@ -3056,6 +3056,25 @@ fn get_pay_later_required_fields() -> HashMap<enums::PaymentMethodType, Connectocommon: HashMap::new(),},),+ (+ Connector::Mollie,+ fields(+ vec![],+ vec![+ RequiredField::BillingAddressCountries(vec![+ "DE", "AT", "NL", "BE", "FR", "UK", "IT", "ES", "PT", "SE", "DK",+ "FI", "NO", "CH", "IR", "CZ", "PL", "GR", "SK",+ ]),+ RequiredField::BillingEmail,+ RequiredField::BillingAddressLine1,+ RequiredField::BillingAddressZip,+ RequiredField::BillingAddressCity,+ RequiredField::BillingUserFirstName,+ RequiredField::BillingUserLastName,+ ],+ vec![],+ ),+ ),]),),(diff --git a/loadtest/config/development.toml b/loadtest/config/development.tomlindex 4c02a03a66..ed2df4fcef 100644--- a/loadtest/config/development.toml+++ b/loadtest/config/development.toml@@ -377,6 +377,7 @@ paze = { currency = "USD,SEK" }eps = { country = "AT", currency = "EUR" }ideal = { country = "NL", currency = "EUR" }przelewy24 = { country = "PL", currency = "PLN,EUR" }+klarna = { country = "DE,AT,NL,BE,FR,GB,IT,ES,PT,SE,DK,FI,NO,CH,IR,CZ,PL,GR,SK", currency = "EUR,GBP,DKK,SEK,NOK,CHF,PLN,CZK" }[pm_filters.mifinity]mifinity = { country = "BR,CN,SG,MY,DE,CH,DK,GB,ES,AD,GI,FI,FR,GR,HR,IT,JP,MX,AR,CO,CL,PE,VE,UY,PY,BO,EC,GT,HN,SV,NI,CR,PA,DO,CU,PR,NL,NO,PL,PT,SE,RU,TR,TW,HK,MO,AX,AL,DZ,AS,AO,AI,AG,AM,AW,AU,AT,AZ,BS,BH,BD,BB,BE,BZ,BJ,BM,BT,BQ,BA,BW,IO,BN,BG,BF,BI,KH,CM,CA,CV,KY,CF,TD,CX,CC,KM,CG,CK,CI,CW,CY,CZ,DJ,DM,EG,GQ,ER,EE,ET,FK,FO,FJ,GF,PF,TF,GA,GM,GE,GH,GL,GD,GP,GU,GG,GN,GW,GY,HT,HM,VA,IS,IN,ID,IE,IM,IL,JE,JO,KZ,KE,KI,KW,KG,LA,LV,LB,LS,LI,LT,LU,MK,MG,MW,MV,ML,MT,MH,MQ,MR,MU,YT,FM,MD,MC,MN,ME,MS,MA,MZ,NA,NR,NP,NC,NZ,NE,NG,NU,NF,MP,OM,PK,PW,PS,PG,PH,PN,QA,RE,RO,RW,BL,SH,KN,LC,MF,PM,VC,WS,SM,ST,SA,SN,RS,SC,SL,SX,SK,SI,SB,SO,ZA,GS,KR,LK,SR,SJ,SZ,TH,TL,TG,TK,TO,TT,TN,TM,TC,TV,UG,UA,AE,UZ,VU,VN,VG,VI,WF,EH,ZM", currency = "AUD,CAD,CHF,CNY,CZK,DKK,EUR,GBP,INR,JPY,NOK,NZD,PLN,RUB,SEK,ZAR,USD,EGP,UYU,UZS" }