PHP code example of mix-code / daftra-client

1. Go to this page and download the library: Download mix-code/daftra-client 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/ */

    

mix-code / daftra-client example snippets


use MixCode\DaftraClient\DaftraClient;

class ClientController
{

    public function listClients()
    {
        $daftraClient = new DaftraClient();

        return $daftraClient->listClients();
    }
}

use MixCode\DaftraClient\DaftraClientFacade as Daftra;

$clients = Daftra::listClients();

use MixCode\DaftraClient\DaftraClient;

class ClientController
{
    public function __construct(private DaftraClient $daftraClient) {}

    public function listClients()
    {
        return $this->daftraClient->listClients();
    }
}

$clients = $daftraClient->listClients();

$client = $daftraClient->showClient($clientId);

use MixCode\DaftraClient\Payloads\ClientPayload;

$payload = new ClientPayload(
    name: 'John Doe',
    email: '[email protected]'
);

$response = $daftraClient->createClient($payload);

use MixCode\DaftraClient\Payloads\ClientPayload;

$payload = new ClientPayload(
    name: 'John Doe',
    email: '[email protected]'
);

$response = $daftraClient->updateClient($payload);

$response = $daftraClient->deleteClient($clientId);

$products = $daftraClient->listProducts();

$product = $daftraClient->showProduct($productId);

use MixCode\DaftraClient\Payloads\ProductPayload;

$payload = new ProductPayload(
    name: 'Sample Product',
    price: 100.00
);

$response = $daftraClient->createProduct($payload);

use MixCode\DaftraClient\Payloads\ProductPayload;

$payload = new ProductPayload(
    name: 'Sample Product',
    price: 100.00
);

$response = $daftraClient->updateProduct($payload);

$product = $daftraClient->deleteProduct($productId);

use MixCode\DaftraClient\Payloads\InvoicePayload;
use MixCode\DaftraClient\Payloads\InvoiceItemPayload;

$items = [
    new InvoiceItemPayload(productId: 1, quantity: 2, price: 50.00)
];

$invoicePayload = new InvoicePayload(
    clientId: 123,
    date: now()->toDateString(),
    items: $items
);

$invoice = $daftraClient->createInvoice($invoicePayload);

use MixCode\DaftraClient\Payloads\InvoicePaymentPayload;

$paymentPayload = new InvoicePaymentPayload(
    invoiceId: $invoice->id,
    amount: 100.00,
    paymentMethod: 'credit_card'
);

$payment = $daftraClient->payInvoice($paymentPayload);

use MixCode\DaftraClient\Payloads\InvoicePayload;
use MixCode\DaftraClient\Payloads\InvoiceItemPayload;

$items = [
    new InvoiceItemPayload(productId: 1, quantity: 2, price: 50.00)
];

$invoicePayload = new InvoicePayload(
    clientId: 123,
    date: now()->toDateString(),
    items: $items
);

$response = $daftraClient->createAndPayInvoice($invoicePayload, 100.00, 'credit_card');
bash
php artisan vendor:publish --tag=daftra-client