<?php
require_once __DIR__ . '/vendor/autoload.php';

use Ubnt\UcrmPluginSdk\Service\PluginConfigManager;
use GuzzleHttp\Client;

$config = PluginConfigManager::create()->loadConfig();

$ip = $config['ipPuppeteer'] ?? '127.0.0.1'; // Fallback
$port = $config['portPuppeteer'] ?? '4100'; // Fallback, docker-compose says 4100 host -> 4000 container
$paymentId = 907;
$oxxoMethodId = 'b01c0b35-b42c-48d9-9ad9-ea6591adfbbb';

echo "Testing Microservice Patch on Payment $paymentId to OXXO Pay ($oxxoMethodId)...\n";

$client = new Client();
try {
    $url = "http://$ip:$port/payments/$paymentId/method";
    echo "URL: $url\n";

    $response = $client->patch($url, [
        'json' => ['methodId' => $oxxoMethodId]
    ]);

    echo "Response Code: " . $response->getStatusCode() . "\n";
    echo "Body: " . $response->getBody()->getContents() . "\n";
} catch (\Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
    if (method_exists($e, 'getResponse') && $e->getResponse()) {
        echo "Response Error: " . $e->getResponse()->getBody()->getContents() . "\n";
    }
}
