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

Klarna checkout #6590

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
62 changes: 59 additions & 3 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,9 @@ pub struct PaymentsRequest {
// Makes the field mandatory in PaymentsCreateRequest
pub amount: Option<Amount>,

#[schema(value_type = Option<i64>, example = 6540)]
pub order_tax_amount: Option<MinorUnit>,

/// The three letter ISO currency code in uppercase. Eg: 'USD' to charge US Dollars
#[schema(example = "USD", value_type = Option<Currency>)]
#[mandatory_in(PaymentsCreateRequest = Currency)]
Expand Down Expand Up @@ -858,6 +861,8 @@ pub struct PaymentsRequest {

/// Whether to calculate tax for this payment intent
pub skip_external_tax_calculation: Option<bool>,
pub merchant_urls: Option<MerchantURLs>,

}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -1692,6 +1697,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
Expand Down Expand Up @@ -1749,6 +1755,7 @@ impl GetAddressFromPaymentMethodData for PayLaterData {
| Self::WalleyRedirect {}
| Self::AlmaRedirect {}
| Self::KlarnaSdk { .. }
| Self::KlarnaCheckout {}
| Self::AffirmRedirect {}
| Self::AtomeRedirect {} => None,
}
Expand Down Expand Up @@ -2195,6 +2202,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,
Expand Down Expand Up @@ -2402,6 +2410,7 @@ pub enum AdditionalPaymentData {
},
PayLater {
klarna_sdk: Option<KlarnaSdkPaymentMethod>,
klarna_checkout: Option<KlarnaCheckoutPaymentMethod>,
},
BankTransfer {
#[serde(flatten)]
Expand Down Expand Up @@ -2457,6 +2466,12 @@ pub struct KlarnaSdkPaymentMethod {
pub payment_type: Option<String>,
}

#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)]

pub struct KlarnaCheckoutPaymentMethod {
pub payment_type: Option<String>,
}

#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum BankRedirectData {
Expand Down Expand Up @@ -3658,6 +3673,7 @@ pub struct VoucherResponse {
#[derive(Eq, PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct PaylaterResponse {
klarna_sdk: Option<KlarnaSdkPaymentMethodResponse>,
klarna_checkout: Option<KlarnaCheckoutPaymentMethodResponse>,
}

#[derive(Eq, PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
Expand All @@ -3682,6 +3698,12 @@ pub struct KlarnaSdkPaymentMethodResponse {
pub payment_type: Option<String>,
}

#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]

pub struct KlarnaCheckoutPaymentMethodResponse {
pub payment_type: Option<String>,
}

#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, ToSchema, serde::Serialize)]
pub struct PaymentMethodDataResponseWithBilling {
// The struct is flattened in order to provide backwards compatibility
Expand Down Expand Up @@ -3744,6 +3766,16 @@ pub struct Address {
pub email: Option<Email>,
}

#[derive(Default, Clone, Debug, Eq, PartialEq, ToSchema, serde::Deserialize, serde::Serialize)]
#[serde(deny_unknown_fields)]
pub struct MerchantURLs {
terms: String,
checkout: String,
confirmation: String,
push: String,
}


impl masking::SerializableSecret for Address {}

impl Address {
Expand Down Expand Up @@ -5120,6 +5152,17 @@ impl From<KlarnaSdkPaymentMethod> for PaylaterResponse {
klarna_sdk: Some(KlarnaSdkPaymentMethodResponse {
payment_type: klarna_sdk.payment_type,
}),
klarna_checkout: None,
}
}
}
impl From<KlarnaCheckoutPaymentMethod> for PaylaterResponse {
fn from(klarna_checkout: KlarnaCheckoutPaymentMethod) -> Self {
Self {
klarna_checkout: Some(KlarnaCheckoutPaymentMethodResponse {
payment_type: klarna_checkout.payment_type,
}),
klarna_sdk: None,
}
}
}
Expand All @@ -5128,10 +5171,19 @@ impl From<AdditionalPaymentData> 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 } => 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,
google_pay,
Expand Down Expand Up @@ -5261,6 +5313,8 @@ pub struct OrderDetailsWithAmount {
pub quantity: u16,
/// the amount per quantity of product
pub amount: MinorUnit,
pub tax_rate: Option<i64>,
pub total_tax_amount: Option<i64>,
// Does the order includes shipping
pub requires_shipping: Option<bool>,
/// The image URL of the product
Expand Down Expand Up @@ -5289,6 +5343,8 @@ pub struct OrderDetails {
/// The quantity of the product to be purchased
#[schema(example = 1)]
pub quantity: u16,
pub tax_rate:Option<i64>,
pub total_tax_amount:Option<i64>,
// Does the order include shipping
pub requires_shipping: Option<bool>,
/// The image URL of the product
Expand Down
1 change: 1 addition & 0 deletions crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,7 @@ pub enum PaymentMethodType {
Interac,
Indomaret,
Klarna,
KlarnaCheckout,
KakaoPay,
LocalBankRedirect,
MandiriVa,
Expand Down
1 change: 1 addition & 0 deletions crates/common_enums/src/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,7 @@ impl From<PaymentMethodType> 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,
Expand Down
3 changes: 3 additions & 0 deletions crates/diesel_models/src/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3448,6 +3448,9 @@ pub enum RedirectForm {
form_fields: std::collections::HashMap<String, String>,
collection_id: Option<String>,
},
KlarnaCheckout{
html_snippet: String,
},
}

common_utils::impl_to_sql_from_sql_json!(RedirectForm);
Expand Down
3 changes: 3 additions & 0 deletions crates/diesel_models/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pub struct OrderDetailsWithAmount {
pub product_type: Option<common_enums::ProductType>,
/// The tax code for the product
pub product_tax_code: Option<String>,
pub tax_rate: Option<i64>,
pub total_tax_amount: Option<i64>,

}

impl masking::SerializableSecret for OrderDetailsWithAmount {}
Expand Down
1 change: 1 addition & 0 deletions crates/euclid/src/frontend/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ mod test {
dirval!(CardType = Credit),
dirval!(CardNetwork = Visa),
dirval!(PayLaterType = Klarna),
dirval!(PayLaterType = KlarnaCheckout),
dirval!(WalletType = Paypal),
dirval!(BankRedirectType = Sofort),
dirval!(BankDebitType = Bacs),
Expand Down
1 change: 1 addition & 0 deletions crates/euclid/src/frontend/dir/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub enum PayLaterType {
AfterpayClearpay,
Alma,
Klarna,
KlarnaCheckout,
PayBright,
Walley,
Atome,
Expand Down
1 change: 1 addition & 0 deletions crates/euclid/src/frontend/dir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ impl From<enums::PayLaterType> 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,
Expand Down
1 change: 1 addition & 0 deletions crates/euclid/src/frontend/dir/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,8 @@ impl TryFrom<&MultisafepayRouterData<&types::PaymentsAuthorizeRouterData>>
Some(GatewayInfo::PayLater(PayLaterInfo {
email: Some(match paylater {
PayLaterData::KlarnaRedirect {} => item.router_data.get_billing_email()?,
PayLaterData::KlarnaSdk { token: _ }
PayLaterData::KlarnaCheckout {}
| PayLaterData::KlarnaSdk { .. }
| PayLaterData::AffirmRedirect {}
| PayLaterData::AfterpayClearpayRedirect {}
| PayLaterData::PayBrightRedirect {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { .. }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@ impl TryFrom<&PayLaterData> for ZenPaymentsRequest {
match value {
PayLaterData::KlarnaRedirect { .. }
| PayLaterData::KlarnaSdk { .. }
| PayLaterData::KlarnaCheckout {}
| PayLaterData::AffirmRedirect {}
| PayLaterData::AfterpayClearpayRedirect { .. }
| PayLaterData::PayBrightRedirect {}
Expand Down
2 changes: 2 additions & 0 deletions crates/hyperswitch_connectors/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,7 @@ pub enum PaymentMethodDataType {
SwishQr,
KlarnaRedirect,
KlarnaSdk,
KlarnaCheckout,
AffirmRedirect,
AfterpayClearpayRedirect,
PayBrightRedirect,
Expand Down Expand Up @@ -2039,6 +2040,7 @@ impl From<PaymentMethodData> 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
Expand Down
8 changes: 8 additions & 0 deletions crates/hyperswitch_domain_models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ impl ApiModelToDieselModelConvertor<ApiOrderDetailsWithAmount> for OrderDetailsW
brand,
product_type,
product_tax_code,
tax_rate,
total_tax_amount
} = from;
Self {
product_name,
Expand All @@ -145,6 +147,8 @@ impl ApiModelToDieselModelConvertor<ApiOrderDetailsWithAmount> for OrderDetailsW
brand,
product_type,
product_tax_code,
tax_rate,
total_tax_amount
}
}

Expand All @@ -161,6 +165,8 @@ impl ApiModelToDieselModelConvertor<ApiOrderDetailsWithAmount> for OrderDetailsW
brand,
product_type,
product_tax_code,
tax_rate,
total_tax_amount
} = self;
ApiOrderDetailsWithAmount {
product_name,
Expand All @@ -174,6 +180,8 @@ impl ApiModelToDieselModelConvertor<ApiOrderDetailsWithAmount> for OrderDetailsW
brand,
product_type,
product_tax_code,
tax_rate,
total_tax_amount
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/hyperswitch_domain_models/src/payment_method_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ pub enum CardRedirectData {
pub enum PayLaterData {
KlarnaRedirect {},
KlarnaSdk { token: String },
KlarnaCheckout {},
AffirmRedirect {},
AfterpayClearpayRedirect {},
PayBrightRedirect {},
Expand Down Expand Up @@ -897,6 +898,7 @@ impl From<api_models::payments::PayLaterData> 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 {}
Expand Down Expand Up @@ -1549,6 +1551,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,
Expand Down
9 changes: 9 additions & 0 deletions crates/hyperswitch_domain_models/src/router_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ pub struct RouterData<Flow, Request, Response> {
pub additional_merchant_data: Option<api_models::admin::AdditionalMerchantData>,

pub header_payload: Option<payments::HeaderPayload>,
// pub html_snippet: Option<String>,


pub connector_mandate_request_reference_id: Option<String>,
}
Expand Down Expand Up @@ -346,6 +348,7 @@ pub enum AdditionalPaymentMethodConnectorResponse {
},
PayLater {
klarna_sdk: Option<KlarnaSdkResponse>,
klarna_checkout: Option<KlarnaCheckoutResponse>,
},
}

Expand All @@ -354,6 +357,12 @@ pub struct KlarnaSdkResponse {
pub payment_type: Option<String>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct KlarnaCheckoutResponse {
pub payment_type: Option<String>,
// pub html_snippet: Option<String>,
}

#[derive(Clone, Debug, serde::Serialize)]
pub struct ErrorResponse {
pub code: String,
Expand Down
11 changes: 11 additions & 0 deletions crates/hyperswitch_domain_models/src/router_request_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct PaymentsAuthorizeData {
/// get_total_surcharge_amount() // returns surcharge_amount + tax_on_surcharge_amount
/// ```
pub amount: i64,
pub order_tax_amount: i64,
pub email: Option<pii::Email>,
pub customer_name: Option<Secret<String>>,
pub currency: storage_enums::Currency,
Expand Down Expand Up @@ -70,6 +71,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<String>,
pub merchant_urls: Option<MerchantURLs>,
pub integrity_object: Option<AuthoriseIntegrityObject>,
pub shipping_cost: Option<MinorUnit>,
pub additional_payment_method_data: Option<AdditionalPaymentData>,
Expand Down Expand Up @@ -498,6 +500,15 @@ pub struct BrowserInformation {
pub user_agent: Option<String>,
}

#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
pub struct MerchantURLs {
pub terms: Option<String>,
pub checkout : Option<String>,
pub confirmation: Option<String>,
pub push: Option<String>,
}


#[derive(Debug, Clone, Default, Serialize)]
pub enum ResponseId {
ConnectorTransactionId(String),
Expand Down
Loading
Loading