Support » Plugin: BTCPay for WooCommerce (Legacy) » Order status handling

  • Resolved slate

    (@meanwood)


    Hello,
    If we have a virtual & downloadable product, the default “WooCommerce” flow would be to set the order to “Completed” upon receipt of payment.

    A product, that is only virtual or only downloadable will go to “Processing”. I am using this functionality in my shop for certain products to distinguish which of them will go to completed and which go to processing (as they require manual interaction).

    View post on imgur.com

    Looking at the plugin configuration, there only seems to be a way to “statically” configure the Order states.

    How can I make btcpay work the way WooCommerce does by default?

    To give an example, this plugin from a 3rd party crypto payment processor does implement it this way, maybe that helps: https://wordpress.org/plugins/coinpayments-payment-gateway-for-woocommerce/

    If I interpret this correctly, we would have to call https://woocommerce.wp-a2z.org/oik_api/wc_orderpayment_complete/ instead of forcing the order status externally.

    Example implementation from the aforementioned plugin:

    
    /**
         * Successful Payment!
         *
         * @access public
         * @param array $posted
         * @return void
         */
        function successful_request( $posted ) {
            global $woocommerce;
    
            $posted = stripslashes_deep( $posted );
    
            // Custom holds post ID
            if (!empty($_POST['invoice']) && !empty($_POST['custom'])) {
                    $order = $this->get_coinpayments_order( $posted );
                    if ($order === FALSE) {
                        die("IPN Error: Could not find order info for order: ".$_POST['invoice']);
                    }
    
                $this->log->add( 'coinpayments', 'Order #'.$order->get_id().' payment status: ' . $posted['status_text'] );
                 $order->add_order_note('CoinPayments.net Payment Status: '.$posted['status_text']);
    
                 if ( $order->get_status() != 'completed' && get_post_meta( $order->get_id(), 'CoinPayments payment complete', true ) != 'Yes' ) {
                     // no need to update status if it's already done
                if ( ! empty( $posted['txn_id'] ) )
                     update_post_meta( $order->get_id(), 'Transaction ID', $posted['txn_id'] );
                if ( ! empty( $posted['first_name'] ) )
                     update_post_meta( $order->get_id(), 'Payer first name', $posted['first_name'] );
                if ( ! empty( $posted['last_name'] ) )
                     update_post_meta( $order->get_id(), 'Payer last name', $posted['last_name'] );
                if ( ! empty( $posted['email'] ) )
                     update_post_meta( $order->get_id(), 'Payer email', $posted['email'] );
    
                            if ($posted['status'] >= 100 || $posted['status'] == 2 || ($this->allow_zero_confirm && $posted['status'] >= 0 && $posted['received_confirms'] > 0 && $posted['received_amount'] >= $posted['amount2'])) {
                                print "Marking complete\n";
                                update_post_meta( $order->get_id(), 'CoinPayments payment complete', 'Yes' );
                     $order->payment_complete();
                            } else if ($posted['status'] < 0) {
                                print "Marking cancelled\n";
                  $order->update_status('cancelled', 'CoinPayments.net Payment cancelled/timed out: '.$posted['status_text']);
                                mail( get_option( 'admin_email' ), sprintf( __( 'Payment for order %s cancelled/timed out', 'woocommerce' ), $order->get_order_number() ), $posted['status_text'] );
                } else {
                                print "Marking pending\n";
                                $order->update_status('pending', 'CoinPayments.net Payment pending: '.$posted['status_text']);
                            }
                }
                die("IPN OK");
            }
        }
    
    • This topic was modified 2 years, 4 months ago by slate.
    • This topic was modified 2 years, 4 months ago by slate.
    • This topic was modified 2 years, 4 months ago by slate.
    • This topic was modified 2 years, 4 months ago by slate.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Order status handling’ is closed to new replies.