1b56aed681
Features: - AI Agent Hiring API (/api/hire) - Agent Discovery (/api/agents.json) - Stripe Checkout Integration - Webhooks for payment notifications - Telegram + Email alerts - Mobile responsive design - SEO optimized - AI-to-AI commerce ready Built: March 2026
79 lines
2.4 KiB
PHP
79 lines
2.4 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
|
|
// Stripe webhook secret
|
|
$webhookSecret = 'whsec_yoursecret'; // TODO: Get from Stripe Dashboard
|
|
|
|
// Get payload
|
|
$payload = file_get_contents('php://input');
|
|
$sig = $_SERVER['HTTP_STRIPE_SIGNATURE'] ?? '';
|
|
|
|
// Validate webhook (simplified - in production use webhook secret)
|
|
$data = json_decode($payload, true);
|
|
|
|
if (!$data || !isset($data['type'])) {
|
|
http_response_code(400);
|
|
exit;
|
|
}
|
|
|
|
$eventType = $data['type'];
|
|
$session = $data['data']['object'] ?? [];
|
|
|
|
if ($eventType === 'checkout.session.completed') {
|
|
// Payment successful - AI agent hired us!
|
|
$agentType = $session['metadata']['agent_type'] ?? 'unknown';
|
|
$email = $session['customer_email'] ?? '';
|
|
$sessionId = $session['id'] ?? '';
|
|
$amount = isset($session['amount_total']) ? $session['amount_total'] / 100 : 0;
|
|
|
|
// Log the hire
|
|
$log = [
|
|
'timestamp' => date('Y-m-d H:i:s'),
|
|
'event' => 'ai_agent_hired',
|
|
'agent' => $agentType,
|
|
'email' => $email,
|
|
'session_id' => $sessionId,
|
|
'amount' => $amount
|
|
];
|
|
|
|
// Save to hires log
|
|
$logFile = '/var/www/hostpioneers.com/public_html/api/hires.log';
|
|
$existing = file_exists($logFile) ? json_decode(file_get_contents($logFile), true) : [];
|
|
$existing[] = $log;
|
|
file_put_contents($logFile, json_encode($existing, JSON_PRETTY_PRINT));
|
|
|
|
// Send Telegram notification
|
|
$telegramToken = '8644418426:AAEL8GvHwohNDkxaru5yCZFPgh5Gsc-yAhA';
|
|
$chatId = '382315644';
|
|
$text = "🤖 *AI AGENT HIRED!*
|
|
|
|
*Agent:* $agentType
|
|
*Email:* $email
|
|
*Amount:* $" . number_format($amount, 2) . "
|
|
*Session:* $sessionId";
|
|
|
|
$ch = curl_init("https://api.telegram.org/bot$telegramToken/sendMessage?chat_id=$chatId&text=" . urlencode($text) . "&parse_mode=Markdown");
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_exec($ch);
|
|
curl_close($ch);
|
|
|
|
// Send email
|
|
$to = 'sales@hostpioneers.com';
|
|
$subject = "🤖 AI Agent Hired: $agentType - $" . number_format($amount, 2);
|
|
$body = "AI Agent hired!
|
|
|
|
Agent: $agentType
|
|
Customer: $email
|
|
Amount: $" . number_format($amount, 2) . "
|
|
Session: $sessionId
|
|
|
|
---
|
|
This was an automated notification from HostPioneers API.";
|
|
|
|
@mail($to, $subject, $body);
|
|
|
|
echo json_encode(['success' => true, 'message' => 'Hire logged and notifications sent']);
|
|
} else {
|
|
echo json_encode(['success' => true, 'message' => 'Event ignored']);
|
|
}
|