Впервые интегрируя платежный шлюз, после интеграции PayUmoney в php отображается черная страница - PullRequest
1 голос
/ 05 октября 2019

Первая интеграция платежного шлюза на любом сайте. Я использую PayUmoney в форме регистрации, и когда я интегрирую болт PayUmoney и приступаю к оплате, он просто показывает мне пустую страницу. Ошибка не выдается, если нет ошибки, которую я могу попытаться найти, но не смог.

register.php

<code><?php

    error_reporting( E_ALL );
    ini_set( 'display_errors', 1 );


    /* change this to include YOUR db connection or edit as appropriate */
    $dbhost =   '127.0.0.1';
    $dbuser =   'root'; 
    $dbpwd  =   ''; 
    $dbname =   'xxx';
    $db = new mysqli( $dbhost, $dbuser, $dbpwd, $dbname );





    if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') == 0){

        function uploaderror( $error ){ 
            switch( $error ) { 
                case UPLOAD_ERR_INI_SIZE: return "The uploaded file exceeds the upload_max_filesize directive in php.ini"; 
                case UPLOAD_ERR_FORM_SIZE: return "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"; 
                case UPLOAD_ERR_PARTIAL: return "The uploaded file was only partially uploaded"; 
                case UPLOAD_ERR_NO_FILE: return "No file was uploaded"; 
                case UPLOAD_ERR_NO_TMP_DIR: return "Missing a temporary folder"; 
                case UPLOAD_ERR_CANT_WRITE: return "Failed to write file to disk"; 
                case UPLOAD_ERR_EXTENSION: return "File upload stopped by extension"; 
                default: return "Unknown upload error";
            }
        }

        //Request hash
    $contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';   
    if(strcasecmp($contentType, 'application/json') == 0){
        $data = json_decode(file_get_contents('php://input'));
        $hash=hash('sha512', $data->key.'|'.$data->txnid.'|'.$data->amount.'|'.$data->name.'|'.$data->email.'|||||'.$data->udf5.'||||||'.$data->salt);
        $json=array();
        $json['success'] = $hash;
        echo json_encode($json);

    }
    exit(0);

        $status=null;
        $errors=[];

        $valid_extensions = array('jpeg', 'jpg', 'png', 'gif', 'bmp' , 'pdf' , 'doc' , 'ppt');




        /* Edit as appropriate */
        $path = 'uploads/';   #   'uploads/'




        /* all mandatory fields */
        $required=array(
            'name'              =>  FILTER_SANITIZE_STRING,
            'gender'            =>  FILTER_SANITIZE_STRING,
            'mobile'            =>  FILTER_SANITIZE_STRING,
            'email'             =>  FILTER_SANITIZE_STRING,
            'address'           =>  FILTER_SANITIZE_STRING,
            'performing'        =>  FILTER_SANITIZE_STRING,
            'facebook'          =>  FILTER_SANITIZE_STRING, 
            'twitter'           =>  FILTER_SANITIZE_STRING, 
            'instagram'         =>  FILTER_SANITIZE_STRING, 
            'about'             =>  FILTER_SANITIZE_STRING,
            'amount'            =>  FILTER_SANITIZE_STRING
        );
        /* Probably at least 1 is required */
        $optional=array(
            'dj'                =>  FILTER_SANITIZE_NUMBER_INT,
            'vj'                =>  FILTER_SANITIZE_NUMBER_INT,
            'producer'          =>  FILTER_SANITIZE_NUMBER_INT,
            'bollywood'         =>  FILTER_SANITIZE_NUMBER_INT,
            'techno'            =>  FILTER_SANITIZE_NUMBER_INT,
            'trap'              =>  FILTER_SANITIZE_NUMBER_INT,
            'trance'            =>  FILTER_SANITIZE_NUMBER_INT,
            'bigroom'           =>  FILTER_SANITIZE_NUMBER_INT,
            'hiphop'            =>  FILTER_SANITIZE_NUMBER_INT,
            'housemusic'        =>  FILTER_SANITIZE_NUMBER_INT,
            'substep'           =>  FILTER_SANITIZE_NUMBER_INT,
            'retro'             =>  FILTER_SANITIZE_NUMBER_INT,
            'psytrance'         =>  FILTER_SANITIZE_NUMBER_INT,
            'turntabulist'      =>  FILTER_SANITIZE_NUMBER_INT,
            'other'             =>  FILTER_SANITIZE_NUMBER_INT
        );

        /* all required */
        $filefields=array(
            'image',
            'attach_file'
        );

        /* Ensure that all the required fields are populated */
        foreach( array_keys( $required ) as $key ){
            try{
                if( !isset( $_POST[ $key ] ) ) throw new Exception( sprintf( 'The field "%s" cannot be empty', $key ) );
            }catch( Exception $e ){
                $errors[]=$e->getMessage();
                continue;
            }
        }

        /* Ensure that all image fields are populated */
        foreach( $filefields as $field ){
            try{
                if( empty( $_FILES[ $field ] ) ) throw new Exception( sprintf( 'The file field "%s" is required', $field ) );
            }catch( Exception $e ){
                $errors[]=$e->getMessage();
                continue;
            }
        }




        if( empty( $errors ) ){

            $sql='insert into `registration`
                ( `name`,`gender`,`mobile`,`email`,`address`,`performing`,`dj`,`vj`,`producer`,`bollywood`,`techno`,`trap`,`trance`,`bigroom`,`hiphop`,`housemusic`,`dubstep`,`retro`,`psytrance`,`turntabulist`,`other`,`facebook`,`twitter`,`instagram`,`about`,`amount`,`image`,`attach_file` )
                values
                ( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? )';

            $stmt=$db->prepare( $sql );
            if( !$stmt ) {
                /* Investigate errors and make corrections to db table &/or sql statement */
                exit( sprintf( 'Bad Foo! - %s', $db->error )  );
            }
            $stmt->bind_param(
                'ssssssiiiiiiiiiiiiiiisssssss',
                $name,
                $gender,
                $mobile,
                $email,
                $address,
                $performing,
                $dj,
                $vj,
                $producer,
                $bollywood,
                $techno,
                $trap,
                $trance,
                $bigroom,
                $hiphop,
                $housemusic,
                $dubstep,
                $retro,
                $psytrance,
                $turntabulist,
                $other,
                $facebook,
                $twitter,
                $instagram,
                $about,
                $amount,
                $image,
                $attach_file
            );



            $images=array();

            foreach( $filefields as $index => $field ){
                try{
                    /* assign a variable variable - cast as an object for convenience */
                    $obj=(object)$_FILES[ $field ];

                    if( isset( $obj ) ){

                        /* get details of the file */
                        $name=$obj->name;
                        $ext=strtolower( pathinfo( $name, PATHINFO_EXTENSION ) );
                        $tmp=$obj->tmp_name;
                        $size=$obj->size;
                        $error=$obj->error;

                        if( !in_array( $ext, $valid_extensions ) ) throw new Exception( sprintf('The file "%s" has an illegal file extension "%s"',$name,$ext ) );


                        if( $error==UPLOAD_ERR_OK && is_uploaded_file( $tmp ) ){

                            /* create the final name for the file to be saved */
                            $saveas = sprintf( '%s/%d.%s', $path, mt_rand( 1000, 1000000 ), $name );
                            $bytes  = move_uploaded_file( $tmp, $saveas );

                            if( $bytes ){
                                $images[ $field ]=(object)array(
                                    'name'  =>  $name,
                                    'size'  =>  $size
                                );                              
                            } else {
                                throw new Exception( sprintf( 'There was an error storing "%s"', $name ) );
                            }
                        } else {
                            throw new Exception( sprintf( 'There was a problem with "%s" - %s', $name, uploaderror( $error ) ) );
                        }
                    }
                }catch( Exception $e ){
                    $errors[]=$e->getMessage();
                    continue;
                }
            }




            $args=array_merge( $required, $optional );
            filter_input_array( INPUT_POST, $args );
            extract( $_POST );



            foreach( $filefields as $field ){
                ${$field}=$images[ $field ]->name;
            }



            if( empty( $errors ) ){
                $status=$stmt->execute();
                if( $stmt->errno!= 0 ) exit( sprintf( 'Critical Error: [%d] - %s',$stmt->errno,$stmt->error) );
                $stmt->close();
            }



        }
    }

?>
<!DOCTYPE html>
<html lang='en'>
    <head>
        <meta charset='utf-8' />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" >
        <script id="bolt" src="https://sboxcheckout-static.citruspay.com/bolt/run/bolt.min.js" bolt-
color="e34524" bolt-logo="logo.png"></script>


    </head>
    <body>
        <?php
            function getCallbackUrl()
{
    $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
    return $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . 'response.php';
}
        ?>
        <form method='post' enctype='multipart/form-data'>
            <input type="hidden" id="udf5" name="udf5" value="BOLT_KIT_PHP7" />
            <input type="hidden" id="surl" name="surl" value="<?php echo getCallbackUrl(); ?>" />
            <input type="hidden" id="key" name="key" value="hOxjEeU3" /> 
            <input type="hidden" id="salt" name="salt" value="05TBBdE1ZG" />
            <input type="hidden" id="hash" name="hash" placeholder="Hash" value="" />
            <div class='row' style='margin-top: 50px;'>
                <div class='col-md-6'>
                    <input type='text' class='form-control' id='name' name='name' placeholder='Enter name' required />
                </div>
                <div class='col-md-6'>
                    <input type='text' class='form-control' id='gender' name='gender' placeholder='Gender' required />
                </div>
                <div class='col-md-6'>
                    <input type='number' class='form-control' id='mobile' name='mobile' placeholder='Mobile Number' min="10" max="12" required />
                </div>
                <div class='col-md-6'>
                    <input type='text' class='form-control' id='email' name='email' placeholder='Email' required />
                </div>
                <div class='col-md-6'>
                    <input type='text' class='form-control' id='address' name='address' placeholder='Enter Your Full Address' required />
                </div>
                <div class='col-md-6'>
                    <input type='text' class='form-control' id='performing' name='performing' placeholder='Performing Since' required />
                </div>
                <div class='col-md-4' style='margin-top: 35px;'>
                    <input type='checkbox' name='dj' value='1'> DJ<br>
                </div>
                <div class='col-md-4' style='margin-top: 35px;'>
                    <input type='checkbox' name='vj' value='1'> VJ<br>
                </div>
                <div class='col-md-4' style='margin-top: 35px;'>
                    <input type='checkbox' name='producer' value='1'> Producer<br>
                </div>


                <div class='col-md-6' style='margin-top: 20px;'>
                    <h3>Category</h3>
                </div>


                <div class='col-md-6'></div>


                <div class='col-md-4' style='margin-top: 5px;'>
                    <input type='checkbox' name='bollywood' value='1'> Bollywood DJ<br>
                </div>
                <div class='col-md-4' style='margin-top: 5px;'>
                    <input type='checkbox' name='techno' value='1'> Techno DJ<br>
                </div>
                <div class='col-md-4' style='margin-top: 5px;'>
                    <input type='checkbox' name='trap' value='1'> Trap DJ<br>
                </div>
                <div class='col-md-4' style='margin-top: 5px;'>
                    <input type='checkbox' name='trance' value='1'> Trance DJ<br>
                </div>
                <div class='col-md-4' style='margin-top: 5px;'>
                    <input type='checkbox' name='bigroom' value='1'> Big Room DJ<br>
                </div>
                <div class='col-md-4' style='margin-top: 5px;'>
                    <input type='checkbox' name='hiphop' value='1'> Hip Hop DJ<br>
                </div>
                <div class='col-md-4' style='margin-top: 5px;'>
                    <input type='checkbox' name='housemusic' value='1'> House Music DJ<br>
                </div>
                <div class='col-md-4' style='margin-top: 5px;'>
                    <input type='checkbox' name='dubstep' value='1'> dubstep dj<br>
                </div>
                <div class='col-md-4' style='margin-top: 5px;'>
                    <input type='checkbox' name='retro' value='1'> Retro DJ<br>
                </div>
                <div class='col-md-4' style='margin-top: 5px;'>
                    <input type='checkbox' name='psytrance' value='1'> Psy-Trance DJ<br>
                </div>
                <div class='col-md-4' style='margin-top: 5px;'>
                    <input type='checkbox' name='turntabulist' value='1'> Turntabulist DJ<br>
                </div>
                <div class='col-md-4' style='margin-top: 5px; margin-bottom: 20px;'>
                    <input type='checkbox' name='other' value='1'> Any Other<br>
                </div>


                <div class='col-md-6'>
                    <input class='form-control' type='file' accept='image/*' name='image' />
                </div>
                <div class='col-md-6'>
                    <input class='form-control' type='file' accept='image/*' name='attach_file' />
                </div>


                <div class='col-md-6'>
                    <input type='url' class='form-control' id='facebook' name='facebook' placeholder='Facebook Url' required />
                </div>
                <div class='col-md-6'>
                    <input type='url' class='form-control' id='twitter' name='twitter' placeholder='Twitter Url' required />
                </div>
                <div class='col-md-6'>
                    <input type='url' class='form-control' id='instagram' name='instagram' placeholder='Instagram Url' required />
                </div>
                <div class='col-md-6'>
                    <input type='text' class='form-control' id='about' name='about' placeholder='About Yourself' required />
                </div>


                <div class='col-md-12' style='background-color: #fff; color: #000; margin-top: 50px;'>
                        <textarea rows="5" cols="50" name="amount" value="2500" readonly>Registration Charges.., INR 2500 &#13;&#10;This includes &#13;&#10;• Nomination for delhiites top 50 DJ's of the year &#13;&#10;• Promotional kit for social media.
                        </textarea>
                </div>
                <div class="col-md-12" style="color: #000">
                   <input type="checkbox" name="" required="">I agree to the T&C of Delhiits top 50 DJ's of the year. Privicy Policy
                </div>



            </div>
            <div class='col-md-12'>
                <input type='submit' value="Proceed to Payment" onclick="launchBOLT(); return false;" />
            </div>

        </form>
        <?php
            if( $_SERVER['REQUEST_METHOD']=='POST' ){
                /* were there any errors? display them perhaps... */
                if( !empty( $errors ) ) printf( '<pre>%s
', print_r ($ errors, правда ) );}?>

1 Ответ

0 голосов
/ 06 октября 2019

Здесь много чего происходит, и я не уверен в ходе программы здесь, но, возможно, есть некоторые интересные моменты:

Вы звоните $('#payment_form').bind(... ~ где payment_form? Точно так же вы вызываете $('#alertinfo') где alertinfo ??

В логике обработки массива POST есть часть кода для генерации хэша, но после этого у вас есть exit, поэтому выполнение программы будетвсегда останавливайтесь на этом пункте, который НЕ является тем, что, как я думаю, вы намереваетесь - так, возможно, больше похоже на:

//Request hash
$contentType = isset( $_SERVER["CONTENT_TYPE"] ) ? trim( $_SERVER["CONTENT_TYPE"] ) : '';

if( strcasecmp( $contentType, 'application/json') == 0 ){

    $data = json_decode( file_get_contents( 'php://input' ) );
    if( !$data )exit('ERROR');

    $hash=hash( 'sha512', $data->key.'|'.$data->txnid.'|'.$data->amount.'|'.$data->name.'|'.$data->email.'|||||'.$data->udf5.'||||||'.$data->salt );

    $json=array(
        'success' => $hash
    );

   exit( json_encode( $json ) ); //exit here within the `IF` statement rather than after...
}

Новые поля, которые есть в вашей HTML-форме, не отображаются в массиве $ args, используемом для FILTERмассив POST, они должны. Итак, эти поля:

<input type="hidden" id="udf5" name="udf5" value="BOLT_KIT_PHP7" />
<input type="hidden" id="surl" name="surl" value="<?php echo getCallbackUrl(); ?>" />
<input type="hidden" id="key" name="key" value="hOxjEeU3" /> 
<input type="hidden" id="salt" name="salt" value="05TBBdE1ZG" />
<input type="hidden" id="hash" name="hash" placeholder="Hash" value="" />

Имена, вероятно, должны быть включены в массив $ args ... так:

$required=array(
    'name'              =>  FILTER_SANITIZE_STRING,
    'gender'            =>  FILTER_SANITIZE_STRING,
    'mobile'            =>  FILTER_SANITIZE_STRING,
    'email'             =>  FILTER_SANITIZE_STRING,
    'address'           =>  FILTER_SANITIZE_STRING,
    'performing'        =>  FILTER_SANITIZE_STRING,
    'facebook'          =>  FILTER_SANITIZE_STRING, 
    'twitter'           =>  FILTER_SANITIZE_STRING, 
    'instagram'         =>  FILTER_SANITIZE_STRING, 
    'about'             =>  FILTER_SANITIZE_STRING,
    'amount'            =>  FILTER_SANITIZE_STRING,
    /* new fields */
    'udf5'              =>  FILTER_SANITIZE_STRING,
    'surl'              =>  FILTER_SANITIZE_STRING,
    'key'               =>  FILTER_SANITIZE_STRING,
    'salt'              =>  FILTER_SANITIZE_STRING,
    'hash'              =>  FILTER_SANITIZE_STRING
);

Я не буду признаться, чтобы понять, что на самом деле является JavaScriptделать на этом этапе, чтобы проблема могла лежать там, я не знаю.

Одна вещь - это посмотреть журнал ошибок PHP и посмотреть, есть ли там очевидные вещи. Вы включили error_reporting( E_ALL ) и т. Д.?

Возможно, вышеизложенное могло бы как-то помочь - надеюсь, что так. Удачи

...