btcpayserver / woocommerce-plugin

Plugin for connecting Woocommerce with BTCPayServer
https://btcpayserver.org/
Other
51 stars 41 forks source link

Product stock does not increase after expired order #33

Closed rangemaxx closed 4 years ago

rangemaxx commented 5 years ago

When an order expires because the customer doesn't pay, I expected the stock for the product to increase so that the inventory is accurate.

In this scenario, order is placed, stock gets decreased from 9 to 8. After the order expires, and status gets set to cancelled, the stock remains at 8. However, if I manually change the status from cancelled to processing, and back to cancelled, then the stock increases to 9.

Server logs look normal: 2019-10-19 17:18:37.435 +00:00 [INF] Invoice dg1CMAfVwuVxnvABx7VUD new event: invoice_created (1001) 2019-10-19 17:18:37.772 +00:00 [INF] IPN (1001 invoice_created) sent for invoice dg1CMAfVwuVxnvABx7VUD 2019-10-19 17:19:32.036 +00:00 [INF] Invoice status is expired 2019-10-19 17:19:32.084 +00:00 [INF] Invoice dg1CMAfVwuVxnvABx7VUD new event: invoice_expired (1004) 2019-10-19 17:19:33.008 +00:00 [INF] IPN (1004 invoice_expired) sent for invoice dg1CMAfVwuVxnvABx7VUD 2019-10-19 17:19:33.243 +00:00 [INF] IPN (1004 invoice_expired) sent for invoice dg1CMAfVwuVxnvABx7VUD

And there's nothing in the woocommerce-plugin logs.

I am running WordPress v 5.2.4, along with WooCommerce 3.7.1.

I'm at a loss for what's happening here, and what the issue might be. Is this expected behavior? Do most users just manually update the stock after an order expires? Any assistance is greatly appreciated.

NicolasDorier commented 5 years ago

ping @astupidmoose I think he used another plugin for managing stocks. The stock management is not something simple with a one size fit all solution afaik.

rangemaxx commented 5 years ago

@astupidmoose Can you provide any insight into this? Quite stuck with this at the moment.

astupidmoose commented 5 years ago

Actually I don't use a separate plugin. My stock seems to be working without issue for the most part.

NicolasDorier commented 5 years ago

So if an order expire, it goes back to stock?

rangemaxx commented 5 years ago

Huh, peculiar! Does it update in the notes when the stock level is increased? I've checked both the product, and the notes, but it doesn't seem to increase. Same scenario (but different message) for cancelled(expired) and failed(didn't confirm in time) orders.

Unpaid order cancelled – time limit reached. Order status changed from Pending payment to Cancelled. Stock levels reduced: foobar 1 (fb) 6→5

NicolasDorier commented 5 years ago

@rangemaxx I checked btcpay code, and I confirm you that we don't replenish the stock.

So @astupidmoose must be using a hack or something.

astupidmoose commented 5 years ago

I checked and I don't have anything that would auto restock.

Do you have the hold stock option enabled? https://docs.woocommerce.com/document/configuring-woocommerce-settings/#inventory-options

The only other thing I can think of is maybe your order status flow is off. Are you using custom order statuses?

astupidmoose commented 5 years ago

Also, FYI this is an order being restocked automatically on expire:

image-d48475e6-b1ff-4e0c-a7a1-b9f539095659

rangemaxx commented 5 years ago

@astupidmoose I do have hold stock enabled set to 5 minutes for testing, with the invoice expiration also set to 5 minutes. I don't believe I have custom order statuses enabled, I changed very little with woocommerce after installing. Here are my order notes for an expired order. image

astupidmoose commented 5 years ago

Is that your full order notes?

Can you post your btcpay order status settings?

rangemaxx commented 5 years ago

Yes, those are the full order notes. Here are my btcpay order status settings, and below it are the logs for an order I just let expire. The order notes for this one look the same as the one in my last screenshot. image


10-30-2019 @ 11:26:02 -     [Info] Key and token empty checks passed.  Parameters in client set accordingly...
10-30-2019 @ 11:26:02 -     [Info] The IPN check appears to be valid.
10-30-2019 @ 11:26:02 -     [Info] Order ID is: 123
10-30-2019 @ 11:26:02 -     [Info] Order details retrieved successfully...
10-30-2019 @ 11:26:02 -     [Info] The current order status for this order is pending
10-30-2019 @ 11:26:02 -     [Info] The current status for this invoice is expired
10-30-2019 @ 11:26:02 -     [Info] The invoice is in the "expired" status...
10-30-2019 @ 11:26:02 -     [Info] Leaving ipn_callback()...
10-30-2019 @ 11:26:03 - BTCPay Woocommerce payment plugin object constructor called. Plugin is v3.0.9 and server is PHP v7.3```
astupidmoose commented 5 years ago

Our system is a bit different from these statuses but we do have a few custom ones so I can't see any issues.

The other thing I've noticed is our hold stock option is set to 60 minutes, but BTCPay expires in 30 minutes, so instead of woocommerce forcing the cancellation, its BTCPay through a manual cancellation. Perhaps a manual cancellation restocks and not an automatic expiry one?

not really sure what else to suggest. Maybe @pavlenex has further ideas

pavlenex commented 5 years ago

I don't have inventory/stocks, so can't be of much help here. Though you're sending processing status for two types of invoices, perhaps leave confirmed as blank. Not really sure.

rangemaxx commented 5 years ago

Hmm, still no luck. I tried setting hold stock to 10 minutes, BTCPay expiration to 5, but same thing. I tweaked the statuses a bit too - changed confirmed to blank with no change. I even reinstalled the btcpay woocommerce plugin with the same result. I also disabled the woocommerce stripe plugin as well just to be safe.

@astupidmoose What version of wordpress do you use? I'm currently using 5.2.4, with WooCommerce 3.7.1, and I have WooCommerce Admin disabled if that matters.

rangemaxx commented 5 years ago

Just checking in to see if anyone else has any ideas. I've created a fresh btcpay instance and reinstalled woocommerce but still have the same issue.

rangemaxx commented 4 years ago

In case anyone else runs into this issue, using a modified version of the answer here solves the problem.

Kukks commented 4 years ago

Or look at our docs :)

https://docs.btcpayserver.org/faq-and-common-issues/faq-integrations#error-if-you-use-an-alternative-order-numbering-system-please-see-class-wc-gateway-btcpayphp-to-apply-a-search-filter

On Sun, Dec 15, 2019 at 6:30 PM rangemaxx notifications@github.com wrote:

In case anyone else runs into this issue, using a modified version of the answer here https://stackoverflow.com/questions/43371621/increase-stock-when-ordering-in-woocommerce solves the problem.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/btcpayserver/woocommerce-plugin/issues/33?email_source=notifications&email_token=AAN357V2S45LVONVJYKODZTQYZSTLA5CNFSM4JCQWHKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEG456OA#issuecomment-565829432, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN357SV33XBWZ7C5LSKJCLQYZSTLANCNFSM4JCQWHKA .

rangemaxx commented 4 years ago

FWIW I'm 99% certain my numbering system is the default, especially since everything else seems to work fine.

NicolasDorier commented 4 years ago

Thanks for coming back with your workaround. On my side, not really using woocommerce myself, so I am quite lost at what can be happening :(

rangemaxx commented 4 years ago

No worries. I plan on setting up a second site with a fresh wordpress+woocommerce+btcpay server setup, so I'll be sure to take note of whether or not I have any issues, since it seems like it works properly for @astupidmoose right out of the box.

pavlenex commented 4 years ago

This seems like a custom thing that's not even covered in Woocommerce, closing this since the workaround has been documented here.