the php web video script that I’m trying to modify allows Users to purchase videos successfully, however, the video price that is reflected in the db (‘u_paid_videos’) table (where transaction info is stored) appears to show the default video price (video_play_price from the ‘config’ db table) every time, instead of the accurate video price. I’m not sure if this code needs to be tweaked so that the actual price will show in the ‘video_play_price’ column (in ‘u_paid_videos’ table):
// get cost video // get the default video price, to use if there is no per video play price
$db->where('name', 'video_play_price');
$db_cost = $db->getOne('config');
$video_cost = (float)$db_cost->value;
// the number of submitted videos - used to determine if all records were inserted
$count_video = count($id_array);
$user_id = $user->id;
$wallet = (float)str_replace(',', '', $user->wallet);
$balance = (float)str_replace(',', '', $user->balance);
// add up the video prices
$amount = 0;
foreach ($id_array as $id) {
$video_id = (int)PT_Secure($id);
// get video data
$video = $db->where('id', $id)->getOne(T_VIDEOS);
// add the video play price if any, or the default price
$amount += $video->video_play_price?$video->video_play_price:$video_cost;
}
// determine if the user has enough credits
if( ($wallet >= $amount) OR ($balance + $wallet >= $amount) ) {
$db->startTransaction();
$inserted_records = 0;
foreach ($id_array as $id){
$video_id = (int)PT_Secure($id);
// get video data
$video = $db->where('id', $id)->getOne(T_VIDEOS);
// use the video play price if any, or the default price
$video_cost_new = $video->video_play_price?$video->video_play_price:$video_cost;
$uploader_amount = $video_cost_new *0.50;
// add data to paid table
$insert_buy = $db->insert('u_paid_videos', [
'id_user' => $user_id,
'id_video' => $video_id,
'session_key' => $_SESSION['session_key'],
'video_play_price' => (string)$video_cost,
'video_title' => $video->title,
'user_id_uploaded' => $video->user_id,
'earned_amount' => $uploader_amount
]);
any suggestions are welcomed