-2

I have got an error message for custom payment wordpress plugin when processing the payment such as:

Parse error: syntax error, unexpected T_PUBLIC in /home/galer258/public_html/dev/wp-content/plugins/bcasakuku/result.php on line 3

or please check out this link for further info.

Here result.php script

<?php

public function doPayment(){

    $_POST = json_decode(file_get_contents("php://input"), 1);
    if( $_SERVER['REQUEST_METHOD'] == 'POST' ){
        if( isset( $_POST['MerchantID'] ) AND isset( $_POST['TransactionID'] ) AND isset( $_POST['TransactionReffID'] ) AND isset( $_POST['Signature'] ) ){

            //VALIDATE MERCHANT ID
            if( $_POST['MerchantID'] ==  $_POST['MerchantID'] ){

                $orders = $_POST['TransactionID'];
                if( $orders AND is_numeric( $_POST['TransactionID'] ) ){

                    if( $orders['order_status_id'] == $this->$_POST['TransactionID'] {

                        $sakukuOrder = $_POST['TransactionID'];
                        if( $sakukuOrder ){
                            $str =  $sakukuOrder['AccToken'].$sakukuOrder['TransactionID'].$sakukuOrder['Amount'].$sakukuOrder['PaymentID'];
                            $validate = strtoupper( hash('sha256', $str) );

                            if( $_POST['Signature'] == $validate ){
                                $this->$sakukuOrder['TransactionID'], 5;
                                $this->generateOutput( 0, "00" );
                            }else{
                                $this->generateOutput( 1, "01" );
                            }

                        }else{
                            $this->generateOutput( 1, "01" );
                        }
                    }else{
                        $this->generateOutput( 2, "01" );
                    }           

                }else{
                    $this->generateOutput( 1, "01" );
                }
            }else{
                $this->generateOutput( 1, "01" );
            }

        }else{
            $this->generateOutput( 1, "01" );
        }
    }else{
        $this->generateOutput( 1, "01" );
    }
}

private function generateOutput( $rs, $status ){

    $reason = array(
        "Indonesian" => array("Sukses","Transaksi tidak dapat diproses.","Transaksi sudah dibayar."),
        "English" => array("Success","Transaction cannot be processed.","Transaction has been paid."),
    );

    $output = array(
            "MerchantID" => ( !isset( $_POST['MerchantID'] ) ) ? '' : $_POST['MerchantID'],
            "TransactionID" => ( !isset( $_POST['TransactionID'] ) ) ? '' : $_POST['TransactionID'],
            "FlagStatus" => "01",
            "ReasonStatus" => array( "Indonesian" => "", "English" => "" )
        );

    $output['FlagStatus'] = $status;
    $output['ReasonStatus']['Indonesian'] = $reason['Indonesian'][ $rs ];
    $output['ReasonStatus']['English'] = $reason['English'][ $rs ];
    echo json_encode($output);      
}
?>

You can try to buy one product on this link using BCA sakuku as payment option like screenshot below:

BCA SAkuku Payment Option

Any help would be much appreciated.

UPDATED #1:

Here latest result.php script

  <?php

function doPayment(){

    $_POST = json_decode(file_get_contents("php://input"), 1);
    if( $_SERVER['REQUEST_METHOD'] == 'POST' ){
        if( isset( $_POST['MerchantID'] ) AND isset( $_POST['TransactionID'] ) AND isset( $_POST['TransactionReffID'] ) AND isset( $_POST['Signature'] ) ){

            //VALIDATE MERCHANT ID
            if( $_POST['MerchantID'] ==  $_POST['MerchantID'] ){
                $sakukuOrder = $_POST['TransactionID'];  
                $orders = $_POST['TransactionID'];
                if( $orders AND is_numeric( $_POST['TransactionID'] ) ){

                    if( $orders['order_status_id'] == $this->$_POST['TransactionID'] {


                        if( $sakukuOrder ){
                            $str =  $sakukuOrder['AccToken'].$sakukuOrder['TransactionID'].$sakukuOrder['Amount'].$sakukuOrder['PaymentID'];
                            $validate = strtoupper( hash('sha256', $str) );

                            if( $_POST['Signature'] == $validate ){
                                $this->$sakukuOrder['TransactionID'], 5;
                                $this->generateOutput( 0, "00" );
                            }else{
                                $this->generateOutput( 1, "01" );
                            }

                        }else{
                            $this->generateOutput( 1, "01" );
                        }
                    }else{
                        $this->generateOutput( 2, "01" );
                    }           

                }else{
                    $this->generateOutput( 1, "01" );
                }
            }else{
                $this->generateOutput( 1, "01" );
            }

        }else{
            $this->generateOutput( 1, "01" );
        }
    }else{
        $this->generateOutput( 1, "01" );
    }
}

private function generateOutput( $rs, $status ){

    $reason = array(
        "Indonesian" => array("Sukses","Transaksi tidak dapat diproses.","Transaksi sudah dibayar."),
        "English" => array("Success","Transaction cannot be processed.","Transaction has been paid."),
    );

    $output = array(
            "MerchantID" => ( !isset( $_POST['MerchantID'] ) ) ? '' : $_POST['MerchantID'],
            "TransactionID" => ( !isset( $_POST['TransactionID'] ) ) ? '' : $_POST['TransactionID'],
            "FlagStatus" => "01",
            "ReasonStatus" => array( "Indonesian" => "", "English" => "" )
        );

    $output['FlagStatus'] = $status;
    $output['ReasonStatus']['Indonesian'] = $reason['Indonesian'][ $rs ];
    $output['ReasonStatus']['English'] = $reason['English'][ $rs ];
    echo json_encode($output);      
}
?>

Got another error message such as:

Parse error: syntax error, unexpected T_IF in /home/galer258/public_html/dev/wp-content/plugins/bcasakuku/result.php on line 18

So How I can fix it?

user3077416
  • 271
  • 2
  • 10
  • 31
  • Functions can only be declared public or private inside Classes, Interfaces or Traits. – prehfeldt Feb 25 '16 at 10:24
  • It seems that the plugin is not correctly installed, or is not working at all. It looks incomplete. I believe that you aren't supposed to call `result.php` directly. – Michiel Pater Feb 25 '16 at 10:25
  • `if( $orders['order_status_id'] == $this->$_POST['TransactionID'] {`. You missed a closing brace. – Michiel Pater Feb 25 '16 at 10:53
  • Try to use any PHP editor in order to see what and where are you errors. NtBeans IDE is a good start. `$this->$sakukuOrder['TransactionID'], 5;` also is not valid syntax. – mitkosoft Feb 25 '16 at 10:55
  • @MichielPater its already fixed please check out my another problem on [this link](http://stackoverflow.com/questions/36308017/php-logic-always-fails-when-generate-different-output-for-same-flag-status) – user3077416 Apr 05 '16 at 02:49

1 Answers1

1

The public keyword is used only in function/variable declarations from within a class. Since you're not using a class you need to remove it from your code.

mitkosoft
  • 5,262
  • 1
  • 13
  • 31