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