Successful »;
} else {
echo « CheckConnection() -> Error: » . curl_error($curl);
}
// Fermer la session cURL
curl_close($curl);
}
function CheckConnectionSoap()
{
global $API_ENDPOINT;
try {
// Juste créer le client pour voir si le WSDL est disponible
$client = new SoapClient($API_ENDPOINT, [
« trace » => 1,
« exceptions » => true
]);
echo « CheckConnectionSoap() -> Successful »;
} catch (Exception $ex) {
echo « CheckConnectionSoap() -> Error: » . $ex->getMessage();
}
}
function GetSessionID(): ?ApiLogin
{
global $API_ENDPOINT, $API_USERNAME, $API_KEY;
$login = new ApiLogin();
$login->Username = $API_USERNAME;
$login->ApiKey = $API_KEY;
try {
$client = new SoapClient($API_ENDPOINT, [« trace » => 1, « exceptions » => true]);
// Important : la clé doit être le nom exact du paramètre côté .NET (ex: « pv_login »)
$response = $client->GetSessionID([« pv_login » => $login]);
$apiResponse = $response->GetSessionIDResult;
if ($apiResponse->StatusCode === « Successful ») {
$login->SessionID = $apiResponse->Value;
return $login;
} else {
echo « GetSessionID() -> Erreur : » . $apiResponse->StatusCode;
return null;
}
} catch (SoapFault $fault) {
echo « GetSessionID() -> Erreur SOAP : » . $fault->getMessage();
return null;
}
}
function CreateClient()
{
global $API_ENDPOINT;
$login = GetSessionID();
if ($login !== null) {
// Créer un client test
$customer = new ApiCustomer();
$customer->Name = « Test Client »;
$customer->Phone = « 514-123-4567 »;
$customer->Address = « 123 rue Exemple »;
$customer->City = « Montréal »;
$customer->ProvinceCode = « QC »;
$customer->PostalCode = « H2Z1A1 »;
$client = new SoapClient($API_ENDPOINT, [« trace » => 1, « exceptions » => true]);
$res = $client->CreateCustomer([« pv_login » => $login, « pv_customer » => $customer]);
if ($res->CreateCustomerResult->StatusCode === « Successful ») {
echo « CreateClient() -> Client créé avec succès »;
} else {
echo « CreateClient() -> Erreur : » . $res->CreateCustomerResult->Value;
}
} else {
echo « CreateClient() -> Erreur de session ! »;
}
}
function CreateCall()
{
global $API_ENDPOINT;
$login = GetSessionID();
if ($login !== null) {
// Créer un client test
$call = new ApiCall();
$call->Customer = new ApiCustomer();
$call->Customer->Name = « Famille Tremblay »;
$call->Customer->ContactFirstName = « Jean »;
$call->Customer->ContactLastName = « Tremblay »;
$call->Customer->Phone = « 4181234567 »;
$call->Customer->Mobile = « 4180000000 »;
$call->Customer->Email = « jean.tremblay@example.com »;
$call->Customer->Address = « 123 rue Ici »;
$call->Customer->Appartment = « »;
$call->Customer->City = « Québec »;
$call->Customer->ProvinceCode = « QC »;
$call->Customer->PostalCode = « G1G1G1 »;
$call->Customer->PropertySize = « 0 »;
$call->CallTypeID = 1; // Exemple : 1 = Demande d’estimation
$call->Date = date(« c »); // Date ISO 8601
$call->Message = « Bonjour, j’aimerais une estimation pour un nouveau service. »;
try {
$client = new SoapClient($API_ENDPOINT, [« trace » => 1, « exceptions » => true]);
$res = $client->CreateCall([« pv_login » => $login, « pv_call » => $call]);
if ($res->CreateCallResult->StatusCode === « Successful ») {
echo « CreateCall() -> Appel de service / demande d’estimation créé avec succès »;
} else {
echo « CreateCall() -> Erreur : » . $res->CreateCallResult->Value;
}
} catch (SoapFault $e) {
echo « CreateCall() -> Erreur SOAP : » . $e->getMessage();
}
} else {
echo « CreateCall() -> Erreur de session ! »;
}
}
function CreateContract()
{
global $API_ENDPOINT;
$login = GetSessionID();
if ($login !== null) {
$contract = new ApiContract();
// Client principal
$contract->Customer = new ApiCustomer();
$contract->Customer->Name = « Famille Tremblay »;
$contract->Customer->ContactFirstName = « Jean »;
$contract->Customer->ContactLastName = « Tremblay »;
$contract->Customer->Phone = « 4181234567 »;
$contract->Customer->Mobile = « 4180000000 »;
$contract->Customer->Email = « jean.tremblay@example.com »;
$contract->Customer->Address = « 123 rue Ici »;
$contract->Customer->Appartment = « »;
$contract->Customer->City = « Québec »;
$contract->Customer->ProvinceCode = « QC »;
$contract->Customer->PostalCode = « G1G1G1 »;
$contract->Customer->PropertySize = « 0 »;
// Client de facturation optionnel (null si identique)
$contract->BillingCustomer = null;
// Statut : 1 = Nouveau
$contract->ContratStatutID = 1;
// Succursale
$contract->SuccursaleID = 1;
// Info additionnelle
$contract->ConfirmationIpAddress = $_SERVER[‘REMOTE_ADDR’] ?? « 0.0.0.0 »;
$contract->OrderNumber = « CMD-20250601-ABC »;
$contract->Date = date(« c »); // format ISO 8601
$contract->CustomerNote = « Merci de valider rapidement cette commande. »;
// Services
$service = new ApiService();
$service->IsServicePlan = true;
$service->ServiceID = 101;
$service->Subtotal = 199.99;
$service->Total = 229.99;
$contract->Services = [$service];
// Paiement automatique avec versements
$contract->IsAutoPayment = true;
$installment1 = new ApiInstallment();
$installment1->Date = « 2025-06-01T00:00:00 »;
$installment1->Amount = 100.00;
$installment2 = new ApiInstallment();
$installment2->Date = « 2025-07-01T00:00:00 »;
$installment2->Amount = 129.99;
$contract->Installments = [$installment1, $installment2];
// Montant payé manuellement (dans ce cas, aucun)
$contract->Payment = 0.0;
try {
$client = new SoapClient($API_ENDPOINT, [« trace » => 1, « exceptions » => true]);
$res = $client->CreateContract([« pv_login » => $login, « pv_contract » => $contract]);
if ($res->CreateContractResult->StatusCode === « Successful ») {
echo « CreateContract() -> Contrat créé avec succès. »;
} else {
echo « CreateContract() -> Erreur : » . $res->CreateContractResult->Value;
}
} catch (SoapFault $e) {
echo « CreateContract() -> Erreur SOAP : » . $e->getMessage();
}
} else {
echo « CreateContract() -> Erreur de session ! »;
}
}
// POST : Action
if (isset($_POST[‘action’])) {
if ($_POST[‘action’] === ‘postphpinfo’) {
phpinfo();
exit;
} else if ($_POST[‘action’] === ‘postcheckconnection’) {
CheckConnection();
} else if ($_POST[‘action’] === ‘postcheckconnectionsoap’) {
CheckConnectionSoap();
} else if ($_POST[‘action’] === ‘postgetsessionid’) {
$login = GetSessionID();
if ($login !== null) {
echo « GetSessionID avec succès ! »;
}
} else if ($_POST[‘action’] === ‘postcreateclient’) {
CreateClient();
}
}
?>
UsoftAPI – Exemple PHP v1.0