Authorization fails when applying shipping promotions that are not included in the price

Created on 6 September 2021, almost 3 years ago
Updated 7 February 2023, over 1 year ago

Problem/Motivation

Authorization fails when applying shipping promotions that are not included in the price as the un-adjusted shipping amount is sent to Klarna.

Steps to reproduce

Add a shipping promotion that is not included in the price
- Select offer type 'Fixed amount off shipment amount.' or 'Percentage off the shipment amount'
- Select "Only show the discount on the order total summary."

Add product to your cart.
Navigate to checkout.
Apply the shipping promotion (use coupon or fulfill condition defined when adding the promotion).
Proceed to pay with Klarna.
You will receive the error "An unknown error occurred. Please contact store administration if the problem persists."
In the Klarna logs you will see a 400 response with the error code BAD_VALUE, as the order total is not equal to the sum of the line items.

Proposed resolution

Modify the Drupal\commerce_klarna_payments\Request\Payment\RequestBuilder::createShippingOrderLine($shipment) method to call $shipment->getAdjustedAmount() instead of $shipment->getAmount(). This will then handle shipping promotions using the adjusted price analogously to how the createOrderLine() method indirectly handles order item based promotions using the adjusted price.

Remaining tasks

A merge request is to follow.

User interface changes

None.

API changes

None.

Data model changes

None.

✨ Feature request
Status

Fixed

Version

3.0

Component

Code

Created by

🇨🇭Switzerland tcrawford

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024