-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat(klarna): Klarna Kustom Checkout Integration #6590
base: main
Are you sure you want to change the base?
Conversation
@@ -84,7 +84,7 @@ 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>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we remove the commented lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] | ||
pub struct KlarnaCheckoutResponse { | ||
pub payment_type: Option<String>, | ||
// pub html_snippet: Option<String>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
@@ -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>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
@@ -5273,6 +5326,8 @@ pub struct OrderDetailsWithAmount { | |||
pub quantity: u16, | |||
/// the amount per quantity of product | |||
pub amount: MinorUnit, | |||
pub tax_rate: Option<i64>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to add these 2 fields?
.merchant_order_reference_id | ||
.clone(), | ||
merchant_urls:None, | ||
auto_capture: request.is_auto_capture()?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run cargo +nightly fmt --all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
purchase_country: item.router_data.get_billing_country()?, | ||
purchase_currency: request.currency, | ||
order_amount: item.amount, | ||
order_tax_amount: Some(0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we hardcoding to 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
..item.data | ||
}) | ||
}, | ||
hyperswitch_domain_models::payment_method_data::PaymentMethodData::Card(_card) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
combine the cases with the same outcome using the | operator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
}, | ||
} | ||
} | ||
hyperswitch_domain_models::payment_method_data::PaymentMethodData::Card(_card) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
combine the cases with the same outcome using the | operator
// domain::PaymentMethodData::PayLater(_) => Ok(Some( | ||
// api_models::payments::AdditionalPaymentData::PayLater { klarna_sdk: None }, | ||
// )), | ||
domain::PaymentMethodData::PayLater(pay_later) => match pay_later { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we dont need match pay_later
if outcome is always the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
1c78c1b
to
3d5508c
Compare
43df930
to
b338b35
Compare
d0ed9b4
to
476ef14
Compare
67c9f33
to
cfc70cf
Compare
@@ -2252,6 +2252,12 @@ impl<'a> | |||
|
|||
Ok(AdyenPaymentMethod::AdyenKlarna(Box::new(klarna))) | |||
} | |||
domain::payments::PayLaterData::KlarnaCheckout { .. } => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add KlarnaCheckout
at the last of this function using or
to avoid throwing the same error twice
domain::payments::PayLaterData::KlarnaSdk { .. }
| domain::payments::PayLaterData::KlarnaCheckout { .. } => {
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("Adyen"),
)
.into())
}
@@ -445,8 +449,26 @@ impl | |||
.change_context(errors::ConnectorError::RequestEncodingFailed)?; | |||
let endpoint = | |||
build_region_specific_endpoint(self.base_url(connectors), &req.connector_meta_data)?; | |||
let checkout_endpoint = get_klarna_checkout_endpoint(self.base_url(connectors)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need get_klarna_checkout_endpoint function, this case is already handled in build_region_specific_endpoint
function, so you can use endpoint
for both case.
@@ -531,6 +552,8 @@ impl | |||
.ok_or_else(connector_utils::missing_field_err("payment_method_type"))?; | |||
let endpoint = | |||
build_region_specific_endpoint(self.base_url(connectors), &req.connector_meta_data)?; | |||
let checkout_endpoint = get_klarna_checkout_endpoint(self.base_url(connectors)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
quantity: data.quantity, | ||
unit_price: data.amount, | ||
total_amount: data.amount * data.quantity, | ||
tax_amount: data.total_tax_amount, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we sending tax_amount
and tax_rate
for KlarnaSdk
} | ||
}, | ||
); | ||
let payment_method_data = item.data.request.payment_method_data.clone(); | ||
|
||
match payment_method_data { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can match directly on the response type, similar to how you handled the psync response.
@@ -2252,6 +2253,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), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove this comment
@@ -2474,6 +2479,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz | |||
integrity_object: None, | |||
additional_payment_method_data, | |||
shipping_cost, | |||
// merchant_urls:None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove this comment
@@ -59,6 +60,7 @@ impl VerifyConnectorData { | |||
integrity_object: None, | |||
additional_payment_method_data: None, | |||
shipping_cost: None, | |||
// merchant_urls:None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove this comment
Type of Change
Description
Klarna Kustom Checkout (KCO) integration
Klarna provides two payment methods:
Any one of the methods can be used at a time and switching between Klarna Payments and Klarna Checkout is been done. Based on the PML got, there will be a switching between Klarna Payments and Klarna Checkout.
The redirect_to_url link from response is used to complete the payment.
Additional Changes
Motivation and Context
How did you test it?
I tested it using postman by hitting the required endpoints. Curl to the postman setup:
Response:
Response:
Checklist
cargo +nightly fmt --all
cargo clippy