| | |
| | | 'treated' => $this->actionUpdateStatus($request, 'treated'), |
| | | 'remove' => $this->actionRemove($request), |
| | | 'resend' => $this->actionResend($request), |
| | | default => $this->error('Invalid action', 'invalid_action', 400) |
| | | default => $this->error('Invalid action', 'invalid_action') |
| | | }; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | if (empty($sanitized_invitations)) { |
| | | return $this->error('No valid invitations provided', 'no_invitations', 400); |
| | | return $this->error('No valid invitations provided', 'no_invitations',); |
| | | } |
| | | |
| | | $operationID = sanitize_text_field($request->get_param('id')); |
| | |
| | | |
| | | $referral_id = $request->get_param('referral_id'); |
| | | if (!$referral_id) { |
| | | return $this->error('referral_id required', 'missing_id', 400); |
| | | return $this->error('referral_id required', 'missing_id'); |
| | | } |
| | | |
| | | [$success, $message] = Referrals::getInstance()->updateStatus($referral_id, $status); |
| | |
| | | { |
| | | $referral_id = $request->get_param('referral_id'); |
| | | if (!$referral_id) { |
| | | return $this->error('referral_id required', 'missing_id', 400); |
| | | return $this->error('referral_id required', 'missing_id'); |
| | | } |
| | | |
| | | $result = Referrals::getInstance()->removeReferral($referral_id, get_current_user_id()); |
| | |
| | | { |
| | | $referral_id = $request->get_param('referral_id'); |
| | | if (!$referral_id) { |
| | | return $this->error('referral_id required', 'missing_id', 400); |
| | | return $this->error('referral_id required', 'missing_id'); |
| | | } |
| | | |
| | | $result = Referrals::getInstance()->resendInvitation($referral_id, get_current_user_id()); |
| | |
| | | $code = Referrals::getInstance()->getUserReferralCode($user_id); |
| | | |
| | | if (is_wp_error($code)) { |
| | | return $this->error($code->get_error_message(), 'code_error', 400); |
| | | return $this->error($code->get_error_message(), 'code_error'); |
| | | } |
| | | |
| | | return $this->success([ |
| | |
| | | $code = strtoupper(sanitize_text_field($request->get_param('code')??'')); |
| | | |
| | | if (empty($code)) { |
| | | return $this->error('Code required', 'missing_code', 400); |
| | | return $this->error('Code required', 'missing_code'); |
| | | } |
| | | |
| | | $referrer = Referrals::getInstance()->getUserByReferralCode($code); |
| | |
| | | public function handleClientUpload(WP_REST_Request $request): WP_REST_Response |
| | | { |
| | | if (empty($_FILES['file'])) { |
| | | return $this->error('No file uploaded', 'no_file', 400); |
| | | return $this->error('No file uploaded', 'no_file'); |
| | | } |
| | | |
| | | $file = $_FILES['file']; |
| | | |
| | | if ($file['error'] !== UPLOAD_ERR_OK) { |
| | | return $this->error('File upload error: ' . $file['error'], 'upload_error', 400); |
| | | return $this->error('File upload error: ' . $file['error'], 'upload_error'); |
| | | } |
| | | |
| | | // Validate file type |
| | |
| | | finfo_close($finfo); |
| | | |
| | | if (!in_array($mime_type, $allowed_types) && !in_array($file['type'], $allowed_types)) { |
| | | return $this->error('File must be a CSV', 'invalid_file_type', 400); |
| | | return $this->error('File must be a CSV', 'invalid_file_type'); |
| | | } |
| | | |
| | | // Validate file size (10MB max) |
| | | if ($file['size'] > 10 * 1024 * 1024) { |
| | | return $this->error('File size exceeds 10MB limit', 'file_too_large', 400); |
| | | return $this->error('File size exceeds 10MB limit', 'file_too_large'); |
| | | } |
| | | |
| | | // Import using JaneAppClientImporter |
| | |
| | | public function handleSalesUpload(WP_REST_Request $request): WP_REST_Response |
| | | { |
| | | if (empty($_FILES['file'])) { |
| | | return $this->error('No file uploaded', 'no_file', 400); |
| | | return $this->error('No file uploaded', 'no_file'); |
| | | } |
| | | |
| | | $file = $_FILES['file']; |
| | | |
| | | if ($file['error'] !== UPLOAD_ERR_OK) { |
| | | return $this->error('File upload error: ' . $file['error'], 'upload_error', 400); |
| | | return $this->error('File upload error: ' . $file['error'], 'upload_error'); |
| | | } |
| | | |
| | | // Validate file type |
| | |
| | | finfo_close($finfo); |
| | | |
| | | if (!in_array($mime_type, $allowed_types) && !in_array($file['type'], $allowed_types)) { |
| | | return $this->error('File must be a CSV', 'invalid_file_type', 400); |
| | | return $this->error('File must be a CSV', 'invalid_file_type'); |
| | | } |
| | | |
| | | // Validate file size (10MB max) |
| | | if ($file['size'] > 10 * 1024 * 1024) { |
| | | return $this->error('File size exceeds 10MB limit', 'file_too_large', 400); |
| | | return $this->error('File size exceeds 10MB limit', 'file_too_large'); |
| | | } |
| | | |
| | | // Import using JaneAppSalesImporter |