Skip to content

Commit

Permalink
kco authorization added
Browse files Browse the repository at this point in the history
  • Loading branch information
Sweta Sharma authored and Sweta Sharma committed Nov 8, 2024
1 parent 0dba763 commit 5d118a0
Show file tree
Hide file tree
Showing 27 changed files with 624 additions and 41 deletions.
54 changes: 51 additions & 3 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,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 @@ -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
Expand Down Expand Up @@ -1660,6 +1664,8 @@ impl GetAddressFromPaymentMethodData for PayLaterData {
| Self::WalleyRedirect {}
| Self::AlmaRedirect {}
| Self::KlarnaSdk { .. }
| Self::KlarnaCheckout {}

| Self::AffirmRedirect {}
| Self::AtomeRedirect {} => None,
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -2296,6 +2304,7 @@ pub enum AdditionalPaymentData {
},
PayLater {
klarna_sdk: Option<KlarnaSdkPaymentMethod>,
klarna_checkout: Option<KlarnaCheckoutPaymentMethod>,
},
BankTransfer {
#[serde(flatten)]
Expand Down Expand Up @@ -2347,6 +2356,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 @@ -3526,6 +3541,8 @@ 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 @@ -3549,6 +3566,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 @@ -4792,6 +4815,18 @@ 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 @@ -4800,9 +4835,13 @@ 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,
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,
Expand Down Expand Up @@ -4929,6 +4968,10 @@ pub struct OrderDetailsWithAmount {
pub quantity: u16,
/// the amount per quantity of product
pub amount: i64,

pub tax_rate: Option<i64>,
pub total_tax_amount: Option<i64>,
// pub total_amount:Option<i64>,
// Does the order includes shipping
pub requires_shipping: Option<bool>,
/// The image URL of the product
Expand All @@ -4945,6 +4988,7 @@ pub struct OrderDetailsWithAmount {
pub product_type: Option<ProductType>,
/// The tax code for the product
pub product_tax_code: Option<String>,

}

impl masking::SerializableSecret for OrderDetailsWithAmount {}
Expand All @@ -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<i64>,
pub total_tax_amount:Option<i64>,
// pub total_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 @@ -1630,6 +1630,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 @@ -1826,6 +1826,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
1 change: 1 addition & 0 deletions crates/euclid/src/frontend/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
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 @@ -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
2 changes: 2 additions & 0 deletions crates/hyperswitch_connectors/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,7 @@ pub enum PaymentMethodDataType {
SwishQr,
KlarnaRedirect,
KlarnaSdk,
KlarnaCheckout,
AffirmRedirect,
AfterpayClearpayRedirect,
PayBrightRedirect,
Expand Down Expand Up @@ -1915,6 +1916,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
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 @@ -150,6 +150,7 @@ pub enum CardRedirectData {
pub enum PayLaterData {
KlarnaRedirect {},
KlarnaSdk { token: String },
KlarnaCheckout {},
AffirmRedirect {},
AfterpayClearpayRedirect {},
PayBrightRedirect {},
Expand Down Expand Up @@ -881,6 +882,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 @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions crates/hyperswitch_domain_models/src/router_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ pub enum AdditionalPaymentMethodConnectorResponse {
},
PayLater {
klarna_sdk: Option<KlarnaSdkResponse>,
klarna_checkout: Option<KlarnaCheckoutResponse>,

},
}

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

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

#[derive(Clone, Debug, serde::Serialize)]
pub struct ErrorResponse {
pub code: String,
Expand Down
9 changes: 9 additions & 0 deletions crates/hyperswitch_domain_models/src/router_request_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
// pub merchant_urls: Option<MerchantURLs>,
pub integrity_object: Option<AuthoriseIntegrityObject>,
}

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions crates/kgraph_utils/src/mca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions crates/kgraph_utils/src/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/adyen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(()),
Expand Down
6 changes: 6 additions & 0 deletions crates/router/src/connector/adyen/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?;
Expand Down
Loading

0 comments on commit 5d118a0

Please sign in to comment.