true, CURLOPT_HTTPHEADER => ['X-API-Key: ' . FRAUDSPY_API_KEY, 'Content-Type: application/json'], CURLOPT_POSTFIELDS => json_encode(['phone' => $phone]), CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 8, ]); $res = curl_exec($ch); curl_close($ch); $data = json_decode((string) $res, true); if (empty($data['success'])) { http_response_code(200); exit('fraudspy check failed, order left untagged'); } $risk = $data['data']['risk'] ?? 'unknown'; $note = sprintf( 'FraudSpy: %s risk — %s%% success rate (%d/%d delivered)', strtoupper($risk), $data['data']['success_rate'] ?? '?', $data['data']['delivered'] ?? 0, $data['data']['total_orders'] ?? 0, ); // ── 4. Tag + note the order back in Shopify ───────────────────────────── $existingTags = trim((string) ($order['tags'] ?? '')); $newTag = 'fraudspy-' . $risk . '-risk'; $tags = $existingTags === '' ? $newTag : $existingTags . ', ' . $newTag; $updatePayload = json_encode(['order' => ['id' => $order['id'], 'tags' => $tags, 'note' => $note]]); $ch = curl_init("https://" . SHOPIFY_STORE_DOMAIN . "/admin/api/" . SHOPIFY_API_VERSION . "/orders/{$order['id']}.json"); curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_HTTPHEADER => ['X-Shopify-Access-Token: ' . SHOPIFY_ADMIN_TOKEN, 'Content-Type: application/json'], CURLOPT_POSTFIELDS => $updatePayload, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 8, ]); curl_exec($ch); curl_close($ch); http_response_code(200); echo 'tagged: ' . $risk;