Giter VIP home page Giter VIP logo

klarna-order-management-for-woocommerce's Introduction

Klarna Order Management for WooCommerce

Provides order management via Klarna API for Klarna Payments for WooCommerce plugin.

klarna-order-management-for-woocommerce's People

Contributors

a-larsson avatar dekadinious avatar fredrik-krokedil avatar kontrazen avatar kristian-andersson avatar krokedilmartin avatar louise-krokedil avatar mathias-krokedil avatar michaelbengtsson avatar mntzrr avatar mstojanovic013 avatar niklashogefjord avatar oxyc avatar slobodan avatar zaglov avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

klarna-order-management-for-woocommerce's Issues

Minor bug when order item list contains products which is not "connected" to any one product within a store.

This code generates a critical error in some cases, because it tries to use $product->get_permalink() on bool.

https://github.com/krokedil/klarna-order-management-for-woocommerce/blob/master/includes/klarna-order-management-functions.php#L43-L66

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

Fix refund messaging if no capture has been made

In this line

$order->add_order_note( 'Klarna order has already been captured and cannot be refunded.' );
it says:

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.

Move Fraud functionality to KCO plugin?

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?

support sending shipment tracking info to Klarna when order is shipped

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

Order management doesn't work if KP plugin is active but KP (or KCOv3) is not activated

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:

  1. place a KP order, e.g. see 140d9837-fc6a-5e90-804e-bbd6497e4b6c
  2. disable KP
    image
  3. change Woo order status from Processing to Completed. The Woo order notes show an error: "Klarna order could not be captured due to an error." No API call is sent to Klarna.
    image

Order management should still work even if the Klarna front end (KP or KCO) is not active.

Syncing Orders doesn't send taxes from Woo->Klarna

Followup to #50

There's another scenario here with AvaTax and Klarna.

Scenario is:

  • Have an order in processing (so thus at Klarna)
  • Bring order back to on-hold
  • Edit the order (remove an item)
  • Hit Recalculate (to recalculate taxes)
  • Change to Processing again
  • Hit Update to save

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.

Completing order removes taxes from Woo

Note; We can repro this with just AvaTax, Woo, and Klarna Payments and Order Management installed, with no custom code.

Here's what happens:

  • Place a Klarna order via Woo to state (US) with taxes on it. It's in processing and shows the tax in the admin view (and purchaser order history)
  • Add tracking info manually (or wait for it to ship in real life), it still shows the tax in Woo admin view (and purchaser order history)
  • Mark it as "COMPLETED" (which causes Klarna to capture it) - the tax disappears from woo admin view (and purchaser order history)

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.

Fix error message when refund attempted prior to capture

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:

$order->add_order_note( 'Klarna order has already been captured and cannot be refunded.' );

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?

improve flow for pending FRAUD_RISK_STOPPED notification

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")?

Mismatching order total with coupons

Steps to reproduce

  1. Create order with regular discount coupon (30% discount)
  2. Capture order on Woocommerce order admin
  3. Review the order on Klarna merchant portal

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.

Notes

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.

Warnings are displayed in KOM settings

{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

Could OM via Woo admin work for orders added manually via Woo admin (and in Klarna via Seller's App)?

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?

image

image

Fatal error with release 1.8.0

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.

Fraud risk rejected orders no longer updating Woo order status - 500 error

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

Handle OM for KCO orders created using previous KCO plugin (woocommerce-gateway-klarna)

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.

Log Output in successful Checkout Summary - Use of undefined constant KCO_WC_VERSION...

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.