I keep getting the error above when checking out. The code is used for an app where the buyer makes a purchase. The purchase is successful but the error pops up during the check out process. In particular it says: "Warning: illegal offset 'OrderSession' on line 7" OrderSession is the name of my PHP file.
Line 7 is --> $Order_Data=$Order_Data['msg']['OrderSession']['string'];
<?php
include('config.php');
//print_r($_POST);
//echo $Order_Data=@$_POST;
//$Order_Data=key(@$_POST);
$Order_Data=$Order_Data['msg']['OrderSession']['string'];
//if app data recive store into session for use it later
if(isset($_GET['id']))
{
$_SESSION['App_Data']=$Order_Data;
}
//$json_data=base64_decode($json_data);
$App_Data=$_SESSION['App_Data'];
if($App_Data=="")
{
echo"access denied";
die();
}
//covert base64 to normal json from session App_Data
$json_data=base64_decode($App_Data);
//convert normal json into array
$order_data=json_decode($json_data, true);
$total_price=$order_data['price'];
if (isset($_GET['payment']))
{
//print_r($_POST);
if ($_GET['payment'] == 'paypal')
{
try
{
// login with paypal module
$payer = new \PayPal\Api\Payer();
$payer->setPaymentMethod('paypal');
$amount = new \PayPal\Api\Amount();
$amount->setTotal($total_price);
$amount->setCurrency(PAYPAL_CURRENCY);
$transaction = new \PayPal\Api\Transaction();
$transaction->setAmount($amount);
$redirectUrls = new \PayPal\Api\RedirectUrls();
$redirectUrls->setReturnUrl(SET_RETURN_URL)
->setCancelUrl(SET_CANCEL_URL);
$payment = new \PayPal\Api\Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setTransactions(array($transaction))
->setRedirectUrls($redirectUrls);
$payment->create($apiContext);
// login with paypal module
echo "<script>window.location='".$payment->getApprovalLink() ."'</script>";
}
catch (\PayPal\Exception\PayPalConnectionException $ex)
{
// This will print the detailed information on the exception.
//REALLY HELPFUL FOR DEBUGGING
echo $ex->getData();
}
}
}
$url=BASE_URL.'api/showUserDetail';
$data =array(
"user_id" => $order_data['user_id'],
"restaurant_id" => $order_data['restaurant_id']
);
$user_data=@curl_request($data,$url);
// print_r($user_data);
$user_cards=$user_data['msg']['UserInfo']['Cards'];
$restaurantName=$user_data['msg']['Restaurant']['Restaurant']['name'];
$restaurantImage=$user_data['msg']['Restaurant']['Restaurant']['image'];
$currency_symbol=$user_data['msg']['Restaurant']['Currency']['symbol'];
$tax=$user_data['msg']['Restaurant']['Tax']['tax'];
?>
<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Payment | Checkout</title>
<meta name="viewport" content="width=device-width, initial-scale = 1.0, maximum-scale = 1.0, user-scalable=no">
<link href="assets/css/fonts.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="assets/css/style.css?time<?php echo time(); ?>">
<!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">-->
<script src="assets/js/jquery-1.12.4.js"></script>
<script>
$(window).load(function() {
$('#status').fadeOut();
$('#preloader').delay(350).fadeOut('slow');
$('body').delay(350).css({'overflow':'visible'});
})
</script>
</head>
<body>
<div id="preloader" align="center">
<div id="loading">
<div class="spinner loading"></div>
</div>
</div>
<div class="mainServicesDetail">
<?php
//paypal thank you page
if(isset($_GET['status']))
{
?>
<br><br>
<div class="container">
<div class="restaurantInfo" style="text-align: center;">
<img src="assets/images/done.png" style="width: 80px;">
<h2 style="margin: 10px 0px;font-weight: 600;font-size: 18px; color:#363B3F;">Thank You</h2>
<p>Your Payment is Successfully Done</p>
</div>
</div>
<?php
die();
}
else
if(isset($_GET['paymentId']) && isset($_GET['token']) && isset($_GET['PayerID']))
{
$paymentId=$_GET['paymentId'];
$App_Data;
//covert base64 to normal json from session App_Data
$json_data=base64_decode($App_Data);
//convert normal json into array
$json_app_date=json_decode($json_data, true);
// print_r($json_app_date);
//modify json_array
$transaction_obj=array(
"cod"=>"0",
"payment_id"=>"0",
"transaction"=> array
(
"value"=>$paymentId,
"type"=>"paypal"
)
);
$newArrayPost=array_replace($json_app_date,$transaction_obj);
// post data on service
$url=BASE_URL.'api/placeOrder';
$data =$newArrayPost;
//echo json_encode($data);
$result_data=@curl_request($data,$url);
if($result_data['code']=="200")
{
echo "<script>window.location='./?status=paymentSuccess'</script>";
}
?>
<?php
die();
}
else
if(isset($_GET['payment']) || isset($_GET['p']))
{
if(@$_GET['payment'] == 'cards')
{
?>
<style>
.singleCard
{
padding: 10px 0 10px 10px;
border: solid 1px #eee;
margin: 8px 0 0 0;
border-radius: 4px;
color: #575757;
font-size: 14px;
cursor: pointer;
}
.cards
{
margin: 0 20px 0 20px;
}
.singleCard img
{
width: 40px;
vertical-align: middle;
margin-right: 10px;
}
</style>
<br><br>
<div class="container">
<div class="mainSecureCheckout">
<div class="sectionHeading padding20">
<h3>secure checkout</h3>
</div>
<hr>
<div class="paymentMethod">
<h3 class="padding20">Payment Method</h3>
<div class="itsSafeToPay padding20">
<i class="fa fa-lock" aria-hidden="true"></i>
<p style="color:#797A7E;font-weight: 300;font-size: 13px;">
It's safe to pay. All transactions are protected by SSL encryption.
</p>
</div>
<div class="pamentTypes" style="margin-top: 10px;">
<form id="formvisa" action="index.php?payment=payCardNow" method="get">
<input type="hidden" name="payment" value="payCardNow">
<div class="cards">
<?php
//print_r($_SESSION);
// echo $user_cards;
if($user_cards!="")
{
foreach ($user_cards as $single_row):
?>
<div class="singleCard" onclick="selectPayment('<?php echo $single_row['PaymentMethod']['id']; ?>')">
<input type="radio" id="<?php echo $single_row['PaymentMethod']['id']; ?>" name="selectCard" value="<?php echo $single_row['PaymentMethod']['id']; ?>" required>
<img src="assets/images/<?php echo $single_row['brand'] ?>.jpg">
**** **** **** <?php echo $single_row['last4'] ?>
</div>
<?php
endforeach;
}
?>
<a href="index.php?p=addNewCard" style="text-decoration: none; border: 0px;">
<div class="singleCard">
+ Add New Card
</div>
</a>
</div>
<button type="submit" class="proceedBtn">
Continue
</button>
</form>
</div>
</div>
</form>
</div>
</div>
<?php
}
else
if($_GET['payment'] == 'payCardNow')
{
$selectCard=@$_GET['selectCard'];
if(@$_GET['selectCard']=="")
{
echo "<script>window.location='index.php?payment=cards&status=error'</script>";
}
$App_Data;
//covert base64 to normal json from session App_Data
$json_data=base64_decode($App_Data);
//convert normal json into array
$json_app_date=json_decode($json_data, true);
// print_r($json_app_date);
//modify json_array
$transaction_obj=array(
"cod"=>"0",
"payment_id"=>$selectCard,
"transaction"=> array
(
"value"=>"1",
"type"=>"stripe"
)
);
$newArrayPost=array_replace($json_app_date,$transaction_obj);
// post data on service
$url=BASE_URL.'api/placeOrder';
$data =$newArrayPost;
//echo json_encode($data);
$result_data=@curl_request($data,$url);
if($result_data['code']=="200")
{
echo "<script>window.location='./?status=paymentSuccess'</script>";
}
}
else
if($_GET['p'] == 'addNewCard')
{
?>
<style>
.singlefield
{
border: solid 1px #eee;
margin: 8px 0 0 0;
border-radius: 4px;
height: 38px;
padding: 3px;
}
.formField
{
margin: 0 20px 0 20px;
}
.singlefield input
{
width: 290px;
height: 35px;
padding-left: 5px;
color: #575757;
font-size: 13px;
font-weight: 400;
border: none;
outline: 0;
}
</style>
<br><br>
<div class="container">
<div class="mainSecureCheckout">
<div class="sectionHeading padding20">
<h3>Add New Card</h3>
<img src="assets/images/cards.png" style="width: 180px;margin-top: 10px;">
</div>
<hr>
<div class="singlefield">
<input type="number" name="cvv_number" id="cvv_number" placeholder="CVV">
</div>
</div>
<button type="button" name="submit" class="proceedBtn" onclick="addCard()">
Continue
</button>
</div>
</div>
</div>
</div>
<?php
}
else
if($_GET['payment'] == 'cod')
{
$App_Data;
//covert base64 to normal json from session App_Data
$json_data=base64_decode($App_Data);
//convert normal json into array
$json_app_date=json_decode($json_data, true);
// print_r($json_app_date);
//modify json_array
$transaction_obj=array(
"cod"=>"1",
"payment_id"=>"0",
"transaction"=> array
(
"value"=>"1",
"type"=>"cod"
)
);
$newArrayPost=array_replace($json_app_date,$transaction_obj);
// post data on service
$url=BASE_URL.'api/placeOrder';
$data =$newArrayPost;
//echo json_encode($data);
$result_data=@curl_request($data,$url);
if($result_data['code']=="200")
{
echo "<script>window.location='./?status=paymentSuccess'</script>";
}
else
{
echo "<script>window.location='./?status=paymentFaild'</script>";
}
}
}
else
{
?>
<div class="container">
<div class="serviceDetails">
<div class="restaurantInfo" style="text-align: center;">
<div style="background: url('<?php echo BASE_URL.$restaurantImage; ?>') , grey;margin-left:35%;height: 80px;width: 80px;background-repeat: no-repeat;border-radius: 50%;background-size: cover;background-position: center;"></div>
<h2 style="margin: 10px 0px;font-weight: 500;font-size: 18px; color:#363B3F;"><?php echo $restaurantName; ?></h2>
</div>
<div class="detailOption">
<hr>
<p style="color: #6E6F74;font-size: 14px;font-weight: 300;">Services Detail</p>
<div class="options">
<ul>
<li><span>Rider Tip</span></li>
<li><span>Sub total</span></li>
<li><span>Tax (<?php echo $tax; ?>%)</span></li>
<li><span>Discount (0%)</span></li>
<li><span>Delivery Fee</span></li>
</ul>
<ul class="textRight">
<li><span><?php echo $currency_symbol.$order_data['rider_tip']; ?></span></li>
<li><span><?php echo $currency_symbol.$order_data['sub_total']; ?></span></li>
<li><span><?php echo $currency_symbol.$order_data['tax']; ?></span></li>
<li><span> </span></li>
<li><span><?php echo $currency_symbol.$order_data['delivery_fee']; ?></span></li>
</ul>
</div>
<hr>
<div class="total">
<ul>
<li><span>total</span></li>
<li class="dollar textRight "><span><?php echo $currency_symbol.$order_data['price']; ?></span></li>
</ul>
</div>
</div>
</div>
</div>
<style>
body
{
-webkit-user-select: none; /* Safari */
-ms-user-select: none; /* IE 10+ and Edge */
user-select: none; /* Standard syntax */
}
</style>
<div class="container">
<div class="mainSecureCheckout">
<div class="sectionHeading padding20">
<h3>secure checkout</h3>
</div>
<hr>
<form id="formvisa" action="index.php?action=payNow" method="get">
<div class="paymentMethod">
<h3 class="padding20">Payment Method</h3>
<div class="itsSafeToPay padding20">
<i class="fa fa-lock" aria-hidden="true"></i>
<p style="color:#797A7E;font-weight: 300;font-size: 13px;">
It's safe to pay. All transactions are protected by SSL encryption.
</p>
</div>
<div class="pamentTypes" style="margin-top: 10px;">
<div class="choseOption" onclick="selectPayment('cod');">
<input type="radio" id="cod" name="payment" value="cod" style="border: 0px; text-decoration: none;" checked>
<img src="assets/images/cod.png">
</div>
<div class="choseOption" onclick="selectPayment('cards');">
<input type="radio" id="cards" name="payment" value="cards">
<img src="assets/images/cards.png">
</div>
<div class="choseOption" onclick="selectPayment('paypal');">
<input type="radio" id="paypal" name="payment" value="paypal">
<img src="assets/images/paypal.png">
</div>
<button type="submit" class="proceedBtn" onclick="showLoading()">
Continue
</button>
</div>
</div>
</form>
</div>
</div>
<?php
}
?>
</div>
<script>
function showLoading()
{
$('#preloader').fadeIn();
}
function selectPayment(payment_method)
{
document.getElementById(payment_method).checked = true;
}
function addCard()
{
document.getElementById("preloader").style.display = "block";
var full_name=document.getElementById("full_name").value;
var car_number=document.getElementById("car_number").value;
var month=document.getElementById("month").value;
var year=document.getElementById("year").value;
var cvv_number=document.getElementById("cvv_number").value;
if(full_name=="" || car_number=="" || month=="" || year=="" || cvv_number=="")
{
document.getElementById("preloader").style.display = "none";
alert("Information must be filled");
return false;
}
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function ()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
//alert(xmlhttp.responseText);
//document.getElementById('contentReceived').innerHTML = xmlhttp.responseText;
if(xmlhttp.responseText=="200")
{
document.getElementById("preloader").style.display = "block";
window.location='index.php?payment=cards';
}
else
{
//alert(xmlhttp.responseText);
if(xmlhttp.responseText)
{
window.location='./?payment=cards';
document.getElementById("preloader").style.display = "none";
}
}
}
}
xmlhttp.open("GET", "ajex-event.php?q=addNewCard&full_name="+full_name+"&car_number="+car_number+"&month="+month+"&year="+year+"&cvv_number="+cvv_number);
xmlhttp.send();
}
</script>
</body>
</html>