Order on hold, Even if successful payment on Custom Payment gateway in WooCommerce

Viewed 19

I created a custom payment gateway in WooCommerce Just wondering is why order status is still set to 'on-hold' status even the transaction is Complete. is there a wrong in my code?


                            if($successCode == "0"){                                
                                if($order -> status == 'processing'){
                                    //do nothing
                                }else{                                  
                                    $this -> msg['message'] = 'Thank you for shopping with us. Your account has been charged and your transaction is successful. We will be shipping your order to you soon. Payment reference no: ' . $payRef;
                                    $this -> msg['class'] = 'woocommerce_message';
                                    
                                    $order -> payment_complete();
                                    $order -> add_order_note('Your payment was successful! Payment reference no: '.$payRef);
                                    $woocommerce -> cart -> empty_cart();   
                                    echo ' - Payment Success!';
                                }
                            }else{  
                                if($order -> status == 'processing'){
                                    //do nothing
                                }else{                          
                                    $this -> msg['message'] = 'Thank you for shopping with us. However, the transaction has been declined. Payment reference no: '. $payRef;
                                    $this -> msg['class'] = 'woocommerce_error';
                                    
                                    $order -> update_status('failed');
                                    $order -> add_order_note('Sorry! your payment was unsuccessful! Payment reference no: '.$payRef);                               
                                    echo ' - Payment Failed!';
                                }
                            }
                        }else{
                            $this -> msg['message'] = 'Security Error. Illegal access detected. Payment reference no: '.$payRef;
                            $this -> msg['class'] = 'error';
                            
                            $order -> update_status('failed');
                            $order -> add_order_note('Secure Hash checking failed! Payment reference no: '.$payRef);
                            echo ' - Secure Hash Failed!';
                        }
                        
                        add_action('the_content', array(&$this, 'showMessage'));
                    
                    }

                }

            }
            
            exit();
            
        }
1 Answers
Related