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.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | commerce_klarna_payments-use-the-adjusted-shipment-amount-3231562-8.patch | 1.01 KB | tcrawford |
Issue fork commerce_klarna_payments-3231562
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
tcrawford commentedComment #3
tcrawford commentedComment #4
tcrawford commentedComment #8
tcrawford commentedI have created a merge request and a patch (for those still using in their workflow).
Comment #9
tcrawford commentedI see tests are failing as the fake shipment interface does not include the getAdjustedAmount method. I will rectify this when time permits.
Comment #11
tuutti commentedThis should be fixed in 3.x branch now. I haven't tested it properly yet tho.
Comment #12
tuutti commented