PHP code example of iaematt / cafeapi

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

    

iaematt / cafeapi example snippets




aematt\CafeApi\Me;

$me = new Me('api.site.com', '[email protected]', '123@mudar');

/** Me */
$user = $me->me();

/** Update */
$user->update([
    'first_name' => 'Robson',
    'last_name' => 'Leite',
    'genre' => 'male',
    'date_birth' => '1980-01-02',
    'document' => '888888888',
]);

/** Photo */
$user->photo($_FILES['photo']);

/** Test and result */
if ($user->error()) {
    $user->error(); /** Object */
} else {
    $user->response(); /** Object */
}



obsonVLeite\CafeApi\Invoices;

$invoices = new Invoices('api.site.com', '[email protected]', '123@mudar');

/** Index */
$index = $invoices->index(null);

/** Index filter */
$index = $invoices->index([
    'wallet_id' => 23,
    'type' => 'fixed_income',
    'status' => 'paid',
    'page' => 2,
]);

/** Create */
$invoices->create([
    'wallet_id' => 23,
    'category_id' => 3,
    'description' => 'Pagamento Cartão',
    'type' => 'expense',
    'value' => '25000.20',
    'due_at' => '2019-10-02',
    'repeat_when' => 'single',
    'period' => 'month',
    'enrollments' => '1',
]);

/** Read */
$invoices->read(91);

/** Update */
$invoiceId = 91;
$invoices->update($invoiceId, [
    'wallet_id' => 23,
    'category_id' => 3,
    'description' => 'Pagamento Cartão',
    'value' => '25000.20',
    'due_day' => 25,
    'status' => 'paid',
]);

/** Delete */
$invoices->delete(91);

/** Test and result */
if ($invoices->error()) {
    $invoices->error(); /** Object */
} else {
    $invoices->response(); /** Object */
}