<?php
include "../connection/config.php";
include 'config.php';
extract($_REQUEST);

$dd = query("select session,active from users where mobile='$mobile'");
$d = fetch($dd);
if($d['session'] != $_REQUEST['session']){
    $data['success'] = "0";
    $data['msg'] = "You are not authorized to use this";
    $data['session0'] = $d['session'];
    $data['session1'] = $_REQUEST['session'];

    echo json_encode($data);
    return;
}

$order_id = md5($mobile.$amount.$d['session']);

$hash = openssl_encrypt($order_id, "AES-128-ECB", $_REQUEST['hash_key']);

$data['hash0'] = $hash;


$hash = openssl_encrypt($order_id, "AES-128-ECB", $_REQUEST['hash_key']);

$data['hash2'] = $hash;


$gateway = query("INSERT INTO `gateway_temp`( `user`, `amount`, `hash`, `type`) VALUES ('$mobile','$amount','$hash','$type')");

//notification start
    $user_details=mysqli_query($con,"select sn,tocken from users where mobile='$mobile'");
        if(mysqli_num_rows($user_details)>0)
        {
            $row=mysqli_fetch_assoc($user_details);
              
            if($row['tocken']!='')
            {
                $_REQUEST['token']=$row['tocken'];
      
              $msg = array
              (
        	   'body' 	=> 'Congratulation your add '.$points.' point'.' 🤑🤩🥳😍',
        	   'title'	=> 'PLUS LIFE',
        	   'vibrate' => 1,
        	   'sound' => 1,
        	   'image'=>'https://www.digitalkee.com/online_test/application_admin/assets/product/2096198.jpg'
               );
            	$fields = array
            			(
            				'to'		=> $_REQUEST['token'],
            				'notification'	=> $msg,
            				
            			);
            	$headers = array
            			(
            				//'Authorization: key=' . API_ACCESS_KEY,
            				'Authorization: key= AAAAj2wUFTg:APA91bF7grm_Se13eOkBKGEHa1_bECRlGolYgYLQWW_of1bKvB_gvnFfSdPVwIWmTRKrxhKoiOjtMDQZuo-oDHbjN8Uou9vgQnMeIfFH_c-rk7l8vc9nc-nGL9DTor_Imt6hJs-VgeOZ' ,
            				'Content-Type: application/json'
            			);	
            		$ch = curl_init();
            		curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
            		curl_setopt( $ch,CURLOPT_POST, true );
            		curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
            		curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
            		curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
            		curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
            		$result = curl_exec($ch );
                	//	echo $result; die();
            		
            		curl_close( $ch );
            }
        }
		
		//notification end

$data['success'] = "1";
$data['hash'] = $order_id;

echo json_encode($data);