#!/bin/bash
# Тест Florex CarrierService callback.
# Важно: OVH (ModSecurity) блокирует стандартный User-Agent курла — поэтому подставляем браузерный.

URL="https://webhook.florex.es/shipping/rates.php"
UA="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0 Safari/537.36"

test_zip () {
  echo "== CP $1 · корзина $2 € · ожидаем: $4 =="
  curl -s -X POST "$URL" -A "$UA" -H 'Content-Type: application/json' -d "{
    \"rate\": {
      \"destination\": { \"postal_code\": \"$1\", \"country\": \"ES\" },
      \"items\": [ { \"price\": $3, \"quantity\": 1, \"requires_shipping\": true } ],
      \"currency\": \"EUR\"
    }
  }"
  echo; echo
}

test_zip 03560 47 4700  "10 € El Campello"
test_zip 03005 65 6500  "0 € gratis Alicante"
test_zip 03501 75 7500  "25 € Benidorm"
test_zip 03700 50 5000  "35 € Denia"
test_zip 03204 72 7200  "0 € gratis Elche"
test_zip 03710 90 9000  "30 € Calpe"
test_zip 28001 60 6000  "пустой список rates:[]"

echo "== Проверка User-Agent Shopify (важно!) =="
curl -s -X POST "$URL" -A "Shopify/1.0" -H 'Content-Type: application/json' -d '{
  "rate": { "destination": {"postal_code":"03560","country":"ES"},
  "items": [{"price":4700,"quantity":1,"requires_shipping":true}], "currency":"EUR" } }'
echo
