fix(medusa-payment-klarna): Calculate shipping totals correctly (#1848)

This commit is contained in:
Sebastian Rindom
2022-07-18 18:10:58 +02:00
committed by GitHub
parent 4dd7fdf61c
commit 0e5f0d8cd6
4 changed files with 18 additions and 11 deletions

View File

@@ -0,0 +1,5 @@
---
"medusa-payment-klarna": patch
---
Fixes issue where shipping totals are calculated incorrectly

View File

@@ -73,6 +73,7 @@ export default async (req, res) => {
"gift_card_total",
"subtotal",
"total",
"shipping_total",
"tax_total",
"discount_total",
"subtotal",

View File

@@ -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

View File

@@ -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,
})
}