Jump to content

Help with reflecting accurate price


Chrisj

Recommended Posts

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
				]);

 

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.