PHP code example of vitorccs / alterdata-bimer-php

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

    

vitorccs / alterdata-bimer-php example snippets


$person = (new \Bimer\PersonCharacteristicService())->all();

$person = (new \Bimer\PersonService())->find($strId);

$customer = (new \Bimer\CustomerService())->create($arrayData);

$person = (new \Bimer\PersonService())->update($strId, $arrayData);

$postalCode = (new \Bimer\PostalCodeService())->getByCode('03943000');
$people = (new \Bimer\PersonService())->getByName('maria', true);
$people = (new \Bimer\PersonService())->getByCpfCnpj('123.456.789-01');

error_reporting(E_ALL);
ini_set('display_errors', 1);

('BIMER_API_ID=client_id');
putenv('BIMER_API_SECRET=client_secret');
putenv('BIMER_API_USER=username');
putenv('BIMER_API_PWD=password');

use Bimer\CustomerService;
use Bimer\Exceptions\BimerApiException;
use Bimer\Exceptions\BimerRequestException;
use Bimer\PersonService;
use Bimer\PersonCharacteristicService;

try {
    // define serviços
    $personCharacteristicService = new PersonCharacteristicService();
    $personService = new PersonService();
    $customerService = new CustomerService();

    // obter lista de Características
    $characteristics = $personCharacteristicService->all();
    print_r($characteristics);

    // encontrar Pessoa por ID
    $person = $personService->find('00A0000SQ4');
    print_r($person);

    // atualizar Pessoa por ID
    $person = $personService->update('00A0000SQ4', [
        'Nome' => 'Nome Completo2',
        'NomeCurto' => 'Nome Curto2'
    ]);
    print_r($person);

    // encontrar pessoa por nome
    $people = $personService->getByName('NOME', true);
    print_r($people);

    // encontrar pessoa por CPF ou CNPJ
    $people = $personService->getByCpfCnpj('123.456.789-01');
    print_r($people);

    // criar Cliente
    $customer = $customerService->create([
        'Tipo' => 'F',
        'CpfCnpj' => '01234567894',
        'DataNascimento' => '1980-04-26T00:00:00:000Z',
        'Nome' => 'Nome Completo',
        'NomeCurto' => 'Nome Curto'
    ]);
    print_r($customer);

} catch (BimerApiException $e) { // erros retornados pela API Bimer
    echo sprintf("BimerApiException %s (%s)", $e->getMessage(), $e->getErrorCode());
} catch (BimerRequestException $e) { // erros de servidor (erros HTTP 4xx e 5xx)
    echo sprintf("BimerRequestException %s (%s)", $e->getMessage(), $e->getErrorCode());
} catch (\Exception $e) { // demais erros
    echo $e->getMessage();
}
bash
composer