It seems we can’t find what you’re looking for. Perhaps searching can help.
sky ai agent 'Please sign in or create an account to run audits.')); } $user_id = get_current_user_id(); $tool_type = sanitize_text_field($_POST['tool_type']); $user_text = sanitize_textarea_field($_POST['input_data']); if (empty($user_text)) { wp_send_json_error(array('message' => 'Please provide document text, invoices, or billing details.')); } // क्रेडिट नियम $pricing = array( 'tax_scanner' => array('cost' => 1, 'name' => '1099 Expense & Tax Deduction Scanner'), 'contract_hub' => array('cost' => 5, 'name' => 'Legal Contract & Risk Auditor'), 'medical_bill' => array('cost' => 10, 'name' => 'Medical Bill Error & Dispute Auditor'), ); if (!isset($pricing[$tool_type])) { wp_send_json_error(array('message' => 'Invalid service selection.')); } $cost = $pricing[$tool_type]['cost']; $current_credits = intval(get_user_meta($user_id, 'sk_credits', true)); if ($current_credits < $cost) { wp_send_json_error(array('message' => 'Insufficient credits. Required: ' . $cost . ' Credits. Please refill your balance.')); } // AI Prompts तैयार करना $system_prompts = array( 'tax_scanner' => "You are a US Certified Public Accountant (CPA) expert in IRS Schedule C and 1099 freelance deductions. Analyze the provided text. Group expenses into strict IRS categories. Highlight clear deductions, questionable deductions, and estimated tax write-off savings.", 'contract_hub' => "You are a top US Commercial Contract Attorney. Review the contract or agreement text. Identify aggressive indemnification clauses, one-sided termination terms, uncapped liabilities, intellectual property risks, and non-compete issues under US legal frameworks. Provide specific redlined improvements.", 'medical_bill' => "You are a leading US Medical Billing Auditor and Patient Advocate. Examine the medical invoice/charges. Identify frequent coding errors, unbundling, double billing, or prices exceeding standard Medicare/Fair Health benchmarks. Include a formal, ready-to-mail Dispute Letter addressed to the billing department." ); // Gemini API Request $api_url = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent?key=' . SK_GEMINI_API_KEY; $body = array( 'systemInstruction' => array( 'parts' => array( array('text' => $system_prompts[$tool_type]) ) ), 'contents' => array( array( 'parts' => array( array('text' => $user_text) ) ) ), 'generationConfig' => array( 'temperature' => 0.2, 'maxOutputTokens' => 2000 ) ); $response = wp_remote_post($api_url, array( 'headers' => array( 'Content-Type' => 'application/json', ), 'body' => json_encode($body), 'timeout' => 60 )); if (is_wp_error($response)) { wp_send_json_error(array('message' => 'AI engine connection error. Please try again.')); } $res_data = json_decode(wp_remote_retrieve_body($response), true); if (isset($res_data['error'])) { wp_send_json_error(array('message' => 'Engine Error: ' . $res_data['error']['message'])); } // Gemini Response Parsing $ai_output = $res_data['candidates'][0]['content']['parts'][0]['text']; // क्रेडिट काटना और नया बैलेंस सेव करना $new_balance = $current_credits - $cost; update_user_meta($user_id, 'sk_credits', $new_balance); wp_send_json_success(array( 'output' => $ai_output, 'remaining_credits' => $new_balance )); } // ========================================== // 3. STRIPE CHECKOUT API // ========================================== add_action('wp_ajax_sk_create_stripe_checkout', 'sk_create_stripe_checkout_session'); function sk_create_stripe_checkout_session() { check_ajax_referer('sk_agent_nonce', 'security'); if (!is_user_logged_in()) { wp_send_json_error(array('message' => 'Please login before purchasing credits.')); } $plan = sanitize_text_field($_POST['plan']); $user_id = get_current_user_id(); $tiers = array( 'pro' => array('price' => 1200, 'credits' => 40, 'name' => 'Pro Plan - 40 Credits'), 'biz' => array('price' => 2900, 'credits' => 120, 'name' => 'Business Plan - 120 Credits') ); if (!isset($tiers[$plan])) { wp_send_json_error(array('message' => 'Invalid plan.')); } $selected_tier = $tiers[$plan]; $response = wp_remote_post('https://api.stripe.com/v1/checkout/sessions', array( 'headers' => array( 'Authorization' => 'Bearer ' . SK_STRIPE_SECRET_KEY, 'Content-Type' => 'application/x-www-form-urlencoded', ), 'body' => http_build_query(array( 'payment_method_types' => array('card'), 'line_items' => array(array( 'price_data' => array( 'currency' => 'usd', 'unit_amount' => $selected_tier['price'], 'product_data' => array('name' => $selected_tier['name']), ), 'quantity' => 1, )), 'mode' => 'payment', 'client_reference_id' => $user_id, 'metadata' => array( 'credits_to_add' => $selected_tier['credits'] ), 'success_url' => home_url('/workspace/?payment=success'), 'cancel_url' => home_url('/pricing/?payment=cancelled'), )) )); $session = json_decode(wp_remote_retrieve_body($response), true); if (isset($session['url'])) { wp_send_json_success(array('checkout_url' => $session['url'])); } else { wp_send_json_error(array('message' => 'Stripe error: ' . ($session['error']['message'] ?? 'Could not initialize session.'))); } } // ========================================== // 4. STRIPE WEBHOOK // ========================================== add_action('rest_api_init', function () { register_rest_route('sk-agent/v1', '/stripe-webhook', array( 'methods' => 'POST', 'callback' => 'sk_handle_stripe_webhook', 'permission_callback' => '__return_true' )); }); function sk_handle_stripe_webhook(WP_REST_Request $request) { $payload = $request->get_body(); $event = json_decode($payload, true); if ($event && $event['type'] === 'checkout.session.completed') { $session = $event['data']['object']; $user_id = intval($session['client_reference_id']); $credits = intval($session['metadata']['credits_to_add']); if ($user_id > 0 && $credits > 0) { $existing_credits = intval(get_user_meta($user_id, 'sk_credits', true)); update_user_meta($user_id, 'sk_credits', $existing_credits + $credits); } } return new WP_REST_Response(array('status' => 'received'), 200); } // ========================================== // 5. ENQUEUE JAVASCRIPT & AJAX NONCE // ========================================== add_action('wp_enqueue_scripts', function() { wp_enqueue_script('jquery'); wp_localize_script('jquery', 'sk_engine', array( 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('sk_agent_nonce'), 'user_id' => get_current_user_id() )); }); // ========================================== // 6. SHORTCODE: USER CREDITS // ========================================== add_shortcode('sk_user_credits', function() { if (!is_user_logged_in()) return '0'; $credits = get_user_meta(get_current_user_id(), 'sk_credits', true); return $credits !== '' ? esc_html($credits) : '0'; }); ?>