这是控制器中的代码:
function verify_transaction(){
$db = $this->GetModel();
$tablename = $this->tablename;
$ref = $_GET['reference'];
if($ref = ""){
header("Location:javascript://history.go(-1)");
}
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.paystack.co/transaction/verify/:reference",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer sk_test_c3197c645471e98ea33a6dd2e010e7ade7fe1aee",
"Cache-Control: no-cache",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
//echo $response;
$result = json_decode($response);
}
if($result->data->status == 'success'){
$status = $result->data->status;
$reference = $result->data->reference;
$amount = $result->data->amount;
$fname = $result->data->customer->first_name;
$lname = $result->data->customer->last_name;
$fullname = $lname.' '.$fname;
$cus_email = $result->data->customer->email;
$date_time = date('m/d/y h:i:s a',time());
$table_data = array(
"fullname" => $fullname,
"amount" => $amount,
"status" => $status,
"reference" => $reference,
"date_paid" => $date_time,
"email" => $cus_email
);
$rec_id = $this->rec_id=$db->insert($tablename, $table_data);
if($rec_id){
header("Location: successful.php?status=success");
exit;
}
else{
$this->set_page_error();
}
}
}
错误如下:
注意:未定义的属性:stdClass::$data,位于C:\wamp64\www\hms\app\controllers\PaymentsController.php的359 行
注意:试图在第359行上获取C:\wamp64\www\hms\app\controllers\PaymentsController.php中非对象的属性"status">
您正在尝试检查一个不存在的对象的状态。尝试在其他块中进行检查,如下所示:
if ($err) {
echo "cURL Error #:" . $err;
} else {
//echo $response;
$result = json_decode($response);
//Now that you have result, you can check for the status now
if($result->data->status == 'success'){
$status = $result->data->status;
........
}