PHP code example of ophelix / ophelix-php

1. Go to this page and download the library: Download ophelix/ophelix-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ophelix / ophelix-php example snippets


use Ophelix\OphelixClient;

$ophelix = new OphelixClient(getenv('OPHELIX_API_KEY'));

// Un praticien naît de la lecture de sa carte CPS, un patient de celle de sa carte Vitale.
$practitioner = $ophelix->practitioners->create(['card' => 'cps_doctor']);
$coverage = $ophelix->coverages->create(['source' => 'vitale_card', 'card' => 'vitale_ok']);

$claim = $ophelix->claims->create([
    'practitioner' => $practitioner->id,
    'patient' => $coverage->patient,
    'third_party_amo' => true,
    'context' => ['care_pathway' => 'treating_doctor', 'common_law_accident' => false],
    'lines' => [['nomenclature' => 'ngap', 'code' => 'ZC', 'service_date' => '2026-11-06', 'unit_price_cents' => 2650]],
]);

$ophelix->claims->finalize($claim->id);
$ophelix->claims->secure($claim->id);

// En mode test, les retours de l'Assurance Maladie se déclenchent à la main.
$ophelix->testHelpers->claims->simulateReturn($claim->id, ['scenario' => 'arl_positive']);
$paid = $ophelix->testHelpers->claims->simulateReturn($claim->id, ['scenario' => 'payment']);

echo $paid->status; // paid

$ophelix = new OphelixClient($key, ['max_retries' => 4, 'timeout' => 20.0]);
$ophelix->livemode;   // false pour une clé de test

$claim = $ophelix->claims->retrieve('clm_…', ['expand' => ['patient']]);
$claim->patient->quality;                    // un Ophelix\Resources\Patient
$claim->getLastResponse()->requestId;        // à retrouver dans Développeurs › Requêtes

$page = $ophelix->claims->all(['status' => 'paid', 'limit' => 50]);
$page->data;       // cette page
$page->has_more;

foreach ($ophelix->claims->all(['status' => 'paid']) as $claim) {
    // toutes les factures payées
}

$ophelix->claims->create($params, ['idempotency_key' => $commande->uuid]);

use Ophelix\Exception\InvalidRequestException;

try {
    $ophelix->claims->retrieve('clm_inconnu');
} catch (InvalidRequestException $exception) {
    $exception->getErrorCode();   // resource_missing
    $exception->getDocUrl();      // https://docs.ophelix.fr/erreurs#resource_missing
    $exception->getRequestId();   // req_…
}

use Ophelix\Exception\SignatureVerificationException;
use Ophelix\Webhook;

try {
    $event = Webhook::constructEvent(
        file_get_contents('php://input'),
        $_SERVER['HTTP_OPHELIX_SIGNATURE'] ?? null,
        getenv('OPHELIX_WEBHOOK_SECRET'),
    );
} catch (SignatureVerificationException) {
    http_response_code(400);
    exit;
}

if ($event->type === 'claim.paid') {
    $claim = $event->data['object'];   // un Ophelix\Resources\Claim
}
bash
composer