Skip to content
This repository has been archived by the owner on Feb 23, 2022. It is now read-only.

Need help with custom order numbers #45

Open
maxdamage101 opened this issue Apr 8, 2020 · 2 comments
Open

Need help with custom order numbers #45

maxdamage101 opened this issue Apr 8, 2020 · 2 comments

Comments

@maxdamage101
Copy link

Hello,
First of all, I've installed a docker installation, it's working perfectly with woocommerce. Until I activate the custom order numbers plugin. I've created a support ticket on their side to- https://wordpress.org/support/topic/need-help-letting-my-payment-plugin-find-custom-order_id/#post-12644818

I'm using a custom order numbers plugin, and I'm trying to get the IPN messages to work with my custom order numbers. I've tried messing with the filter(Below) alot, but I can't seem to be able to get it to work. It's only giving me "500" errors.

`function get_order_id_from_custom_order_style($orderid){
if(is_string($orderid)){
$result = preg_replace('\D', '', $orderid);
return $result;
}
return $orderid;
}

add_filter('woocommerce_order_id_from_number', 'get_order_id_from_custom_order_style', 1);`

Now the thing is, when I have the custom order numbers plugin activated. It finds the custom numbers and puts it in the invoice generated on the invoice menu.
(plugin enabled)

Order Id | 3057723049
  | Error while sending IPN (1001 invoice_created): Unexpected return code: 500

Now my qeustion is, how do I find the customerID before I activated the plugin? Because when I disable this plugin I get this information in the invoice menu and everything works fine.
(plugin disabled)

Order Id | 1703
IPN (1005 invoice_confirmed) sent for invoice 2xdB8RwnMkZPtS83vYNEXW

If I could get assistance with this, I could really appreciate it.

@pavlenex pavlenex transferred this issue from btcpayserver/btcpayserver Apr 8, 2020
@dennisreimann
Copy link
Member

dennisreimann commented Dec 7, 2020

Can you check whether or not this helps? #40 (comment)

@dennisreimann
Copy link
Member

I've researched this a bit and maybe these notes help to proceed further.

Generate invoice

  • The process_payment($order_id) function receives the Order ID from WooCommerce. This is the actual database ID of the WooCommerce order (== WordPress post).
  • It turns this ID into an order number and sets the order number as the invoice's order ID for BTCPay (reference)
  • From there on, all data coming from BTCPay back into WooCommerce references the order number generated by any custom order number plugin before.
  • If no such plugin is used, the order number is equal to the order ID

Invoice callbacks

  • The ipn_callback() gets the order number from the invoice (see above), referencing it as $order_id
  • It applies the woocommerce_order_id_from_number filter, which is the users code that is supposed to turn it into the actual WooCommerce order id in the database. This code depends on the custom order number plugin being used.
  • The woocommerce_order_id_from_number filter function gets the custom order number. Referencing it as $orderid (as in the docs sample) is confusing, so we should clean that up.
  • The order lookup is done using the WooCommerce order ID, hence any failure leading to an error 500 is based upon the woocommerce_order_id_from_number not dereferencing the order number properly.

Proposal

  • Attach original WooCommerce order ID as custom data to the invoice object, so that it can be referenced back (debugging, accounting, etc.)
  • Offer code samples for popular "custom order number" plugin solutions in WordPress. There are multiple of them, which seems to be a source of confusion, as people might think the code from the docs is a one size fits all solution.
  • Clean up the gateway code to be precise about the different usages of oder id vs. number – variables as well as the debugging logs

dennisreimann added a commit to dennisreimann/woocommerce-plugin that referenced this issue Dec 11, 2020
Builds on [this proposal](btcpayserver#45 (comment)) and removes the ambiguity of order ID and number:

- Replaces references to the order number with the actual order ID
- Removes the `woocommerce_order_id_from_number `, because it is obsolete then
- Adds order number as well as other custom data for reference to the `posData` field of the invoice
- Changes logging output to mention order ID as well as number
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants