btcpayserver / woocommerce-plugin

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

POST /wc-api/WC_Gateway_BtcPay/ 500 #35

Closed gillesgoetsch closed 4 years ago

gillesgoetsch commented 4 years ago

For the record, cause I didn't found the solution online.

I've setup a btcpayjungle server and using this plugin.

When an order is pending, my access log shows: XX.XXX.XXX.XXX - - [04/Nov/2019:20:32:29 +0100] "POST /wc-api/WC_Gateway_BtcPay/ HTTP/1.1" 500 6538 "-" "-"

Server Events showing: Error while sending IPN (1003 invoice_paidInFull): Unexpected return code: 500

WooCommerce-BTCPay Error Log shows: The BTCPay payment plugin was called to process an IPN message but could not retrieve the order details for order_id: "59287". If you use an alternative order numbering system, please see class-wc-gateway-btcpay.php to apply a search filter.

I'm using the "WooCommerce Sequential Order Numbers" Plugin. Order expires in WC-Admin after several 500, even though it was paid.

gillesgoetsch commented 4 years ago

It's happening because you use a different order number system.

See class-wc-gateway-btcpay.php telling you:

        //this is for the basic and advanced woocommerce order numbering plugins
        //if we need to apply other filters, just add them in place of the this one
            $order_id = apply_filters('woocommerce_order_id_from_number', $order_id);

            $order = wc_get_order($order_id);

This solves the issue and returns the correct order_id:

/**
 * Get correct order id for BTCPay Order
*/

function _theme_get_sequential_order_id($order_id) {
    $seq_id = wc_sequential_order_numbers()->find_order_by_order_number( $order_id );

    if($seq_id) {
        return $seq_id;
    } else {
        return $order_id;
    }
}
add_filter( 'woocommerce_order_id_from_number', '_theme_get_sequential_order_id' );
Kukks commented 4 years ago

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

On Wed, Nov 6, 2019 at 12:26 PM gillesgoetsch notifications@github.com wrote:

It's happening because you use a different order number system.

See class-wc-gateway-btcpay.php telling you:

  //this is for the basic and advanced woocommerce order numbering plugins
  //if we need to apply other filters, just add them in place of the this one
        $order_id = apply_filters('woocommerce_order_id_from_number', $order_id);

        $order = wc_get_order($order_id);

This solves the issue and returns the correct order_id:

  • Get correct order id for BTCPay Order */

function _theme_get_sequential_order_id($order_id) { $seq_id = wc_sequential_order_numbers()->find_order_by_order_number( $order_id );

if($seq_id) {
    return $seq_id;
} else {
    return $order_id;
}

} add_filter( 'woocommerce_order_id_from_number', '_theme_get_sequential_order_id' );

— 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/35?email_source=notifications&email_token=AAN357R6CYOBLUANZL32MY3QSKSUPA5CNFSM4JJTP7WKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDGG4BQ#issuecomment-550268422, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN357WQG7BTHEPH773TCF3QSKSUPANCNFSM4JJTP7WA .