fix(medusa-payment-klarna): Calculate shipping totals correctly (#1848)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"medusa-payment-klarna": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixes issue where shipping totals are calculated incorrectly
|
||||||
@@ -73,6 +73,7 @@ export default async (req, res) => {
|
|||||||
"gift_card_total",
|
"gift_card_total",
|
||||||
"subtotal",
|
"subtotal",
|
||||||
"total",
|
"total",
|
||||||
|
"shipping_total",
|
||||||
"tax_total",
|
"tax_total",
|
||||||
"discount_total",
|
"discount_total",
|
||||||
"subtotal",
|
"subtotal",
|
||||||
|
|||||||
@@ -28,21 +28,19 @@ export default async (req, res) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const ids = selected_shipping_option.id.split(".")
|
const ids = selected_shipping_option.id.split(".")
|
||||||
await Promise.all(
|
for (const id of ids) {
|
||||||
ids.map(async (id) => {
|
const option = shippingOptions.find((so) => so.id === id)
|
||||||
const option = shippingOptions.find((so) => so.id === id)
|
if (option) {
|
||||||
|
await cartService.addShippingMethod(cart.id, option.id, option.data)
|
||||||
if (option) {
|
}
|
||||||
await cartService.addShippingMethod(cart.id, option.id, option.data)
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
const newCart = await cartService.retrieve(cart.id, {
|
const newCart = await cartService.retrieve(cart.id, {
|
||||||
select: [
|
select: [
|
||||||
"gift_card_total",
|
"gift_card_total",
|
||||||
"subtotal",
|
"subtotal",
|
||||||
"total",
|
"total",
|
||||||
|
"shipping_total",
|
||||||
"tax_total",
|
"tax_total",
|
||||||
"discount_total",
|
"discount_total",
|
||||||
"subtotal",
|
"subtotal",
|
||||||
@@ -61,6 +59,7 @@ export default async (req, res) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const order = await klarnaProviderService.cartToKlarnaOrder(newCart)
|
const order = await klarnaProviderService.cartToKlarnaOrder(newCart)
|
||||||
|
|
||||||
res.json(order)
|
res.json(order)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error
|
throw error
|
||||||
|
|||||||
@@ -92,7 +92,9 @@ class KlarnaProviderService extends PaymentService {
|
|||||||
totals.tax_lines.reduce((acc, next) => acc + next.rate, 0) / 100
|
totals.tax_lines.reduce((acc, next) => acc + next.rate, 0) / 100
|
||||||
|
|
||||||
name.push(next?.shipping_option.name)
|
name.push(next?.shipping_option.name)
|
||||||
taxRate += (totals.total / cart.shipping_total) * methodTaxRate
|
|
||||||
|
total += totals.total
|
||||||
|
taxRate += (totals.price / cart.shipping_total) * methodTaxRate
|
||||||
tax += totals.tax_total
|
tax += totals.tax_total
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,7 +105,7 @@ class KlarnaProviderService extends PaymentService {
|
|||||||
type: "shipping_fee",
|
type: "shipping_fee",
|
||||||
unit_price: total,
|
unit_price: total,
|
||||||
tax_rate: taxRate * 10000,
|
tax_rate: taxRate * 10000,
|
||||||
total_amount: cart.shipping_total,
|
total_amount: total,
|
||||||
total_tax_amount: tax,
|
total_tax_amount: tax,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user