PHP code example of firebed / aade-mydata

1. Go to this page and download the library: Download firebed/aade-mydata 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/ */

    

firebed / aade-mydata example snippets


$env = "dev"; // For production use "prod"
$user_id = "your-user-id";
$subscription_key = "your-subscription-key";

MyDataRequest::setEnvironment($env);
MyDataRequest::setCredentials($user_id, $subscription_key);

MyDataRequest::verifyClient(false);

use Firebed\AadeMyData\Http\SendInvoices;
use Firebed\AadeMyData\Models\Invoice;
use Firebed\AadeMyData\Exceptions\MyDataException;

// Prepare your invoices, for simplicity we will use an array of empty
// Invoice objects. You should populate these objects with your own data.
$invoices = [new Invoice(), new Invoice()];
$sender = new SendInvoices();

try {
    $responses = $sender->handle($invoices);
    
    $errors = [];
    foreach ($responses as $response) {
        if ($response->isSuccessful()) { 
            // This invoice was successfully sent to myDATA.     
            // Each response has an index value which corresponds
            // to the index (-1) of the $invoices array.
            
            $index = $response->getIndex();
            $uid = $response->getInvoiceUid();
            $mark = $response->getInvoiceMark();
            $cancelledByMark = $response->getCancellationMark();
            $qrUrl = $response->getQrUrl();
    
            // If you need to relate the response to your local invoice
            // $invoice = $invoices[$index - 1];    
    
            print_r(compact('index', 'uid', 'mark', 'cancelledByMark', 'qrUrl'));
        } else {
            // There were some errors for a specific invoice. See errors for details.
            foreach ($response->getErrors() as $error) {
                $errors[$response->getIndex() - 1][] = $error->getCode() . ': ' . $error->getMessage();
            }
        }
    }
} catch (MyDataException $e) {
    // There was a communication error. None of the invoices were sent.
    echo "Σφάλμα επικοινωνίας: " . $e->getMessage();
}