Provides order management via Klarna API for Klarna Payments for WooCommerce plugin.
krokedil / klarna-order-management-for-woocommerce Goto Github PK
View Code? Open in Web Editor NEWLicense: GNU General Public License v3.0
License: GNU General Public License v3.0
While this data is not translated and thus not appropriate for display publicly to customers (JT-1635), the order's initial payment method could be displayed in Woo admin (and is currently displayed in Klarna Merchant Portal).
https://developers.klarna.com/api/#order-management-api__order__initial_payment_method
This code generates a critical error in some cases, because it tries to use $product->get_permalink() on bool.
Fix:
/**
* Get the product and its image URLs.
*
* @param WC_Order_Item_Product $item The order item.
* @return array The product and image URL if available, otherwise an empty array.
*/
function kom_maybe_add_product_urls( $item ) {
$product_data = array();
$settings = get_option( 'woocommerce_kco_settings', array() );
if ( isset( $settings['send_product_urls'] ) && 'yes' === $settings['send_product_urls'] ) {
$product = wc_get_product( $item->get_product_id() );
if ( $product instanceof WC_Product ) {
if ( $product->get_image_id() > 0 ) {
$image_id = $product->get_image_id();
$image_url = wp_get_attachment_image_url( $image_id, 'shop_single', false );
$product_data['image_url'] = $image_url;
}
$product_data['product_url'] = $product->get_permalink();
}
}
return $product_data;
}
I moved $product_data['product_url'] = $product->get_permalink(); inside the if-check, to make sure the $product is an instance of WC_Product.
I've noticed this when I importered two orders into a store, which had no connected products, and tried to sync it to Klarna.
Woo: 8.5.2
WP: 6.4.3
PHP: 8.1
Getting a 500 error when capturing a KP order.
VM2499 load-scripts.php:3 POST https://redacted.com/wp-admin/post.php 500 (Internal Server Error)
WC version: 3.1.2
In this line
Klarna order has already been captured and cannot be refunded. if _wc_klarna_capture_id is missing.
But if the id is missing no capture has been triggered from woocommerce yet.
Instead it probably should say Klarna order has not been captured and cannot be refunded.
KCO orders can get stuck in fraud control. In this plugin we have a listener for updating the order when status changes in Klarnas system.
Some merchants don't use the order management plugin since they handle activations, cancelations and refunds from an ERP system instead. By having the fraud follow up logic in the OM plugin orders won't get updated in this scenario.
Do you think that we should move the fraud logic to KCO plugin @kristibarbosky?
If a Woo store uses the 'official' WooCommerce shipment tracking info extension, only supported for this plugin: https://docs.woocommerce.com/document/shipment-tracking/, send the shipment tracking info to Klarna (could this happen either on capture or after capture depending on how the shipment tracking extension works).
(I unfortunately do not have the plugin available.)
For API info, see https://developers.klarna.com/api/#order-management-api-add-shipping-info-to-a-capture
Although Woo currently only provides full capture, it would still be helpful to easily see the amount of a order capture or order refund in the Woo order note.
Reporting for a live merchant (relating to Klarna internal ticket: PI-267), but I was able to recreate this in my Woo test store as well:
Order management should still work even if the Klarna front end (KP or KCO) is not active.
klarna_checkout_for_woocommerce -> kco
For Klarna to be able to provide VAT info to merchants in settlement data, we need to send order lines data in the capture & refund calls. Example error below because we aren't sending order lines currently:
https://developers.klarna.com/api/#order-management-api-capture
Followup to #50
There's another scenario here with AvaTax and Klarna.
Scenario is:
This sends it to Klarna - and it writes into order notes that the order is updated.
It correctly updates the items in Klarna, but the amount doesn't include the taxes anymore and the taxes line is zero'd out.
Would be useful per https://wordpress.org/support/topic/partial-customer-details/
Note; We can repro this with just AvaTax, Woo, and Klarna Payments and Order Management installed, with no custom code.
Here's what happens:
Note: Klarna (and AvaTax) still believe there's tax - only the Woo Admin View (and thus any analytics or API usage as well) is impacted.
This is impacting a large % of our orders right now, significantly impacting our analysis.
Cancelled or Processing orders aren't impacted - only COMPLETED ones.
Currently, if a merchant attempts to refund a Woo Klarna order, but the order was not captured in Woo, the order note error says "Klarna order has already been captured and cannot be refunded.", which is not correct. see:
In addition to fixing the issue, since merchants could capture the order directly in Klarna via the Merchant Portal, should we still post the refund request to Klarna regardless of the capture status in Woo and just return an error if Klarna responds with an error?
Currently only full captures are available in OM. Could partial captures also be supported?
Steps to recreate:
At minimum, add a note to the order that the Klarna posted a stop request for this order, e.g. "Klarna order STOPPED. Contact Klarna before processing order further."
Perhaps should the order status also be set to "On Hold" (perhaps only if the order's current status was "Processing")?
Expected:
Order is captured.
Current:
Order is captured, but with notice:
The captured amount (€118.30) was not equal to the sum of the order lines (€159.19) and this might affect your experience in handling this order.
Inspecting the OM logs show the following:
"id": "da0b35c4-af79-26cf-9b51-xxxxxxxxxxxxx",
"type": "POST",
"title": "Capture Klarna order",
"request": {
"headers": {
"Authorization": "Basic xxxxxxxxxxxxx",
"Content-Type": "application\/json"
},
"user-agent": "WordPress\/5.8.3; https:\/\/xxxxxx.fi - WooCommerce: 6.0.0 - OM:1.6.8 - PHP Version: 7.4.23 - Krokedil",
"method": "POST",
"body": {
"order_lines": [
{
"reference": "XXXXXX03401BE",
"type": "physical",
"name": "XXXXXXXXXXX - 37",
"quantity": 1,
"unit_price": 16900,
"tax_rate": 2400,
"total_amount": 11830,
"total_discount_amount": 5070,
"total_tax_amount": 2290
},
{
"reference": "matkahuolto:2",
"type": "shipping_fee",
"name": "Toimitus l\u00e4himp\u00e4\u00e4n Matkahuollon noutopisteeseen",
"quantity": 1,
"unit_price": 0,
"tax_rate": null,
"total_amount": 0,
"total_discount_amount": 0,
"total_tax_amount": 0
},
{
"reference": "Discount",
"type": "discount",
"name": "night",
"quantity": 1,
"unit_price": 4089,
"tax_rate": 0,
"total_amount": 4089,
"total_discount_amount": 0,
"total_tax_amount": 981
}
],
"order_amount": 11830,
"order_tax_amount": 0,
"shipping_info": [
{
"tracking_number": "",
"tracking_uri": ""
}
],
"captured_amount": 11830
}
},
To my understanding, the method \WC_Klarna_Order_Management_Order_Lines::process_order_item_coupon
is supposed to include coupon lines only if 'smart_coupon' === $coupon->get_discount_type() || 'US' === $this->klarna_country
, but the return variable gets a value already in the beginning of the method, making it return the coupon line in any case.
After push notification, but before pending decision, KCO orders stay in Pending Payment status, but they should move to On Hold status to match KP pending flow,
{site url}/wp-admin/admin.php?page=kom-settings
Warning: call_user_func_array() expects parameter 1 to be a valid callback, array must have exactly two members in /app/public/wp-includes/class-wp-hook.php on line 286 Warning: count(): Parameter must be an array or an object that implements Countable in /app/public/wp-content/plugins/klarna-order-management-for-woocommerce/includes/class-wc-klarna-order-management-settings.php on line 243
Warning: Invalid argument supplied for foreach() in /app/public/wp-content/plugins/klarna-order-management-for-woocommerce/includes/class-wc-klarna-order-management-settings.php on line 247
Currently, when I create matching manual orders in 1) Klarna's playground merchant portal and 2) Woo test store admin (with KP as the payment method and adding the Klarna order_id as the Woo 'Transaction ID'), and then change the Woo order status to Completed, the order cannot be captured in Klarna. I don't see a call to Klarna (in Splunk logs) for this capture attempt, so I suspect the problem is on the Woo side that perhaps it doesn't have all the data necessary for the order. Could we enable this to work? Do I need to set any other fields on the Woo order?
We have accidentally tested release 1.8.0 with 4.8.1 WC version and got fatal error:
Stack trace:
#0 /EDITED/wp-content/plugins/woocommerce/src/Internal/DependencyManagement/ExtendedContainer.php(116): Automattic\WooCommerce\Vendor\League\Container\Container->get()
#1 /EDITED/wp-content/plugins/woocommerce/src/Container.php(72): Automattic\WooCommerce\Internal\DependencyManagement\ExtendedContainer->get()
#2 /EDITED/wp-content/plugins/klarna-order-management-for-woocommerce/classes/class-wc-klarna-meta-box.php(49): Automattic\WooCommerce\Container->get()
#3 /EDITED/wp-includes/class-wp-hook.php(310): WC_Klarna_Meta_Box->kom_meta_box()
#4 /EDITED/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()
#5 /EDITED/wp-includes/plugin.php(517): WP_Hook->do_action()
#6 /EDITED/wp-admin/includes/meta-boxes.php(1701): do_action()
#7 /EDITED/wp-admin/edit-form-advanced.php(271): register_and_do_post_meta_boxes()
#8 /EDITED/wp-admin/post-new.php(75): require('/mnt/BLOCKSTORA...')
#9 {main}
thrown in /EDITED/wp-content/plugins/woocommerce/vendor/league/container/src/Container.php on line 188
On WC product edit page or WC order edit page.
Reverting to 1.7.2 solved issue.
Please add version check for feature you using and update WC requires at least
plugin header value.
Issue is reproduced on clean WP (6.2.2) + WC (4.8.1) + KOM (1.8.0) installation.
Actual behavior:
When visiting /wp-admin/post-new.php?post_type=shop_order
getting fatal error message.
Expected behavior:
When visiting /wp-admin/post-new.php?post_type=shop_order
getting order creation page.
Order stays stuck in "On Hold" status, but should be Cancelled (if not already captured) as rejected by Klarna (at least with an order note) and the notification should be successfully handled.
merchant_id: N100135
message: Notification request of type FRAUD_RISK_REJECTED for order id FRAUD_RISK_REJECTED returned an unexpected status. Status: 500, response body: '', URL: https://wptest.mageklarna.com/wc-api/WC_Gateway_Klarna_Payments/?order_id=1061
order_id: 08af0d68-2e15-60e4-960c-10177898c5a9
timestamp: 2018-10-17T19:26:53.179Z
uid: 5ca36c1b-5cc7-4a4a-afd5-0fdfe2ebf9fe
OM plugin Version 1.2.4
KP plugin Version 1.6.1
For merchants transitioning from previous KCO plugin (woocommerce-gateway-klarna) to new KCO plugin (klarna-checkout-for-woocommerce), if reasonable, could orders created using the old plugin still work for order management calls using the new OM plugin (klarna-order-management-for-woocommerce).
Currently it does not work, so merchants can use the Klarna Merchant Portal for order management as a workaround.
Version: 1.6.0
Payments successful
Logging turned off
Below the WooCommerce checkout summary we get this output:
Warning: Use of undefined constant KCO_WC_VERSION - assumed 'KCO_WC_VERSION' (this will throw an Error in a future version of PHP) in /var/www/web2/htdocs/wp-content/plugins/klarna-order-management-for-woocommerce/includes/class-wc-klarna-logger.php on line 74
Warning: Use of undefined constant KCO_WC_VERSION - assumed 'KCO_WC_VERSION' (this will throw an Error in a future version of PHP) in /var/www/web2/htdocs/wp-content/plugins/klarna-order-management-for-woocommerce/includes/class-wc-klarna-logger.php on line 74
Temporary fix:
Changing the constant KCO_WC_VERSION into WC_KLARNA_ORDER_MANAGEMENT_VERSION in class-wc-klarna-logger.php
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.