• Dear Vipps Support Team,

    I hope this message finds you well.

    We are reaching out regarding an issue we are experiencing with the “Pay with Vipps and MobilePay for WooCommerce (v2.1.4)” plugin installed on our WordPress WooCommerce(v9.0.2) e-commerce site.

    We have set up integrations using the API to export orders to Warehouse software, where our client manages all their orders, products, and stock. Unfortunately, we are encountering a problem where orders are being sent twice to the warehouse API. This issue is occurring due to the woocommerce_payment_complete hook, which we use to export/upload orders to the Warehouse software.

    It appears that this hook is being triggered twice by the Vipps gateway, resulting in duplicate orders being sent to the Warehouse software. This creates significant problems for our client, as they receive duplicate orders on their end. Additionally, we have observed that Vipps logs are appearing twice, which suggests that some events at Vipps may be triggering twice (please see the following links for reference).

    <a href=”https://prnt.sc/OXc2wsyCGhuT “>https://prnt.sc/OXc2wsyCGhuT
    https://prnt.sc/0ODU7DuT4fWJ

    We kindly request your assistance in investigating this issue to determine why the woocommerce_payment_complete hook is being triggered twice and to resolve the duplication problem.

    We look forward to your prompt assistance.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Iver Odin Kvello

    (@iverok)

    Hello,

    First, just as a general notice, I’ve noticed that there are several woo hooks that can be called more than once, so it may not be 100% safe to rely on this in any case – you may want to additionally mark exported ordrers as such to avoid duplicate imports.

    That being said, you should not be getting the double lines in the order log like this. Could you also post the relevant logs from Woocommerce/status/logs?

    Further, the Express Checkout and Vipps Checkout flow works a bit differently from the normal WooCommerce order flow. Which order flow do you see these duplicate events for?

    Thread Starter kilowott

    (@kilowott)

    Hello. Thank you for your response.

    I wanted to provide you with an overview of our order flow within the system:

    In our system, we maintain several states as order meta. The order progresses through the following states:

    1. Initial State: When an order is created in WooCommerce, it is set to the “Initial” state.
    2. Processing State: Once the payment is completed, the woocommerce_payment_complete hook is triggered, and the order state changes to “Processing”.
    3. Sending State: We then take orders in the “Processing” state and send them to our Warehouse software through an API. Just before sending, we mark the order status as “Sending.”
    4. Complete/Failed State: After the order is uploaded to the Warehouse software, we update the status to either “Complete” or “Failed,” depending on the API response.

    Additionally, we are tracking and saving each state that the order passes through as order meta. Please see this screenshot for reference.

    Here, you’ll notice that the order goes through the “Initial” state even when it’s in the “Sending” state (i.e., during the process of sending to the Warehouse software). This suggests that the payment hook triggered by Vipps is being triggered twice.

    We do not have?Express Checkout?enabled on our site, so we are using the Vipps Checkout workflow. Only this is generated by vipps logs.

    Could you please take a look and let us know if you have any insights on this?

    Thanks. We look forward to your prompt assistance.

    Plugin Author Iver Odin Kvello

    (@iverok)

    Is “Sending” a custom Woo order status? It seems some of these statuses are specific to your system and not woo-statuses. The normal Woo status progress is “Pending” -> “Processing” -> “Complete”.

    The Vipps Checkout process, like the express checkout one, is particular in that it first creates the order without shipping, and then updates the order with shipping and user info after it has been completed. The ‘woocommerce_payment_complete’ hook should only fire once however. Have you actually logged that it fires more than once for this order? That is, something like

    add_action('woocommerce_payment_complete', function ($orderid) {
    $order = wc_get_order($orderid);
    if (!$order) return;
    if ($order->get_payment_method() != 'vipps') return;
    error_log("woocommerce_payment_complete called for order $orderid");
    });

    There *may* be a very rare race condition here that could cause some orders to be completed twice, but it should be extremely rare, so I don’t think that’s what happening.

    You may want to change the hook you are using to something like

    'woocommerce_order_status_pending_to_processing'

    and

    'woocommerce_order_status_failed_to_processing'

    — that may be a bit clearer.

    Thread Starter kilowott

    (@kilowott)

    Hi. We need to use woocommerce_payment_complete to export only paid orders. Can you suggest a way to prevent the race condition that is causing duplicate orders? Can the race condition be handled in the Vipps plugin?

    Plugin Author Iver Odin Kvello

    (@iverok)

    I really don’t think you are seeing the race condition, but if you are, and you are hosting this on a Unix system but not on an NFS drive, there is an option under “Advanced” named Use flock() to lock orders for Express Checkout which should ensure it doesn’t happen. You could try to log the event as noted above to check.

    I think a better approach is to mark your orders after export and then only export unmarked orders.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.