diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index fd1286a555ea..f33bc916a117 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -507,6 +507,9 @@ pub struct PaymentsRequest { // Makes the field mandatory in PaymentsCreateRequest pub amount: Option, + #[schema(value_type = Option, example = 6540)] + pub order_tax_amount: Option, + /// The three letter ISO currency code in uppercase. Eg: 'USD' to charge US Dollars #[schema(example = "USD", value_type = Option)] #[mandatory_in(PaymentsCreateRequest = Currency)] @@ -1603,6 +1606,7 @@ pub enum PayLaterData { /// The token for the sdk workflow token: String, }, + KlarnaCheckout {}, /// For Affirm redirect as PayLater Option AffirmRedirect {}, /// For AfterpayClearpay redirect as PayLater Option @@ -1660,6 +1664,8 @@ impl GetAddressFromPaymentMethodData for PayLaterData { | Self::WalleyRedirect {} | Self::AlmaRedirect {} | Self::KlarnaSdk { .. } + | Self::KlarnaCheckout {} + | Self::AffirmRedirect {} | Self::AtomeRedirect {} => None, } @@ -2089,6 +2095,8 @@ impl GetPaymentMethodType for PayLaterData { match self { Self::KlarnaRedirect { .. } => api_enums::PaymentMethodType::Klarna, Self::KlarnaSdk { .. } => api_enums::PaymentMethodType::Klarna, + Self::KlarnaCheckout { .. } => api_enums::PaymentMethodType::KlarnaCheckout, + Self::AffirmRedirect {} => api_enums::PaymentMethodType::Affirm, Self::AfterpayClearpayRedirect { .. } => api_enums::PaymentMethodType::AfterpayClearpay, Self::PayBrightRedirect {} => api_enums::PaymentMethodType::PayBright, @@ -2296,6 +2304,7 @@ pub enum AdditionalPaymentData { }, PayLater { klarna_sdk: Option, + klarna_checkout: Option, }, BankTransfer { #[serde(flatten)] @@ -2347,6 +2356,12 @@ pub struct KlarnaSdkPaymentMethod { pub payment_type: Option, } +#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)] + +pub struct KlarnaCheckoutPaymentMethod { + pub payment_type: Option, +} + #[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)] #[serde(rename_all = "snake_case")] pub enum BankRedirectData { @@ -3526,6 +3541,8 @@ pub struct VoucherResponse { #[derive(Eq, PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)] pub struct PaylaterResponse { klarna_sdk: Option, + klarna_checkout: Option, + } #[derive(Eq, PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)] @@ -3549,6 +3566,12 @@ pub struct KlarnaSdkPaymentMethodResponse { pub payment_type: Option, } +#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)] + +pub struct KlarnaCheckoutPaymentMethodResponse { + pub payment_type: Option, +} + #[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, ToSchema, serde::Serialize)] pub struct PaymentMethodDataResponseWithBilling { // The struct is flattened in order to provide backwards compatibility @@ -4792,6 +4815,18 @@ impl From for PaylaterResponse { klarna_sdk: Some(KlarnaSdkPaymentMethodResponse { payment_type: klarna_sdk.payment_type, }), + klarna_checkout: None, + } + } +} + +impl From for PaylaterResponse { + fn from(klarna_checkout: KlarnaCheckoutPaymentMethod) -> Self { + Self { + klarna_checkout: Some(KlarnaCheckoutPaymentMethodResponse { + payment_type: klarna_checkout.payment_type, + }), + klarna_sdk: None, } } } @@ -4800,9 +4835,13 @@ impl From for PaymentMethodDataResponse { fn from(payment_method_data: AdditionalPaymentData) -> Self { match payment_method_data { AdditionalPaymentData::Card(card) => Self::Card(Box::new(CardResponse::from(*card))), - AdditionalPaymentData::PayLater { klarna_sdk } => match klarna_sdk { - Some(sdk) => Self::PayLater(Box::new(PaylaterResponse::from(sdk))), - None => Self::PayLater(Box::new(PaylaterResponse { klarna_sdk: None })), + AdditionalPaymentData::PayLater { klarna_sdk, + klarna_checkout + } => + match (klarna_sdk, klarna_checkout) { + (Some(sdk),_) => Self::PayLater(Box::new(PaylaterResponse::from(sdk))), + (_,Some(checkout)) => Self::PayLater(Box::new(PaylaterResponse::from(checkout))), + (None,None) => Self::PayLater(Box::new(PaylaterResponse { klarna_sdk: None, klarna_checkout: None })), }, AdditionalPaymentData::Wallet { apple_pay, @@ -4929,6 +4968,10 @@ pub struct OrderDetailsWithAmount { pub quantity: u16, /// the amount per quantity of product pub amount: i64, + + pub tax_rate: Option, + pub total_tax_amount: Option, + // pub total_amount:Option, // Does the order includes shipping pub requires_shipping: Option, /// The image URL of the product @@ -4945,6 +4988,7 @@ pub struct OrderDetailsWithAmount { pub product_type: Option, /// The tax code for the product pub product_tax_code: Option, + } impl masking::SerializableSecret for OrderDetailsWithAmount {} @@ -4969,6 +5013,10 @@ pub struct OrderDetails { /// The quantity of the product to be purchased #[schema(example = 1)] pub quantity: u16, + pub tax_rate:Option, + pub total_tax_amount:Option, + // pub total_amount:Option, + // Does the order include shipping pub requires_shipping: Option, /// The image URL of the product diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index e36a6d74994e..1ce30b473419 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -1630,6 +1630,7 @@ pub enum PaymentMethodType { Interac, Indomaret, Klarna, + KlarnaCheckout, KakaoPay, LocalBankRedirect, MandiriVa, diff --git a/crates/common_enums/src/transformers.rs b/crates/common_enums/src/transformers.rs index 4fba749ef637..fe7f8a97c13f 100644 --- a/crates/common_enums/src/transformers.rs +++ b/crates/common_enums/src/transformers.rs @@ -1826,6 +1826,7 @@ impl From for PaymentMethod { PaymentMethodType::Mifinity => Self::Wallet, PaymentMethodType::Ideal => Self::BankRedirect, PaymentMethodType::Klarna => Self::PayLater, + PaymentMethodType::KlarnaCheckout => Self::PayLater, PaymentMethodType::KakaoPay => Self::Wallet, PaymentMethodType::Knet => Self::CardRedirect, PaymentMethodType::LocalBankRedirect => Self::BankRedirect, diff --git a/crates/euclid/src/frontend/dir.rs b/crates/euclid/src/frontend/dir.rs index 9a7134e708a7..2d708e9ae851 100644 --- a/crates/euclid/src/frontend/dir.rs +++ b/crates/euclid/src/frontend/dir.rs @@ -817,6 +817,7 @@ mod test { dirval!(CardType = Credit), dirval!(CardNetwork = Visa), dirval!(PayLaterType = Klarna), + dirval!(PayLaterType = KlarnaCheckout), dirval!(WalletType = Paypal), dirval!(BankRedirectType = Sofort), dirval!(BankDebitType = Bacs), diff --git a/crates/euclid/src/frontend/dir/enums.rs b/crates/euclid/src/frontend/dir/enums.rs index 136cdf4d9817..786d12af6dfe 100644 --- a/crates/euclid/src/frontend/dir/enums.rs +++ b/crates/euclid/src/frontend/dir/enums.rs @@ -49,6 +49,7 @@ pub enum PayLaterType { AfterpayClearpay, Alma, Klarna, + KlarnaCheckout, PayBright, Walley, Atome, diff --git a/crates/euclid/src/frontend/dir/lowering.rs b/crates/euclid/src/frontend/dir/lowering.rs index da589ec3748e..a45bd72bc9f9 100644 --- a/crates/euclid/src/frontend/dir/lowering.rs +++ b/crates/euclid/src/frontend/dir/lowering.rs @@ -27,6 +27,7 @@ impl From for global_enums::PaymentMethodType { enums::PayLaterType::AfterpayClearpay => Self::AfterpayClearpay, enums::PayLaterType::Alma => Self::Alma, enums::PayLaterType::Klarna => Self::Klarna, + enums::PayLaterType::KlarnaCheckout => Self::KlarnaCheckout, enums::PayLaterType::PayBright => Self::PayBright, enums::PayLaterType::Walley => Self::Walley, enums::PayLaterType::Atome => Self::Atome, diff --git a/crates/euclid/src/frontend/dir/transformers.rs b/crates/euclid/src/frontend/dir/transformers.rs index de0b619b1203..913979f8293b 100644 --- a/crates/euclid/src/frontend/dir/transformers.rs +++ b/crates/euclid/src/frontend/dir/transformers.rs @@ -15,6 +15,7 @@ impl IntoDirValue for (global_enums::PaymentMethodType, global_enums::PaymentMet global_enums::PaymentMethodType::Eps => Ok(dirval!(BankRedirectType = Eps)), global_enums::PaymentMethodType::Fps => Ok(dirval!(RealTimePaymentType = Fps)), global_enums::PaymentMethodType::Klarna => Ok(dirval!(PayLaterType = Klarna)), + global_enums::PaymentMethodType::KlarnaCheckout => Ok(dirval!(PayLaterType = KlarnaCheckout)), global_enums::PaymentMethodType::Affirm => Ok(dirval!(PayLaterType = Affirm)), global_enums::PaymentMethodType::AfterpayClearpay => { Ok(dirval!(PayLaterType = AfterpayClearpay)) diff --git a/crates/hyperswitch_connectors/src/connectors/square/transformers.rs b/crates/hyperswitch_connectors/src/connectors/square/transformers.rs index b2151c524be9..9a2ffe130f61 100644 --- a/crates/hyperswitch_connectors/src/connectors/square/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/square/transformers.rs @@ -85,6 +85,7 @@ impl TryFrom<(&types::TokenizationRouterData, PayLaterData)> for SquareTokenRequ PayLaterData::AfterpayClearpayRedirect { .. } | PayLaterData::KlarnaRedirect { .. } | PayLaterData::KlarnaSdk { .. } + | PayLaterData::KlarnaCheckout {} | PayLaterData::AffirmRedirect { .. } | PayLaterData::PayBrightRedirect { .. } | PayLaterData::WalleyRedirect { .. } diff --git a/crates/hyperswitch_connectors/src/utils.rs b/crates/hyperswitch_connectors/src/utils.rs index 0134253f2f95..14911f065c27 100644 --- a/crates/hyperswitch_connectors/src/utils.rs +++ b/crates/hyperswitch_connectors/src/utils.rs @@ -1792,6 +1792,7 @@ pub enum PaymentMethodDataType { SwishQr, KlarnaRedirect, KlarnaSdk, + KlarnaCheckout, AffirmRedirect, AfterpayClearpayRedirect, PayBrightRedirect, @@ -1915,6 +1916,7 @@ impl From for PaymentMethodDataType { PaymentMethodData::PayLater(pay_later_data) => match pay_later_data { hyperswitch_domain_models::payment_method_data::PayLaterData::KlarnaRedirect { .. } => Self::KlarnaRedirect, hyperswitch_domain_models::payment_method_data::PayLaterData::KlarnaSdk { .. } => Self::KlarnaSdk, + hyperswitch_domain_models::payment_method_data::PayLaterData::KlarnaCheckout { .. } => Self::KlarnaCheckout, hyperswitch_domain_models::payment_method_data::PayLaterData::AffirmRedirect {} => Self::AffirmRedirect, hyperswitch_domain_models::payment_method_data::PayLaterData::AfterpayClearpayRedirect { .. } => { Self::AfterpayClearpayRedirect diff --git a/crates/hyperswitch_domain_models/src/payment_method_data.rs b/crates/hyperswitch_domain_models/src/payment_method_data.rs index e5f5fad99011..add8a340d576 100644 --- a/crates/hyperswitch_domain_models/src/payment_method_data.rs +++ b/crates/hyperswitch_domain_models/src/payment_method_data.rs @@ -150,6 +150,7 @@ pub enum CardRedirectData { pub enum PayLaterData { KlarnaRedirect {}, KlarnaSdk { token: String }, + KlarnaCheckout {}, AffirmRedirect {}, AfterpayClearpayRedirect {}, PayBrightRedirect {}, @@ -881,6 +882,7 @@ impl From for PayLaterData { match value { api_models::payments::PayLaterData::KlarnaRedirect { .. } => Self::KlarnaRedirect {}, api_models::payments::PayLaterData::KlarnaSdk { token } => Self::KlarnaSdk { token }, + api_models::payments::PayLaterData::KlarnaCheckout { .. } => Self::KlarnaCheckout {}, api_models::payments::PayLaterData::AffirmRedirect {} => Self::AffirmRedirect {}, api_models::payments::PayLaterData::AfterpayClearpayRedirect { .. } => { Self::AfterpayClearpayRedirect {} @@ -1512,6 +1514,7 @@ impl GetPaymentMethodType for PayLaterData { match self { Self::KlarnaRedirect { .. } => api_enums::PaymentMethodType::Klarna, Self::KlarnaSdk { .. } => api_enums::PaymentMethodType::Klarna, + Self::KlarnaCheckout { } => api_enums::PaymentMethodType::KlarnaCheckout, Self::AffirmRedirect {} => api_enums::PaymentMethodType::Affirm, Self::AfterpayClearpayRedirect { .. } => api_enums::PaymentMethodType::AfterpayClearpay, Self::PayBrightRedirect {} => api_enums::PaymentMethodType::PayBright, diff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rs index b41b42eaa2d2..d282adcc8178 100644 --- a/crates/hyperswitch_domain_models/src/router_data.rs +++ b/crates/hyperswitch_domain_models/src/router_data.rs @@ -344,6 +344,8 @@ pub enum AdditionalPaymentMethodConnectorResponse { }, PayLater { klarna_sdk: Option, + klarna_checkout: Option, + }, } @@ -352,6 +354,11 @@ pub struct KlarnaSdkResponse { pub payment_type: Option, } +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +pub struct KlarnaCheckoutResponse { + pub payment_type: Option, +} + #[derive(Clone, Debug, serde::Serialize)] pub struct ErrorResponse { pub code: String, diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rs index fb4c0fd08002..7e1a7bf311ab 100644 --- a/crates/hyperswitch_domain_models/src/router_request_types.rs +++ b/crates/hyperswitch_domain_models/src/router_request_types.rs @@ -70,6 +70,7 @@ pub struct PaymentsAuthorizeData { /// if the connector provides support to accept multiple reference ids. /// In case the connector supports only one reference id, Hyperswitch's Payment ID will be sent as reference. pub merchant_order_reference_id: Option, + // pub merchant_urls: Option, pub integrity_object: Option, } @@ -92,6 +93,14 @@ pub struct AuthoriseIntegrityObject { pub currency: storage_enums::Currency, } +// #[derive(Debug, Clone, PartialEq)] +// pub struct MerchantURLs { +// pub terms: String, +// pub checkout: String, +// pub confirmation: String, +// pub push: String, +// } + #[derive(Debug, Clone, PartialEq)] pub struct SyncIntegrityObject { /// Sync amount diff --git a/crates/kgraph_utils/src/mca.rs b/crates/kgraph_utils/src/mca.rs index e897292d6ff1..7325e9ad7c21 100644 --- a/crates/kgraph_utils/src/mca.rs +++ b/crates/kgraph_utils/src/mca.rs @@ -27,6 +27,7 @@ fn get_dir_value_payment_method( api_enums::PaymentMethodType::Sofort => Ok(dirval!(BankRedirectType = Sofort)), api_enums::PaymentMethodType::Eps => Ok(dirval!(BankRedirectType = Eps)), api_enums::PaymentMethodType::Klarna => Ok(dirval!(PayLaterType = Klarna)), + api_enums::PaymentMethodType::KlarnaCheckout => Ok(dirval!(PayLaterType = KlarnaCheckout)), api_enums::PaymentMethodType::Affirm => Ok(dirval!(PayLaterType = Affirm)), api_enums::PaymentMethodType::AfterpayClearpay => { Ok(dirval!(PayLaterType = AfterpayClearpay)) diff --git a/crates/kgraph_utils/src/transformers.rs b/crates/kgraph_utils/src/transformers.rs index 3aaeb0586d63..cde847e1f5f6 100644 --- a/crates/kgraph_utils/src/transformers.rs +++ b/crates/kgraph_utils/src/transformers.rs @@ -136,6 +136,7 @@ impl IntoDirValue for (api_enums::PaymentMethodType, api_enums::PaymentMethod) { api_enums::PaymentMethodType::Sofort => Ok(dirval!(BankRedirectType = Sofort)), api_enums::PaymentMethodType::Eps => Ok(dirval!(BankRedirectType = Eps)), api_enums::PaymentMethodType::Klarna => Ok(dirval!(PayLaterType = Klarna)), + api_enums::PaymentMethodType::KlarnaCheckout => Ok(dirval!(PayLaterType = Klarna)), api_enums::PaymentMethodType::Affirm => Ok(dirval!(PayLaterType = Affirm)), api_enums::PaymentMethodType::AfterpayClearpay => { Ok(dirval!(PayLaterType = AfterpayClearpay)) diff --git a/crates/router/src/connector/adyen.rs b/crates/router/src/connector/adyen.rs index e5215022e944..8fc332e40df6 100644 --- a/crates/router/src/connector/adyen.rs +++ b/crates/router/src/connector/adyen.rs @@ -135,6 +135,7 @@ impl ConnectorValidation for Adyen { | PaymentMethodType::Bacs | PaymentMethodType::Givex | PaymentMethodType::Klarna + | PaymentMethodType::KlarnaCheckout | PaymentMethodType::Twint | PaymentMethodType::Walley => match capture_method { enums::CaptureMethod::Automatic | enums::CaptureMethod::Manual => Ok(()), diff --git a/crates/router/src/connector/adyen/transformers.rs b/crates/router/src/connector/adyen/transformers.rs index ca13e57e401f..a6d141085da7 100644 --- a/crates/router/src/connector/adyen/transformers.rs +++ b/crates/router/src/connector/adyen/transformers.rs @@ -2218,6 +2218,12 @@ impl<'a> Ok(AdyenPaymentMethod::AdyenKlarna(Box::new(klarna))) } + domain::payments::PayLaterData::KlarnaCheckout { .. } => { + Err(errors::ConnectorError::NotImplemented( + utils::get_unimplemented_payment_method_error_message("Adyen"), + ) + .into()) + } domain::payments::PayLaterData::AffirmRedirect { .. } => { check_required_field(shopper_email, "email")?; check_required_field(shopper_name, "billing.first_name, billing.last_name")?; diff --git a/crates/router/src/connector/klarna.rs b/crates/router/src/connector/klarna.rs index 0c362d26edfe..f7a2c2a822ad 100644 --- a/crates/router/src/connector/klarna.rs +++ b/crates/router/src/connector/klarna.rs @@ -494,10 +494,13 @@ impl req: &types::PaymentsAuthorizeRouterData, connectors: &settings::Connectors, ) -> CustomResult)>, errors::ConnectorError> { + println!("in klarna set headers "); self.build_headers(req, connectors) } fn get_content_type(&self) -> &'static str { + println!("in klarna get content type "); + self.common_get_content_type() } @@ -506,6 +509,8 @@ impl req: &types::PaymentsAuthorizeRouterData, connectors: &settings::Connectors, ) -> CustomResult { + println!("in klarna get url "); + let payment_method_data = &req.request.payment_method_data; let payment_experience = req .request @@ -520,15 +525,23 @@ impl let endpoint = build_region_specific_endpoint(self.base_url(connectors), &req.connector_meta_data)?; + println! ("payment_method_data : {:?} ", payment_method_data); + println! ("payment_experience : {:?} ", payment_experience); + println! ("payment_method_type : {:?} ", payment_method_type); + + match payment_method_data { domain::PaymentMethodData::PayLater(domain::PayLaterData::KlarnaSdk { token }) => { match (payment_experience, payment_method_type) { ( common_enums::PaymentExperience::InvokeSdkClient, common_enums::PaymentMethodType::Klarna, - ) => Ok(format!( + ) => { + println!("klarna SDK endpoint hit"); + + Ok(format!( "{endpoint}payments/v1/authorizations/{token}/order", - )), + ))}, ( common_enums::PaymentExperience::DisplayQrCode | common_enums::PaymentExperience::DisplayWaitScreen @@ -577,6 +590,7 @@ impl | common_enums::PaymentMethodType::Interac | common_enums::PaymentMethodType::Indomaret | common_enums::PaymentMethodType::Klarna + | common_enums::PaymentMethodType::KlarnaCheckout | common_enums::PaymentMethodType::KakaoPay | common_enums::PaymentMethodType::MandiriVa | common_enums::PaymentMethodType::Knet @@ -638,6 +652,130 @@ impl } } + domain::PaymentMethodData::PayLater(domain::PayLaterData::KlarnaCheckout {}) => { + println!("inside klarna Checkout endpoint"); + + match (payment_experience, payment_method_type) { + ( + common_enums::PaymentExperience::InvokeSdkClient, + common_enums::PaymentMethodType::KlarnaCheckout, + ) => { + println!("klarna Checkout endpoint hit"); + + Ok(format!( + "https://api.playground.klarna.com/checkout/v3/orders", + ))}, + ( + common_enums::PaymentExperience::DisplayQrCode + | common_enums::PaymentExperience::DisplayWaitScreen + | common_enums::PaymentExperience::InvokePaymentApp + | common_enums::PaymentExperience::InvokeSdkClient + | common_enums::PaymentExperience::LinkWallet + | common_enums::PaymentExperience::OneClick + | common_enums::PaymentExperience::RedirectToUrl, + common_enums::PaymentMethodType::Ach + | common_enums::PaymentMethodType::Affirm + | common_enums::PaymentMethodType::AfterpayClearpay + | common_enums::PaymentMethodType::Alfamart + | common_enums::PaymentMethodType::AliPay + | common_enums::PaymentMethodType::AliPayHk + | common_enums::PaymentMethodType::Alma + | common_enums::PaymentMethodType::ApplePay + | common_enums::PaymentMethodType::Atome + | common_enums::PaymentMethodType::Bacs + | common_enums::PaymentMethodType::BancontactCard + | common_enums::PaymentMethodType::Becs + | common_enums::PaymentMethodType::Benefit + | common_enums::PaymentMethodType::Bizum + | common_enums::PaymentMethodType::Blik + | common_enums::PaymentMethodType::Boleto + | common_enums::PaymentMethodType::BcaBankTransfer + | common_enums::PaymentMethodType::BniVa + | common_enums::PaymentMethodType::BriVa + | common_enums::PaymentMethodType::CardRedirect + | common_enums::PaymentMethodType::CimbVa + | common_enums::PaymentMethodType::ClassicReward + | common_enums::PaymentMethodType::Credit + | common_enums::PaymentMethodType::CryptoCurrency + | common_enums::PaymentMethodType::Cashapp + | common_enums::PaymentMethodType::Dana + | common_enums::PaymentMethodType::DanamonVa + | common_enums::PaymentMethodType::Debit + | common_enums::PaymentMethodType::Efecty + | common_enums::PaymentMethodType::Eps + | common_enums::PaymentMethodType::Evoucher + | common_enums::PaymentMethodType::Giropay + | common_enums::PaymentMethodType::Givex + | common_enums::PaymentMethodType::GooglePay + | common_enums::PaymentMethodType::GoPay + | common_enums::PaymentMethodType::Gcash + | common_enums::PaymentMethodType::Ideal + | common_enums::PaymentMethodType::Interac + | common_enums::PaymentMethodType::Indomaret + | common_enums::PaymentMethodType::Klarna + | common_enums::PaymentMethodType::KlarnaCheckout + | common_enums::PaymentMethodType::KakaoPay + | common_enums::PaymentMethodType::MandiriVa + | common_enums::PaymentMethodType::Knet + | common_enums::PaymentMethodType::MbWay + | common_enums::PaymentMethodType::MobilePay + | common_enums::PaymentMethodType::Momo + | common_enums::PaymentMethodType::MomoAtm + | common_enums::PaymentMethodType::Multibanco + | common_enums::PaymentMethodType::LocalBankRedirect + | common_enums::PaymentMethodType::OnlineBankingThailand + | common_enums::PaymentMethodType::OnlineBankingCzechRepublic + | common_enums::PaymentMethodType::OnlineBankingFinland + | common_enums::PaymentMethodType::OnlineBankingFpx + | common_enums::PaymentMethodType::OnlineBankingPoland + | common_enums::PaymentMethodType::OnlineBankingSlovakia + | common_enums::PaymentMethodType::Oxxo + | common_enums::PaymentMethodType::PagoEfectivo + | common_enums::PaymentMethodType::PermataBankTransfer + | common_enums::PaymentMethodType::OpenBankingUk + | common_enums::PaymentMethodType::PayBright + | common_enums::PaymentMethodType::Paypal + | common_enums::PaymentMethodType::Paze + | common_enums::PaymentMethodType::Pix + | common_enums::PaymentMethodType::PaySafeCard + | common_enums::PaymentMethodType::Przelewy24 + | common_enums::PaymentMethodType::Pse + | common_enums::PaymentMethodType::RedCompra + | common_enums::PaymentMethodType::RedPagos + | common_enums::PaymentMethodType::SamsungPay + | common_enums::PaymentMethodType::Sepa + | common_enums::PaymentMethodType::Sofort + | common_enums::PaymentMethodType::Swish + | common_enums::PaymentMethodType::TouchNGo + | common_enums::PaymentMethodType::Trustly + | common_enums::PaymentMethodType::Twint + | common_enums::PaymentMethodType::UpiCollect + | common_enums::PaymentMethodType::UpiIntent + | common_enums::PaymentMethodType::Venmo + | common_enums::PaymentMethodType::Vipps + | common_enums::PaymentMethodType::Walley + | common_enums::PaymentMethodType::WeChatPay + | common_enums::PaymentMethodType::SevenEleven + | common_enums::PaymentMethodType::Lawson + | common_enums::PaymentMethodType::LocalBankTransfer + | common_enums::PaymentMethodType::MiniStop + | common_enums::PaymentMethodType::FamilyMart + | common_enums::PaymentMethodType::Seicomart + | common_enums::PaymentMethodType::PayEasy + | common_enums::PaymentMethodType::Mifinity + | common_enums::PaymentMethodType::Fps + | common_enums::PaymentMethodType::DuitNow + | common_enums::PaymentMethodType::PromptPay + | common_enums::PaymentMethodType::VietQr + | common_enums::PaymentMethodType::OpenBankingPIS, + ) => Err(error_stack::report!(errors::ConnectorError::NotSupported { + message: payment_method_type.to_string(), + connector: "klarna", + })), + } + } + + domain::PaymentMethodData::Card(_) | domain::PaymentMethodData::CardRedirect(_) | domain::PaymentMethodData::Wallet(_) @@ -670,6 +808,8 @@ impl req: &types::PaymentsAuthorizeRouterData, _connectors: &settings::Connectors, ) -> CustomResult { + println!("in klarna get request body "); + let connector_router_data = klarna::KlarnaRouterData::try_from(( &self.get_currency_unit(), req.request.currency, @@ -677,6 +817,7 @@ impl req, ))?; let connector_req = klarna::KlarnaPaymentsRequest::try_from(&connector_router_data)?; + println!("in klarna get request body {:?}",connector_req); Ok(RequestContent::Json(Box::new(connector_req))) } @@ -686,6 +827,8 @@ impl req: &types::PaymentsAuthorizeRouterData, connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { + println!("in klarna build request "); + Ok(Some( services::RequestBuilder::new() .method(services::Method::Post) @@ -713,7 +856,10 @@ impl .response .parse_struct("KlarnaPaymentsResponse") .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; + println!("in handle response of klarna "); + println!("{:?}",response); + event_builder.map(|i| i.set_response_body(&response)); router_env::logger::info!(connector_response=?response); @@ -730,6 +876,8 @@ impl res: Response, event_builder: Option<&mut ConnectorEvent>, ) -> CustomResult { + println!("in klarna error response "); + self.build_error_response(res, event_builder) } } diff --git a/crates/router/src/connector/klarna/transformers.rs b/crates/router/src/connector/klarna/transformers.rs index e6f0bab9c2c8..ab3aeeaa8070 100644 --- a/crates/router/src/connector/klarna/transformers.rs +++ b/crates/router/src/connector/klarna/transformers.rs @@ -2,6 +2,8 @@ use api_models::payments; use common_utils::pii; use error_stack::{report, ResultExt}; use hyperswitch_domain_models::router_data::KlarnaSdkResponse; +use hyperswitch_domain_models::router_data::KlarnaCheckoutResponse; + use masking::{ExposeInterface, Secret}; use serde::{Deserialize, Serialize}; @@ -10,7 +12,7 @@ use crate::{ self, AddressData, AddressDetailsData, PaymentsAuthorizeRequestData, RouterData, }, core::errors, - types::{self, api, storage::enums, transformers::ForeignFrom}, + types::{self, api, storage::enums, transformers::ForeignFrom, domain}, }; #[derive(Debug, Serialize)] @@ -80,7 +82,41 @@ pub struct KlarnaPaymentsRequest { merchant_reference1: Option, merchant_reference2: Option, shipping_address: Option, -} + order_tax_amount: Option, + // merchant_urls: Option, + +} + +// #[derive(Default, Debug, Serialize)] +// pub enum KlarnaPaymentsRequest{ +// SDK (KlarnaSDKRequest), +// Checkout (KlarnaCheckoutRequest), +// } + +// #[derive(Debug)] +// pub struct KlarnaSDKRequest { +// auto_capture: bool, +// order_lines: Vec, +// order_amount: i64, +// purchase_country: enums::CountryAlpha2, +// purchase_currency: enums::Currency, +// merchant_reference1: Option, +// merchant_reference2: Option, +// shipping_address: Option, +// } + +// pub struct KlarnaCheckoutRequest { +// auto_capture: bool, +// order_lines: Vec, +// order_amount: i64, +// purchase_country: enums::CountryAlpha2, +// purchase_currency: enums::Currency, +// // merchant_urls: Option, + +// merchant_reference1: Option, +// merchant_reference2: Option, +// shipping_address: Option, +// } #[derive(Debug, Deserialize, Serialize)] pub struct KlarnaPaymentsResponse { @@ -97,11 +133,30 @@ pub struct AuthorizedPaymentMethod { impl From for types::AdditionalPaymentMethodConnectorResponse { fn from(item: AuthorizedPaymentMethod) -> Self { - Self::PayLater { - klarna_sdk: Some(KlarnaSdkResponse { - payment_type: Some(item.payment_type), - }), + match item.payment_type.as_str(){ + "klarna_sdk"=> Self::PayLater { + klarna_sdk: Some(KlarnaSdkResponse { + payment_type: Some(item.payment_type), + }), + klarna_checkout: None, + }, + "klarna_checkout" => Self::PayLater { + klarna_checkout: Some(KlarnaCheckoutResponse { + payment_type: Some(item.payment_type), + }), + klarna_sdk: None, + }, + _ => Self::PayLater { + klarna_sdk: None, + klarna_checkout: None + }, } + + // Self::PayLater { + // klarna_sdk: Some(KlarnaSdkResponse { + // payment_type: Some(item.payment_type), + // }), + // } } } @@ -129,6 +184,14 @@ pub struct KlarnaShippingAddress { street_address2: Option>, } +#[derive(Debug, Serialize)] +pub struct MerchantURLs { + terms: String, + checkout: String, + confirmation: String, + push: String, +} + #[derive(Deserialize, Serialize, Debug)] pub struct KlarnaSessionResponse { pub client_token: Secret, @@ -141,6 +204,10 @@ impl TryFrom<&KlarnaRouterData<&types::PaymentsSessionRouterData>> for KlarnaSes item: &KlarnaRouterData<&types::PaymentsSessionRouterData>, ) -> Result { let request = &item.router_data.request; + println!("1 request of auth {:?} ",request); + println!("2 item {:?} ",item); + + match request.order_details.clone() { Some(order_details) => Ok(Self { intent: KlarnaSessionIntent::Buy, @@ -158,6 +225,8 @@ impl TryFrom<&KlarnaRouterData<&types::PaymentsSessionRouterData>> for KlarnaSes quantity: data.quantity, unit_price: data.amount, total_amount: i64::from(data.quantity) * (data.amount), + tax_rate:None, + total_tax_amount:None }) .collect(), shipping_address: get_address_info(item.router_data.get_optional_shipping()) @@ -199,33 +268,256 @@ impl TryFrom<&KlarnaRouterData<&types::PaymentsAuthorizeRouterData>> for KlarnaP item: &KlarnaRouterData<&types::PaymentsAuthorizeRouterData>, ) -> Result { let request = &item.router_data.request; - match request.order_details.clone() { - Some(order_details) => Ok(Self { - purchase_country: item.router_data.get_billing_country()?, - purchase_currency: request.currency, - order_amount: item.amount, - order_lines: order_details - .iter() - .map(|data| OrderLines { - name: data.product_name.clone(), - quantity: data.quantity, - unit_price: data.amount, - total_amount: i64::from(data.quantity) * (data.amount), - }) - .collect(), - merchant_reference1: Some(item.router_data.connector_request_reference_id.clone()), - merchant_reference2: item.router_data.request.merchant_order_reference_id.clone(), - auto_capture: request.is_auto_capture()?, - shipping_address: get_address_info(item.router_data.get_optional_shipping()) - .transpose()?, - }), - None => Err(report!(errors::ConnectorError::MissingRequiredField { - field_name: "order_details" - })), + println!("klarna auth request {:?} ",request); + println!("klarna auth item {:?} ",item); + + let payment_method_data = request.payment_method_data.clone(); + let payment_experience = request.payment_experience; + let payment_method_type = request.payment_method_type; + // match request.order_details.clone() { + // match payment_method_data { + // domain::PaymentMethodData::PayLater(domain::PayLaterData::KlarnaSdk { token }) => { + // match (payment_experience, payment_method_type) { + // ( + // common_enums::PaymentExperience::InvokeSdkClient, + // common_enums::PaymentMethodType::Klarna, + // ) => { + // println!("klarna payments called"); + + + // Ok(KlarnaPaymentsRequest::SDK(KlarnaSDKRequest{ + // purchase_country: item.router_data.get_billing_country()?, + // purchase_currency: request.currency, + // order_amount: item.amount, + // order_lines: order_details + // .iter() + // .map(|data| OrderLines { + // name: data.product_name.clone(), + // quantity: data.quantity, + // unit_price: data.amount, + // total_amount: i64::from(data.quantity) * (data.amount), + // }) + // .collect(), + // merchant_reference1: Some( + // item.router_data.connector_request_reference_id.clone(), + // ), + // merchant_reference2: item + // .router_data + // .request + // .merchant_order_reference_id + // .clone(), + // auto_capture: request.is_auto_capture()?, + // shipping_address: get_address_info( + // item.router_data.get_optional_shipping(), + // ) + // .transpose()?, + // })) + // } + // (None, None) => todo!(), + // (None, Some(_)) => todo!(), + // (Some(_), None) => todo!(), + // (Some(_), Some(_)) => todo!(), + // } + // } + // domain::PaymentMethodData::PayLater(domain::PayLaterData::KlarnaCheckout {}) => { + // match (payment_experience, payment_method_type) { + // ( + // common_enums::PaymentExperience::InvokeSdkClient, + // common_enums::PaymentMethodType::KlarnaCheckout, + // ) => { + // println!("klarna SDK called"); + // Ok(KlarnaPaymentsRequest::Checkout(KlarnaCheckoutRequest{ + // purchase_country: item.router_data.get_billing_country()?, + // purchase_currency: request.currency, + // order_amount: item.amount, + // order_lines: order_details + // .iter() + // .map(|data| OrderLines { + // name: data.product_name.clone(), + // quantity: data.quantity, + // unit_price: data.amount, + // total_amount: i64::from(data.quantity) * (data.amount), + // }) + // .collect(), + + // merchant_urls: item + // .router_data + // .request + // .merchant_urls + // .clone(), + // auto_capture: request.is_auto_capture()?, + // shipping_address: get_address_info( + // item.router_data.get_optional_shipping(), + // ) + // .transpose()?, + // })) + // } + // (None, None) => todo!(), + // (None, Some(_)) => todo!(), + // (Some(_), None) => todo!(), + // (Some(_), Some(_)) => todo!(), + // } + // } + // hyperswitch_domain_models::payment_method_data::PaymentMethodData::Card(card) => todo!(), + // hyperswitch_domain_models::payment_method_data::PaymentMethodData::CardDetailsForNetworkTransactionId(card_details_for_network_transaction_id) => todo!(), + // hyperswitch_domain_models::payment_method_data::PaymentMethodData::CardRedirect(card_redirect_data) => todo!(), + // hyperswitch_domain_models::payment_method_data::PaymentMethodData::Wallet(wallet_data) => todo!(), + // hyperswitch_domain_models::payment_method_data::PaymentMethodData::PayLater(pay_later_data) => todo!(), + // hyperswitch_domain_models::payment_method_data::PaymentMethodData::BankRedirect(bank_redirect_data) => todo!(), + // hyperswitch_domain_models::payment_method_data::PaymentMethodData::BankDebit(bank_debit_data) => todo!(), + // hyperswitch_domain_models::payment_method_data::PaymentMethodData::BankTransfer(bank_transfer_data) => todo!(), + // hyperswitch_domain_models::payment_method_data::PaymentMethodData::Crypto(crypto_data) => todo!(), + // hyperswitch_domain_models::payment_method_data::PaymentMethodData::MandatePayment => todo!(), + // hyperswitch_domain_models::payment_method_data::PaymentMethodData::Reward => todo!(), + // hyperswitch_domain_models::payment_method_data::PaymentMethodData::RealTimePayment(real_time_payment_data) => todo!(), + // hyperswitch_domain_models::payment_method_data::PaymentMethodData::Upi(upi_data) => todo!(), + // hyperswitch_domain_models::payment_method_data::PaymentMethodData::Voucher(voucher_data) => todo!(), + // hyperswitch_domain_models::payment_method_data::PaymentMethodData::GiftCard(gift_card_data) => todo!(), + // hyperswitch_domain_models::payment_method_data::PaymentMethodData::CardToken(card_token) => todo!(), + // hyperswitch_domain_models::payment_method_data::PaymentMethodData::OpenBanking(open_banking_data) => todo!(), + // hyperswitch_domain_models::payment_method_data::PaymentMethodData::NetworkToken(network_token_data) => todo!(), + + + + // } + + match payment_method_data { + domain::PaymentMethodData::PayLater(domain::PayLaterData::KlarnaSdk { token }) => { + match request.order_details.clone() { + Some(order_details)=> { + println!("klarna payments called"); + + Ok(Self{ + purchase_country: item.router_data.get_billing_country()?, + purchase_currency: request.currency, + order_amount: item.amount, + order_tax_amount:None, + order_lines: order_details + .iter() + .map(|data| OrderLines { + name: data.product_name.clone(), + quantity: data.quantity, + unit_price: data.amount, + total_amount: i64::from(data.quantity) * (data.amount), + total_tax_amount:None, + tax_rate:None + }) + .collect(), + merchant_reference1: Some( + item.router_data.connector_request_reference_id.clone(), + ), + merchant_reference2: item + .router_data + .request + .merchant_order_reference_id + .clone(), + // merchant_urls:None, + auto_capture: request.is_auto_capture()?, + shipping_address: get_address_info( + item.router_data.get_optional_shipping(), + ) + .transpose()?, + }) + + } + None => todo!(), + // None => todo!(), + } + } + domain::PaymentMethodData::PayLater(domain::PayLaterData::KlarnaCheckout {}) => { + match request.order_details.clone() { + + Some(order_details)=> { + println!("klarna Checkout called, order details: {:?}", order_details); + + Ok(Self{ + purchase_country: item.router_data.get_billing_country()?, + purchase_currency: request.currency, + order_amount: item.amount, + order_tax_amount: Some(item.amount), + order_lines: order_details + .iter() + .map(|data| OrderLines { + name: data.product_name.clone(), + quantity: data.quantity, + unit_price: data.amount, + total_tax_amount:data.total_tax_amount, + tax_rate:data.tax_rate, + total_amount: i64::from(data.quantity) * (data.amount), + + // total_amount: i64::from(data.quantity) * (data.amount), + }) + .collect(), + + // merchant_urls: request.merchant_urls, + // merchant_urls:None, + merchant_reference1: None, + merchant_reference2: None, + auto_capture: request.is_auto_capture()?, + shipping_address: get_address_info( + item.router_data.get_optional_shipping(), + ) + .transpose()?, + }) + + + } + None => todo!(), + } + } + hyperswitch_domain_models::payment_method_data::PaymentMethodData::Card(card) => todo!(), + hyperswitch_domain_models::payment_method_data::PaymentMethodData::CardDetailsForNetworkTransactionId(card_details_for_network_transaction_id) => todo!(), + hyperswitch_domain_models::payment_method_data::PaymentMethodData::CardRedirect(card_redirect_data) => todo!(), + hyperswitch_domain_models::payment_method_data::PaymentMethodData::Wallet(wallet_data) => todo!(), + hyperswitch_domain_models::payment_method_data::PaymentMethodData::PayLater(pay_later_data) => todo!(), + hyperswitch_domain_models::payment_method_data::PaymentMethodData::BankRedirect(bank_redirect_data) => todo!(), + hyperswitch_domain_models::payment_method_data::PaymentMethodData::BankDebit(bank_debit_data) => todo!(), + hyperswitch_domain_models::payment_method_data::PaymentMethodData::BankTransfer(bank_transfer_data) => todo!(), + hyperswitch_domain_models::payment_method_data::PaymentMethodData::Crypto(crypto_data) => todo!(), + hyperswitch_domain_models::payment_method_data::PaymentMethodData::MandatePayment => todo!(), + hyperswitch_domain_models::payment_method_data::PaymentMethodData::Reward => todo!(), + hyperswitch_domain_models::payment_method_data::PaymentMethodData::RealTimePayment(real_time_payment_data) => todo!(), + hyperswitch_domain_models::payment_method_data::PaymentMethodData::Upi(upi_data) => todo!(), + hyperswitch_domain_models::payment_method_data::PaymentMethodData::Voucher(voucher_data) => todo!(), + hyperswitch_domain_models::payment_method_data::PaymentMethodData::GiftCard(gift_card_data) => todo!(), + hyperswitch_domain_models::payment_method_data::PaymentMethodData::CardToken(card_token) => todo!(), + hyperswitch_domain_models::payment_method_data::PaymentMethodData::OpenBanking(open_banking_data) => todo!(), + hyperswitch_domain_models::payment_method_data::PaymentMethodData::NetworkToken(network_token_data) => todo!(), } + + + + + + // match request.order_details.clone() { + // Some(order_details) => Ok(Self { + // purchase_country: item.router_data.get_billing_country()?, + // purchase_currency: request.currency, + // order_amount: item.amount, + // order_lines: order_details + // .iter() + // .map(|data| OrderLines { + // name: data.product_name.clone(), + // quantity: data.quantity, + // unit_price: data.amount, + // total_amount: i64::from(data.quantity) * (data.amount), + // }) + // .collect(), + // merchant_reference1: Some(item.router_data.connector_request_reference_id.clone()), + // merchant_reference2: item.router_data.request.merchant_order_reference_id.clone(), + // auto_capture: request.is_auto_capture()?, + // shipping_address: get_address_info(item.router_data.get_optional_shipping()) + // .transpose()?, + // }), + // None => Err(report!(errors::ConnectorError::MissingRequiredField { + // field_name: "order_details" + // })), + // } + } } + fn get_address_info( address: Option<&payments::Address>, ) -> Option>> { @@ -256,17 +548,18 @@ impl TryFrom> fn try_from( item: types::PaymentsResponseRouterData, ) -> Result { + println!("in response of auth "); let connector_response = types::ConnectorResponseData::with_additional_payment_method_data( match item.response.authorized_payment_method { Some(authorized_payment_method) => { types::AdditionalPaymentMethodConnectorResponse::from(authorized_payment_method) } None => { - types::AdditionalPaymentMethodConnectorResponse::PayLater { klarna_sdk: None } + types::AdditionalPaymentMethodConnectorResponse::PayLater { klarna_sdk: None, klarna_checkout: todo!() } } }, ); - + println!("2 response of auth {:?} ",connector_response); Ok(Self { response: Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId( @@ -296,6 +589,8 @@ pub struct OrderLines { quantity: u16, unit_price: i64, total_amount: i64, + tax_rate:Option, + total_tax_amount:Option, } #[derive(Debug, Serialize)] diff --git a/crates/router/src/connector/multisafepay/transformers.rs b/crates/router/src/connector/multisafepay/transformers.rs index 9db1cb3701a1..2932407daf8e 100644 --- a/crates/router/src/connector/multisafepay/transformers.rs +++ b/crates/router/src/connector/multisafepay/transformers.rs @@ -737,6 +737,7 @@ impl TryFrom<&MultisafepayRouterData<&types::PaymentsAuthorizeRouterData>> item.router_data.get_billing_email()? } domain::PayLaterData::KlarnaSdk { token: _ } + | domain::PayLaterData::KlarnaCheckout {} | domain::PayLaterData::AffirmRedirect {} | domain::PayLaterData::AfterpayClearpayRedirect {} | domain::PayLaterData::PayBrightRedirect {} diff --git a/crates/router/src/connector/nuvei/transformers.rs b/crates/router/src/connector/nuvei/transformers.rs index d1d7122f49ef..000d1d975a3e 100644 --- a/crates/router/src/connector/nuvei/transformers.rs +++ b/crates/router/src/connector/nuvei/transformers.rs @@ -977,6 +977,7 @@ where get_pay_later_info(AlternativePaymentMethodType::AfterPay, item) } domain::PayLaterData::KlarnaSdk { .. } + | domain::PayLaterData::KlarnaCheckout {} | domain::PayLaterData::AffirmRedirect {} | domain::PayLaterData::PayBrightRedirect {} | domain::PayLaterData::WalleyRedirect {} diff --git a/crates/router/src/connector/paypal/transformers.rs b/crates/router/src/connector/paypal/transformers.rs index 30aaf5a84a86..082a24e19f91 100644 --- a/crates/router/src/connector/paypal/transformers.rs +++ b/crates/router/src/connector/paypal/transformers.rs @@ -831,6 +831,7 @@ impl TryFrom<&domain::PayLaterData> for PaypalPaymentsRequest { match value { domain::PayLaterData::KlarnaRedirect { .. } | domain::PayLaterData::KlarnaSdk { .. } + | domain::PayLaterData::KlarnaCheckout {} | domain::PayLaterData::AffirmRedirect {} | domain::PayLaterData::AfterpayClearpayRedirect { .. } | domain::PayLaterData::PayBrightRedirect {} diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs index 63720696ef4b..fa3e06a005f7 100644 --- a/crates/router/src/connector/stripe/transformers.rs +++ b/crates/router/src/connector/stripe/transformers.rs @@ -659,6 +659,7 @@ impl TryFrom for StripePaymentMethodType { enums::PaymentMethodType::Credit => Ok(Self::Card), enums::PaymentMethodType::Debit => Ok(Self::Card), enums::PaymentMethodType::Klarna => Ok(Self::Klarna), + enums::PaymentMethodType::KlarnaCheckout => Ok(Self::Klarna), enums::PaymentMethodType::Affirm => Ok(Self::Affirm), enums::PaymentMethodType::AfterpayClearpay => Ok(Self::AfterpayClearpay), enums::PaymentMethodType::Eps => Ok(Self::Eps), @@ -989,6 +990,7 @@ impl TryFrom<&domain::payments::PayLaterData> for StripePaymentMethodType { } domain::PayLaterData::KlarnaSdk { .. } + | domain::PayLaterData::KlarnaCheckout {} | domain::PayLaterData::PayBrightRedirect {} | domain::PayLaterData::WalleyRedirect {} | domain::PayLaterData::AlmaRedirect {} diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs index 34397b5db6df..d93a2ea7ba74 100644 --- a/crates/router/src/connector/utils.rs +++ b/crates/router/src/connector/utils.rs @@ -2738,6 +2738,7 @@ pub enum PaymentMethodDataType { SwishQr, KlarnaRedirect, KlarnaSdk, + KlarnaCheckout, AffirmRedirect, AfterpayClearpayRedirect, PayBrightRedirect, @@ -2860,6 +2861,7 @@ impl From for PaymentMethodDataType { domain::payments::PaymentMethodData::PayLater(pay_later_data) => match pay_later_data { domain::payments::PayLaterData::KlarnaRedirect { .. } => Self::KlarnaRedirect, domain::payments::PayLaterData::KlarnaSdk { .. } => Self::KlarnaSdk, + domain::payments::PayLaterData::KlarnaCheckout { .. } => Self::KlarnaCheckout, domain::payments::PayLaterData::AffirmRedirect {} => Self::AffirmRedirect, domain::payments::PayLaterData::AfterpayClearpayRedirect { .. } => { Self::AfterpayClearpayRedirect diff --git a/crates/router/src/connector/zen/transformers.rs b/crates/router/src/connector/zen/transformers.rs index 799753fd52c1..77e784a25c28 100644 --- a/crates/router/src/connector/zen/transformers.rs +++ b/crates/router/src/connector/zen/transformers.rs @@ -744,6 +744,7 @@ impl TryFrom<&domain::payments::PayLaterData> for ZenPaymentsRequest { match value { domain::payments::PayLaterData::KlarnaRedirect { .. } | domain::payments::PayLaterData::KlarnaSdk { .. } + | domain::payments::PayLaterData::KlarnaCheckout { .. } | domain::payments::PayLaterData::AffirmRedirect {} | domain::payments::PayLaterData::AfterpayClearpayRedirect { .. } | domain::payments::PayLaterData::PayBrightRedirect {} diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 27d73d0df46d..8c9c7c7f1bae 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -35,7 +35,7 @@ use hyperswitch_domain_models::{ payment_attempt::PaymentAttempt, payment_intent::PaymentIntentFetchConstraints, PaymentIntent, }, - router_data::KlarnaSdkResponse, + router_data::{KlarnaCheckoutResponse, KlarnaSdkResponse}, }; use hyperswitch_interfaces::integrity::{CheckIntegrity, FlowIntegrity, GetIntegrityObject}; use josekit::jwe; @@ -2638,6 +2638,7 @@ pub fn validate_payment_method_type_against_payment_method( | api_enums::PaymentMethodType::Alma | api_enums::PaymentMethodType::AfterpayClearpay | api_enums::PaymentMethodType::Klarna + | api_enums::PaymentMethodType::KlarnaCheckout | api_enums::PaymentMethodType::PayBright | api_enums::PaymentMethodType::Atome | api_enums::PaymentMethodType::Walley @@ -4470,9 +4471,39 @@ pub async fn get_additional_payment_data( google_pay: None, })), }, - domain::PaymentMethodData::PayLater(_) => Ok(Some( - api_models::payments::AdditionalPaymentData::PayLater { klarna_sdk: None }, - )), + // domain::PaymentMethodData::PayLater(_) => Ok(Some( + // api_models::payments::AdditionalPaymentData::PayLater {klarna_sdk:None} }, + // )), + // domain::PaymentMethodData::PayLater(pay_later) => match pay_later{ + // domain::PayLaterData::KlarnaSdk(klarna_sdk_data)=>{Ok(Some( + // api_models::payments::AdditionalPaymentData::PayLater {klarna_sdk:None, klarna_checkout:None,} , + // ))}, + // domain::PayLaterData::KlarnaCheckout(klarna_checkout_data)=>{Ok(Some( + // api_models::payments::AdditionalPaymentData::PayLater {klarna_sdk:None, klarna_checkout:None,} , + // ))}, + // _ => Ok(Some(api_models::payments::AdditionalPaymentData::PayLater { + // klarna_sdk: None, + // klarna_checkout: None, + // })), + // }, + domain::PaymentMethodData::PayLater(pay_later) => match pay_later { + domain::PayLaterData::KlarnaSdk{token} => { + Ok(Some(api_models::payments::AdditionalPaymentData::PayLater { + klarna_sdk: None, + klarna_checkout: None, + })) + } + domain::PayLaterData::KlarnaCheckout{} => { + Ok(Some(api_models::payments::AdditionalPaymentData::PayLater { + klarna_sdk: None, + klarna_checkout: None, + })) + } + _ => Ok(Some(api_models::payments::AdditionalPaymentData::PayLater { + klarna_sdk: None, + klarna_checkout: None, + })), + }, domain::PaymentMethodData::BankTransfer(bank_transfer) => Ok(Some( api_models::payments::AdditionalPaymentData::BankTransfer { details: Some((*(bank_transfer.to_owned())).into()), @@ -5553,9 +5584,21 @@ pub fn add_connector_response_to_additional_payment_data( api_models::payments::AdditionalPaymentData::PayLater { .. }, AdditionalPaymentMethodConnectorResponse::PayLater { klarna_sdk: Some(KlarnaSdkResponse { payment_type }), + klarna_checkout, }, ) => api_models::payments::AdditionalPaymentData::PayLater { klarna_sdk: Some(api_models::payments::KlarnaSdkPaymentMethod { payment_type }), + klarna_checkout:None + }, + ( + api_models::payments::AdditionalPaymentData::PayLater { .. }, + AdditionalPaymentMethodConnectorResponse::PayLater { + klarna_sdk: None, + klarna_checkout: Some(KlarnaCheckoutResponse { payment_type }), + }, + ) => api_models::payments::AdditionalPaymentData::PayLater { + klarna_sdk:None, + klarna_checkout: Some(api_models::payments::KlarnaCheckoutPaymentMethod { payment_type }), }, _ => additional_payment_data, diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 03ae1c880087..ed7b46d0d8c0 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -1685,6 +1685,9 @@ pub fn change_order_details_to_new_type( brand: order_details.brand, product_type: order_details.product_type, product_tax_code: order_details.product_tax_code, + tax_rate:order_details.tax_rate, + // total_amount: Some(order_details.total_amount), + total_tax_amount: order_details.total_tax_amount }]) } @@ -1847,7 +1850,7 @@ impl TryFrom> for types::PaymentsAuthoriz .payment_intent .merchant_order_reference_id .clone(); - + Ok(Self { payment_method_data: (payment_method_data.get_required_value("payment_method_data")?), setup_future_usage: payment_data.payment_intent.setup_future_usage, diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs index 2146ab342713..fa63602aa7c1 100644 --- a/crates/router/src/types/transformers.rs +++ b/crates/router/src/types/transformers.rs @@ -495,6 +495,7 @@ impl ForeignFrom for api_enums::PaymentMethod { | api_enums::PaymentMethodType::Alma | api_enums::PaymentMethodType::AfterpayClearpay | api_enums::PaymentMethodType::Klarna + | api_enums::PaymentMethodType::KlarnaCheckout | api_enums::PaymentMethodType::PayBright | api_enums::PaymentMethodType::Atome | api_enums::PaymentMethodType::Walley => Self::PayLater,