PHP code example of mavart / axerve-client-sdk

1. Go to this page and download the library: Download mavart/axerve-client-sdk 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/ */

    

mavart / axerve-client-sdk example snippets




xerve\Payment\AxerveClient;

// Inizializza il client con le tue credenziali
$client = new AxerveClient(
    'LA_TUA_API_KEY',
    'IL_TUO_SHOP_LOGIN',
    false // false (o omesso) per l'ambiente di produzione, true per l'ambiente sandbox
);

// Inizializza il client in modalità sandbox
$client = new AxerveClient(
    'LA_TUA_API_KEY',
    'IL_TUO_SHOP_LOGIN',
    true
);

$client->payment->create($data)

$client->payment->getDetail($paymentId)

$client->payment->retrieveDetails($data)

$client->payment->update($data)

$client->payment->submit($data, $paymentToken)

$client->payment->capture($data)

$client->payment->cancel($data)

$client->payment->refund($data)

$client->payment->getMethods($paymentId, $languageId, $paymentToken)

$client->check->creditCard($data)

$client->shop->getMethods($shopLogin)

try {
    $response = $client->payment->create($paymentRequest);
    
    if (!$response->hasError()) {
        // Accesso diretto ai metodi della risposta tipizzata
        echo "Payment ID: " . $response->getPaymentId();
        echo "Token: " . $response->getPaymentToken();
        
        // Verifica se è richiesto un redirect e ottieni l'URL
        if ($response->isRedirect()) {
            header('Location: ' . $response->getRedirectUrl());
            exit;
        }
        
        // Accesso diretto alle proprietà con sintassi semplificata
        echo "Payment ID: " . $response->paymentID;
        echo "Token: " . $response->paymentToken;
    }
} catch (ApiException $e) {
    echo "Errore: " . $e->getMessage();
}

try {
    $response = $client->payment->getDetail($paymentId);
    
    if ($response->isSuccessful()) {
        // Accesso diretto ai metodi della risposta tipizzata
        echo "Payment ID: " . $response->getPaymentId();
        echo "Shop Transaction ID: " . $response->getShopTransactionId();
        echo "Bank Transaction ID: " . $response->getBankTransactionId();
        
        // Accesso diretto alle proprietà con sintassi semplificata
        echo "Metodo pagamento: " . $response->paymentMethod;
        echo "Importo: " . $response->amount . " " . $response->currency;
        
        // Accesso ad array complessi come eventi e dati carta
        if (isset($response->cardData)) {
            echo "Circuito: " . $response->cardData['circuit'];
        }
        
        if (isset($response->events)) {
            foreach ($response->events as $event) {
                echo "Evento: " . $event['eventType'] . " - " . $event['eventStatus'];
            }
        }
    }
} catch (ApiException $e) {
    echo "Errore: " . $e->getMessage();
}

try {
    // Chiamata API
    $result = $client->payment->create($paymentData);
} catch (Axerve\Payment\Exception\AuthenticationException $e) {
    // Errore di autenticazione
    echo "Errore di autenticazione: " . $e->getMessage();
} catch (Axerve\Payment\Exception\ValidationException $e) {
    // Errore di validazione
    echo "Errore di validazione: " . $e->getMessage();
    var_dump($e->getErrors()); // Ottieni i dettagli degli errori di validazione
} catch (Axerve\Payment\Exception\ApiException $e) {
    // Altri errori API
    echo "Errore API: " . $e->getMessage();
}
bash
composer