<?php
//paystack
$serName = $_SERVER['HTTP_HOST'];

$request_dir = $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']);
$callback_url = "https://$request_dir/GetPayCheck.php";

$email = $data['email'];
$phone = $data['phone'];

$email = str_replace( array( '+', ',', '-', '/', '(', ')',   '_', '//', 'drop', 'update', 'delete', 'insert', 'add',  '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $email);

$phone = str_replace( array( '+', ',', '-', '/', '(', ')',   '_', '//', 'drop', 'update', 'delete', 'insert', 'add',  '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $phone);

$fname = str_replace( array( '+', ',', '-', '/', '(', ')',   '_', '//', 'drop', 'update', 'delete', 'insert', 'add',  '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $fname);

$lname = str_replace( array( '+', ',', '-', '/', '(', ')',   '_', '//', 'drop', 'update', 'delete', 'insert', 'add',  '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $lname);

$uid = str_replace( array( '+', ',', '-', '/', '(', ')',   '_', '//', 'drop', 'update', 'delete', 'insert', 'add',  '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $uid);

$callback_url = str_replace( array( '+', ',', '(', ')',  'drop', 'update', 'delete', 'insert', 'add',  '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $callback_url);

$txt = str_replace( array( '+', ',', '-', '/', '(', ')',  '//', 'drop', 'update', 'delete', 'insert', 'add',  '{',   '}',   '<',  '>',  '='), '', $pro);


$message = utf8_encode($txt);
$memo = urlencode($message);


   $qryApi = mysqli_query($conn,"SELECT * FROM payment");
    $apidata = mysqli_fetch_array($qryApi);


	
	$getpaykey = $apidata['getpaykey']; //email address()
    $getpaysec = $apidata['getpaysec'];
     $getpayurl = $apidata['getpayurl'];
    $feebearer = $apidata['feeBearer']; 


 $host="https://$getpayurl/api/v1/payment/?apikey=$getpaykey&firstName=$fname&lastName=$lname&customerEmail=$email&customerPhone=$phone&amount=$amount&referenceID=$uid&redirect_url=$callback_url&description=$memo&feeBearer=$feebearer&paymentMethod=$Paymethod";




//Initialize cURL.

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $host);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);


$response = curl_exec($ch);

$data = curl_exec($ch);

$result = json_decode($data);

//Close the cURL handle.

curl_close($ch);


$APImessage = $result->data->message;


$paymentLink = $result->data->paymentLink;


$tranx = json_decode($response, true);

//echo $link = $tranx['data']['paymentLink'];




	echo '<script> 
window.location.href=" '.$tranx['data']['paymentLink'].' "; </script>';



 ?>