kingtommy dot com

MeetCritique video upload

Client project · Excerpts from the live MeetCritique code

MeetCritique customers spend a credit to submit a routine video for a judge's review. This is the submit request.

Before touching the file, the request checks the customer's credit balance and, if it is short, returns a redirect to the credit store. Single-skill critiques are paid for with a separate SkillCritique credit, and regular credits can never cover them.

With the balance confirmed, upload_video() sends the file to S3 and creates an AWS Elemental MediaConvert job to compress it. Compression finishes on MediaConvert after the request returns, so the customer gets an immediate answer while the heavy work runs in AWS.

The credit is spent last. The request writes a receipt row to app_transactions with the cost and the new balance, then updates the user's _download_credits. The receipt gives every debit an audit trail.

Check the balance ajax/submit.php:427-434
$credits = do_shortcode('[user_credits]');
if(!$credits || $credits<$cost) {
  $return->success = false;
  $return->message = 'Hang on! You need '. $cost.' Credit(s) to submit a video for review.';
  $return->redirect = '/get-credits';
  echo json_encode($return);
  return false;
}
Upload and start the transcode ajax/submit.php:566, 4592
$video_response = upload_video();
// …
$result = $mediaConvertClient->createJob($job);
Record the receipt and debit ajax/submit.php:768, 786, 790
$new_credits = intval($credits)-intval($cost);
// …
$result = $wpdb->insert($table,$data,$format);
// …
update_user_meta($userid, '_download_credits', $new_credits, $credits);

All demos