<?php
// Fonction de formatage des données
function Formatage($value, $maxLength) {
    $value = strtoupper(Transliterator::create('NFD; [:Nonspacing Mark:] Remove; NFC')->transliterate($value));
    $value = preg_replace('/[^A-Z0-9\s]/', '', $value);
    $value = preg_replace('/\s+/', ' ', $value);
    return trim(substr($value, 0, $maxLength));
}

// Déclaration des variables
$pbx_site = '9085381';
$pbx_rang = '001';
$pbx_identifiant = '38038233';
$pbx_total = '1000';  // Montant en centimes (par exemple 10.00 euros)
$pbx_cmd = '001';
$pbx_porteur = 'globalservice@orange.fr';
$pbx_repondre_a = 'https://www.votre-site.extention/page-de-back-office-site';
$pbx_retour = 'Mt:M;Ref:R;Auto:A;Erreur:E';
$pbx_effectue = 'https://www.votre-site.extention/accepte.php';
$pbx_annule = 'https://www.votre-site.extention/annule.php';
$pbx_refuse = 'https://www.votre-site.extention/refuse.php';
$dateTime = date("c");

$pbx_nb_produit = '1';
$pbx_shoppingcart = "<?xml version=\"1.0\" encoding=\"utf-8\"?><shoppingcart><total><totalQuantity>".$pbx_nb_produit."</totalQuantity></total></shoppingcart>";
$pbx_souhaitauthent = '02';

$pbx_prenom_fact = Formatage('prenom de l utilisateur de facturation', 22);
$pbx_nom_fact = Formatage('nom de l utilisateur de facturation', 22);
$pbx_adresse1_fact = Formatage('ligne1 de l adresse de facturation', 50);
$pbx_adresse2_fact = Formatage('ligne2 de l adresse de facturation', 50);
$pbx_zipcode_fact = Formatage('code postal de l adresse de facturation', 16);
$pbx_city_fact = Formatage('ville de l adresse de facturation', 50);
$pbx_country_fact = Formatage('250', 3);
$pbx_country_code_mobile_phone = '+33';
$pbx_mobile_phone = '0612345675';

$pbx_billing = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Billing><Address><FirstName>".$pbx_prenom_fact."</FirstName>".
                "<LastName>".$pbx_nom_fact."</LastName><Address1>".$pbx_adresse1_fact."</Address1>".
                "<Address2>".$pbx_adresse2_fact."</Address2><ZipCode>".$pbx_zipcode_fact."</ZipCode>".
                "<City>".$pbx_city_fact."</City><CountryCode>".$pbx_country_fact."</CountryCode>".
                "<CountryCodeMobilePhone>".$pbx_country_code_mobile_phone."</CountryCodeMobilePhone><MobilePhone>".$pbx_mobile_phone."</MobilePhone>".
                "</Address></Billing>";

// Construction de la chaîne de données
$msg = "PBX_SITE=".$pbx_site.
"&PBX_RANG=".$pbx_rang.
"&PBX_IDENTIFIANT=".$pbx_identifiant.
"&PBX_TOTAL=".$pbx_total.
"&PBX_DEVI