Klarna Payments集成报错:order_lines[0].total_tax_amount值异常求助
Let's break down why you're getting that BAD_VALUE error for order_lines[0].total_tax_amount—it all comes down to mismatched calculations between your order line fields and the overall order totals.
The Root Cause
Klarna's API strictly validates that the tax and amount values in your order lines align mathematically with each other and the top-level order fields. Looking at your request data:
- Your
unit_priceis 10000 (€100, presumably exclusive of tax) tax_rateis 1600 (16%)- You set
total_tax_amountto 1600 (€16), which is correct for that unit price and rate—but yourtotal_amountfor the line is 10000 (€100), which is the pre-tax value, not the inclusive total.
Klarna expects total_amount for an order line to be the tax-inclusive total (pre-tax price + tax). Additionally, the top-level order_amount must equal the sum of all total_amount values in your order lines. Right now, your order_amount is 10000, but the tax-inclusive total should be 11600.
Corrected Request Data
Here's the fixed version of your request that should resolve the error:
{ "purchase_country": "DE", "purchase_currency": "EUR", "locale": "de-DE", "order_amount": 11600, "order_tax_amount": 1600, "order_lines": [ { "type": "physical", "reference": "19-402", "name": "Battery Power Pack", "image_url": "https://www.exampleobjects.com/logo.png", "product_url": "https://www.estore.com/products/f2a8d7e34", "quantity": 1, "tax_rate": 1600, "total_amount": 11600, "total_tax_amount": 1600, "unit_price": 10000 } ] }
Key Validation Rules to Remember
- For each order line:
total_amount = (unit_price * quantity) + total_tax_amount - For each order line:
total_tax_amount = (unit_price * quantity * tax_rate) / 10000(since tax_rate is in per-mille) - Top-level
order_amountmust equal the sum of alltotal_amountvalues in order_lines - Top-level
order_tax_amountmust equal the sum of alltotal_tax_amountvalues in order_lines
Double-checking these calculations every time you build your request will prevent this kind of validation error.
内容的提问来源于stack exchange,提问作者MrNasto

