function ss_check_code_before_process($code)
 {
     $repo = SS_Envato_API()->purchase_repo;
     $result = array('status' => 'error', 'msg' => '', 'data' => '');
     // Check if already in the database
     $existed = $repo->is_exists($code);
     if (!empty($existed) && isset($existed[0]['user_id'])) {
         $user = get_userdata($existed[0]['user_id']);
         $user_email = ss_hide_mail($user->user_email);
         $result = array('status' => 'error', 'msg' => __('Sorry, this key is already in the database. Registered for email <strong>', 'ss-envato-api') . $user_email . '</strong>');
         return $result;
     } else {
         $valid = $repo->validate_code($code);
         if ($valid) {
             $result = array('status' => 'success', 'data' => $valid);
         } else {
             $result = array('status' => 'error', 'msg' => __('Wrong validation code, please try again', 'ss-envato-api'));
         }
     }
     return $result;
 }
 /**
  * Process the purchase form.
  */
 public function process_purchase_code()
 {
     if (!empty($_POST['ss-envato-license'])) {
         $code = sanitize_text_field($_POST['ss-envato-license']);
         $existed = $this->_purchase_repo->is_exists($code);
         $purchase_info = $this->_purchase_repo->validate_code($code);
         /*if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
         			pr($purchase_info);
         		    die();
         		}*/
         if (!empty($existed) && isset($existed[0]['user_id'])) {
             $user = get_userdata($existed[0]['user_id']);
             $user_email = ss_hide_mail($user->user_email);
             $msg = __('Sorry, this key is already in the database. Registered for email <strong>', 'ss-envato-api') . $user_email . '</strong>';
             $this->_notices->add_error($msg);
         } else {
             if ($purchase_info) {
                 if ($this->_purchase_repo->add_code($code, $purchase_info)) {
                     // Successfully added
                     $this->_notices->add_success('Successfully added, now you can visit our forum');
                     if (defined('DOING_AJAX') && DOING_AJAX) {
                         $this->_notices->add_success('Page will be reloaded in 5 seconds.<script type="text/javascript">setTimeout(function() { window.location.reload(); }, 5000)</script>');
                     }
                 } else {
                     // Code already exists or something else
                     $this->_notices->add_error('Code can not be added to the database');
                 }
             } else {
                 // Wrong validation code, please try again
                 $this->_notices->add_error('Wrong validation code, please try again');
             }
         }
         if (defined('DOING_AJAX') && DOING_AJAX) {
             $this->_notices->show_msgs();
             die;
         }
         return;
     }
 }